29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/slab.h>
35 #include <linux/pci.h>
60 endp = (end -
sizeof(
struct hrt) + 1);
62 for (fp = begin; fp <= endp; fp += 16) {
79 dbg(
"Discovered Hotplug Resource Table at %p\n", fp);
94 dbg(
"INFO: pci_dev still null\n");
102 dbg(
"ERROR: pci_dev still null\n");
109 child = func->
pci_dev->subordinate;
126 for (j=0; j<8 ; j++) {
140 if (pci_bus_read_config_dword (bus, devfn,
PCI_VENDOR_ID, &vendID) == -1)
142 if (vendID == 0xffffffff)
144 return pci_bus_read_config_dword (bus, devfn, offset, value);
166 if (!fakedev || !fakebus) {
172 fakedev->
devfn = dev_num << 3;
173 fakedev->
bus = fakebus;
174 fakebus->
number = bus_num;
175 dbg(
"%s: dev %d, bus %d, pin %d, num %d\n",
176 __func__, dev_num, bus_num, int_pin, irq_num);
180 dbg(
"%s: rc %d\n", __func__, rc);
185 temp_word =
inb(0x4d0);
186 temp_word |=
inb(0x4d1) << 8;
188 temp_word |= 0x01 << irq_num;
193 outb((
u8) (temp_word & 0xFF), 0x4d0);
outb((
u8) ((temp_word &
194 0xFF00) >> 8), 0x4d1); rc = 0; }
206 ctrl->
pci_bus->number = bus_num;
208 for (tdevice = 0; tdevice < 0xFF; tdevice++) {
210 if (PCI_RefinedAccessConfig(ctrl->
pci_bus, tdevice, 0x08, &work) == -1)
212 dbg(
"Looking for nonbridge bus_num %d dev_num %d\n", bus_num, tdevice);
220 for (tdevice = 0; tdevice < 0xFF; tdevice++) {
222 if (PCI_RefinedAccessConfig(ctrl->
pci_bus, tdevice, 0x08, &work) == -1)
224 dbg(
"Looking for bridge bus_num %d dev_num %d\n", bus_num, tdevice);
229 dbg(
"Recurse on bus_num %d tdevice %d\n", tbus, tdevice);
242 u8 tbus, tdevice, tslot;
244 len = cpqhp_routing_table_length();
245 for (loop = 0; loop < len; ++loop) {
255 if (!nobridge || (work == 0xffffffff))
258 dbg(
"bus_num %d devfn %d\n", *bus_num, *dev_num);
264 dbg(
"Scan bus for Non Bridge: bus %d\n", tbus);
265 if (PCI_ScanBusForNonBridge(ctrl, tbus, dev_num) == 0) {
280 return PCI_GetBusDevHelper(ctrl, bus_num, dev_num, slot, 0);
323 FirstSupported = is_hot_plug >> 4;
324 LastSupported = FirstSupported + (is_hot_plug & 0x0F) - 1;
327 LastSupported = 0x1F;
331 ctrl->
pci_bus->number = busnumber;
332 for (device = FirstSupported; device <= LastSupported; device++) {
336 if (ID == 0xFFFFFFFF) {
342 if (new_slot ==
NULL)
345 new_slot->
bus = (
u8) busnumber;
355 rc = pci_bus_read_config_byte(ctrl->
pci_bus,
PCI_DEVFN(device, 0), 0x0B, &class_code);
364 if (header_type & 0x80)
381 sub_bus = (
int) secondary_bus;
389 ctrl->
pci_bus->number = busnumber;
402 if (new_slot ==
NULL)
406 new_slot->
bus = (
u8) busnumber;
412 new_slot->
status = DevError;
415 for (cloop = 0; cloop < 0x20; cloop++) {
430 while ((
function < max_functions) && (!stop_it)) {
432 if (ID == 0xFFFFFFFF) {
436 rc = pci_bus_read_config_byte(ctrl->
pci_bus,
PCI_DEVFN(device,
function), 0x0B, &class_code);
447 }
while (
function < max_functions);
480 if (ID == 0xFFFFFFFF)
486 if (header_type & 0x80)
491 while (
function < max_functions) {
496 sub_bus = (
int) secondary_bus;
510 for (cloop = 0; cloop < 0x20; cloop++)
520 while ((
function < max_functions) && (!stop_it)) {
523 if (ID == 0xFFFFFFFF)
563 while (func !=
NULL) {
568 pci_bus_read_config_byte (pci_bus, devfn,
PCI_HEADER_TYPE, &header_type);
573 sub_bus = (
int) secondary_bus;
577 while (next !=
NULL) {
590 for (cloop = 0x10; cloop <= 0x14; cloop += 4) {
591 temp_register = 0xFFFFFFFF;
592 pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
593 pci_bus_read_config_dword (pci_bus, devfn, cloop, &base);
601 base = base & 0xFFFFFFFE;
607 base = base & 0xFFFFFFF0;
620 func->
base_type[(cloop - 0x10) >> 2] = type;
624 }
else if ((header_type & 0x7F) == 0x00) {
626 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
627 temp_register = 0xFFFFFFFF;
628 pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
629 pci_bus_read_config_dword (pci_bus, devfn, cloop, &base);
638 base = base & 0xFFFFFFFE;
647 base = base & 0xFFFFFFF0;
659 func->
base_type[(cloop - 0x10) >> 2] = type;
713 pci_bus_read_config_word(pci_bus, devfn,
PCI_COMMAND, &save_command);
717 pci_bus_write_config_word(pci_bus, devfn,
PCI_COMMAND, command);
720 pci_bus_read_config_byte(pci_bus, devfn,
PCI_HEADER_TYPE, &header_type);
734 bus_node->
length = temp_byte - secondary_bus + 1;
740 pci_bus_read_config_byte(pci_bus, devfn,
PCI_IO_BASE, &b_base);
741 pci_bus_read_config_byte(pci_bus, devfn,
PCI_IO_LIMIT, &b_length);
743 if ((b_base <= b_length) && (save_command & 0x01)) {
748 io_node->
base = (b_base & 0xF0) << 8;
749 io_node->
length = (b_length - b_base + 0x10) << 8;
759 if ((w_base <= w_length) && (save_command & 0x02)) {
764 mem_node->
base = w_base << 16;
765 mem_node->
length = (w_length - w_base + 0x10) << 16;
775 if ((w_base <= w_length) && (save_command & 0x02)) {
780 p_mem_node->
base = w_base << 16;
781 p_mem_node->
length = (w_length - w_base + 0x10) << 16;
787 for (cloop = 0x10; cloop <= 0x14; cloop += 4) {
788 pci_bus_read_config_dword (pci_bus, devfn, cloop, &save_base);
790 temp_register = 0xFFFFFFFF;
791 pci_bus_write_config_dword(pci_bus, devfn, cloop, temp_register);
792 pci_bus_read_config_dword(pci_bus, devfn, cloop, &base);
794 temp_register = base;
798 if (((base & 0x03L) == 0x01)
799 && (save_command & 0x01)) {
804 temp_register = base & 0xFFFFFFFE;
805 temp_register = (~temp_register) + 1;
807 io_node =
kmalloc(
sizeof(*io_node),
813 save_base & (~0x03
L);
814 io_node->
length = temp_register;
819 if (((base & 0x0BL) == 0x08)
820 && (save_command & 0x02)) {
822 temp_register = base & 0xFFFFFFF0;
823 temp_register = (~temp_register) + 1;
825 p_mem_node =
kmalloc(
sizeof(*p_mem_node),
830 p_mem_node->
base = save_base & (~0x0F
L);
831 p_mem_node->
length = temp_register;
836 if (((base & 0x0BL) == 0x00)
837 && (save_command & 0x02)) {
839 temp_register = base & 0xFFFFFFF0;
840 temp_register = (~temp_register) + 1;
842 mem_node =
kmalloc(
sizeof(*mem_node),
847 mem_node->
base = save_base & (~0x0F
L);
848 mem_node->
length = temp_register;
857 }
else if ((header_type & 0x7F) == 0x00) {
859 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
860 pci_bus_read_config_dword(pci_bus, devfn, cloop, &save_base);
862 temp_register = 0xFFFFFFFF;
863 pci_bus_write_config_dword(pci_bus, devfn, cloop, temp_register);
864 pci_bus_read_config_dword(pci_bus, devfn, cloop, &base);
866 temp_register = base;
870 if (((base & 0x03L) == 0x01)
871 && (save_command & 0x01)) {
876 temp_register = base & 0xFFFFFFFE;
877 temp_register = (~temp_register) + 1;
879 io_node =
kmalloc(
sizeof(*io_node),
884 io_node->
base = save_base & (~0x01
L);
885 io_node->
length = temp_register;
890 if (((base & 0x0BL) == 0x08)
891 && (save_command & 0x02)) {
893 temp_register = base & 0xFFFFFFF0;
894 temp_register = (~temp_register) + 1;
896 p_mem_node =
kmalloc(
sizeof(*p_mem_node),
901 p_mem_node->
base = save_base & (~0x0F
L);
902 p_mem_node->
length = temp_register;
907 if (((base & 0x0BL) == 0x00)
908 && (save_command & 0x02)) {
910 temp_register = base & 0xFFFFFFF0;
911 temp_register = (~temp_register) + 1;
913 mem_node =
kmalloc(
sizeof(*mem_node),
918 mem_node->
base = save_base & (~0x0F
L);
919 mem_node->
length = temp_register;
961 while (func !=
NULL) {
968 for (cloop = 0x3C; cloop > 0; cloop -= 4)
969 pci_bus_write_config_dword (pci_bus, devfn, cloop, func->
config_space[cloop >> 2]);
971 pci_bus_read_config_byte (pci_bus, devfn,
PCI_HEADER_TYPE, &header_type);
977 sub_bus = (
int) secondary_bus;
981 while (next !=
NULL) {
994 for (cloop = 16; cloop < 40; cloop += 4) {
995 pci_bus_read_config_dword (pci_bus, devfn, cloop, &temp);
998 dbg(
"Config space compare failure!!! offset = %x\n", cloop);
1000 dbg(
"temp = %x, config space = %x\n\n", temp, func->
config_space[cloop >> 2]);
1030 u32 temp_register = 0;
1043 while (func !=
NULL) {
1047 pci_bus_read_config_dword (pci_bus, devfn,
PCI_VENDOR_ID, &temp_register);
1050 if (temp_register == 0xFFFFFFFF)
1064 pci_bus_read_config_byte (pci_bus, devfn,
PCI_HEADER_TYPE, &header_type);
1073 pci_bus_write_config_dword (pci_bus, devfn,
PCI_PRIMARY_BUS, temp_register);
1075 secondary_bus = (temp_register >> 8) & 0xFF;
1079 while (next !=
NULL) {
1099 && (temp_register == 0x00L)))
1103 for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
1104 temp_register = 0xFFFFFFFF;
1105 pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
1106 pci_bus_read_config_dword (pci_bus, devfn, cloop, &base);
1115 base = base & 0xFFFFFFFE;
1121 base = base & 0xFFFFFFF0;
1132 if (func->
base_length[(cloop - 0x10) >> 2] != base)
1172 void __iomem *rom_resource_table;
1181 rom_resource_table = detect_HRT_floating_pointer(rom_start, rom_start+0xffff);
1182 dbg(
"rom_resource_table = %p\n", rom_resource_table);
1184 if (rom_resource_table ==
NULL)
1231 one_slot = rom_resource_table +
sizeof (
struct hrt);
1234 dbg(
"number_of_entries = %d\n", i);
1239 dbg(
"dev|IO base|length|Mem base|length|Pre base|length|PB SB MB\n");
1253 dbg(
"%2.2x | %4.4x | %4.4x | %4.4x | %4.4x | %4.4x | %4.4x |%2.2x %2.2x %2.2x\n",
1254 dev_func, io_base, io_length, mem_base, mem_length, pre_mem_base, pre_mem_length,
1255 primary_bus, secondary_bus, max_bus);
1258 if (primary_bus != ctrl->
bus) {
1260 one_slot +=
sizeof (
struct slot_rt);
1266 dbg(
"temp_D_word = %x\n", temp_dword);
1268 if (temp_dword != 0xFFFFFFFF) {
1272 while (func && (func->
function != (dev_func & 0x07))) {
1273 dbg(
"func = %p (bus, dev, fun) = (%d, %d, %d)\n", func, primary_bus, dev_func >> 3,
index);
1280 one_slot +=
sizeof (
struct slot_rt);
1284 if (secondary_bus != primary_bus)
1300 if ((io_base) && (temp_dword < 0x10000)) {
1308 dbg(
"found io_node(base, length) = %x, %x\n",
1310 dbg(
"populated slot =%d \n", populated_slot);
1311 if (!populated_slot) {
1322 if ((mem_base) && (temp_dword < 0x10000)) {
1327 mem_node->
base = mem_base << 16;
1329 mem_node->
length = mem_length << 16;
1331 dbg(
"found mem_node(base, length) = %x, %x\n",
1333 dbg(
"populated slot =%d \n", populated_slot);
1334 if (!populated_slot) {
1347 if ((pre_mem_base) && (temp_dword < 0x10000)) {
1352 p_mem_node->
base = pre_mem_base << 16;
1354 p_mem_node->
length = pre_mem_length << 16;
1355 dbg(
"found p_mem_node(base, length) = %x, %x\n",
1357 dbg(
"populated slot =%d \n", populated_slot);
1359 if (!populated_slot) {
1372 if (secondary_bus && (secondary_bus != primary_bus)) {
1378 bus_node->
length = max_bus - secondary_bus + 1;
1379 dbg(
"found bus_node(base, length) = %x, %x\n",
1381 dbg(
"populated slot =%d \n", populated_slot);
1382 if (!populated_slot) {
1392 one_slot +=
sizeof (
struct slot_rt);
1421 dbg(
"%s\n", __func__);
1429 t_node = node->
next;
1430 return_resource(&(resources->
io_head), node);
1437 t_node = node->
next;
1438 return_resource(&(resources->
mem_head), node);
1445 t_node = node->
next;
1446 return_resource(&(resources->
p_mem_head), node);
1453 t_node = node->
next;
1454 return_resource(&(resources->
bus_head), node);