broadcom_bus.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Read address ranges from a Broadcom CNB20LE Host Bridge
  3. *
  4. * Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/acpi.h>
  12. #include <linux/delay.h>
  13. #include <linux/dmi.h>
  14. #include <linux/pci.h>
  15. #include <linux/init.h>
  16. #include <asm/pci_x86.h>
  17. #include <asm/pci-direct.h>
  18. #include "bus_numa.h"
  19. static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
  20. {
  21. struct pci_root_info *info;
  22. struct pci_root_res *root_res;
  23. struct resource res;
  24. u16 word1, word2;
  25. u8 fbus, lbus;
  26. /* read the PCI bus numbers */
  27. fbus = read_pci_config_byte(bus, slot, func, 0x44);
  28. lbus = read_pci_config_byte(bus, slot, func, 0x45);
  29. info = alloc_pci_root_info(fbus, lbus, 0, 0);
  30. /*
  31. * Add the legacy IDE ports on bus 0
  32. *
  33. * These do not exist anywhere in the bridge registers, AFAICT. I do
  34. * not have the datasheet, so this is the best I can do.
  35. */
  36. if (fbus == 0) {
  37. update_res(info, 0x01f0, 0x01f7, IORESOURCE_IO, 0);
  38. update_res(info, 0x03f6, 0x03f6, IORESOURCE_IO, 0);
  39. update_res(info, 0x0170, 0x0177, IORESOURCE_IO, 0);
  40. update_res(info, 0x0376, 0x0376, IORESOURCE_IO, 0);
  41. update_res(info, 0xffa0, 0xffaf, IORESOURCE_IO, 0);
  42. }
  43. /* read the non-prefetchable memory window */
  44. word1 = read_pci_config_16(bus, slot, func, 0xc0);
  45. word2 = read_pci_config_16(bus, slot, func, 0xc2);
  46. if (word1 != word2) {
  47. res.start = ((resource_size_t) word1 << 16) | 0x0000;
  48. res.end = ((resource_size_t) word2 << 16) | 0xffff;
  49. res.flags = IORESOURCE_MEM;
  50. update_res(info, res.start, res.end, res.flags, 0);
  51. }
  52. /* read the prefetchable memory window */
  53. word1 = read_pci_config_16(bus, slot, func, 0xc4);
  54. word2 = read_pci_config_16(bus, slot, func, 0xc6);
  55. if (word1 != word2) {
  56. res.start = ((resource_size_t) word1 << 16) | 0x0000;
  57. res.end = ((resource_size_t) word2 << 16) | 0xffff;
  58. res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  59. update_res(info, res.start, res.end, res.flags, 0);
  60. }
  61. /* read the IO port window */
  62. word1 = read_pci_config_16(bus, slot, func, 0xd0);
  63. word2 = read_pci_config_16(bus, slot, func, 0xd2);
  64. if (word1 != word2) {
  65. res.start = word1;
  66. res.end = word2;
  67. res.flags = IORESOURCE_IO;
  68. update_res(info, res.start, res.end, res.flags, 0);
  69. }
  70. /* print information about this host bridge */
  71. res.start = fbus;
  72. res.end = lbus;
  73. res.flags = IORESOURCE_BUS;
  74. printk(KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n", &res);
  75. list_for_each_entry(root_res, &info->resources, list)
  76. printk(KERN_INFO "host bridge window %pR\n", &root_res->res);
  77. }
  78. static int __init broadcom_postcore_init(void)
  79. {
  80. u8 bus = 0, slot = 0;
  81. u32 id;
  82. u16 vendor, device;
  83. #ifdef CONFIG_ACPI
  84. /*
  85. * We should get host bridge information from ACPI unless the BIOS
  86. * doesn't support it.
  87. */
  88. if (!acpi_disabled && acpi_os_get_root_pointer())
  89. return 0;
  90. #endif
  91. id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
  92. vendor = id & 0xffff;
  93. device = (id >> 16) & 0xffff;
  94. if (vendor == PCI_VENDOR_ID_SERVERWORKS &&
  95. device == PCI_DEVICE_ID_SERVERWORKS_LE) {
  96. cnb20le_res(bus, slot, 0);
  97. cnb20le_res(bus, slot, 1);
  98. }
  99. return 0;
  100. }
  101. postcore_initcall(broadcom_postcore_init);