pci_common.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. /* $Id: pci_common.c,v 1.29 2002/02/01 00:56:03 davem Exp $
  2. * pci_common.c: PCI controller common support.
  3. *
  4. * Copyright (C) 1999 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/string.h>
  7. #include <linux/slab.h>
  8. #include <linux/init.h>
  9. #include <asm/pbm.h>
  10. #include <asm/prom.h>
  11. #include <asm/of_device.h>
  12. #include "pci_impl.h"
  13. /* Fix self device of BUS and hook it into BUS->self.
  14. * The pci_scan_bus does not do this for the host bridge.
  15. */
  16. void __init pci_fixup_host_bridge_self(struct pci_bus *pbus)
  17. {
  18. struct pci_dev *pdev;
  19. list_for_each_entry(pdev, &pbus->devices, bus_list) {
  20. if (pdev->class >> 8 == PCI_CLASS_BRIDGE_HOST) {
  21. pbus->self = pdev;
  22. return;
  23. }
  24. }
  25. prom_printf("PCI: Critical error, cannot find host bridge PDEV.\n");
  26. prom_halt();
  27. }
  28. /* Find the OBP PROM device tree node for a PCI device. */
  29. static struct device_node * __init
  30. find_device_prom_node(struct pci_pbm_info *pbm, struct pci_dev *pdev,
  31. struct device_node *bus_node,
  32. struct linux_prom_pci_registers **pregs,
  33. int *nregs)
  34. {
  35. struct device_node *dp;
  36. *nregs = 0;
  37. /*
  38. * Return the PBM's PROM node in case we are it's PCI device,
  39. * as the PBM's reg property is different to standard PCI reg
  40. * properties. We would delete this device entry otherwise,
  41. * which confuses XFree86's device probing...
  42. */
  43. if ((pdev->bus->number == pbm->pci_bus->number) && (pdev->devfn == 0) &&
  44. (pdev->vendor == PCI_VENDOR_ID_SUN) &&
  45. (pdev->device == PCI_DEVICE_ID_SUN_PBM ||
  46. pdev->device == PCI_DEVICE_ID_SUN_SCHIZO ||
  47. pdev->device == PCI_DEVICE_ID_SUN_TOMATILLO ||
  48. pdev->device == PCI_DEVICE_ID_SUN_SABRE ||
  49. pdev->device == PCI_DEVICE_ID_SUN_HUMMINGBIRD))
  50. return bus_node;
  51. dp = bus_node->child;
  52. while (dp) {
  53. struct linux_prom_pci_registers *regs;
  54. struct property *prop;
  55. int len;
  56. prop = of_find_property(dp, "reg", &len);
  57. if (!prop)
  58. goto do_next_sibling;
  59. regs = prop->value;
  60. if (((regs[0].phys_hi >> 8) & 0xff) == pdev->devfn) {
  61. *pregs = regs;
  62. *nregs = len / sizeof(struct linux_prom_pci_registers);
  63. return dp;
  64. }
  65. do_next_sibling:
  66. dp = dp->sibling;
  67. }
  68. return NULL;
  69. }
  70. /* Older versions of OBP on PCI systems encode 64-bit MEM
  71. * space assignments incorrectly, this fixes them up. We also
  72. * take the opportunity here to hide other kinds of bogus
  73. * assignments.
  74. */
  75. static void __init fixup_obp_assignments(struct pci_dev *pdev,
  76. struct pcidev_cookie *pcp)
  77. {
  78. int i;
  79. if (pdev->vendor == PCI_VENDOR_ID_AL &&
  80. (pdev->device == PCI_DEVICE_ID_AL_M7101 ||
  81. pdev->device == PCI_DEVICE_ID_AL_M1533)) {
  82. int i;
  83. /* Zap all of the normal resources, they are
  84. * meaningless and generate bogus resource collision
  85. * messages. This is OpenBoot's ill-fated attempt to
  86. * represent the implicit resources that these devices
  87. * have.
  88. */
  89. pcp->num_prom_assignments = 0;
  90. for (i = 0; i < 6; i++) {
  91. pdev->resource[i].start =
  92. pdev->resource[i].end =
  93. pdev->resource[i].flags = 0;
  94. }
  95. pdev->resource[PCI_ROM_RESOURCE].start =
  96. pdev->resource[PCI_ROM_RESOURCE].end =
  97. pdev->resource[PCI_ROM_RESOURCE].flags = 0;
  98. return;
  99. }
  100. for (i = 0; i < pcp->num_prom_assignments; i++) {
  101. struct linux_prom_pci_registers *ap;
  102. int space;
  103. ap = &pcp->prom_assignments[i];
  104. space = ap->phys_hi >> 24;
  105. if ((space & 0x3) == 2 &&
  106. (space & 0x4) != 0) {
  107. ap->phys_hi &= ~(0x7 << 24);
  108. ap->phys_hi |= 0x3 << 24;
  109. }
  110. }
  111. }
  112. /* Fill in the PCI device cookie sysdata for the given
  113. * PCI device. This cookie is the means by which one
  114. * can get to OBP and PCI controller specific information
  115. * for a PCI device.
  116. */
  117. static void __init pdev_cookie_fillin(struct pci_pbm_info *pbm,
  118. struct pci_dev *pdev,
  119. struct device_node *bus_node)
  120. {
  121. struct linux_prom_pci_registers *pregs = NULL;
  122. struct pcidev_cookie *pcp;
  123. struct device_node *dp;
  124. struct property *prop;
  125. int nregs, len;
  126. dp = find_device_prom_node(pbm, pdev, bus_node,
  127. &pregs, &nregs);
  128. if (!dp) {
  129. /* If it is not in the OBP device tree then
  130. * there must be a damn good reason for it.
  131. *
  132. * So what we do is delete the device from the
  133. * PCI device tree completely. This scenario
  134. * is seen, for example, on CP1500 for the
  135. * second EBUS/HappyMeal pair if the external
  136. * connector for it is not present.
  137. */
  138. pci_remove_bus_device(pdev);
  139. return;
  140. }
  141. pcp = kzalloc(sizeof(*pcp), GFP_ATOMIC);
  142. if (pcp == NULL) {
  143. prom_printf("PCI_COOKIE: Fatal malloc error, aborting...\n");
  144. prom_halt();
  145. }
  146. pcp->pbm = pbm;
  147. pcp->prom_node = dp;
  148. pcp->op = of_find_device_by_node(dp);
  149. memcpy(pcp->prom_regs, pregs,
  150. nregs * sizeof(struct linux_prom_pci_registers));
  151. pcp->num_prom_regs = nregs;
  152. /* We can't have the pcidev_cookie assignments be just
  153. * direct pointers into the property value, since they
  154. * are potentially modified by the probing process.
  155. */
  156. prop = of_find_property(dp, "assigned-addresses", &len);
  157. if (!prop) {
  158. pcp->num_prom_assignments = 0;
  159. } else {
  160. memcpy(pcp->prom_assignments, prop->value, len);
  161. pcp->num_prom_assignments =
  162. (len / sizeof(pcp->prom_assignments[0]));
  163. }
  164. if (strcmp(dp->name, "ebus") == 0) {
  165. struct linux_prom_ebus_ranges *erng;
  166. int iter;
  167. /* EBUS is special... */
  168. prop = of_find_property(dp, "ranges", &len);
  169. if (!prop) {
  170. prom_printf("EBUS: Fatal error, no range property\n");
  171. prom_halt();
  172. }
  173. erng = prop->value;
  174. len = (len / sizeof(erng[0]));
  175. for (iter = 0; iter < len; iter++) {
  176. struct linux_prom_ebus_ranges *ep = &erng[iter];
  177. struct linux_prom_pci_registers *ap;
  178. ap = &pcp->prom_assignments[iter];
  179. ap->phys_hi = ep->parent_phys_hi;
  180. ap->phys_mid = ep->parent_phys_mid;
  181. ap->phys_lo = ep->parent_phys_lo;
  182. ap->size_hi = 0;
  183. ap->size_lo = ep->size;
  184. }
  185. pcp->num_prom_assignments = len;
  186. }
  187. fixup_obp_assignments(pdev, pcp);
  188. pdev->sysdata = pcp;
  189. }
  190. void __init pci_fill_in_pbm_cookies(struct pci_bus *pbus,
  191. struct pci_pbm_info *pbm,
  192. struct device_node *dp)
  193. {
  194. struct pci_dev *pdev, *pdev_next;
  195. struct pci_bus *this_pbus, *pbus_next;
  196. /* This must be _safe because the cookie fillin
  197. routine can delete devices from the tree. */
  198. list_for_each_entry_safe(pdev, pdev_next, &pbus->devices, bus_list)
  199. pdev_cookie_fillin(pbm, pdev, dp);
  200. list_for_each_entry_safe(this_pbus, pbus_next, &pbus->children, node) {
  201. struct pcidev_cookie *pcp = this_pbus->self->sysdata;
  202. pci_fill_in_pbm_cookies(this_pbus, pbm, pcp->prom_node);
  203. }
  204. }
  205. static void __init bad_assignment(struct pci_dev *pdev,
  206. struct linux_prom_pci_registers *ap,
  207. struct resource *res,
  208. int do_prom_halt)
  209. {
  210. prom_printf("PCI: Bogus PROM assignment. BUS[%02x] DEVFN[%x]\n",
  211. pdev->bus->number, pdev->devfn);
  212. if (ap)
  213. prom_printf("PCI: phys[%08x:%08x:%08x] size[%08x:%08x]\n",
  214. ap->phys_hi, ap->phys_mid, ap->phys_lo,
  215. ap->size_hi, ap->size_lo);
  216. if (res)
  217. prom_printf("PCI: RES[%016lx-->%016lx:(%lx)]\n",
  218. res->start, res->end, res->flags);
  219. if (do_prom_halt)
  220. prom_halt();
  221. }
  222. static struct resource *
  223. __init get_root_resource(struct linux_prom_pci_registers *ap,
  224. struct pci_pbm_info *pbm)
  225. {
  226. int space = (ap->phys_hi >> 24) & 3;
  227. switch (space) {
  228. case 0:
  229. /* Configuration space, silently ignore it. */
  230. return NULL;
  231. case 1:
  232. /* 16-bit IO space */
  233. return &pbm->io_space;
  234. case 2:
  235. /* 32-bit MEM space */
  236. return &pbm->mem_space;
  237. case 3:
  238. /* 64-bit MEM space, these are allocated out of
  239. * the 32-bit mem_space range for the PBM, ie.
  240. * we just zero out the upper 32-bits.
  241. */
  242. return &pbm->mem_space;
  243. default:
  244. printk("PCI: What is resource space %x?\n", space);
  245. return NULL;
  246. };
  247. }
  248. static struct resource *
  249. __init get_device_resource(struct linux_prom_pci_registers *ap,
  250. struct pci_dev *pdev)
  251. {
  252. struct resource *res;
  253. int breg = (ap->phys_hi & 0xff);
  254. switch (breg) {
  255. case PCI_ROM_ADDRESS:
  256. /* Unfortunately I have seen several cases where
  257. * buggy FCODE uses a space value of '1' (I/O space)
  258. * in the register property for the ROM address
  259. * so disable this sanity check for now.
  260. */
  261. #if 0
  262. {
  263. int space = (ap->phys_hi >> 24) & 3;
  264. /* It had better be MEM space. */
  265. if (space != 2)
  266. bad_assignment(pdev, ap, NULL, 0);
  267. }
  268. #endif
  269. res = &pdev->resource[PCI_ROM_RESOURCE];
  270. break;
  271. case PCI_BASE_ADDRESS_0:
  272. case PCI_BASE_ADDRESS_1:
  273. case PCI_BASE_ADDRESS_2:
  274. case PCI_BASE_ADDRESS_3:
  275. case PCI_BASE_ADDRESS_4:
  276. case PCI_BASE_ADDRESS_5:
  277. res = &pdev->resource[(breg - PCI_BASE_ADDRESS_0) / 4];
  278. break;
  279. default:
  280. bad_assignment(pdev, ap, NULL, 0);
  281. res = NULL;
  282. break;
  283. };
  284. return res;
  285. }
  286. static void __init pdev_record_assignments(struct pci_pbm_info *pbm,
  287. struct pci_dev *pdev)
  288. {
  289. struct pcidev_cookie *pcp = pdev->sysdata;
  290. int i;
  291. for (i = 0; i < pcp->num_prom_assignments; i++) {
  292. struct linux_prom_pci_registers *ap;
  293. struct resource *root, *res;
  294. /* The format of this property is specified in
  295. * the PCI Bus Binding to IEEE1275-1994.
  296. */
  297. ap = &pcp->prom_assignments[i];
  298. root = get_root_resource(ap, pbm);
  299. res = get_device_resource(ap, pdev);
  300. if (root == NULL || res == NULL ||
  301. res->flags == 0)
  302. continue;
  303. /* Ok we know which resource this PROM assignment is
  304. * for, sanity check it.
  305. */
  306. if ((res->start & 0xffffffffUL) != ap->phys_lo)
  307. bad_assignment(pdev, ap, res, 1);
  308. /* If it is a 64-bit MEM space assignment, verify that
  309. * the resource is too and that the upper 32-bits match.
  310. */
  311. if (((ap->phys_hi >> 24) & 3) == 3) {
  312. if (((res->flags & IORESOURCE_MEM) == 0) ||
  313. ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  314. != PCI_BASE_ADDRESS_MEM_TYPE_64))
  315. bad_assignment(pdev, ap, res, 1);
  316. if ((res->start >> 32) != ap->phys_mid)
  317. bad_assignment(pdev, ap, res, 1);
  318. /* PBM cannot generate cpu initiated PIOs
  319. * to the full 64-bit space. Therefore the
  320. * upper 32-bits better be zero. If it is
  321. * not, just skip it and we will assign it
  322. * properly ourselves.
  323. */
  324. if ((res->start >> 32) != 0UL) {
  325. printk(KERN_ERR "PCI: OBP assigns out of range MEM address "
  326. "%016lx for region %ld on device %s\n",
  327. res->start, (res - &pdev->resource[0]), pci_name(pdev));
  328. continue;
  329. }
  330. }
  331. /* Adjust the resource into the physical address space
  332. * of this PBM.
  333. */
  334. pbm->parent->resource_adjust(pdev, res, root);
  335. if (request_resource(root, res) < 0) {
  336. int rnum;
  337. /* OK, there is some conflict. But this is fine
  338. * since we'll reassign it in the fixup pass.
  339. *
  340. * Do not print the warning for ROM resources
  341. * as such a conflict is quite common and
  342. * harmless as the ROM bar is disabled.
  343. */
  344. rnum = (res - &pdev->resource[0]);
  345. if (rnum != PCI_ROM_RESOURCE)
  346. printk(KERN_ERR "PCI: Resource collision, "
  347. "region %d "
  348. "[%016lx:%016lx] of device %s\n",
  349. rnum,
  350. res->start, res->end,
  351. pci_name(pdev));
  352. }
  353. }
  354. }
  355. void __init pci_record_assignments(struct pci_pbm_info *pbm,
  356. struct pci_bus *pbus)
  357. {
  358. struct pci_dev *dev;
  359. struct pci_bus *bus;
  360. list_for_each_entry(dev, &pbus->devices, bus_list)
  361. pdev_record_assignments(pbm, dev);
  362. list_for_each_entry(bus, &pbus->children, node)
  363. pci_record_assignments(pbm, bus);
  364. }
  365. /* Return non-zero if PDEV has implicit I/O resources even
  366. * though it may not have an I/O base address register
  367. * active.
  368. */
  369. static int __init has_implicit_io(struct pci_dev *pdev)
  370. {
  371. int class = pdev->class >> 8;
  372. if (class == PCI_CLASS_NOT_DEFINED ||
  373. class == PCI_CLASS_NOT_DEFINED_VGA ||
  374. class == PCI_CLASS_STORAGE_IDE ||
  375. (pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY)
  376. return 1;
  377. return 0;
  378. }
  379. static void __init pdev_assign_unassigned(struct pci_pbm_info *pbm,
  380. struct pci_dev *pdev)
  381. {
  382. u32 reg;
  383. u16 cmd;
  384. int i, io_seen, mem_seen;
  385. io_seen = mem_seen = 0;
  386. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  387. struct resource *root, *res;
  388. unsigned long size, min, max, align;
  389. res = &pdev->resource[i];
  390. if (res->flags & IORESOURCE_IO)
  391. io_seen++;
  392. else if (res->flags & IORESOURCE_MEM)
  393. mem_seen++;
  394. /* If it is already assigned or the resource does
  395. * not exist, there is nothing to do.
  396. */
  397. if (res->parent != NULL || res->flags == 0UL)
  398. continue;
  399. /* Determine the root we allocate from. */
  400. if (res->flags & IORESOURCE_IO) {
  401. root = &pbm->io_space;
  402. min = root->start + 0x400UL;
  403. max = root->end;
  404. } else {
  405. root = &pbm->mem_space;
  406. min = root->start;
  407. max = min + 0x80000000UL;
  408. }
  409. size = res->end - res->start;
  410. align = size + 1;
  411. if (allocate_resource(root, res, size + 1, min, max, align, NULL, NULL) < 0) {
  412. /* uh oh */
  413. prom_printf("PCI: Failed to allocate resource %d for %s\n",
  414. i, pci_name(pdev));
  415. prom_halt();
  416. }
  417. /* Update PCI config space. */
  418. pbm->parent->base_address_update(pdev, i);
  419. }
  420. /* Special case, disable the ROM. Several devices
  421. * act funny (ie. do not respond to memory space writes)
  422. * when it is left enabled. A good example are Qlogic,ISP
  423. * adapters.
  424. */
  425. pci_read_config_dword(pdev, PCI_ROM_ADDRESS, &reg);
  426. reg &= ~PCI_ROM_ADDRESS_ENABLE;
  427. pci_write_config_dword(pdev, PCI_ROM_ADDRESS, reg);
  428. /* If we saw I/O or MEM resources, enable appropriate
  429. * bits in PCI command register.
  430. */
  431. if (io_seen || mem_seen) {
  432. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  433. if (io_seen || has_implicit_io(pdev))
  434. cmd |= PCI_COMMAND_IO;
  435. if (mem_seen)
  436. cmd |= PCI_COMMAND_MEMORY;
  437. pci_write_config_word(pdev, PCI_COMMAND, cmd);
  438. }
  439. /* If this is a PCI bridge or an IDE controller,
  440. * enable bus mastering. In the former case also
  441. * set the cache line size correctly.
  442. */
  443. if (((pdev->class >> 8) == PCI_CLASS_BRIDGE_PCI) ||
  444. (((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) &&
  445. ((pdev->class & 0x80) != 0))) {
  446. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  447. cmd |= PCI_COMMAND_MASTER;
  448. pci_write_config_word(pdev, PCI_COMMAND, cmd);
  449. if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_PCI)
  450. pci_write_config_byte(pdev,
  451. PCI_CACHE_LINE_SIZE,
  452. (64 / sizeof(u32)));
  453. }
  454. }
  455. void __init pci_assign_unassigned(struct pci_pbm_info *pbm,
  456. struct pci_bus *pbus)
  457. {
  458. struct pci_dev *dev;
  459. struct pci_bus *bus;
  460. list_for_each_entry(dev, &pbus->devices, bus_list)
  461. pdev_assign_unassigned(pbm, dev);
  462. list_for_each_entry(bus, &pbus->children, node)
  463. pci_assign_unassigned(pbm, bus);
  464. }
  465. static void __init pdev_fixup_irq(struct pci_dev *pdev)
  466. {
  467. struct pcidev_cookie *pcp = pdev->sysdata;
  468. struct of_device *op = pcp->op;
  469. if (op->irqs[0] == 0xffffffff) {
  470. pdev->irq = PCI_IRQ_NONE;
  471. return;
  472. }
  473. pdev->irq = op->irqs[0];
  474. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
  475. pdev->irq & PCI_IRQ_INO);
  476. }
  477. void __init pci_fixup_irq(struct pci_pbm_info *pbm,
  478. struct pci_bus *pbus)
  479. {
  480. struct pci_dev *dev;
  481. struct pci_bus *bus;
  482. list_for_each_entry(dev, &pbus->devices, bus_list)
  483. pdev_fixup_irq(dev);
  484. list_for_each_entry(bus, &pbus->children, node)
  485. pci_fixup_irq(pbm, bus);
  486. }
  487. static void pdev_setup_busmastering(struct pci_dev *pdev, int is_66mhz)
  488. {
  489. u16 cmd;
  490. u8 hdr_type, min_gnt, ltimer;
  491. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  492. cmd |= PCI_COMMAND_MASTER;
  493. pci_write_config_word(pdev, PCI_COMMAND, cmd);
  494. /* Read it back, if the mastering bit did not
  495. * get set, the device does not support bus
  496. * mastering so we have nothing to do here.
  497. */
  498. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  499. if ((cmd & PCI_COMMAND_MASTER) == 0)
  500. return;
  501. /* Set correct cache line size, 64-byte on all
  502. * Sparc64 PCI systems. Note that the value is
  503. * measured in 32-bit words.
  504. */
  505. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  506. 64 / sizeof(u32));
  507. pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr_type);
  508. hdr_type &= ~0x80;
  509. if (hdr_type != PCI_HEADER_TYPE_NORMAL)
  510. return;
  511. /* If the latency timer is already programmed with a non-zero
  512. * value, assume whoever set it (OBP or whoever) knows what
  513. * they are doing.
  514. */
  515. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &ltimer);
  516. if (ltimer != 0)
  517. return;
  518. /* XXX Since I'm tipping off the min grant value to
  519. * XXX choose a suitable latency timer value, I also
  520. * XXX considered making use of the max latency value
  521. * XXX as well. Unfortunately I've seen too many bogusly
  522. * XXX low settings for it to the point where it lacks
  523. * XXX any usefulness. In one case, an ethernet card
  524. * XXX claimed a min grant of 10 and a max latency of 5.
  525. * XXX Now, if I had two such cards on the same bus I
  526. * XXX could not set the desired burst period (calculated
  527. * XXX from min grant) without violating the max latency
  528. * XXX bound. Duh...
  529. * XXX
  530. * XXX I blame dumb PC bios implementors for stuff like
  531. * XXX this, most of them don't even try to do something
  532. * XXX sensible with latency timer values and just set some
  533. * XXX default value (usually 32) into every device.
  534. */
  535. pci_read_config_byte(pdev, PCI_MIN_GNT, &min_gnt);
  536. if (min_gnt == 0) {
  537. /* If no min_gnt setting then use a default
  538. * value.
  539. */
  540. if (is_66mhz)
  541. ltimer = 16;
  542. else
  543. ltimer = 32;
  544. } else {
  545. int shift_factor;
  546. if (is_66mhz)
  547. shift_factor = 2;
  548. else
  549. shift_factor = 3;
  550. /* Use a default value when the min_gnt value
  551. * is erroneously high.
  552. */
  553. if (((unsigned int) min_gnt << shift_factor) > 512 ||
  554. ((min_gnt << shift_factor) & 0xff) == 0) {
  555. ltimer = 8 << shift_factor;
  556. } else {
  557. ltimer = min_gnt << shift_factor;
  558. }
  559. }
  560. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, ltimer);
  561. }
  562. void pci_determine_66mhz_disposition(struct pci_pbm_info *pbm,
  563. struct pci_bus *pbus)
  564. {
  565. struct pci_dev *pdev;
  566. int all_are_66mhz;
  567. u16 status;
  568. if (pbm->is_66mhz_capable == 0) {
  569. all_are_66mhz = 0;
  570. goto out;
  571. }
  572. all_are_66mhz = 1;
  573. list_for_each_entry(pdev, &pbus->devices, bus_list) {
  574. pci_read_config_word(pdev, PCI_STATUS, &status);
  575. if (!(status & PCI_STATUS_66MHZ)) {
  576. all_are_66mhz = 0;
  577. break;
  578. }
  579. }
  580. out:
  581. pbm->all_devs_66mhz = all_are_66mhz;
  582. printk("PCI%d(PBM%c): Bus running at %dMHz\n",
  583. pbm->parent->index,
  584. (pbm == &pbm->parent->pbm_A) ? 'A' : 'B',
  585. (all_are_66mhz ? 66 : 33));
  586. }
  587. void pci_setup_busmastering(struct pci_pbm_info *pbm,
  588. struct pci_bus *pbus)
  589. {
  590. struct pci_dev *dev;
  591. struct pci_bus *bus;
  592. int is_66mhz;
  593. is_66mhz = pbm->is_66mhz_capable && pbm->all_devs_66mhz;
  594. list_for_each_entry(dev, &pbus->devices, bus_list)
  595. pdev_setup_busmastering(dev, is_66mhz);
  596. list_for_each_entry(bus, &pbus->children, node)
  597. pci_setup_busmastering(pbm, bus);
  598. }
  599. void pci_register_legacy_regions(struct resource *io_res,
  600. struct resource *mem_res)
  601. {
  602. struct resource *p;
  603. /* VGA Video RAM. */
  604. p = kzalloc(sizeof(*p), GFP_KERNEL);
  605. if (!p)
  606. return;
  607. p->name = "Video RAM area";
  608. p->start = mem_res->start + 0xa0000UL;
  609. p->end = p->start + 0x1ffffUL;
  610. p->flags = IORESOURCE_BUSY;
  611. request_resource(mem_res, p);
  612. p = kzalloc(sizeof(*p), GFP_KERNEL);
  613. if (!p)
  614. return;
  615. p->name = "System ROM";
  616. p->start = mem_res->start + 0xf0000UL;
  617. p->end = p->start + 0xffffUL;
  618. p->flags = IORESOURCE_BUSY;
  619. request_resource(mem_res, p);
  620. p = kzalloc(sizeof(*p), GFP_KERNEL);
  621. if (!p)
  622. return;
  623. p->name = "Video ROM";
  624. p->start = mem_res->start + 0xc0000UL;
  625. p->end = p->start + 0x7fffUL;
  626. p->flags = IORESOURCE_BUSY;
  627. request_resource(mem_res, p);
  628. }
  629. /* Generic helper routines for PCI error reporting. */
  630. void pci_scan_for_target_abort(struct pci_controller_info *p,
  631. struct pci_pbm_info *pbm,
  632. struct pci_bus *pbus)
  633. {
  634. struct pci_dev *pdev;
  635. struct pci_bus *bus;
  636. list_for_each_entry(pdev, &pbus->devices, bus_list) {
  637. u16 status, error_bits;
  638. pci_read_config_word(pdev, PCI_STATUS, &status);
  639. error_bits =
  640. (status & (PCI_STATUS_SIG_TARGET_ABORT |
  641. PCI_STATUS_REC_TARGET_ABORT));
  642. if (error_bits) {
  643. pci_write_config_word(pdev, PCI_STATUS, error_bits);
  644. printk("PCI%d(PBM%c): Device [%s] saw Target Abort [%016x]\n",
  645. p->index, ((pbm == &p->pbm_A) ? 'A' : 'B'),
  646. pci_name(pdev), status);
  647. }
  648. }
  649. list_for_each_entry(bus, &pbus->children, node)
  650. pci_scan_for_target_abort(p, pbm, bus);
  651. }
  652. void pci_scan_for_master_abort(struct pci_controller_info *p,
  653. struct pci_pbm_info *pbm,
  654. struct pci_bus *pbus)
  655. {
  656. struct pci_dev *pdev;
  657. struct pci_bus *bus;
  658. list_for_each_entry(pdev, &pbus->devices, bus_list) {
  659. u16 status, error_bits;
  660. pci_read_config_word(pdev, PCI_STATUS, &status);
  661. error_bits =
  662. (status & (PCI_STATUS_REC_MASTER_ABORT));
  663. if (error_bits) {
  664. pci_write_config_word(pdev, PCI_STATUS, error_bits);
  665. printk("PCI%d(PBM%c): Device [%s] received Master Abort [%016x]\n",
  666. p->index, ((pbm == &p->pbm_A) ? 'A' : 'B'),
  667. pci_name(pdev), status);
  668. }
  669. }
  670. list_for_each_entry(bus, &pbus->children, node)
  671. pci_scan_for_master_abort(p, pbm, bus);
  672. }
  673. void pci_scan_for_parity_error(struct pci_controller_info *p,
  674. struct pci_pbm_info *pbm,
  675. struct pci_bus *pbus)
  676. {
  677. struct pci_dev *pdev;
  678. struct pci_bus *bus;
  679. list_for_each_entry(pdev, &pbus->devices, bus_list) {
  680. u16 status, error_bits;
  681. pci_read_config_word(pdev, PCI_STATUS, &status);
  682. error_bits =
  683. (status & (PCI_STATUS_PARITY |
  684. PCI_STATUS_DETECTED_PARITY));
  685. if (error_bits) {
  686. pci_write_config_word(pdev, PCI_STATUS, error_bits);
  687. printk("PCI%d(PBM%c): Device [%s] saw Parity Error [%016x]\n",
  688. p->index, ((pbm == &p->pbm_A) ? 'A' : 'B'),
  689. pci_name(pdev), status);
  690. }
  691. }
  692. list_for_each_entry(bus, &pbus->children, node)
  693. pci_scan_for_parity_error(p, pbm, bus);
  694. }