broadcom_bus.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 resource res;
  23. u16 word1, word2;
  24. u8 fbus, lbus;
  25. int i;
  26. info = &pci_root_info[pci_root_num];
  27. pci_root_num++;
  28. /* read the PCI bus numbers */
  29. fbus = read_pci_config_byte(bus, slot, func, 0x44);
  30. lbus = read_pci_config_byte(bus, slot, func, 0x45);
  31. info->bus_min = fbus;
  32. info->bus_max = lbus;
  33. /*
  34. * Add the legacy IDE ports on bus 0
  35. *
  36. * These do not exist anywhere in the bridge registers, AFAICT. I do
  37. * not have the datasheet, so this is the best I can do.
  38. */
  39. if (fbus == 0) {
  40. update_res(info, 0x01f0, 0x01f7, IORESOURCE_IO, 0);
  41. update_res(info, 0x03f6, 0x03f6, IORESOURCE_IO, 0);
  42. update_res(info, 0x0170, 0x0177, IORESOURCE_IO, 0);
  43. update_res(info, 0x0376, 0x0376, IORESOURCE_IO, 0);
  44. update_res(info, 0xffa0, 0xffaf, IORESOURCE_IO, 0);
  45. }
  46. /* read the non-prefetchable memory window */
  47. word1 = read_pci_config_16(bus, slot, func, 0xc0);
  48. word2 = read_pci_config_16(bus, slot, func, 0xc2);
  49. if (word1 != word2) {
  50. res.start = (word1 << 16) | 0x0000;
  51. res.end = (word2 << 16) | 0xffff;
  52. res.flags = IORESOURCE_MEM;
  53. update_res(info, res.start, res.end, res.flags, 0);
  54. }
  55. /* read the prefetchable memory window */
  56. word1 = read_pci_config_16(bus, slot, func, 0xc4);
  57. word2 = read_pci_config_16(bus, slot, func, 0xc6);
  58. if (word1 != word2) {
  59. res.start = (word1 << 16) | 0x0000;
  60. res.end = (word2 << 16) | 0xffff;
  61. res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  62. update_res(info, res.start, res.end, res.flags, 0);
  63. }
  64. /* read the IO port window */
  65. word1 = read_pci_config_16(bus, slot, func, 0xd0);
  66. word2 = read_pci_config_16(bus, slot, func, 0xd2);
  67. if (word1 != word2) {
  68. res.start = word1;
  69. res.end = word2;
  70. res.flags = IORESOURCE_IO;
  71. update_res(info, res.start, res.end, res.flags, 0);
  72. }
  73. /* print information about this host bridge */
  74. res.start = fbus;
  75. res.end = lbus;
  76. res.flags = IORESOURCE_BUS;
  77. printk(KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n", &res);
  78. for (i = 0; i < info->res_num; i++)
  79. printk(KERN_INFO "host bridge window %pR\n", &info->res[i]);
  80. }
  81. static int __init broadcom_postcore_init(void)
  82. {
  83. u8 bus = 0, slot = 0;
  84. u32 id;
  85. u16 vendor, device;
  86. #ifdef CONFIG_ACPI
  87. /*
  88. * We should get host bridge information from ACPI unless the BIOS
  89. * doesn't support it.
  90. */
  91. if (acpi_os_get_root_pointer())
  92. return 0;
  93. #endif
  94. id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
  95. vendor = id & 0xffff;
  96. device = (id >> 16) & 0xffff;
  97. if (vendor == PCI_VENDOR_ID_SERVERWORKS &&
  98. device == PCI_DEVICE_ID_SERVERWORKS_LE) {
  99. cnb20le_res(bus, slot, 0);
  100. cnb20le_res(bus, slot, 1);
  101. }
  102. return 0;
  103. }
  104. postcore_initcall(broadcom_postcore_init);