2 * Compaq Hot Plug Controller Driver
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Send feedback to <greg@kroah.com>
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/slab.h>
34 #include <linux/proc_fs.h>
35 #include <linux/pci.h>
37 #include "cpqphp_nvram.h"
38 #include "../../arch/i386/kernel/pci-i386.h" /* horrible hack showing how processor dependant we are... */
44 static u16 unused_IRQ;
47 static int is_pci_dev_in_use(struct pci_dev* dev)
50 * dev->driver will be set if the device is in use by a new-style
51 * driver -- otherwise, check the device's regions to see if any
52 * driver has claimed them
57 if (dev->driver) return 1; //assume driver feels responsible
59 for (i = 0; !dev->driver && !inuse && (i < 6); i++) {
60 if (!pci_resource_start(dev, i))
63 if (pci_resource_flags(dev, i) & IORESOURCE_IO)
64 inuse = check_region(pci_resource_start(dev, i),
65 pci_resource_len(dev, i));
66 else if (pci_resource_flags(dev, i) & IORESOURCE_MEM)
67 inuse = check_mem_region(pci_resource_start(dev, i),
68 pci_resource_len(dev, i));
76 static int pci_hp_remove_device(struct pci_dev *dev)
78 if (is_pci_dev_in_use(dev)) {
79 err("***Cannot safely power down device -- "
80 "it appears to be in use***\n");
83 pci_remove_device(dev);
89 * detect_HRT_floating_pointer
91 * find the Hot Plug Resource Table in the specified region of memory.
94 static void *detect_HRT_floating_pointer(void *begin, void *end)
98 u8 temp1, temp2, temp3, temp4;
101 endp = (end - sizeof(struct hrt) + 1);
103 for (fp = begin; fp <= endp; fp += 16) {
104 temp1 = readb(fp + SIG0);
105 temp2 = readb(fp + SIG1);
106 temp3 = readb(fp + SIG2);
107 temp4 = readb(fp + SIG3);
120 dbg("Discovered Hotplug Resource Table at %p\n", fp);
124 static int configure_visit_pci_dev (struct pci_dev_wrapped *wrapped_dev, struct pci_bus_wrapped *wrapped_bus)
126 struct pci_bus* bus = wrapped_bus->bus;
127 struct pci_dev* dev = wrapped_dev->dev;
128 struct pci_func *temp_func;
131 //We need to fix up the hotplug function representation with the linux representation
133 temp_func = cpqhp_slot_find(dev->bus->number, dev->devfn >> 3, i++);
134 } while (temp_func && (temp_func->function != (dev->devfn & 0x07)));
137 temp_func->pci_dev = dev;
139 //We did not even find a hotplug rep of the function, create it
140 //This code might be taken out if we can guarantee the creation of functions
141 //in parallel (hotplug and Linux at the same time).
142 dbg("@@@@@@@@@@@ cpqhp_slot_create in %s\n", __FUNCTION__);
143 temp_func = cpqhp_slot_create(bus->number);
144 if (temp_func == NULL)
146 temp_func->pci_dev = dev;
149 //Create /proc/bus/pci proc entry for this device and bus device is on
150 //Notify the drivers of the change
151 if (temp_func->pci_dev) {
152 pci_proc_attach_device(temp_func->pci_dev);
153 pci_announce_device_to_drivers(temp_func->pci_dev);
160 static int unconfigure_visit_pci_dev_phase2 (struct pci_dev_wrapped *wrapped_dev, struct pci_bus_wrapped *wrapped_bus)
162 struct pci_dev* dev = wrapped_dev->dev;
164 struct pci_func *temp_func;
167 //We need to remove the hotplug function representation with the linux representation
169 temp_func = cpqhp_slot_find(dev->bus->number, dev->devfn >> 3, i++);
171 dbg("temp_func->function = %d\n", temp_func->function);
173 } while (temp_func && (temp_func->function != (dev->devfn & 0x07)));
175 //Now, remove the Linux Representation
177 if (pci_hp_remove_device(dev) == 0) {
178 kfree(dev); //Now, remove
180 return -1; // problems while freeing, abort visitation
185 temp_func->pci_dev = NULL;
187 dbg("No pci_func representation for bus, devfn = %d, %x\n", dev->bus->number, dev->devfn);
194 static int unconfigure_visit_pci_bus_phase2 (struct pci_bus_wrapped *wrapped_bus, struct pci_dev_wrapped *wrapped_dev)
196 struct pci_bus* bus = wrapped_bus->bus;
198 //The cleanup code for proc entries regarding buses should be in the kernel...
200 dbg("detach_pci_bus %s\n", bus->procdir->name);
201 pci_proc_detach_bus(bus);
202 // The cleanup code should live in the kernel...
203 bus->self->subordinate = NULL;
204 // unlink from parent bus
205 list_del(&bus->node);
215 static int unconfigure_visit_pci_dev_phase1 (struct pci_dev_wrapped *wrapped_dev, struct pci_bus_wrapped *wrapped_bus)
217 struct pci_dev* dev = wrapped_dev->dev;
219 dbg("attempting removal of driver for device (%x, %x, %x)\n", dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
220 //Now, remove the Linux Driver Representation
222 if (dev->driver->remove) {
223 dev->driver->remove(dev);
224 dbg("driver was properly removed\n");
229 return is_pci_dev_in_use(dev);
233 static struct pci_visit configure_functions = {
234 visit_pci_dev: configure_visit_pci_dev,
238 static struct pci_visit unconfigure_functions_phase1 = {
239 post_visit_pci_dev: unconfigure_visit_pci_dev_phase1
242 static struct pci_visit unconfigure_functions_phase2 = {
243 post_visit_pci_bus: unconfigure_visit_pci_bus_phase2,
244 post_visit_pci_dev: unconfigure_visit_pci_dev_phase2
248 int cpqhp_configure_device (struct controller* ctrl, struct pci_func* func)
252 struct pci_bus *child;
253 struct pci_dev* temp;
256 struct pci_dev_wrapped wrapped_dev;
257 struct pci_bus_wrapped wrapped_bus;
258 memset(&wrapped_dev, 0, sizeof(struct pci_dev_wrapped));
259 memset(&wrapped_bus, 0, sizeof(struct pci_bus_wrapped));
261 memset(&dev0, 0, sizeof(struct pci_dev));
263 if (func->pci_dev == NULL)
264 func->pci_dev = pci_find_slot(func->bus, (func->device << 3) | (func->function & 0x7));
266 //Still NULL ? Well then scan for it !
267 if (func->pci_dev == NULL) {
268 dbg("INFO: pci_dev still null\n");
269 dev0.bus = ctrl->pci_dev->bus;
270 dev0.devfn = (func->device << 3) + (func->function & 0x7);
271 dev0.sysdata = ctrl->pci_dev->sysdata;
273 //this will generate pci_dev structures for all functions, but we will only call this case when lookup fails
274 func->pci_dev = pci_scan_slot(&dev0);
275 if (func->pci_dev == NULL) {
276 dbg("ERROR: pci_dev still null\n");
281 if (func->pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
282 pci_read_config_byte(func->pci_dev, PCI_SECONDARY_BUS, &bus);
283 child = (struct pci_bus*) pci_add_new_bus(func->pci_dev->bus, (func->pci_dev), bus);
284 pci_do_scan_bus(child);
288 temp = func->pci_dev;
291 wrapped_dev.dev = temp;
292 wrapped_bus.bus = temp->bus;
293 rc = pci_visit_dev(&configure_functions, &wrapped_dev, &wrapped_bus);
299 int cpqhp_unconfigure_device(struct pci_func* func)
303 struct pci_dev_wrapped wrapped_dev;
304 struct pci_bus_wrapped wrapped_bus;
306 memset(&wrapped_dev, 0, sizeof(struct pci_dev_wrapped));
307 memset(&wrapped_bus, 0, sizeof(struct pci_bus_wrapped));
309 dbg("%s: bus/dev/func = %x/%x/%x\n", __FUNCTION__, func->bus, func->device, func->function);
311 for (j=0; j<8 ; j++) {
312 struct pci_dev* temp = pci_find_slot(func->bus, (func->device << 3) | j);
314 wrapped_dev.dev = temp;
315 wrapped_bus.bus = temp->bus;
316 rc = pci_visit_dev(&unconfigure_functions_phase1, &wrapped_dev, &wrapped_bus);
320 rc = pci_visit_dev(&unconfigure_functions_phase2, &wrapped_dev, &wrapped_bus);
328 static int PCI_RefinedAccessConfig(struct pci_ops *ops, u8 bus, u8 device, u8 function, u8 offset, u32 *value)
332 if (pci_read_config_dword_nodev (ops, bus, device, function, PCI_VENDOR_ID, &vendID) == -1)
334 if (vendID == 0xffffffff)
336 return pci_read_config_dword_nodev (ops, bus, device, function, offset, value);
343 * @bus_num: bus number of PCI device
344 * @dev_num: device number of PCI device
345 * @slot: pointer to u8 where slot number will be returned
347 int cpqhp_set_irq (u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num)
351 struct pci_dev fakedev;
352 struct pci_bus fakebus;
354 fakedev.devfn = dev_num << 3;
355 fakedev.bus = &fakebus;
356 fakebus.number = bus_num;
357 dbg("%s: dev %d, bus %d, pin %d, num %d\n",
358 __FUNCTION__, dev_num, bus_num, int_pin, irq_num);
359 rc = pcibios_set_irq_routing(&fakedev, int_pin - 0x0a, irq_num);
360 dbg("%s:rc %d\n", __FUNCTION__, rc);
364 // set the Edge Level Control Register (ELCR)
365 temp_word = inb(0x4d0);
366 temp_word |= inb(0x4d1) << 8;
368 temp_word |= 0x01 << irq_num;
370 // This should only be for x86 as it sets the Edge Level Control Register
371 outb((u8) (temp_word & 0xFF), 0x4d0);
372 outb((u8) ((temp_word & 0xFF00) >> 8), 0x4d1);
379 * WTF??? This function isn't in the code, yet a function calls it, but the
380 * compiler optimizes it away? strange. Here as a placeholder to keep the
383 static int PCI_ScanBusNonBridge (u8 bus, u8 device)
388 static int PCI_ScanBusForNonBridge(struct controller *ctrl, u8 bus_num, u8 * dev_num)
394 for (tdevice = 0; tdevice < 0x100; tdevice++) {
395 //Scan for access first
396 if (PCI_RefinedAccessConfig(ctrl->pci_ops, bus_num, tdevice >> 3, tdevice & 0x7, 0x08, &work) == -1)
398 dbg("Looking for nonbridge bus_num %d dev_num %d\n", bus_num, tdevice);
399 //Yep we got one. Not a bridge ?
400 if ((work >> 8) != PCI_TO_PCI_BRIDGE_CLASS) {
406 for (tdevice = 0; tdevice < 0x100; tdevice++) {
407 //Scan for access first
408 if (PCI_RefinedAccessConfig(ctrl->pci_ops, bus_num, tdevice >> 3, tdevice & 0x7, 0x08, &work) == -1)
410 dbg("Looking for bridge bus_num %d dev_num %d\n", bus_num, tdevice);
411 //Yep we got one. bridge ?
412 if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
413 pci_read_config_byte_nodev (ctrl->pci_ops, tbus, tdevice, 0, PCI_SECONDARY_BUS, &tbus);
414 dbg("Recurse on bus_num %d tdevice %d\n", tbus, tdevice);
415 if (PCI_ScanBusNonBridge(tbus, tdevice) == 0)
424 static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num, u8 slot, u8 nobridge)
426 struct irq_routing_table *PCIIRQRoutingInfoLength;
431 u8 tbus, tdevice, tslot;
433 PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
435 len = (PCIIRQRoutingInfoLength->size -
436 sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
437 // Make sure I got at least one entry
439 if (PCIIRQRoutingInfoLength != NULL)
440 kfree(PCIIRQRoutingInfoLength );
444 for (loop = 0; loop < len; ++loop) {
445 tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
446 tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn;
447 tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
452 pci_read_config_dword_nodev (ctrl->pci_ops, *bus_num, *dev_num >> 3, *dev_num & 0x7, PCI_VENDOR_ID, &work);
453 if (!nobridge || (work == 0xffffffff)) {
454 if (PCIIRQRoutingInfoLength != NULL)
455 kfree(PCIIRQRoutingInfoLength );
459 dbg("bus_num %d dev_num %d func_num %d\n", *bus_num, *dev_num >> 3, *dev_num & 0x7);
460 pci_read_config_dword_nodev (ctrl->pci_ops, *bus_num, *dev_num >> 3, *dev_num & 0x7, PCI_CLASS_REVISION, &work);
461 dbg("work >> 8 (%x) = BRIDGE (%x)\n", work >> 8, PCI_TO_PCI_BRIDGE_CLASS);
463 if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
464 pci_read_config_byte_nodev (ctrl->pci_ops, *bus_num, *dev_num >> 3, *dev_num & 0x7, PCI_SECONDARY_BUS, &tbus);
465 dbg("Scan bus for Non Bridge: bus %d\n", tbus);
466 if (PCI_ScanBusForNonBridge(ctrl, tbus, dev_num) == 0) {
468 if (PCIIRQRoutingInfoLength != NULL)
469 kfree(PCIIRQRoutingInfoLength );
473 if (PCIIRQRoutingInfoLength != NULL)
474 kfree(PCIIRQRoutingInfoLength );
480 if (PCIIRQRoutingInfoLength != NULL)
481 kfree(PCIIRQRoutingInfoLength );
486 int cpqhp_get_bus_dev (struct controller *ctrl, u8 * bus_num, u8 * dev_num, u8 slot)
488 return PCI_GetBusDevHelper(ctrl, bus_num, dev_num, slot, 0); //plain (bridges allowed)
492 /* More PCI configuration routines; this time centered around hotplug controller */
498 * Reads configuration for all slots in a PCI bus and saves info.
500 * Note: For non-hot plug busses, the slot # saved is the device #
502 * returns 0 if success
504 int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
511 struct pci_func *new_slot;
523 // Decide which slots are supported
526 //*********************************
527 // is_hot_plug is the slot mask
528 //*********************************
529 FirstSupported = is_hot_plug >> 4;
530 LastSupported = FirstSupported + (is_hot_plug & 0x0F) - 1;
533 LastSupported = 0x1F;
536 // Save PCI configuration space for all devices in supported slots
538 for (device = FirstSupported; device <= LastSupported; device++) {
540 rc = pci_read_config_dword_nodev (ctrl->pci_ops, busnumber, device, 0, PCI_VENDOR_ID, &ID);
542 if (ID != 0xFFFFFFFF) { // device in slot
543 rc = pci_read_config_byte_nodev (ctrl->pci_ops, busnumber, device, 0, 0x0B, &class_code);
547 rc = pci_read_config_byte_nodev (ctrl->pci_ops, busnumber, device, 0, PCI_HEADER_TYPE, &header_type);
551 // If multi-function device, set max_functions to 8
552 if (header_type & 0x80)
562 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { // P-P Bridge
563 // Recurse the subordinate bus
564 // get the subordinate bus number
565 rc = pci_read_config_byte_nodev (ctrl->pci_ops, busnumber, device, function, PCI_SECONDARY_BUS, &secondary_bus);
569 sub_bus = (int) secondary_bus;
571 // Save secondary bus cfg spc
572 // with this recursive call.
573 rc = cpqhp_save_config(ctrl, sub_bus, 0);
581 new_slot = cpqhp_slot_find(busnumber, device, index++);
583 (new_slot->function != (u8) function))
584 new_slot = cpqhp_slot_find(busnumber, device, index++);
587 // Setup slot structure.
588 new_slot = cpqhp_slot_create(busnumber);
590 if (new_slot == NULL)
594 new_slot->bus = (u8) busnumber;
595 new_slot->device = (u8) device;
596 new_slot->function = (u8) function;
597 new_slot->is_a_board = 1;
598 new_slot->switch_save = 0x10;
599 // In case of unsupported board
600 new_slot->status = DevError;
601 new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function);
603 for (cloop = 0; cloop < 0x20; cloop++) {
604 rc = pci_read_config_dword_nodev (ctrl->pci_ops, busnumber, device, function, cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
613 // this loop skips to the next present function
614 // reading in Class Code and Header type.
616 while ((function < max_functions)&&(!stop_it)) {
617 rc = pci_read_config_dword_nodev (ctrl->pci_ops, busnumber, device, function, PCI_VENDOR_ID, &ID);
618 if (ID == 0xFFFFFFFF) { // nothing there.
620 } else { // Something there
621 rc = pci_read_config_byte_nodev (ctrl->pci_ops, busnumber, device, function, 0x0B, &class_code);
625 rc = pci_read_config_byte_nodev (ctrl->pci_ops, busnumber, device, function, PCI_HEADER_TYPE, &header_type);
633 } while (function < max_functions);
634 } // End of IF (device in slot?)
635 else if (is_hot_plug) {
636 // Setup slot structure with entry for empty slot
637 new_slot = cpqhp_slot_create(busnumber);
639 if (new_slot == NULL) {
643 new_slot->bus = (u8) busnumber;
644 new_slot->device = (u8) device;
645 new_slot->function = 0;
646 new_slot->is_a_board = 0;
647 new_slot->presence_save = 0;
648 new_slot->switch_save = 0;
657 * cpqhp_save_slot_config
659 * Saves configuration info for all PCI devices in a given slot
660 * including subordinate busses.
662 * returns 0 if success
664 int cpqhp_save_slot_config (struct controller *ctrl, struct pci_func * new_slot)
679 pci_read_config_dword_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, 0, PCI_VENDOR_ID, &ID);
681 if (ID != 0xFFFFFFFF) { // device in slot
682 pci_read_config_byte_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, 0, 0x0B, &class_code);
684 pci_read_config_byte_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, 0, PCI_HEADER_TYPE, &header_type);
686 if (header_type & 0x80) // Multi-function device
694 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { // PCI-PCI Bridge
695 // Recurse the subordinate bus
696 pci_read_config_byte_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, function, PCI_SECONDARY_BUS, &secondary_bus);
698 sub_bus = (int) secondary_bus;
700 // Save the config headers for the secondary bus.
701 rc = cpqhp_save_config(ctrl, sub_bus, 0);
708 new_slot->status = 0;
710 for (cloop = 0; cloop < 0x20; cloop++) {
711 pci_read_config_dword_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, function, cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
718 // this loop skips to the next present function
719 // reading in the Class Code and the Header type.
721 while ((function < max_functions) && (!stop_it)) {
722 pci_read_config_dword_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, function, PCI_VENDOR_ID, &ID);
724 if (ID == 0xFFFFFFFF) { // nothing there.
726 } else { // Something there
727 pci_read_config_byte_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, function, 0x0B, &class_code);
729 pci_read_config_byte_nodev (ctrl->pci_ops, new_slot->bus, new_slot->device, function, PCI_HEADER_TYPE, &header_type);
735 } while (function < max_functions);
736 } // End of IF (device in slot?)
746 * cpqhp_save_base_addr_length
748 * Saves the length of all base address registers for the
749 * specified slot. this is for hot plug REPLACE
751 * returns 0 if success
753 int cpqhp_save_base_addr_length(struct controller *ctrl, struct pci_func * func)
763 struct pci_func *next;
766 func = cpqhp_slot_find(func->bus, func->device, index++);
768 while (func != NULL) {
771 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_HEADER_TYPE, &header_type);
773 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
775 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_SECONDARY_BUS, &secondary_bus);
777 sub_bus = (int) secondary_bus;
779 next = cpqhp_slot_list[sub_bus];
781 while (next != NULL) {
782 rc = cpqhp_save_base_addr_length(ctrl, next);
790 //FIXME: this loop is duplicated in the non-bridge case. The two could be rolled together
791 // Figure out IO and memory base lengths
792 for (cloop = 0x10; cloop <= 0x14; cloop += 4) {
793 temp_register = 0xFFFFFFFF;
794 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, cloop, temp_register);
795 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &base);
797 if (base) { // If this register is implemented
800 // set base = amount of IO space requested
801 base = base & 0xFFFFFFFE;
807 base = base & 0xFFFFFFF0;
817 // Save information in slot structure
818 func->base_length[(cloop - 0x10) >> 2] =
820 func->base_type[(cloop - 0x10) >> 2] = type;
822 } // End of base register loop
825 } else if ((header_type & 0x7F) == 0x00) { // PCI-PCI Bridge
826 // Figure out IO and memory base lengths
827 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
828 temp_register = 0xFFFFFFFF;
829 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, cloop, temp_register);
830 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &base);
832 if (base) { // If this register is implemented
835 // base = amount of IO space requested
836 base = base & 0xFFFFFFFE;
842 // base = amount of memory space requested
843 base = base & 0xFFFFFFF0;
853 // Save information in slot structure
854 func->base_length[(cloop - 0x10) >> 2] = base;
855 func->base_type[(cloop - 0x10) >> 2] = type;
857 } // End of base register loop
859 } else { // Some other unknown header type
862 // find the next device in this slot
863 func = cpqhp_slot_find(func->bus, func->device, index++);
871 * cpqhp_save_used_resources
873 * Stores used resource information for existing boards. this is
874 * for boards that were in the system when this driver was loaded.
875 * this function is for hot plug ADD
877 * returns 0 if success
879 int cpqhp_save_used_resources (struct controller *ctrl, struct pci_func * func)
895 struct pci_resource *mem_node;
896 struct pci_resource *p_mem_node;
897 struct pci_resource *io_node;
898 struct pci_resource *bus_node;
900 func = cpqhp_slot_find(func->bus, func->device, index++);
902 while ((func != NULL) && func->is_a_board) {
903 // Save the command register
904 pci_read_config_word_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_COMMAND, &save_command);
908 pci_write_config_word_nodev(ctrl->pci_ops, func->bus, func->device, func->function, PCI_COMMAND, command);
911 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_HEADER_TYPE, &header_type);
913 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { // PCI-PCI Bridge
914 // Clear Bridge Control Register
916 pci_write_config_word_nodev(ctrl->pci_ops, func->bus, func->device, func->function, PCI_BRIDGE_CONTROL, command);
918 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_SECONDARY_BUS, &secondary_bus);
920 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_SUBORDINATE_BUS, &temp_byte);
922 bus_node =(struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
926 bus_node->base = secondary_bus;
927 bus_node->length = temp_byte - secondary_bus + 1;
929 bus_node->next = func->bus_head;
930 func->bus_head = bus_node;
932 // Save IO base and Limit registers
933 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_IO_BASE, &b_base);
935 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_IO_LIMIT, &b_length);
937 if ((b_base <= b_length) && (save_command & 0x01)) {
938 io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
942 io_node->base = (b_base & 0xF0) << 8;
943 io_node->length = (b_length - b_base + 0x10) << 8;
945 io_node->next = func->io_head;
946 func->io_head = io_node;
948 // Save memory base and Limit registers
949 pci_read_config_word_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_MEMORY_BASE, &w_base);
951 pci_read_config_word_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_MEMORY_LIMIT, &w_length);
953 if ((w_base <= w_length) && (save_command & 0x02)) {
954 mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
958 mem_node->base = w_base << 16;
959 mem_node->length = (w_length - w_base + 0x10) << 16;
961 mem_node->next = func->mem_head;
962 func->mem_head = mem_node;
964 // Save prefetchable memory base and Limit registers
965 pci_read_config_word_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_PREF_MEMORY_BASE, &w_base);
967 pci_read_config_word_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_PREF_MEMORY_LIMIT, &w_length);
969 if ((w_base <= w_length) && (save_command & 0x02)) {
970 p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
974 p_mem_node->base = w_base << 16;
975 p_mem_node->length = (w_length - w_base + 0x10) << 16;
977 p_mem_node->next = func->p_mem_head;
978 func->p_mem_head = p_mem_node;
980 // Figure out IO and memory base lengths
981 for (cloop = 0x10; cloop <= 0x14; cloop += 4) {
982 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &save_base);
984 temp_register = 0xFFFFFFFF;
985 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, cloop, temp_register);
987 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &base);
989 temp_register = base;
991 if (base) { // If this register is implemented
992 if (((base & 0x03L) == 0x01)
993 && (save_command & 0x01)) {
995 // set temp_register = amount of IO space requested
996 temp_register = base & 0xFFFFFFFE;
997 temp_register = (~temp_register) + 1;
999 io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1004 save_base & (~0x03L);
1005 io_node->length = temp_register;
1007 io_node->next = func->io_head;
1008 func->io_head = io_node;
1010 if (((base & 0x0BL) == 0x08)
1011 && (save_command & 0x02)) {
1012 // prefetchable memory base
1013 temp_register = base & 0xFFFFFFF0;
1014 temp_register = (~temp_register) + 1;
1016 p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1020 p_mem_node->base = save_base & (~0x0FL);
1021 p_mem_node->length = temp_register;
1023 p_mem_node->next = func->p_mem_head;
1024 func->p_mem_head = p_mem_node;
1026 if (((base & 0x0BL) == 0x00)
1027 && (save_command & 0x02)) {
1028 // prefetchable memory base
1029 temp_register = base & 0xFFFFFFF0;
1030 temp_register = (~temp_register) + 1;
1032 mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1036 mem_node->base = save_base & (~0x0FL);
1037 mem_node->length = temp_register;
1039 mem_node->next = func->mem_head;
1040 func->mem_head = mem_node;
1044 } // End of base register loop
1045 } else if ((header_type & 0x7F) == 0x00) { // Standard header
1046 // Figure out IO and memory base lengths
1047 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
1048 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &save_base);
1050 temp_register = 0xFFFFFFFF;
1051 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, cloop, temp_register);
1053 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &base);
1055 temp_register = base;
1057 if (base) { // If this register is implemented
1058 if (((base & 0x03L) == 0x01)
1059 && (save_command & 0x01)) {
1061 // set temp_register = amount of IO space requested
1062 temp_register = base & 0xFFFFFFFE;
1063 temp_register = (~temp_register) + 1;
1065 io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1069 io_node->base = save_base & (~0x01L);
1070 io_node->length = temp_register;
1072 io_node->next = func->io_head;
1073 func->io_head = io_node;
1075 if (((base & 0x0BL) == 0x08)
1076 && (save_command & 0x02)) {
1077 // prefetchable memory base
1078 temp_register = base & 0xFFFFFFF0;
1079 temp_register = (~temp_register) + 1;
1081 p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1085 p_mem_node->base = save_base & (~0x0FL);
1086 p_mem_node->length = temp_register;
1088 p_mem_node->next = func->p_mem_head;
1089 func->p_mem_head = p_mem_node;
1091 if (((base & 0x0BL) == 0x00)
1092 && (save_command & 0x02)) {
1093 // prefetchable memory base
1094 temp_register = base & 0xFFFFFFF0;
1095 temp_register = (~temp_register) + 1;
1097 mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1101 mem_node->base = save_base & (~0x0FL);
1102 mem_node->length = temp_register;
1104 mem_node->next = func->mem_head;
1105 func->mem_head = mem_node;
1109 } // End of base register loop
1110 } else { // Some other unknown header type
1113 // find the next device in this slot
1114 func = cpqhp_slot_find(func->bus, func->device, index++);
1122 * cpqhp_configure_board
1124 * Copies saved configuration information to one slot.
1125 * this is called recursively for bridge devices.
1126 * this is for hot plug REPLACE!
1128 * returns 0 if success
1130 int cpqhp_configure_board(struct controller *ctrl, struct pci_func * func)
1136 struct pci_func *next;
1141 func = cpqhp_slot_find(func->bus, func->device, index++);
1143 while (func != NULL) {
1144 // Start at the top of config space so that the control
1145 // registers are programmed last
1146 for (cloop = 0x3C; cloop > 0; cloop -= 4) {
1147 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, cloop, func->config_space[cloop >> 2]);
1150 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_HEADER_TYPE, &header_type);
1152 // If this is a bridge device, restore subordinate devices
1153 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { // PCI-PCI Bridge
1154 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_SECONDARY_BUS, &secondary_bus);
1156 sub_bus = (int) secondary_bus;
1158 next = cpqhp_slot_list[sub_bus];
1160 while (next != NULL) {
1161 rc = cpqhp_configure_board(ctrl, next);
1170 // Check all the base Address Registers to make sure
1171 // they are the same. If not, the board is different.
1173 for (cloop = 16; cloop < 40; cloop += 4) {
1174 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &temp);
1176 if (temp != func->config_space[cloop >> 2]) {
1177 dbg("Config space compare failure!!! offset = %x\n", cloop);
1178 dbg("bus = %x, device = %x, function = %x\n", func->bus, func->device, func->function);
1179 dbg("temp = %x, config space = %x\n\n", temp, func->config_space[cloop]);
1185 func->configured = 1;
1187 func = cpqhp_slot_find(func->bus, func->device, index++);
1195 * cpqhp_valid_replace
1197 * this function checks to see if a board is the same as the
1198 * one it is replacing. this check will detect if the device's
1199 * vendor or device id's are the same
1201 * returns 0 if the board is the same nonzero otherwise
1203 int cpqhp_valid_replace(struct controller *ctrl, struct pci_func * func)
1209 u32 temp_register = 0;
1212 struct pci_func *next;
1215 if (!func->is_a_board)
1216 return(ADD_NOT_SUPPORTED);
1218 func = cpqhp_slot_find(func->bus, func->device, index++);
1220 while (func != NULL) {
1221 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_VENDOR_ID, &temp_register);
1223 // No adapter present
1224 if (temp_register == 0xFFFFFFFF)
1225 return(NO_ADAPTER_PRESENT);
1227 if (temp_register != func->config_space[0])
1228 return(ADAPTER_NOT_SAME);
1230 // Check for same revision number and class code
1231 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_CLASS_REVISION, &temp_register);
1233 // Adapter not the same
1234 if (temp_register != func->config_space[0x08 >> 2])
1235 return(ADAPTER_NOT_SAME);
1238 pci_read_config_byte_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_HEADER_TYPE, &header_type);
1240 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { // PCI-PCI Bridge
1241 // In order to continue checking, we must program the
1242 // bus registers in the bridge to respond to accesses
1243 // for it's subordinate bus(es)
1245 temp_register = func->config_space[0x18 >> 2];
1246 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, PCI_PRIMARY_BUS, temp_register);
1248 secondary_bus = (temp_register >> 8) & 0xFF;
1250 next = cpqhp_slot_list[secondary_bus];
1252 while (next != NULL) {
1253 rc = cpqhp_valid_replace(ctrl, next);
1262 // Check to see if it is a standard config header
1263 else if ((header_type & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
1264 // Check subsystem vendor and ID
1265 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, PCI_SUBSYSTEM_VENDOR_ID, &temp_register);
1267 if (temp_register != func->config_space[0x2C >> 2]) {
1268 // If it's a SMART-2 and the register isn't filled
1269 // in, ignore the difference because
1270 // they just have an old rev of the firmware
1272 if (!((func->config_space[0] == 0xAE100E11)
1273 && (temp_register == 0x00L)))
1274 return(ADAPTER_NOT_SAME);
1276 // Figure out IO and memory base lengths
1277 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
1278 temp_register = 0xFFFFFFFF;
1279 pci_write_config_dword_nodev(ctrl->pci_ops, func->bus, func->device, func->function, cloop, temp_register);
1281 pci_read_config_dword_nodev (ctrl->pci_ops, func->bus, func->device, func->function, cloop, &base);
1283 if (base) { // If this register is implemented
1286 // set base = amount of IO space requested
1287 base = base & 0xFFFFFFFE;
1293 base = base & 0xFFFFFFF0;
1303 // Check information in slot structure
1304 if (func->base_length[(cloop - 0x10) >> 2] != base)
1305 return(ADAPTER_NOT_SAME);
1307 if (func->base_type[(cloop - 0x10) >> 2] != type)
1308 return(ADAPTER_NOT_SAME);
1310 } // End of base register loop
1312 } // End of (type 0 config space) else
1314 // this is not a type 0 or 1 config space header so
1315 // we don't know how to do it
1316 return(DEVICE_TYPE_NOT_SUPPORTED);
1319 // Get the next function
1320 func = cpqhp_slot_find(func->bus, func->device, index++);
1329 * cpqhp_find_available_resources
1331 * Finds available memory, IO, and IRQ resources for programming
1332 * devices which may be added to the system
1333 * this function is for hot plug ADD!
1335 * returns 0 if success
1337 int cpqhp_find_available_resources (struct controller *ctrl, void *rom_start)
1343 struct pci_func *func = NULL;
1346 struct pci_resource *mem_node;
1347 struct pci_resource *p_mem_node;
1348 struct pci_resource *io_node;
1349 struct pci_resource *bus_node;
1350 void *rom_resource_table;
1352 rom_resource_table = detect_HRT_floating_pointer(rom_start, rom_start+0xffff);
1353 dbg("rom_resource_table = %p\n", rom_resource_table);
1355 if (rom_resource_table == NULL) {
1358 // Sum all resources and setup resource maps
1359 unused_IRQ = readl(rom_resource_table + UNUSED_IRQ);
1360 dbg("unused_IRQ = %x\n", unused_IRQ);
1363 while (unused_IRQ) {
1364 if (unused_IRQ & 1) {
1365 cpqhp_disk_irq = temp;
1368 unused_IRQ = unused_IRQ >> 1;
1372 dbg("cpqhp_disk_irq= %d\n", cpqhp_disk_irq);
1373 unused_IRQ = unused_IRQ >> 1;
1376 while (unused_IRQ) {
1377 if (unused_IRQ & 1) {
1378 cpqhp_nic_irq = temp;
1381 unused_IRQ = unused_IRQ >> 1;
1385 dbg("cpqhp_nic_irq= %d\n", cpqhp_nic_irq);
1386 unused_IRQ = readl(rom_resource_table + PCIIRQ);
1390 if (!cpqhp_nic_irq) {
1391 cpqhp_nic_irq = ctrl->interrupt;
1394 if (!cpqhp_disk_irq) {
1395 cpqhp_disk_irq = ctrl->interrupt;
1398 dbg("cpqhp_disk_irq, cpqhp_nic_irq= %d, %d\n", cpqhp_disk_irq, cpqhp_nic_irq);
1400 rc = compaq_nvram_load(rom_start, ctrl);
1404 one_slot = rom_resource_table + sizeof (struct hrt);
1406 i = readb(rom_resource_table + NUMBER_OF_ENTRIES);
1407 dbg("number_of_entries = %d\n", i);
1409 if (!readb(one_slot + SECONDARY_BUS)) {
1413 dbg("dev|IO base|length|Mem base|length|Pre base|length|PB SB MB\n");
1415 while (i && readb(one_slot + SECONDARY_BUS)) {
1416 u8 dev_func = readb(one_slot + DEV_FUNC);
1417 u8 primary_bus = readb(one_slot + PRIMARY_BUS);
1418 u8 secondary_bus = readb(one_slot + SECONDARY_BUS);
1419 u8 max_bus = readb(one_slot + MAX_BUS);
1420 u16 io_base = readw(one_slot + IO_BASE);
1421 u16 io_length = readw(one_slot + IO_LENGTH);
1422 u16 mem_base = readw(one_slot + MEM_BASE);
1423 u16 mem_length = readw(one_slot + MEM_LENGTH);
1424 u16 pre_mem_base = readw(one_slot + PRE_MEM_BASE);
1425 u16 pre_mem_length = readw(one_slot + PRE_MEM_LENGTH);
1427 dbg("%2.2x | %4.4x | %4.4x | %4.4x | %4.4x | %4.4x | %4.4x |%2.2x %2.2x %2.2x\n",
1428 dev_func, io_base, io_length, mem_base, mem_length, pre_mem_base, pre_mem_length,
1429 primary_bus, secondary_bus, max_bus);
1431 // If this entry isn't for our controller's bus, ignore it
1432 if (primary_bus != ctrl->bus) {
1434 one_slot += sizeof (struct slot_rt);
1437 // find out if this entry is for an occupied slot
1438 pci_read_config_dword_nodev (ctrl->pci_ops, primary_bus, dev_func >> 3, dev_func & 0x07, PCI_VENDOR_ID, &temp_dword);
1440 dbg("temp_D_word = %x\n", temp_dword);
1442 if (temp_dword != 0xFFFFFFFF) {
1444 func = cpqhp_slot_find(primary_bus, dev_func >> 3, 0);
1446 while (func && (func->function != (dev_func & 0x07))) {
1447 dbg("func = %p (bus, dev, fun) = (%d, %d, %d)\n", func, primary_bus, dev_func >> 3, index);
1448 func = cpqhp_slot_find(primary_bus, dev_func >> 3, index++);
1451 // If we can't find a match, skip this table entry
1454 one_slot += sizeof (struct slot_rt);
1457 // this may not work and shouldn't be used
1458 if (secondary_bus != primary_bus)
1470 // If we've got a valid IO base, use it
1472 temp_dword = io_base + io_length;
1474 if ((io_base) && (temp_dword < 0x10000)) {
1475 io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1479 io_node->base = io_base;
1480 io_node->length = io_length;
1482 dbg("found io_node(base, length) = %x, %x\n", io_node->base, io_node->length);
1483 dbg("populated slot =%d \n", populated_slot);
1484 if (!populated_slot) {
1485 io_node->next = ctrl->io_head;
1486 ctrl->io_head = io_node;
1488 io_node->next = func->io_head;
1489 func->io_head = io_node;
1493 // If we've got a valid memory base, use it
1494 temp_dword = mem_base + mem_length;
1495 if ((mem_base) && (temp_dword < 0x10000)) {
1496 mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1500 mem_node->base = mem_base << 16;
1502 mem_node->length = mem_length << 16;
1504 dbg("found mem_node(base, length) = %x, %x\n", mem_node->base, mem_node->length);
1505 dbg("populated slot =%d \n", populated_slot);
1506 if (!populated_slot) {
1507 mem_node->next = ctrl->mem_head;
1508 ctrl->mem_head = mem_node;
1510 mem_node->next = func->mem_head;
1511 func->mem_head = mem_node;
1515 // If we've got a valid prefetchable memory base, and
1516 // the base + length isn't greater than 0xFFFF
1517 temp_dword = pre_mem_base + pre_mem_length;
1518 if ((pre_mem_base) && (temp_dword < 0x10000)) {
1519 p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1523 p_mem_node->base = pre_mem_base << 16;
1525 p_mem_node->length = pre_mem_length << 16;
1526 dbg("found p_mem_node(base, length) = %x, %x\n", p_mem_node->base, p_mem_node->length);
1527 dbg("populated slot =%d \n", populated_slot);
1529 if (!populated_slot) {
1530 p_mem_node->next = ctrl->p_mem_head;
1531 ctrl->p_mem_head = p_mem_node;
1533 p_mem_node->next = func->p_mem_head;
1534 func->p_mem_head = p_mem_node;
1538 // If we've got a valid bus number, use it
1539 // The second condition is to ignore bus numbers on
1540 // populated slots that don't have PCI-PCI bridges
1541 if (secondary_bus && (secondary_bus != primary_bus)) {
1542 bus_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
1546 bus_node->base = secondary_bus;
1547 bus_node->length = max_bus - secondary_bus + 1;
1548 dbg("found bus_node(base, length) = %x, %x\n", bus_node->base, bus_node->length);
1549 dbg("populated slot =%d \n", populated_slot);
1550 if (!populated_slot) {
1551 bus_node->next = ctrl->bus_head;
1552 ctrl->bus_head = bus_node;
1554 bus_node->next = func->bus_head;
1555 func->bus_head = bus_node;
1560 one_slot += sizeof (struct slot_rt);
1563 // If all of the following fail, we don't have any resources for
1566 rc &= cpqhp_resource_sort_and_combine(&(ctrl->mem_head));
1567 rc &= cpqhp_resource_sort_and_combine(&(ctrl->p_mem_head));
1568 rc &= cpqhp_resource_sort_and_combine(&(ctrl->io_head));
1569 rc &= cpqhp_resource_sort_and_combine(&(ctrl->bus_head));
1576 * cpqhp_return_board_resources
1578 * this routine returns all resources allocated to a board to
1579 * the available pool.
1581 * returns 0 if success
1583 int cpqhp_return_board_resources(struct pci_func * func, struct resource_lists * resources)
1586 struct pci_resource *node;
1587 struct pci_resource *t_node;
1588 dbg("%s\n", __FUNCTION__);
1593 node = func->io_head;
1594 func->io_head = NULL;
1596 t_node = node->next;
1597 return_resource(&(resources->io_head), node);
1601 node = func->mem_head;
1602 func->mem_head = NULL;
1604 t_node = node->next;
1605 return_resource(&(resources->mem_head), node);
1609 node = func->p_mem_head;
1610 func->p_mem_head = NULL;
1612 t_node = node->next;
1613 return_resource(&(resources->p_mem_head), node);
1617 node = func->bus_head;
1618 func->bus_head = NULL;
1620 t_node = node->next;
1621 return_resource(&(resources->bus_head), node);
1625 rc |= cpqhp_resource_sort_and_combine(&(resources->mem_head));
1626 rc |= cpqhp_resource_sort_and_combine(&(resources->p_mem_head));
1627 rc |= cpqhp_resource_sort_and_combine(&(resources->io_head));
1628 rc |= cpqhp_resource_sort_and_combine(&(resources->bus_head));
1635 * cpqhp_destroy_resource_list
1637 * Puts node back in the resource list pointed to by head
1639 void cpqhp_destroy_resource_list (struct resource_lists * resources)
1641 struct pci_resource *res, *tres;
1643 res = resources->io_head;
1644 resources->io_head = NULL;
1652 res = resources->mem_head;
1653 resources->mem_head = NULL;
1661 res = resources->p_mem_head;
1662 resources->p_mem_head = NULL;
1670 res = resources->bus_head;
1671 resources->bus_head = NULL;
1682 * cpqhp_destroy_board_resources
1684 * Puts node back in the resource list pointed to by head
1686 void cpqhp_destroy_board_resources (struct pci_func * func)
1688 struct pci_resource *res, *tres;
1690 res = func->io_head;
1691 func->io_head = NULL;
1699 res = func->mem_head;
1700 func->mem_head = NULL;
1708 res = func->p_mem_head;
1709 func->p_mem_head = NULL;
1717 res = func->bus_head;
1718 func->bus_head = NULL;