common.c 8.1 KB

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