Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / ia64 / sn / kernel / io_acpi_init.c
blob1cccb456547761f3fd982a003e62fbc057e4db17
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 2006 Silicon Graphics, Inc. All rights reserved.
7 */
9 #include <asm/sn/types.h>
10 #include <asm/sn/addrs.h>
11 #include <asm/sn/pcidev.h>
12 #include <asm/sn/pcibus_provider_defs.h>
13 #include <asm/sn/sn_sal.h>
14 #include "xtalk/hubdev.h"
15 #include <linux/acpi.h>
16 #include <acpi/acnamesp.h>
20 * The code in this file will only be executed when running with
21 * a PROM that has ACPI IO support. (i.e., SN_ACPI_BASE_SUPPORT() == 1)
26 * This value must match the UUID the PROM uses
27 * (io/acpi/defblk.c) when building a vendor descriptor.
29 struct acpi_vendor_uuid sn_uuid = {
30 .subtype = 0,
31 .data = { 0x2c, 0xc6, 0xa6, 0xfe, 0x9c, 0x44, 0xda, 0x11,
32 0xa2, 0x7c, 0x08, 0x00, 0x69, 0x13, 0xea, 0x51 },
35 struct sn_pcidev_match {
36 u8 bus;
37 unsigned int devfn;
38 acpi_handle handle;
42 * Perform the early IO init in PROM.
44 static s64
45 sal_ioif_init(u64 *result)
47 struct ia64_sal_retval isrv = {0,0,0,0};
49 SAL_CALL_NOLOCK(isrv,
50 SN_SAL_IOIF_INIT, 0, 0, 0, 0, 0, 0, 0);
51 *result = isrv.v0;
52 return isrv.status;
56 * sn_acpi_hubdev_init() - This function is called by acpi_ns_get_device_callback()
57 * for all SGIHUB and SGITIO acpi devices defined in the
58 * DSDT. It obtains the hubdev_info pointer from the
59 * ACPI vendor resource, which the PROM setup, and sets up the
60 * hubdev_info in the pda.
63 static acpi_status __init
64 sn_acpi_hubdev_init(acpi_handle handle, u32 depth, void *context, void **ret)
66 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
67 u64 addr;
68 struct hubdev_info *hubdev;
69 struct hubdev_info *hubdev_ptr;
70 int i;
71 u64 nasid;
72 struct acpi_resource *resource;
73 acpi_status status;
74 struct acpi_resource_vendor_typed *vendor;
75 extern void sn_common_hubdev_init(struct hubdev_info *);
77 status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
78 &sn_uuid, &buffer);
79 if (ACPI_FAILURE(status)) {
80 printk(KERN_ERR
81 "sn_acpi_hubdev_init: acpi_get_vendor_resource() "
82 "(0x%x) failed for: ", status);
83 acpi_ns_print_node_pathname(handle, NULL);
84 printk("\n");
85 return AE_OK; /* Continue walking namespace */
88 resource = buffer.pointer;
89 vendor = &resource->data.vendor_typed;
90 if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
91 sizeof(struct hubdev_info *)) {
92 printk(KERN_ERR
93 "sn_acpi_hubdev_init: Invalid vendor data length: %d for: ",
94 vendor->byte_length);
95 acpi_ns_print_node_pathname(handle, NULL);
96 printk("\n");
97 goto exit;
100 memcpy(&addr, vendor->byte_data, sizeof(struct hubdev_info *));
101 hubdev_ptr = __va((struct hubdev_info *) addr);
103 nasid = hubdev_ptr->hdi_nasid;
104 i = nasid_to_cnodeid(nasid);
105 hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
106 *hubdev = *hubdev_ptr;
107 sn_common_hubdev_init(hubdev);
109 exit:
110 kfree(buffer.pointer);
111 return AE_OK; /* Continue walking namespace */
115 * sn_get_bussoft_ptr() - The pcibus_bussoft pointer is found in
116 * the ACPI Vendor resource for this bus.
118 static struct pcibus_bussoft *
119 sn_get_bussoft_ptr(struct pci_bus *bus)
121 u64 addr;
122 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
123 acpi_handle handle;
124 struct pcibus_bussoft *prom_bussoft_ptr;
125 struct acpi_resource *resource;
126 acpi_status status;
127 struct acpi_resource_vendor_typed *vendor;
130 handle = PCI_CONTROLLER(bus)->acpi_handle;
131 status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
132 &sn_uuid, &buffer);
133 if (ACPI_FAILURE(status)) {
134 printk(KERN_ERR "%s: "
135 "acpi_get_vendor_resource() failed (0x%x) for: ",
136 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
137 __FUNCTION__, status);
138 =======
139 __func__, status);
140 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
141 acpi_ns_print_node_pathname(handle, NULL);
142 printk("\n");
143 return NULL;
145 resource = buffer.pointer;
146 vendor = &resource->data.vendor_typed;
148 if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
149 sizeof(struct pcibus_bussoft *)) {
150 printk(KERN_ERR
151 "%s: Invalid vendor data length %d\n",
152 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
153 __FUNCTION__, vendor->byte_length);
154 =======
155 __func__, vendor->byte_length);
156 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
157 kfree(buffer.pointer);
158 return NULL;
160 memcpy(&addr, vendor->byte_data, sizeof(struct pcibus_bussoft *));
161 prom_bussoft_ptr = __va((struct pcibus_bussoft *) addr);
162 kfree(buffer.pointer);
164 return prom_bussoft_ptr;
168 * sn_extract_device_info - Extract the pcidev_info and the sn_irq_info
169 * pointers from the vendor resource using the
170 * provided acpi handle, and copy the structures
171 * into the argument buffers.
173 static int
174 sn_extract_device_info(acpi_handle handle, struct pcidev_info **pcidev_info,
175 struct sn_irq_info **sn_irq_info)
177 u64 addr;
178 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
179 struct sn_irq_info *irq_info, *irq_info_prom;
180 struct pcidev_info *pcidev_ptr, *pcidev_prom_ptr;
181 struct acpi_resource *resource;
182 int ret = 0;
183 acpi_status status;
184 struct acpi_resource_vendor_typed *vendor;
187 * The pointer to this device's pcidev_info structure in
188 * the PROM, is in the vendor resource.
190 status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
191 &sn_uuid, &buffer);
192 if (ACPI_FAILURE(status)) {
193 printk(KERN_ERR
194 "%s: acpi_get_vendor_resource() failed (0x%x) for: ",
195 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
196 __FUNCTION__, status);
197 =======
198 __func__, status);
199 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
200 acpi_ns_print_node_pathname(handle, NULL);
201 printk("\n");
202 return 1;
205 resource = buffer.pointer;
206 vendor = &resource->data.vendor_typed;
207 if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
208 sizeof(struct pci_devdev_info *)) {
209 printk(KERN_ERR
210 "%s: Invalid vendor data length: %d for: ",
211 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
212 __FUNCTION__, vendor->byte_length);
213 =======
214 __func__, vendor->byte_length);
215 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
216 acpi_ns_print_node_pathname(handle, NULL);
217 printk("\n");
218 ret = 1;
219 goto exit;
222 pcidev_ptr = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);
223 if (!pcidev_ptr)
224 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
225 panic("%s: Unable to alloc memory for pcidev_info", __FUNCTION__);
226 =======
227 panic("%s: Unable to alloc memory for pcidev_info", __func__);
228 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
230 memcpy(&addr, vendor->byte_data, sizeof(struct pcidev_info *));
231 pcidev_prom_ptr = __va(addr);
232 memcpy(pcidev_ptr, pcidev_prom_ptr, sizeof(struct pcidev_info));
234 /* Get the IRQ info */
235 irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
236 if (!irq_info)
237 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
238 panic("%s: Unable to alloc memory for sn_irq_info", __FUNCTION__);
239 =======
240 panic("%s: Unable to alloc memory for sn_irq_info", __func__);
241 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
243 if (pcidev_ptr->pdi_sn_irq_info) {
244 irq_info_prom = __va(pcidev_ptr->pdi_sn_irq_info);
245 memcpy(irq_info, irq_info_prom, sizeof(struct sn_irq_info));
248 *pcidev_info = pcidev_ptr;
249 *sn_irq_info = irq_info;
251 exit:
252 kfree(buffer.pointer);
253 return ret;
256 static unsigned int
257 get_host_devfn(acpi_handle device_handle, acpi_handle rootbus_handle)
259 unsigned long adr;
260 acpi_handle child;
261 unsigned int devfn;
262 int function;
263 acpi_handle parent;
264 int slot;
265 acpi_status status;
268 * Do an upward search to find the root bus device, and
269 * obtain the host devfn from the previous child device.
271 child = device_handle;
272 while (child) {
273 status = acpi_get_parent(child, &parent);
274 if (ACPI_FAILURE(status)) {
275 printk(KERN_ERR "%s: acpi_get_parent() failed "
276 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
277 "(0x%x) for: ", __FUNCTION__, status);
278 =======
279 "(0x%x) for: ", __func__, status);
280 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
281 acpi_ns_print_node_pathname(child, NULL);
282 printk("\n");
283 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
284 panic("%s: Unable to find host devfn\n", __FUNCTION__);
285 =======
286 panic("%s: Unable to find host devfn\n", __func__);
287 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
289 if (parent == rootbus_handle)
290 break;
291 child = parent;
293 if (!child) {
294 printk(KERN_ERR "%s: Unable to find root bus for: ",
295 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
296 __FUNCTION__);
297 =======
298 __func__);
299 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
300 acpi_ns_print_node_pathname(device_handle, NULL);
301 printk("\n");
302 BUG();
305 status = acpi_evaluate_integer(child, METHOD_NAME__ADR, NULL, &adr);
306 if (ACPI_FAILURE(status)) {
307 printk(KERN_ERR "%s: Unable to get _ADR (0x%x) for: ",
308 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
309 __FUNCTION__, status);
310 =======
311 __func__, status);
312 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
313 acpi_ns_print_node_pathname(child, NULL);
314 printk("\n");
315 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
316 panic("%s: Unable to find host devfn\n", __FUNCTION__);
317 =======
318 panic("%s: Unable to find host devfn\n", __func__);
319 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
322 slot = (adr >> 16) & 0xffff;
323 function = adr & 0xffff;
324 devfn = PCI_DEVFN(slot, function);
325 return devfn;
329 * find_matching_device - Callback routine to find the ACPI device
330 * that matches up with our pci_dev device.
331 * Matching is done on bus number and devfn.
332 * To find the bus number for a particular
333 * ACPI device, we must look at the _BBN method
334 * of its parent.
336 static acpi_status
337 find_matching_device(acpi_handle handle, u32 lvl, void *context, void **rv)
339 unsigned long bbn = -1;
340 unsigned long adr;
341 acpi_handle parent = NULL;
342 acpi_status status;
343 unsigned int devfn;
344 int function;
345 int slot;
346 struct sn_pcidev_match *info = context;
348 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
349 &adr);
350 if (ACPI_SUCCESS(status)) {
351 status = acpi_get_parent(handle, &parent);
352 if (ACPI_FAILURE(status)) {
353 printk(KERN_ERR
354 "%s: acpi_get_parent() failed (0x%x) for: ",
355 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
356 __FUNCTION__, status);
357 =======
358 __func__, status);
359 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
360 acpi_ns_print_node_pathname(handle, NULL);
361 printk("\n");
362 return AE_OK;
364 status = acpi_evaluate_integer(parent, METHOD_NAME__BBN,
365 NULL, &bbn);
366 if (ACPI_FAILURE(status)) {
367 printk(KERN_ERR
368 "%s: Failed to find _BBN in parent of: ",
369 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
370 __FUNCTION__);
371 =======
372 __func__);
373 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
374 acpi_ns_print_node_pathname(handle, NULL);
375 printk("\n");
376 return AE_OK;
379 slot = (adr >> 16) & 0xffff;
380 function = adr & 0xffff;
381 devfn = PCI_DEVFN(slot, function);
382 if ((info->devfn == devfn) && (info->bus == bbn)) {
383 /* We have a match! */
384 info->handle = handle;
385 return 1;
388 return AE_OK;
392 * sn_acpi_get_pcidev_info - Search ACPI namespace for the acpi
393 * device matching the specified pci_dev,
394 * and return the pcidev info and irq info.
397 sn_acpi_get_pcidev_info(struct pci_dev *dev, struct pcidev_info **pcidev_info,
398 struct sn_irq_info **sn_irq_info)
400 unsigned int host_devfn;
401 struct sn_pcidev_match pcidev_match;
402 acpi_handle rootbus_handle;
403 unsigned long segment;
404 acpi_status status;
406 rootbus_handle = PCI_CONTROLLER(dev)->acpi_handle;
407 status = acpi_evaluate_integer(rootbus_handle, METHOD_NAME__SEG, NULL,
408 &segment);
409 if (ACPI_SUCCESS(status)) {
410 if (segment != pci_domain_nr(dev)) {
411 printk(KERN_ERR
412 "%s: Segment number mismatch, 0x%lx vs 0x%x for: ",
413 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
414 __FUNCTION__, segment, pci_domain_nr(dev));
415 =======
416 __func__, segment, pci_domain_nr(dev));
417 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
418 acpi_ns_print_node_pathname(rootbus_handle, NULL);
419 printk("\n");
420 return 1;
422 } else {
423 printk(KERN_ERR "%s: Unable to get __SEG from: ",
424 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
425 __FUNCTION__);
426 =======
427 __func__);
428 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
429 acpi_ns_print_node_pathname(rootbus_handle, NULL);
430 printk("\n");
431 return 1;
435 * We want to search all devices in this segment/domain
436 * of the ACPI namespace for the matching ACPI device,
437 * which holds the pcidev_info pointer in its vendor resource.
439 pcidev_match.bus = dev->bus->number;
440 pcidev_match.devfn = dev->devfn;
441 pcidev_match.handle = NULL;
443 acpi_walk_namespace(ACPI_TYPE_DEVICE, rootbus_handle, ACPI_UINT32_MAX,
444 find_matching_device, &pcidev_match, NULL);
446 if (!pcidev_match.handle) {
447 printk(KERN_ERR
448 "%s: Could not find matching ACPI device for %s.\n",
449 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
450 __FUNCTION__, pci_name(dev));
451 =======
452 __func__, pci_name(dev));
453 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
454 return 1;
457 if (sn_extract_device_info(pcidev_match.handle, pcidev_info, sn_irq_info))
458 return 1;
460 /* Build up the pcidev_info.pdi_slot_host_handle */
461 host_devfn = get_host_devfn(pcidev_match.handle, rootbus_handle);
462 (*pcidev_info)->pdi_slot_host_handle =
463 ((unsigned long) pci_domain_nr(dev) << 40) |
464 /* bus == 0 */
465 host_devfn;
466 return 0;
470 * sn_acpi_slot_fixup - Obtain the pcidev_info and sn_irq_info.
471 * Perform any SN specific slot fixup.
472 * At present there does not appear to be
473 * any generic way to handle a ROM image
474 * that has been shadowed by the PROM, so
475 * we pass a pointer to it within the
476 * pcidev_info structure.
479 void
480 sn_acpi_slot_fixup(struct pci_dev *dev)
482 void __iomem *addr;
483 struct pcidev_info *pcidev_info = NULL;
484 struct sn_irq_info *sn_irq_info = NULL;
485 size_t image_size, size;
487 if (sn_acpi_get_pcidev_info(dev, &pcidev_info, &sn_irq_info)) {
488 panic("%s: Failure obtaining pcidev_info for %s\n",
489 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
490 __FUNCTION__, pci_name(dev));
491 =======
492 __func__, pci_name(dev));
493 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
496 if (pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE]) {
498 * A valid ROM image exists and has been shadowed by the
499 * PROM. Setup the pci_dev ROM resource with the address
500 * of the shadowed copy, and the actual length of the ROM image.
502 size = pci_resource_len(dev, PCI_ROM_RESOURCE);
503 addr = ioremap(pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE],
504 size);
505 image_size = pci_get_rom_size(addr, size);
506 dev->resource[PCI_ROM_RESOURCE].start = (unsigned long) addr;
507 dev->resource[PCI_ROM_RESOURCE].end =
508 (unsigned long) addr + image_size - 1;
509 dev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_BIOS_COPY;
511 sn_pci_fixup_slot(dev, pcidev_info, sn_irq_info);
514 EXPORT_SYMBOL(sn_acpi_slot_fixup);
518 * sn_acpi_bus_fixup - Perform SN specific setup of software structs
519 * (pcibus_bussoft, pcidev_info) and hardware
520 * registers, for the specified bus and devices under it.
522 void
523 sn_acpi_bus_fixup(struct pci_bus *bus)
525 struct pci_dev *pci_dev = NULL;
526 struct pcibus_bussoft *prom_bussoft_ptr;
528 if (!bus->parent) { /* If root bus */
529 prom_bussoft_ptr = sn_get_bussoft_ptr(bus);
530 if (prom_bussoft_ptr == NULL) {
531 printk(KERN_ERR
532 "%s: 0x%04x:0x%02x Unable to "
533 "obtain prom_bussoft_ptr\n",
534 <<<<<<< HEAD:arch/ia64/sn/kernel/io_acpi_init.c
535 __FUNCTION__, pci_domain_nr(bus), bus->number);
536 =======
537 __func__, pci_domain_nr(bus), bus->number);
538 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/ia64/sn/kernel/io_acpi_init.c
539 return;
541 sn_common_bus_fixup(bus, prom_bussoft_ptr);
543 list_for_each_entry(pci_dev, &bus->devices, bus_list) {
544 sn_acpi_slot_fixup(pci_dev);
549 * sn_io_acpi_init - PROM has ACPI support for IO, defining at a minimum the
550 * nodes and root buses in the DSDT. As a result, bus scanning
551 * will be initiated by the Linux ACPI code.
554 void __init
555 sn_io_acpi_init(void)
557 u64 result;
558 s64 status;
560 /* SN Altix does not follow the IOSAPIC IRQ routing model */
561 acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;
563 /* Setup hubdev_info for all SGIHUB/SGITIO devices */
564 acpi_get_devices("SGIHUB", sn_acpi_hubdev_init, NULL, NULL);
565 acpi_get_devices("SGITIO", sn_acpi_hubdev_init, NULL, NULL);
567 status = sal_ioif_init(&result);
568 if (status || result)
569 panic("sal_ioif_init failed: [%lx] %s\n",
570 status, ia64_sal_strerror(status));