pci.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. /*
  2. * Support for PCI bridges found on Power Macintoshes.
  3. *
  4. * Copyright (C) 2003-2005 Benjamin Herrenschmuidt (benh@kernel.crashing.org)
  5. * Copyright (C) 1997 Paul Mackerras (paulus@samba.org)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/delay.h>
  15. #include <linux/string.h>
  16. #include <linux/init.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/irq.h>
  19. #include <asm/sections.h>
  20. #include <asm/io.h>
  21. #include <asm/prom.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/machdep.h>
  24. #include <asm/pmac_feature.h>
  25. #include <asm/grackle.h>
  26. #include <asm/ppc-pci.h>
  27. #undef DEBUG
  28. #ifdef DEBUG
  29. #define DBG(x...) printk(x)
  30. #else
  31. #define DBG(x...)
  32. #endif
  33. /* XXX Could be per-controller, but I don't think we risk anything by
  34. * assuming we won't have both UniNorth and Bandit */
  35. static int has_uninorth;
  36. #ifdef CONFIG_PPC64
  37. static struct pci_controller *u3_agp;
  38. #else
  39. static int has_second_ohare;
  40. #endif /* CONFIG_PPC64 */
  41. extern int pcibios_assign_bus_offset;
  42. struct device_node *k2_skiplist[2];
  43. /*
  44. * Magic constants for enabling cache coherency in the bandit/PSX bridge.
  45. */
  46. #define BANDIT_DEVID_2 8
  47. #define BANDIT_REVID 3
  48. #define BANDIT_DEVNUM 11
  49. #define BANDIT_MAGIC 0x50
  50. #define BANDIT_COHERENT 0x40
  51. static int __init fixup_one_level_bus_range(struct device_node *node, int higher)
  52. {
  53. for (; node != 0;node = node->sibling) {
  54. const int * bus_range;
  55. const unsigned int *class_code;
  56. int len;
  57. /* For PCI<->PCI bridges or CardBus bridges, we go down */
  58. class_code = of_get_property(node, "class-code", NULL);
  59. if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
  60. (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
  61. continue;
  62. bus_range = of_get_property(node, "bus-range", &len);
  63. if (bus_range != NULL && len > 2 * sizeof(int)) {
  64. if (bus_range[1] > higher)
  65. higher = bus_range[1];
  66. }
  67. higher = fixup_one_level_bus_range(node->child, higher);
  68. }
  69. return higher;
  70. }
  71. /* This routine fixes the "bus-range" property of all bridges in the
  72. * system since they tend to have their "last" member wrong on macs
  73. *
  74. * Note that the bus numbers manipulated here are OF bus numbers, they
  75. * are not Linux bus numbers.
  76. */
  77. static void __init fixup_bus_range(struct device_node *bridge)
  78. {
  79. int *bus_range, len;
  80. struct property *prop;
  81. /* Lookup the "bus-range" property for the hose */
  82. prop = of_find_property(bridge, "bus-range", &len);
  83. if (prop == NULL || prop->length < 2 * sizeof(int))
  84. return;
  85. bus_range = prop->value;
  86. bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);
  87. }
  88. /*
  89. * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers.
  90. *
  91. * The "Bandit" version is present in all early PCI PowerMacs,
  92. * and up to the first ones using Grackle. Some machines may
  93. * have 2 bandit controllers (2 PCI busses).
  94. *
  95. * "Chaos" is used in some "Bandit"-type machines as a bridge
  96. * for the separate display bus. It is accessed the same
  97. * way as bandit, but cannot be probed for devices. It therefore
  98. * has its own config access functions.
  99. *
  100. * The "UniNorth" version is present in all Core99 machines
  101. * (iBook, G4, new IMacs, and all the recent Apple machines).
  102. * It contains 3 controllers in one ASIC.
  103. *
  104. * The U3 is the bridge used on G5 machines. It contains an
  105. * AGP bus which is dealt with the old UniNorth access routines
  106. * and a HyperTransport bus which uses its own set of access
  107. * functions.
  108. */
  109. #define MACRISC_CFA0(devfn, off) \
  110. ((1 << (unsigned int)PCI_SLOT(dev_fn)) \
  111. | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
  112. | (((unsigned int)(off)) & 0xFCUL))
  113. #define MACRISC_CFA1(bus, devfn, off) \
  114. ((((unsigned int)(bus)) << 16) \
  115. |(((unsigned int)(devfn)) << 8) \
  116. |(((unsigned int)(off)) & 0xFCUL) \
  117. |1UL)
  118. static volatile void __iomem *macrisc_cfg_access(struct pci_controller* hose,
  119. u8 bus, u8 dev_fn, u8 offset)
  120. {
  121. unsigned int caddr;
  122. if (bus == hose->first_busno) {
  123. if (dev_fn < (11 << 3))
  124. return NULL;
  125. caddr = MACRISC_CFA0(dev_fn, offset);
  126. } else
  127. caddr = MACRISC_CFA1(bus, dev_fn, offset);
  128. /* Uninorth will return garbage if we don't read back the value ! */
  129. do {
  130. out_le32(hose->cfg_addr, caddr);
  131. } while (in_le32(hose->cfg_addr) != caddr);
  132. offset &= has_uninorth ? 0x07 : 0x03;
  133. return hose->cfg_data + offset;
  134. }
  135. static int macrisc_read_config(struct pci_bus *bus, unsigned int devfn,
  136. int offset, int len, u32 *val)
  137. {
  138. struct pci_controller *hose;
  139. volatile void __iomem *addr;
  140. hose = pci_bus_to_host(bus);
  141. if (hose == NULL)
  142. return PCIBIOS_DEVICE_NOT_FOUND;
  143. if (offset >= 0x100)
  144. return PCIBIOS_BAD_REGISTER_NUMBER;
  145. addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
  146. if (!addr)
  147. return PCIBIOS_DEVICE_NOT_FOUND;
  148. /*
  149. * Note: the caller has already checked that offset is
  150. * suitably aligned and that len is 1, 2 or 4.
  151. */
  152. switch (len) {
  153. case 1:
  154. *val = in_8(addr);
  155. break;
  156. case 2:
  157. *val = in_le16(addr);
  158. break;
  159. default:
  160. *val = in_le32(addr);
  161. break;
  162. }
  163. return PCIBIOS_SUCCESSFUL;
  164. }
  165. static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn,
  166. int offset, int len, u32 val)
  167. {
  168. struct pci_controller *hose;
  169. volatile void __iomem *addr;
  170. hose = pci_bus_to_host(bus);
  171. if (hose == NULL)
  172. return PCIBIOS_DEVICE_NOT_FOUND;
  173. if (offset >= 0x100)
  174. return PCIBIOS_BAD_REGISTER_NUMBER;
  175. addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
  176. if (!addr)
  177. return PCIBIOS_DEVICE_NOT_FOUND;
  178. /*
  179. * Note: the caller has already checked that offset is
  180. * suitably aligned and that len is 1, 2 or 4.
  181. */
  182. switch (len) {
  183. case 1:
  184. out_8(addr, val);
  185. break;
  186. case 2:
  187. out_le16(addr, val);
  188. break;
  189. default:
  190. out_le32(addr, val);
  191. break;
  192. }
  193. return PCIBIOS_SUCCESSFUL;
  194. }
  195. static struct pci_ops macrisc_pci_ops =
  196. {
  197. .read = macrisc_read_config,
  198. .write = macrisc_write_config,
  199. };
  200. #ifdef CONFIG_PPC32
  201. /*
  202. * Verify that a specific (bus, dev_fn) exists on chaos
  203. */
  204. static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset)
  205. {
  206. struct device_node *np;
  207. const u32 *vendor, *device;
  208. if (offset >= 0x100)
  209. return PCIBIOS_BAD_REGISTER_NUMBER;
  210. np = pci_busdev_to_OF_node(bus, devfn);
  211. if (np == NULL)
  212. return PCIBIOS_DEVICE_NOT_FOUND;
  213. vendor = of_get_property(np, "vendor-id", NULL);
  214. device = of_get_property(np, "device-id", NULL);
  215. if (vendor == NULL || device == NULL)
  216. return PCIBIOS_DEVICE_NOT_FOUND;
  217. if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10)
  218. && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24))
  219. return PCIBIOS_BAD_REGISTER_NUMBER;
  220. return PCIBIOS_SUCCESSFUL;
  221. }
  222. static int
  223. chaos_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  224. int len, u32 *val)
  225. {
  226. int result = chaos_validate_dev(bus, devfn, offset);
  227. if (result == PCIBIOS_BAD_REGISTER_NUMBER)
  228. *val = ~0U;
  229. if (result != PCIBIOS_SUCCESSFUL)
  230. return result;
  231. return macrisc_read_config(bus, devfn, offset, len, val);
  232. }
  233. static int
  234. chaos_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  235. int len, u32 val)
  236. {
  237. int result = chaos_validate_dev(bus, devfn, offset);
  238. if (result != PCIBIOS_SUCCESSFUL)
  239. return result;
  240. return macrisc_write_config(bus, devfn, offset, len, val);
  241. }
  242. static struct pci_ops chaos_pci_ops =
  243. {
  244. .read = chaos_read_config,
  245. .write = chaos_write_config,
  246. };
  247. static void __init setup_chaos(struct pci_controller *hose,
  248. struct resource *addr)
  249. {
  250. /* assume a `chaos' bridge */
  251. hose->ops = &chaos_pci_ops;
  252. hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
  253. hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
  254. }
  255. #endif /* CONFIG_PPC32 */
  256. #ifdef CONFIG_PPC64
  257. /*
  258. * These versions of U3 HyperTransport config space access ops do not
  259. * implement self-view of the HT host yet
  260. */
  261. /*
  262. * This function deals with some "special cases" devices.
  263. *
  264. * 0 -> No special case
  265. * 1 -> Skip the device but act as if the access was successful
  266. * (return 0xff's on reads, eventually, cache config space
  267. * accesses in a later version)
  268. * -1 -> Hide the device (unsuccessful access)
  269. */
  270. static int u3_ht_skip_device(struct pci_controller *hose,
  271. struct pci_bus *bus, unsigned int devfn)
  272. {
  273. struct device_node *busdn, *dn;
  274. int i;
  275. /* We only allow config cycles to devices that are in OF device-tree
  276. * as we are apparently having some weird things going on with some
  277. * revs of K2 on recent G5s, except for the host bridge itself, which
  278. * is missing from the tree but we know we can probe.
  279. */
  280. if (bus->self)
  281. busdn = pci_device_to_OF_node(bus->self);
  282. else if (devfn == 0)
  283. return 0;
  284. else
  285. busdn = hose->dn;
  286. for (dn = busdn->child; dn; dn = dn->sibling)
  287. if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn)
  288. break;
  289. if (dn == NULL)
  290. return -1;
  291. /*
  292. * When a device in K2 is powered down, we die on config
  293. * cycle accesses. Fix that here.
  294. */
  295. for (i=0; i<2; i++)
  296. if (k2_skiplist[i] == dn)
  297. return 1;
  298. return 0;
  299. }
  300. #define U3_HT_CFA0(devfn, off) \
  301. ((((unsigned int)devfn) << 8) | offset)
  302. #define U3_HT_CFA1(bus, devfn, off) \
  303. (U3_HT_CFA0(devfn, off) \
  304. + (((unsigned int)bus) << 16) \
  305. + 0x01000000UL)
  306. static void __iomem *u3_ht_cfg_access(struct pci_controller *hose, u8 bus,
  307. u8 devfn, u8 offset, int *swap)
  308. {
  309. *swap = 1;
  310. if (bus == hose->first_busno) {
  311. if (devfn != 0)
  312. return hose->cfg_data + U3_HT_CFA0(devfn, offset);
  313. *swap = 0;
  314. return ((void __iomem *)hose->cfg_addr) + (offset << 2);
  315. } else
  316. return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);
  317. }
  318. static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn,
  319. int offset, int len, u32 *val)
  320. {
  321. struct pci_controller *hose;
  322. void __iomem *addr;
  323. int swap;
  324. hose = pci_bus_to_host(bus);
  325. if (hose == NULL)
  326. return PCIBIOS_DEVICE_NOT_FOUND;
  327. if (offset >= 0x100)
  328. return PCIBIOS_BAD_REGISTER_NUMBER;
  329. addr = u3_ht_cfg_access(hose, bus->number, devfn, offset, &swap);
  330. if (!addr)
  331. return PCIBIOS_DEVICE_NOT_FOUND;
  332. switch (u3_ht_skip_device(hose, bus, devfn)) {
  333. case 0:
  334. break;
  335. case 1:
  336. switch (len) {
  337. case 1:
  338. *val = 0xff; break;
  339. case 2:
  340. *val = 0xffff; break;
  341. default:
  342. *val = 0xfffffffful; break;
  343. }
  344. return PCIBIOS_SUCCESSFUL;
  345. default:
  346. return PCIBIOS_DEVICE_NOT_FOUND;
  347. }
  348. /*
  349. * Note: the caller has already checked that offset is
  350. * suitably aligned and that len is 1, 2 or 4.
  351. */
  352. switch (len) {
  353. case 1:
  354. *val = in_8(addr);
  355. break;
  356. case 2:
  357. *val = swap ? in_le16(addr) : in_be16(addr);
  358. break;
  359. default:
  360. *val = swap ? in_le32(addr) : in_be32(addr);
  361. break;
  362. }
  363. return PCIBIOS_SUCCESSFUL;
  364. }
  365. static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
  366. int offset, int len, u32 val)
  367. {
  368. struct pci_controller *hose;
  369. void __iomem *addr;
  370. int swap;
  371. hose = pci_bus_to_host(bus);
  372. if (hose == NULL)
  373. return PCIBIOS_DEVICE_NOT_FOUND;
  374. if (offset >= 0x100)
  375. return PCIBIOS_BAD_REGISTER_NUMBER;
  376. addr = u3_ht_cfg_access(hose, bus->number, devfn, offset, &swap);
  377. if (!addr)
  378. return PCIBIOS_DEVICE_NOT_FOUND;
  379. switch (u3_ht_skip_device(hose, bus, devfn)) {
  380. case 0:
  381. break;
  382. case 1:
  383. return PCIBIOS_SUCCESSFUL;
  384. default:
  385. return PCIBIOS_DEVICE_NOT_FOUND;
  386. }
  387. /*
  388. * Note: the caller has already checked that offset is
  389. * suitably aligned and that len is 1, 2 or 4.
  390. */
  391. switch (len) {
  392. case 1:
  393. out_8(addr, val);
  394. break;
  395. case 2:
  396. swap ? out_le16(addr, val) : out_be16(addr, val);
  397. break;
  398. default:
  399. swap ? out_le32(addr, val) : out_be32(addr, val);
  400. break;
  401. }
  402. return PCIBIOS_SUCCESSFUL;
  403. }
  404. static struct pci_ops u3_ht_pci_ops =
  405. {
  406. .read = u3_ht_read_config,
  407. .write = u3_ht_write_config,
  408. };
  409. #define U4_PCIE_CFA0(devfn, off) \
  410. ((1 << ((unsigned int)PCI_SLOT(dev_fn))) \
  411. | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
  412. | ((((unsigned int)(off)) >> 8) << 28) \
  413. | (((unsigned int)(off)) & 0xfcU))
  414. #define U4_PCIE_CFA1(bus, devfn, off) \
  415. ((((unsigned int)(bus)) << 16) \
  416. |(((unsigned int)(devfn)) << 8) \
  417. | ((((unsigned int)(off)) >> 8) << 28) \
  418. |(((unsigned int)(off)) & 0xfcU) \
  419. |1UL)
  420. static volatile void __iomem *u4_pcie_cfg_access(struct pci_controller* hose,
  421. u8 bus, u8 dev_fn, int offset)
  422. {
  423. unsigned int caddr;
  424. if (bus == hose->first_busno) {
  425. caddr = U4_PCIE_CFA0(dev_fn, offset);
  426. } else
  427. caddr = U4_PCIE_CFA1(bus, dev_fn, offset);
  428. /* Uninorth will return garbage if we don't read back the value ! */
  429. do {
  430. out_le32(hose->cfg_addr, caddr);
  431. } while (in_le32(hose->cfg_addr) != caddr);
  432. offset &= 0x03;
  433. return hose->cfg_data + offset;
  434. }
  435. static int u4_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
  436. int offset, int len, u32 *val)
  437. {
  438. struct pci_controller *hose;
  439. volatile void __iomem *addr;
  440. hose = pci_bus_to_host(bus);
  441. if (hose == NULL)
  442. return PCIBIOS_DEVICE_NOT_FOUND;
  443. if (offset >= 0x1000)
  444. return PCIBIOS_BAD_REGISTER_NUMBER;
  445. addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
  446. if (!addr)
  447. return PCIBIOS_DEVICE_NOT_FOUND;
  448. /*
  449. * Note: the caller has already checked that offset is
  450. * suitably aligned and that len is 1, 2 or 4.
  451. */
  452. switch (len) {
  453. case 1:
  454. *val = in_8(addr);
  455. break;
  456. case 2:
  457. *val = in_le16(addr);
  458. break;
  459. default:
  460. *val = in_le32(addr);
  461. break;
  462. }
  463. return PCIBIOS_SUCCESSFUL;
  464. }
  465. static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
  466. int offset, int len, u32 val)
  467. {
  468. struct pci_controller *hose;
  469. volatile void __iomem *addr;
  470. hose = pci_bus_to_host(bus);
  471. if (hose == NULL)
  472. return PCIBIOS_DEVICE_NOT_FOUND;
  473. if (offset >= 0x1000)
  474. return PCIBIOS_BAD_REGISTER_NUMBER;
  475. addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
  476. if (!addr)
  477. return PCIBIOS_DEVICE_NOT_FOUND;
  478. /*
  479. * Note: the caller has already checked that offset is
  480. * suitably aligned and that len is 1, 2 or 4.
  481. */
  482. switch (len) {
  483. case 1:
  484. out_8(addr, val);
  485. break;
  486. case 2:
  487. out_le16(addr, val);
  488. break;
  489. default:
  490. out_le32(addr, val);
  491. break;
  492. }
  493. return PCIBIOS_SUCCESSFUL;
  494. }
  495. static struct pci_ops u4_pcie_pci_ops =
  496. {
  497. .read = u4_pcie_read_config,
  498. .write = u4_pcie_write_config,
  499. };
  500. #endif /* CONFIG_PPC64 */
  501. #ifdef CONFIG_PPC32
  502. /*
  503. * For a bandit bridge, turn on cache coherency if necessary.
  504. * N.B. we could clean this up using the hose ops directly.
  505. */
  506. static void __init init_bandit(struct pci_controller *bp)
  507. {
  508. unsigned int vendev, magic;
  509. int rev;
  510. /* read the word at offset 0 in config space for device 11 */
  511. out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + PCI_VENDOR_ID);
  512. udelay(2);
  513. vendev = in_le32(bp->cfg_data);
  514. if (vendev == (PCI_DEVICE_ID_APPLE_BANDIT << 16) +
  515. PCI_VENDOR_ID_APPLE) {
  516. /* read the revision id */
  517. out_le32(bp->cfg_addr,
  518. (1UL << BANDIT_DEVNUM) + PCI_REVISION_ID);
  519. udelay(2);
  520. rev = in_8(bp->cfg_data);
  521. if (rev != BANDIT_REVID)
  522. printk(KERN_WARNING
  523. "Unknown revision %d for bandit\n", rev);
  524. } else if (vendev != (BANDIT_DEVID_2 << 16) + PCI_VENDOR_ID_APPLE) {
  525. printk(KERN_WARNING "bandit isn't? (%x)\n", vendev);
  526. return;
  527. }
  528. /* read the word at offset 0x50 */
  529. out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + BANDIT_MAGIC);
  530. udelay(2);
  531. magic = in_le32(bp->cfg_data);
  532. if ((magic & BANDIT_COHERENT) != 0)
  533. return;
  534. magic |= BANDIT_COHERENT;
  535. udelay(2);
  536. out_le32(bp->cfg_data, magic);
  537. printk(KERN_INFO "Cache coherency enabled for bandit/PSX\n");
  538. }
  539. /*
  540. * Tweak the PCI-PCI bridge chip on the blue & white G3s.
  541. */
  542. static void __init init_p2pbridge(void)
  543. {
  544. struct device_node *p2pbridge;
  545. struct pci_controller* hose;
  546. u8 bus, devfn;
  547. u16 val;
  548. /* XXX it would be better here to identify the specific
  549. PCI-PCI bridge chip we have. */
  550. p2pbridge = of_find_node_by_name(NULL, "pci-bridge");
  551. if (p2pbridge == NULL
  552. || p2pbridge->parent == NULL
  553. || strcmp(p2pbridge->parent->name, "pci") != 0)
  554. goto done;
  555. if (pci_device_from_OF_node(p2pbridge, &bus, &devfn) < 0) {
  556. DBG("Can't find PCI infos for PCI<->PCI bridge\n");
  557. goto done;
  558. }
  559. /* Warning: At this point, we have not yet renumbered all busses.
  560. * So we must use OF walking to find out hose
  561. */
  562. hose = pci_find_hose_for_OF_device(p2pbridge);
  563. if (!hose) {
  564. DBG("Can't find hose for PCI<->PCI bridge\n");
  565. goto done;
  566. }
  567. if (early_read_config_word(hose, bus, devfn,
  568. PCI_BRIDGE_CONTROL, &val) < 0) {
  569. printk(KERN_ERR "init_p2pbridge: couldn't read bridge"
  570. " control\n");
  571. goto done;
  572. }
  573. val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
  574. early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val);
  575. done:
  576. of_node_put(p2pbridge);
  577. }
  578. static void __init init_second_ohare(void)
  579. {
  580. struct device_node *np = of_find_node_by_name(NULL, "pci106b,7");
  581. unsigned char bus, devfn;
  582. unsigned short cmd;
  583. if (np == NULL)
  584. return;
  585. /* This must run before we initialize the PICs since the second
  586. * ohare hosts a PIC that will be accessed there.
  587. */
  588. if (pci_device_from_OF_node(np, &bus, &devfn) == 0) {
  589. struct pci_controller* hose =
  590. pci_find_hose_for_OF_device(np);
  591. if (!hose) {
  592. printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
  593. of_node_put(np);
  594. return;
  595. }
  596. early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
  597. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  598. cmd &= ~PCI_COMMAND_IO;
  599. early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
  600. }
  601. has_second_ohare = 1;
  602. of_node_put(np);
  603. }
  604. /*
  605. * Some Apple desktop machines have a NEC PD720100A USB2 controller
  606. * on the motherboard. Open Firmware, on these, will disable the
  607. * EHCI part of it so it behaves like a pair of OHCI's. This fixup
  608. * code re-enables it ;)
  609. */
  610. static void __init fixup_nec_usb2(void)
  611. {
  612. struct device_node *nec;
  613. for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) {
  614. struct pci_controller *hose;
  615. u32 data;
  616. const u32 *prop;
  617. u8 bus, devfn;
  618. prop = of_get_property(nec, "vendor-id", NULL);
  619. if (prop == NULL)
  620. continue;
  621. if (0x1033 != *prop)
  622. continue;
  623. prop = of_get_property(nec, "device-id", NULL);
  624. if (prop == NULL)
  625. continue;
  626. if (0x0035 != *prop)
  627. continue;
  628. prop = of_get_property(nec, "reg", NULL);
  629. if (prop == NULL)
  630. continue;
  631. devfn = (prop[0] >> 8) & 0xff;
  632. bus = (prop[0] >> 16) & 0xff;
  633. if (PCI_FUNC(devfn) != 0)
  634. continue;
  635. hose = pci_find_hose_for_OF_device(nec);
  636. if (!hose)
  637. continue;
  638. early_read_config_dword(hose, bus, devfn, 0xe4, &data);
  639. if (data & 1UL) {
  640. printk("Found NEC PD720100A USB2 chip with disabled"
  641. " EHCI, fixing up...\n");
  642. data &= ~1UL;
  643. early_write_config_dword(hose, bus, devfn, 0xe4, data);
  644. }
  645. }
  646. }
  647. static void __init setup_bandit(struct pci_controller *hose,
  648. struct resource *addr)
  649. {
  650. hose->ops = &macrisc_pci_ops;
  651. hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
  652. hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
  653. init_bandit(hose);
  654. }
  655. static int __init setup_uninorth(struct pci_controller *hose,
  656. struct resource *addr)
  657. {
  658. ppc_pci_add_flags(PPC_PCI_REASSIGN_ALL_BUS);
  659. has_uninorth = 1;
  660. hose->ops = &macrisc_pci_ops;
  661. hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
  662. hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
  663. /* We "know" that the bridge at f2000000 has the PCI slots. */
  664. return addr->start == 0xf2000000;
  665. }
  666. #endif /* CONFIG_PPC32 */
  667. #ifdef CONFIG_PPC64
  668. static void __init setup_u3_agp(struct pci_controller* hose)
  669. {
  670. /* On G5, we move AGP up to high bus number so we don't need
  671. * to reassign bus numbers for HT. If we ever have P2P bridges
  672. * on AGP, we'll have to move pci_assign_all_busses to the
  673. * pci_controller structure so we enable it for AGP and not for
  674. * HT childs.
  675. * We hard code the address because of the different size of
  676. * the reg address cell, we shall fix that by killing struct
  677. * reg_property and using some accessor functions instead
  678. */
  679. hose->first_busno = 0xf0;
  680. hose->last_busno = 0xff;
  681. has_uninorth = 1;
  682. hose->ops = &macrisc_pci_ops;
  683. hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
  684. hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
  685. u3_agp = hose;
  686. }
  687. static void __init setup_u4_pcie(struct pci_controller* hose)
  688. {
  689. /* We currently only implement the "non-atomic" config space, to
  690. * be optimised later.
  691. */
  692. hose->ops = &u4_pcie_pci_ops;
  693. hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
  694. hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
  695. /* The bus contains a bridge from root -> device, we need to
  696. * make it visible on bus 0 so that we pick the right type
  697. * of config cycles. If we didn't, we would have to force all
  698. * config cycles to be type 1. So we override the "bus-range"
  699. * property here
  700. */
  701. hose->first_busno = 0x00;
  702. hose->last_busno = 0xff;
  703. }
  704. static void __init parse_region_decode(struct pci_controller *hose,
  705. u32 decode)
  706. {
  707. unsigned long base, end, next = -1;
  708. int i, cur = -1;
  709. /* Iterate through all bits. We ignore the last bit as this region is
  710. * reserved for the ROM among other niceties
  711. */
  712. for (i = 0; i < 31; i++) {
  713. if ((decode & (0x80000000 >> i)) == 0)
  714. continue;
  715. if (i < 16) {
  716. base = 0xf0000000 | (((u32)i) << 24);
  717. end = base + 0x00ffffff;
  718. } else {
  719. base = ((u32)i-16) << 28;
  720. end = base + 0x0fffffff;
  721. }
  722. if (base != next) {
  723. if (++cur >= 3) {
  724. printk(KERN_WARNING "PCI: Too many ranges !\n");
  725. break;
  726. }
  727. hose->mem_resources[cur].flags = IORESOURCE_MEM;
  728. hose->mem_resources[cur].name = hose->dn->full_name;
  729. hose->mem_resources[cur].start = base;
  730. hose->mem_resources[cur].end = end;
  731. DBG(" %d: 0x%08lx-0x%08lx\n", cur, base, end);
  732. } else {
  733. DBG(" : -0x%08lx\n", end);
  734. hose->mem_resources[cur].end = end;
  735. }
  736. next = end + 1;
  737. }
  738. }
  739. static void __init setup_u3_ht(struct pci_controller* hose)
  740. {
  741. struct device_node *np = hose->dn;
  742. struct resource cfg_res, self_res;
  743. u32 decode;
  744. hose->ops = &u3_ht_pci_ops;
  745. /* Get base addresses from OF tree
  746. */
  747. if (of_address_to_resource(np, 0, &cfg_res) ||
  748. of_address_to_resource(np, 1, &self_res)) {
  749. printk(KERN_ERR "PCI: Failed to get U3/U4 HT resources !\n");
  750. return;
  751. }
  752. /* Map external cfg space access into cfg_data and self registers
  753. * into cfg_addr
  754. */
  755. hose->cfg_data = ioremap(cfg_res.start, 0x02000000);
  756. hose->cfg_addr = ioremap(self_res.start,
  757. self_res.end - self_res.start + 1);
  758. /*
  759. * /ht node doesn't expose a "ranges" property, we read the register
  760. * that controls the decoding logic and use that for memory regions.
  761. * The IO region is hard coded since it is fixed in HW as well.
  762. */
  763. hose->io_base_phys = 0xf4000000;
  764. hose->pci_io_size = 0x00400000;
  765. hose->io_resource.name = np->full_name;
  766. hose->io_resource.start = 0;
  767. hose->io_resource.end = 0x003fffff;
  768. hose->io_resource.flags = IORESOURCE_IO;
  769. hose->pci_mem_offset = 0;
  770. hose->first_busno = 0;
  771. hose->last_busno = 0xef;
  772. /* Note: fix offset when cfg_addr becomes a void * */
  773. decode = in_be32(hose->cfg_addr + 0x80);
  774. DBG("PCI: Apple HT bridge decode register: 0x%08x\n", decode);
  775. /* NOTE: The decode register setup is a bit weird... region
  776. * 0xf8000000 for example is marked as enabled in there while it's
  777. & actually the memory controller registers.
  778. * That means that we are incorrectly attributing it to HT.
  779. *
  780. * In a similar vein, region 0xf4000000 is actually the HT IO space but
  781. * also marked as enabled in here and 0xf9000000 is used by some other
  782. * internal bits of the northbridge.
  783. *
  784. * Unfortunately, we can't just mask out those bit as we would end
  785. * up with more regions than we can cope (linux can only cope with
  786. * 3 memory regions for a PHB at this stage).
  787. *
  788. * So for now, we just do a little hack. We happen to -know- that
  789. * Apple firmware doesn't assign things below 0xfa000000 for that
  790. * bridge anyway so we mask out all bits we don't want.
  791. */
  792. decode &= 0x003fffff;
  793. /* Now parse the resulting bits and build resources */
  794. parse_region_decode(hose, decode);
  795. }
  796. #endif /* CONFIG_PPC64 */
  797. /*
  798. * We assume that if we have a G3 powermac, we have one bridge called
  799. * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise,
  800. * if we have one or more bandit or chaos bridges, we don't have a MPC106.
  801. */
  802. static int __init pmac_add_bridge(struct device_node *dev)
  803. {
  804. int len;
  805. struct pci_controller *hose;
  806. struct resource rsrc;
  807. char *disp_name;
  808. const int *bus_range;
  809. int primary = 1, has_address = 0;
  810. DBG("Adding PCI host bridge %s\n", dev->full_name);
  811. /* Fetch host bridge registers address */
  812. has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
  813. /* Get bus range if any */
  814. bus_range = of_get_property(dev, "bus-range", &len);
  815. if (bus_range == NULL || len < 2 * sizeof(int)) {
  816. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  817. " bus 0\n", dev->full_name);
  818. }
  819. hose = pcibios_alloc_controller(dev);
  820. if (!hose)
  821. return -ENOMEM;
  822. hose->first_busno = bus_range ? bus_range[0] : 0;
  823. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  824. disp_name = NULL;
  825. /* 64 bits only bridges */
  826. #ifdef CONFIG_PPC64
  827. if (of_device_is_compatible(dev, "u3-agp")) {
  828. setup_u3_agp(hose);
  829. disp_name = "U3-AGP";
  830. primary = 0;
  831. } else if (of_device_is_compatible(dev, "u3-ht")) {
  832. setup_u3_ht(hose);
  833. disp_name = "U3-HT";
  834. primary = 1;
  835. } else if (of_device_is_compatible(dev, "u4-pcie")) {
  836. setup_u4_pcie(hose);
  837. disp_name = "U4-PCIE";
  838. primary = 0;
  839. }
  840. printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number:"
  841. " %d->%d\n", disp_name, hose->first_busno, hose->last_busno);
  842. #endif /* CONFIG_PPC64 */
  843. /* 32 bits only bridges */
  844. #ifdef CONFIG_PPC32
  845. if (of_device_is_compatible(dev, "uni-north")) {
  846. primary = setup_uninorth(hose, &rsrc);
  847. disp_name = "UniNorth";
  848. } else if (strcmp(dev->name, "pci") == 0) {
  849. /* XXX assume this is a mpc106 (grackle) */
  850. setup_grackle(hose);
  851. disp_name = "Grackle (MPC106)";
  852. } else if (strcmp(dev->name, "bandit") == 0) {
  853. setup_bandit(hose, &rsrc);
  854. disp_name = "Bandit";
  855. } else if (strcmp(dev->name, "chaos") == 0) {
  856. setup_chaos(hose, &rsrc);
  857. disp_name = "Chaos";
  858. primary = 0;
  859. }
  860. printk(KERN_INFO "Found %s PCI host bridge at 0x%016llx. "
  861. "Firmware bus number: %d->%d\n",
  862. disp_name, (unsigned long long)rsrc.start, hose->first_busno,
  863. hose->last_busno);
  864. #endif /* CONFIG_PPC32 */
  865. DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  866. hose, hose->cfg_addr, hose->cfg_data);
  867. /* Interpret the "ranges" property */
  868. /* This also maps the I/O region and sets isa_io/mem_base */
  869. pci_process_bridge_OF_ranges(hose, dev, primary);
  870. /* Fixup "bus-range" OF property */
  871. fixup_bus_range(dev);
  872. return 0;
  873. }
  874. void __devinit pmac_pci_irq_fixup(struct pci_dev *dev)
  875. {
  876. #ifdef CONFIG_PPC32
  877. /* Fixup interrupt for the modem/ethernet combo controller.
  878. * on machines with a second ohare chip.
  879. * The number in the device tree (27) is bogus (correct for
  880. * the ethernet-only board but not the combo ethernet/modem
  881. * board). The real interrupt is 28 on the second controller
  882. * -> 28+32 = 60.
  883. */
  884. if (has_second_ohare &&
  885. dev->vendor == PCI_VENDOR_ID_DEC &&
  886. dev->device == PCI_DEVICE_ID_DEC_TULIP_PLUS) {
  887. dev->irq = irq_create_mapping(NULL, 60);
  888. irq_set_irq_type(dev->irq, IRQ_TYPE_LEVEL_LOW);
  889. }
  890. #endif /* CONFIG_PPC32 */
  891. }
  892. void __init pmac_pci_init(void)
  893. {
  894. struct device_node *np, *root;
  895. struct device_node *ht = NULL;
  896. ppc_pci_set_flags(PPC_PCI_CAN_SKIP_ISA_ALIGN);
  897. root = of_find_node_by_path("/");
  898. if (root == NULL) {
  899. printk(KERN_CRIT "pmac_pci_init: can't find root "
  900. "of device tree\n");
  901. return;
  902. }
  903. for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
  904. if (np->name == NULL)
  905. continue;
  906. if (strcmp(np->name, "bandit") == 0
  907. || strcmp(np->name, "chaos") == 0
  908. || strcmp(np->name, "pci") == 0) {
  909. if (pmac_add_bridge(np) == 0)
  910. of_node_get(np);
  911. }
  912. if (strcmp(np->name, "ht") == 0) {
  913. of_node_get(np);
  914. ht = np;
  915. }
  916. }
  917. of_node_put(root);
  918. #ifdef CONFIG_PPC64
  919. /* Probe HT last as it relies on the agp resources to be already
  920. * setup
  921. */
  922. if (ht && pmac_add_bridge(ht) != 0)
  923. of_node_put(ht);
  924. /* Setup the linkage between OF nodes and PHBs */
  925. pci_devs_phb_init();
  926. /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We
  927. * assume there is no P2P bridge on the AGP bus, which should be a
  928. * safe assumptions for now. We should do something better in the
  929. * future though
  930. */
  931. if (u3_agp) {
  932. struct device_node *np = u3_agp->dn;
  933. PCI_DN(np)->busno = 0xf0;
  934. for (np = np->child; np; np = np->sibling)
  935. PCI_DN(np)->busno = 0xf0;
  936. }
  937. /* pmac_check_ht_link(); */
  938. /* We can allocate missing resources if any */
  939. pci_probe_only = 0;
  940. #else /* CONFIG_PPC64 */
  941. init_p2pbridge();
  942. init_second_ohare();
  943. fixup_nec_usb2();
  944. /* We are still having some issues with the Xserve G4, enabling
  945. * some offset between bus number and domains for now when we
  946. * assign all busses should help for now
  947. */
  948. if (ppc_pci_has_flag(PPC_PCI_REASSIGN_ALL_BUS))
  949. pcibios_assign_bus_offset = 0x10;
  950. #endif
  951. }
  952. #ifdef CONFIG_PPC32
  953. int pmac_pci_enable_device_hook(struct pci_dev *dev)
  954. {
  955. struct device_node* node;
  956. int updatecfg = 0;
  957. int uninorth_child;
  958. node = pci_device_to_OF_node(dev);
  959. /* We don't want to enable USB controllers absent from the OF tree
  960. * (iBook second controller)
  961. */
  962. if (dev->vendor == PCI_VENDOR_ID_APPLE
  963. && dev->class == PCI_CLASS_SERIAL_USB_OHCI
  964. && !node) {
  965. printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",
  966. pci_name(dev));
  967. return -EINVAL;
  968. }
  969. if (!node)
  970. return 0;
  971. uninorth_child = node->parent &&
  972. of_device_is_compatible(node->parent, "uni-north");
  973. /* Firewire & GMAC were disabled after PCI probe, the driver is
  974. * claiming them, we must re-enable them now.
  975. */
  976. if (uninorth_child && !strcmp(node->name, "firewire") &&
  977. (of_device_is_compatible(node, "pci106b,18") ||
  978. of_device_is_compatible(node, "pci106b,30") ||
  979. of_device_is_compatible(node, "pci11c1,5811"))) {
  980. pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
  981. pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
  982. updatecfg = 1;
  983. }
  984. if (uninorth_child && !strcmp(node->name, "ethernet") &&
  985. of_device_is_compatible(node, "gmac")) {
  986. pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
  987. updatecfg = 1;
  988. }
  989. /*
  990. * Fixup various header fields on 32 bits. We don't do that on
  991. * 64 bits as some of these have strange values behind the HT
  992. * bridge and we must not, for example, enable MWI or set the
  993. * cache line size on them.
  994. */
  995. if (updatecfg) {
  996. u16 cmd;
  997. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  998. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  999. | PCI_COMMAND_INVALIDATE;
  1000. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1001. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);
  1002. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
  1003. L1_CACHE_BYTES >> 2);
  1004. }
  1005. return 0;
  1006. }
  1007. void __devinit pmac_pci_fixup_ohci(struct pci_dev *dev)
  1008. {
  1009. struct device_node *node = pci_device_to_OF_node(dev);
  1010. /* We don't want to assign resources to USB controllers
  1011. * absent from the OF tree (iBook second controller)
  1012. */
  1013. if (dev->class == PCI_CLASS_SERIAL_USB_OHCI && !node)
  1014. dev->resource[0].flags = 0;
  1015. }
  1016. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, PCI_ANY_ID, pmac_pci_fixup_ohci);
  1017. /* We power down some devices after they have been probed. They'll
  1018. * be powered back on later on
  1019. */
  1020. void __init pmac_pcibios_after_init(void)
  1021. {
  1022. struct device_node* nd;
  1023. for_each_node_by_name(nd, "firewire") {
  1024. if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") ||
  1025. of_device_is_compatible(nd, "pci106b,30") ||
  1026. of_device_is_compatible(nd, "pci11c1,5811"))
  1027. && of_device_is_compatible(nd->parent, "uni-north")) {
  1028. pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
  1029. pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
  1030. }
  1031. }
  1032. for_each_node_by_name(nd, "ethernet") {
  1033. if (nd->parent && of_device_is_compatible(nd, "gmac")
  1034. && of_device_is_compatible(nd->parent, "uni-north"))
  1035. pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
  1036. }
  1037. }
  1038. void pmac_pci_fixup_cardbus(struct pci_dev* dev)
  1039. {
  1040. if (!machine_is(powermac))
  1041. return;
  1042. /*
  1043. * Fix the interrupt routing on the various cardbus bridges
  1044. * used on powerbooks
  1045. */
  1046. if (dev->vendor != PCI_VENDOR_ID_TI)
  1047. return;
  1048. if (dev->device == PCI_DEVICE_ID_TI_1130 ||
  1049. dev->device == PCI_DEVICE_ID_TI_1131) {
  1050. u8 val;
  1051. /* Enable PCI interrupt */
  1052. if (pci_read_config_byte(dev, 0x91, &val) == 0)
  1053. pci_write_config_byte(dev, 0x91, val | 0x30);
  1054. /* Disable ISA interrupt mode */
  1055. if (pci_read_config_byte(dev, 0x92, &val) == 0)
  1056. pci_write_config_byte(dev, 0x92, val & ~0x06);
  1057. }
  1058. if (dev->device == PCI_DEVICE_ID_TI_1210 ||
  1059. dev->device == PCI_DEVICE_ID_TI_1211 ||
  1060. dev->device == PCI_DEVICE_ID_TI_1410 ||
  1061. dev->device == PCI_DEVICE_ID_TI_1510) {
  1062. u8 val;
  1063. /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA
  1064. signal out the MFUNC0 pin */
  1065. if (pci_read_config_byte(dev, 0x8c, &val) == 0)
  1066. pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
  1067. /* Disable ISA interrupt mode */
  1068. if (pci_read_config_byte(dev, 0x92, &val) == 0)
  1069. pci_write_config_byte(dev, 0x92, val & ~0x06);
  1070. }
  1071. }
  1072. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);
  1073. void pmac_pci_fixup_pciata(struct pci_dev* dev)
  1074. {
  1075. u8 progif = 0;
  1076. /*
  1077. * On PowerMacs, we try to switch any PCI ATA controller to
  1078. * fully native mode
  1079. */
  1080. if (!machine_is(powermac))
  1081. return;
  1082. /* Some controllers don't have the class IDE */
  1083. if (dev->vendor == PCI_VENDOR_ID_PROMISE)
  1084. switch(dev->device) {
  1085. case PCI_DEVICE_ID_PROMISE_20246:
  1086. case PCI_DEVICE_ID_PROMISE_20262:
  1087. case PCI_DEVICE_ID_PROMISE_20263:
  1088. case PCI_DEVICE_ID_PROMISE_20265:
  1089. case PCI_DEVICE_ID_PROMISE_20267:
  1090. case PCI_DEVICE_ID_PROMISE_20268:
  1091. case PCI_DEVICE_ID_PROMISE_20269:
  1092. case PCI_DEVICE_ID_PROMISE_20270:
  1093. case PCI_DEVICE_ID_PROMISE_20271:
  1094. case PCI_DEVICE_ID_PROMISE_20275:
  1095. case PCI_DEVICE_ID_PROMISE_20276:
  1096. case PCI_DEVICE_ID_PROMISE_20277:
  1097. goto good;
  1098. }
  1099. /* Others, check PCI class */
  1100. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
  1101. return;
  1102. good:
  1103. pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
  1104. if ((progif & 5) != 5) {
  1105. printk(KERN_INFO "PCI: %s Forcing PCI IDE into native mode\n",
  1106. pci_name(dev));
  1107. (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
  1108. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
  1109. (progif & 5) != 5)
  1110. printk(KERN_ERR "Rewrite of PROGIF failed !\n");
  1111. else {
  1112. /* Clear IO BARs, they will be reassigned */
  1113. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);
  1114. pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);
  1115. pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, 0);
  1116. pci_write_config_dword(dev, PCI_BASE_ADDRESS_3, 0);
  1117. }
  1118. }
  1119. }
  1120. DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);
  1121. #endif /* CONFIG_PPC32 */
  1122. /*
  1123. * Disable second function on K2-SATA, it's broken
  1124. * and disable IO BARs on first one
  1125. */
  1126. static void fixup_k2_sata(struct pci_dev* dev)
  1127. {
  1128. int i;
  1129. u16 cmd;
  1130. if (PCI_FUNC(dev->devfn) > 0) {
  1131. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1132. cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  1133. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1134. for (i = 0; i < 6; i++) {
  1135. dev->resource[i].start = dev->resource[i].end = 0;
  1136. dev->resource[i].flags = 0;
  1137. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
  1138. 0);
  1139. }
  1140. } else {
  1141. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1142. cmd &= ~PCI_COMMAND_IO;
  1143. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1144. for (i = 0; i < 5; i++) {
  1145. dev->resource[i].start = dev->resource[i].end = 0;
  1146. dev->resource[i].flags = 0;
  1147. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
  1148. 0);
  1149. }
  1150. }
  1151. }
  1152. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata);
  1153. /*
  1154. * On U4 (aka CPC945) the PCIe root complex "P2P" bridge resource ranges aren't
  1155. * configured by the firmware. The bridge itself seems to ignore them but it
  1156. * causes problems with Linux which then re-assigns devices below the bridge,
  1157. * thus changing addresses of those devices from what was in the device-tree,
  1158. * which sucks when those are video cards using offb
  1159. *
  1160. * We could just mark it transparent but I prefer fixing up the resources to
  1161. * properly show what's going on here, as I have some doubts about having them
  1162. * badly configured potentially being an issue for DMA.
  1163. *
  1164. * We leave PIO alone, it seems to be fine
  1165. *
  1166. * Oh and there's another funny bug. The OF properties advertize the region
  1167. * 0xf1000000..0xf1ffffff as being forwarded as memory space. But that's
  1168. * actually not true, this region is the memory mapped config space. So we
  1169. * also need to filter it out or we'll map things in the wrong place.
  1170. */
  1171. static void fixup_u4_pcie(struct pci_dev* dev)
  1172. {
  1173. struct pci_controller *host = pci_bus_to_host(dev->bus);
  1174. struct resource *region = NULL;
  1175. u32 reg;
  1176. int i;
  1177. /* Only do that on PowerMac */
  1178. if (!machine_is(powermac))
  1179. return;
  1180. /* Find the largest MMIO region */
  1181. for (i = 0; i < 3; i++) {
  1182. struct resource *r = &host->mem_resources[i];
  1183. if (!(r->flags & IORESOURCE_MEM))
  1184. continue;
  1185. /* Skip the 0xf0xxxxxx..f2xxxxxx regions, we know they
  1186. * are reserved by HW for other things
  1187. */
  1188. if (r->start >= 0xf0000000 && r->start < 0xf3000000)
  1189. continue;
  1190. if (!region || (r->end - r->start) >
  1191. (region->end - region->start))
  1192. region = r;
  1193. }
  1194. /* Nothing found, bail */
  1195. if (region == 0)
  1196. return;
  1197. /* Print things out */
  1198. printk(KERN_INFO "PCI: Fixup U4 PCIe bridge range: %pR\n", region);
  1199. /* Fixup bridge config space. We know it's a Mac, resource aren't
  1200. * offset so let's just blast them as-is. We also know that they
  1201. * fit in 32 bits
  1202. */
  1203. reg = ((region->start >> 16) & 0xfff0) | (region->end & 0xfff00000);
  1204. pci_write_config_dword(dev, PCI_MEMORY_BASE, reg);
  1205. pci_write_config_dword(dev, PCI_PREF_BASE_UPPER32, 0);
  1206. pci_write_config_dword(dev, PCI_PREF_LIMIT_UPPER32, 0);
  1207. pci_write_config_dword(dev, PCI_PREF_MEMORY_BASE, 0);
  1208. }
  1209. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_U4_PCIE, fixup_u4_pcie);