common.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Low-Level PCI Support for PC
  3. *
  4. * (c) 1999--2000 Martin Mares <mj@ucw.cz>
  5. */
  6. #include <linux/sched.h>
  7. #include <linux/pci.h>
  8. #include <linux/ioport.h>
  9. #include <linux/init.h>
  10. #include <linux/dmi.h>
  11. #include <asm/acpi.h>
  12. #include <asm/segment.h>
  13. #include <asm/io.h>
  14. #include <asm/smp.h>
  15. #include "pci.h"
  16. unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
  17. PCI_PROBE_MMCONF;
  18. int pci_routeirq;
  19. int pcibios_last_bus = -1;
  20. unsigned long pirq_table_addr;
  21. struct pci_bus *pci_root_bus;
  22. struct pci_raw_ops *raw_pci_ops;
  23. static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
  24. {
  25. return raw_pci_ops->read(0, bus->number, devfn, where, size, value);
  26. }
  27. static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
  28. {
  29. return raw_pci_ops->write(0, bus->number, devfn, where, size, value);
  30. }
  31. struct pci_ops pci_root_ops = {
  32. .read = pci_read,
  33. .write = pci_write,
  34. };
  35. /*
  36. * legacy, numa, and acpi all want to call pcibios_scan_root
  37. * from their initcalls. This flag prevents that.
  38. */
  39. int pcibios_scanned;
  40. /*
  41. * This interrupt-safe spinlock protects all accesses to PCI
  42. * configuration space.
  43. */
  44. DEFINE_SPINLOCK(pci_config_lock);
  45. /*
  46. * Several buggy motherboards address only 16 devices and mirror
  47. * them to next 16 IDs. We try to detect this `feature' on all
  48. * primary buses (those containing host bridges as they are
  49. * expected to be unique) and remove the ghost devices.
  50. */
  51. static void __devinit pcibios_fixup_ghosts(struct pci_bus *b)
  52. {
  53. struct list_head *ln, *mn;
  54. struct pci_dev *d, *e;
  55. int mirror = PCI_DEVFN(16,0);
  56. int seen_host_bridge = 0;
  57. int i;
  58. DBG("PCI: Scanning for ghost devices on bus %d\n", b->number);
  59. list_for_each(ln, &b->devices) {
  60. d = pci_dev_b(ln);
  61. if ((d->class >> 8) == PCI_CLASS_BRIDGE_HOST)
  62. seen_host_bridge++;
  63. for (mn=ln->next; mn != &b->devices; mn=mn->next) {
  64. e = pci_dev_b(mn);
  65. if (e->devfn != d->devfn + mirror ||
  66. e->vendor != d->vendor ||
  67. e->device != d->device ||
  68. e->class != d->class)
  69. continue;
  70. for(i=0; i<PCI_NUM_RESOURCES; i++)
  71. if (e->resource[i].start != d->resource[i].start ||
  72. e->resource[i].end != d->resource[i].end ||
  73. e->resource[i].flags != d->resource[i].flags)
  74. continue;
  75. break;
  76. }
  77. if (mn == &b->devices)
  78. return;
  79. }
  80. if (!seen_host_bridge)
  81. return;
  82. printk(KERN_WARNING "PCI: Ignoring ghost devices on bus %02x\n", b->number);
  83. ln = &b->devices;
  84. while (ln->next != &b->devices) {
  85. d = pci_dev_b(ln->next);
  86. if (d->devfn >= mirror) {
  87. list_del(&d->global_list);
  88. list_del(&d->bus_list);
  89. kfree(d);
  90. } else
  91. ln = ln->next;
  92. }
  93. }
  94. /*
  95. * Called after each bus is probed, but before its children
  96. * are examined.
  97. */
  98. void __devinit pcibios_fixup_bus(struct pci_bus *b)
  99. {
  100. pcibios_fixup_ghosts(b);
  101. pci_read_bridge_bases(b);
  102. }
  103. /*
  104. * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
  105. */
  106. #ifdef __i386__
  107. static int __devinit assign_all_busses(struct dmi_system_id *d)
  108. {
  109. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  110. printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
  111. " (pci=assign-busses)\n", d->ident);
  112. return 0;
  113. }
  114. #endif
  115. /*
  116. * Laptops which need pci=assign-busses to see Cardbus cards
  117. */
  118. static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
  119. #ifdef __i386__
  120. {
  121. .callback = assign_all_busses,
  122. .ident = "Samsung X20 Laptop",
  123. .matches = {
  124. DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
  125. DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
  126. },
  127. },
  128. #endif /* __i386__ */
  129. {}
  130. };
  131. struct pci_bus * __devinit pcibios_scan_root(int busnum)
  132. {
  133. struct pci_bus *bus = NULL;
  134. dmi_check_system(pciprobe_dmi_table);
  135. while ((bus = pci_find_next_bus(bus)) != NULL) {
  136. if (bus->number == busnum) {
  137. /* Already scanned */
  138. return bus;
  139. }
  140. }
  141. printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
  142. return pci_scan_bus_parented(NULL, busnum, &pci_root_ops, NULL);
  143. }
  144. extern u8 pci_cache_line_size;
  145. static int __init pcibios_init(void)
  146. {
  147. struct cpuinfo_x86 *c = &boot_cpu_data;
  148. if (!raw_pci_ops) {
  149. printk(KERN_WARNING "PCI: System does not support PCI\n");
  150. return 0;
  151. }
  152. /*
  153. * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
  154. * and P4. It's also good for 386/486s (which actually have 16)
  155. * as quite a few PCI devices do not support smaller values.
  156. */
  157. pci_cache_line_size = 32 >> 2;
  158. if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
  159. pci_cache_line_size = 64 >> 2; /* K7 & K8 */
  160. else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
  161. pci_cache_line_size = 128 >> 2; /* P4 */
  162. pcibios_resource_survey();
  163. #ifdef CONFIG_PCI_BIOS
  164. if ((pci_probe & PCI_BIOS_SORT) && !(pci_probe & PCI_NO_SORT))
  165. pcibios_sort();
  166. #endif
  167. return 0;
  168. }
  169. subsys_initcall(pcibios_init);
  170. char * __devinit pcibios_setup(char *str)
  171. {
  172. if (!strcmp(str, "off")) {
  173. pci_probe = 0;
  174. return NULL;
  175. }
  176. #ifdef CONFIG_PCI_BIOS
  177. else if (!strcmp(str, "bios")) {
  178. pci_probe = PCI_PROBE_BIOS;
  179. return NULL;
  180. } else if (!strcmp(str, "nobios")) {
  181. pci_probe &= ~PCI_PROBE_BIOS;
  182. return NULL;
  183. } else if (!strcmp(str, "nosort")) {
  184. pci_probe |= PCI_NO_SORT;
  185. return NULL;
  186. } else if (!strcmp(str, "biosirq")) {
  187. pci_probe |= PCI_BIOS_IRQ_SCAN;
  188. return NULL;
  189. } else if (!strncmp(str, "pirqaddr=", 9)) {
  190. pirq_table_addr = simple_strtoul(str+9, NULL, 0);
  191. return NULL;
  192. }
  193. #endif
  194. #ifdef CONFIG_PCI_DIRECT
  195. else if (!strcmp(str, "conf1")) {
  196. pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
  197. return NULL;
  198. }
  199. else if (!strcmp(str, "conf2")) {
  200. pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
  201. return NULL;
  202. }
  203. #endif
  204. #ifdef CONFIG_PCI_MMCONFIG
  205. else if (!strcmp(str, "nommconf")) {
  206. pci_probe &= ~PCI_PROBE_MMCONF;
  207. return NULL;
  208. }
  209. #endif
  210. else if (!strcmp(str, "noacpi")) {
  211. acpi_noirq_set();
  212. return NULL;
  213. }
  214. #ifndef CONFIG_X86_VISWS
  215. else if (!strcmp(str, "usepirqmask")) {
  216. pci_probe |= PCI_USE_PIRQ_MASK;
  217. return NULL;
  218. } else if (!strncmp(str, "irqmask=", 8)) {
  219. pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
  220. return NULL;
  221. } else if (!strncmp(str, "lastbus=", 8)) {
  222. pcibios_last_bus = simple_strtol(str+8, NULL, 0);
  223. return NULL;
  224. }
  225. #endif
  226. else if (!strcmp(str, "rom")) {
  227. pci_probe |= PCI_ASSIGN_ROMS;
  228. return NULL;
  229. } else if (!strcmp(str, "assign-busses")) {
  230. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  231. return NULL;
  232. } else if (!strcmp(str, "routeirq")) {
  233. pci_routeirq = 1;
  234. return NULL;
  235. }
  236. return str;
  237. }
  238. unsigned int pcibios_assign_all_busses(void)
  239. {
  240. return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
  241. }
  242. int pcibios_enable_device(struct pci_dev *dev, int mask)
  243. {
  244. int err;
  245. if ((err = pcibios_enable_resources(dev, mask)) < 0)
  246. return err;
  247. return pcibios_enable_irq(dev);
  248. }
  249. void pcibios_disable_device (struct pci_dev *dev)
  250. {
  251. pcibios_disable_resources(dev);
  252. if (pcibios_disable_irq)
  253. pcibios_disable_irq(dev);
  254. }