pci.c 35 KB

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