pci.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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. #ifdef CONFIG_PPC64
  783. static int pmac_pci_root_bridge_prepare(struct pci_host_bridge *bridge)
  784. {
  785. struct pci_controller *hose = pci_bus_to_host(bridge->bus);
  786. struct device_node *np, *child;
  787. if (hose != u3_agp)
  788. return 0;
  789. /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We
  790. * assume there is no P2P bridge on the AGP bus, which should be a
  791. * safe assumptions for now. We should do something better in the
  792. * future though
  793. */
  794. np = hose->dn;
  795. PCI_DN(np)->busno = 0xf0;
  796. for_each_child_of_node(np, child)
  797. PCI_DN(child)->busno = 0xf0;
  798. return 0;
  799. }
  800. #endif /* CONFIG_PPC64 */
  801. void __init pmac_pci_init(void)
  802. {
  803. struct device_node *np, *root;
  804. struct device_node *ht = NULL;
  805. pci_set_flags(PCI_CAN_SKIP_ISA_ALIGN);
  806. root = of_find_node_by_path("/");
  807. if (root == NULL) {
  808. printk(KERN_CRIT "pmac_pci_init: can't find root "
  809. "of device tree\n");
  810. return;
  811. }
  812. for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
  813. if (np->name == NULL)
  814. continue;
  815. if (strcmp(np->name, "bandit") == 0
  816. || strcmp(np->name, "chaos") == 0
  817. || strcmp(np->name, "pci") == 0) {
  818. if (pmac_add_bridge(np) == 0)
  819. of_node_get(np);
  820. }
  821. if (strcmp(np->name, "ht") == 0) {
  822. of_node_get(np);
  823. ht = np;
  824. }
  825. }
  826. of_node_put(root);
  827. #ifdef CONFIG_PPC64
  828. /* Probe HT last as it relies on the agp resources to be already
  829. * setup
  830. */
  831. if (ht && pmac_add_bridge(ht) != 0)
  832. of_node_put(ht);
  833. ppc_md.pcibios_root_bridge_prepare = pmac_pci_root_bridge_prepare;
  834. /* pmac_check_ht_link(); */
  835. #else /* CONFIG_PPC64 */
  836. init_p2pbridge();
  837. init_second_ohare();
  838. fixup_nec_usb2();
  839. /* We are still having some issues with the Xserve G4, enabling
  840. * some offset between bus number and domains for now when we
  841. * assign all busses should help for now
  842. */
  843. if (pci_has_flag(PCI_REASSIGN_ALL_BUS))
  844. pcibios_assign_bus_offset = 0x10;
  845. #endif
  846. }
  847. #ifdef CONFIG_PPC32
  848. static bool pmac_pci_enable_device_hook(struct pci_dev *dev)
  849. {
  850. struct device_node* node;
  851. int updatecfg = 0;
  852. int uninorth_child;
  853. node = pci_device_to_OF_node(dev);
  854. /* We don't want to enable USB controllers absent from the OF tree
  855. * (iBook second controller)
  856. */
  857. if (dev->vendor == PCI_VENDOR_ID_APPLE
  858. && dev->class == PCI_CLASS_SERIAL_USB_OHCI
  859. && !node) {
  860. printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",
  861. pci_name(dev));
  862. return false;
  863. }
  864. if (!node)
  865. return true;
  866. uninorth_child = node->parent &&
  867. of_device_is_compatible(node->parent, "uni-north");
  868. /* Firewire & GMAC were disabled after PCI probe, the driver is
  869. * claiming them, we must re-enable them now.
  870. */
  871. if (uninorth_child && !strcmp(node->name, "firewire") &&
  872. (of_device_is_compatible(node, "pci106b,18") ||
  873. of_device_is_compatible(node, "pci106b,30") ||
  874. of_device_is_compatible(node, "pci11c1,5811"))) {
  875. pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
  876. pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
  877. updatecfg = 1;
  878. }
  879. if (uninorth_child && !strcmp(node->name, "ethernet") &&
  880. of_device_is_compatible(node, "gmac")) {
  881. pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
  882. updatecfg = 1;
  883. }
  884. /*
  885. * Fixup various header fields on 32 bits. We don't do that on
  886. * 64 bits as some of these have strange values behind the HT
  887. * bridge and we must not, for example, enable MWI or set the
  888. * cache line size on them.
  889. */
  890. if (updatecfg) {
  891. u16 cmd;
  892. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  893. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  894. | PCI_COMMAND_INVALIDATE;
  895. pci_write_config_word(dev, PCI_COMMAND, cmd);
  896. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);
  897. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
  898. L1_CACHE_BYTES >> 2);
  899. }
  900. return true;
  901. }
  902. void pmac_pci_fixup_ohci(struct pci_dev *dev)
  903. {
  904. struct device_node *node = pci_device_to_OF_node(dev);
  905. /* We don't want to assign resources to USB controllers
  906. * absent from the OF tree (iBook second controller)
  907. */
  908. if (dev->class == PCI_CLASS_SERIAL_USB_OHCI && !node)
  909. dev->resource[0].flags = 0;
  910. }
  911. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, PCI_ANY_ID, pmac_pci_fixup_ohci);
  912. /* We power down some devices after they have been probed. They'll
  913. * be powered back on later on
  914. */
  915. void __init pmac_pcibios_after_init(void)
  916. {
  917. struct device_node* nd;
  918. for_each_node_by_name(nd, "firewire") {
  919. if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") ||
  920. of_device_is_compatible(nd, "pci106b,30") ||
  921. of_device_is_compatible(nd, "pci11c1,5811"))
  922. && of_device_is_compatible(nd->parent, "uni-north")) {
  923. pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
  924. pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
  925. }
  926. }
  927. for_each_node_by_name(nd, "ethernet") {
  928. if (nd->parent && of_device_is_compatible(nd, "gmac")
  929. && of_device_is_compatible(nd->parent, "uni-north"))
  930. pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
  931. }
  932. }
  933. void pmac_pci_fixup_cardbus(struct pci_dev* dev)
  934. {
  935. if (!machine_is(powermac))
  936. return;
  937. /*
  938. * Fix the interrupt routing on the various cardbus bridges
  939. * used on powerbooks
  940. */
  941. if (dev->vendor != PCI_VENDOR_ID_TI)
  942. return;
  943. if (dev->device == PCI_DEVICE_ID_TI_1130 ||
  944. dev->device == PCI_DEVICE_ID_TI_1131) {
  945. u8 val;
  946. /* Enable PCI interrupt */
  947. if (pci_read_config_byte(dev, 0x91, &val) == 0)
  948. pci_write_config_byte(dev, 0x91, val | 0x30);
  949. /* Disable ISA interrupt mode */
  950. if (pci_read_config_byte(dev, 0x92, &val) == 0)
  951. pci_write_config_byte(dev, 0x92, val & ~0x06);
  952. }
  953. if (dev->device == PCI_DEVICE_ID_TI_1210 ||
  954. dev->device == PCI_DEVICE_ID_TI_1211 ||
  955. dev->device == PCI_DEVICE_ID_TI_1410 ||
  956. dev->device == PCI_DEVICE_ID_TI_1510) {
  957. u8 val;
  958. /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA
  959. signal out the MFUNC0 pin */
  960. if (pci_read_config_byte(dev, 0x8c, &val) == 0)
  961. pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
  962. /* Disable ISA interrupt mode */
  963. if (pci_read_config_byte(dev, 0x92, &val) == 0)
  964. pci_write_config_byte(dev, 0x92, val & ~0x06);
  965. }
  966. }
  967. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);
  968. void pmac_pci_fixup_pciata(struct pci_dev* dev)
  969. {
  970. u8 progif = 0;
  971. /*
  972. * On PowerMacs, we try to switch any PCI ATA controller to
  973. * fully native mode
  974. */
  975. if (!machine_is(powermac))
  976. return;
  977. /* Some controllers don't have the class IDE */
  978. if (dev->vendor == PCI_VENDOR_ID_PROMISE)
  979. switch(dev->device) {
  980. case PCI_DEVICE_ID_PROMISE_20246:
  981. case PCI_DEVICE_ID_PROMISE_20262:
  982. case PCI_DEVICE_ID_PROMISE_20263:
  983. case PCI_DEVICE_ID_PROMISE_20265:
  984. case PCI_DEVICE_ID_PROMISE_20267:
  985. case PCI_DEVICE_ID_PROMISE_20268:
  986. case PCI_DEVICE_ID_PROMISE_20269:
  987. case PCI_DEVICE_ID_PROMISE_20270:
  988. case PCI_DEVICE_ID_PROMISE_20271:
  989. case PCI_DEVICE_ID_PROMISE_20275:
  990. case PCI_DEVICE_ID_PROMISE_20276:
  991. case PCI_DEVICE_ID_PROMISE_20277:
  992. goto good;
  993. }
  994. /* Others, check PCI class */
  995. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
  996. return;
  997. good:
  998. pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
  999. if ((progif & 5) != 5) {
  1000. printk(KERN_INFO "PCI: %s Forcing PCI IDE into native mode\n",
  1001. pci_name(dev));
  1002. (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
  1003. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
  1004. (progif & 5) != 5)
  1005. printk(KERN_ERR "Rewrite of PROGIF failed !\n");
  1006. else {
  1007. /* Clear IO BARs, they will be reassigned */
  1008. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);
  1009. pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);
  1010. pci_write_config_dword(dev, PCI_BASE_ADDRESS_2, 0);
  1011. pci_write_config_dword(dev, PCI_BASE_ADDRESS_3, 0);
  1012. }
  1013. }
  1014. }
  1015. DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);
  1016. #endif /* CONFIG_PPC32 */
  1017. /*
  1018. * Disable second function on K2-SATA, it's broken
  1019. * and disable IO BARs on first one
  1020. */
  1021. static void fixup_k2_sata(struct pci_dev* dev)
  1022. {
  1023. int i;
  1024. u16 cmd;
  1025. if (PCI_FUNC(dev->devfn) > 0) {
  1026. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1027. cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  1028. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1029. for (i = 0; i < 6; i++) {
  1030. dev->resource[i].start = dev->resource[i].end = 0;
  1031. dev->resource[i].flags = 0;
  1032. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
  1033. 0);
  1034. }
  1035. } else {
  1036. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1037. cmd &= ~PCI_COMMAND_IO;
  1038. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1039. for (i = 0; i < 5; i++) {
  1040. dev->resource[i].start = dev->resource[i].end = 0;
  1041. dev->resource[i].flags = 0;
  1042. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
  1043. 0);
  1044. }
  1045. }
  1046. }
  1047. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata);
  1048. /*
  1049. * On U4 (aka CPC945) the PCIe root complex "P2P" bridge resource ranges aren't
  1050. * configured by the firmware. The bridge itself seems to ignore them but it
  1051. * causes problems with Linux which then re-assigns devices below the bridge,
  1052. * thus changing addresses of those devices from what was in the device-tree,
  1053. * which sucks when those are video cards using offb
  1054. *
  1055. * We could just mark it transparent but I prefer fixing up the resources to
  1056. * properly show what's going on here, as I have some doubts about having them
  1057. * badly configured potentially being an issue for DMA.
  1058. *
  1059. * We leave PIO alone, it seems to be fine
  1060. *
  1061. * Oh and there's another funny bug. The OF properties advertize the region
  1062. * 0xf1000000..0xf1ffffff as being forwarded as memory space. But that's
  1063. * actually not true, this region is the memory mapped config space. So we
  1064. * also need to filter it out or we'll map things in the wrong place.
  1065. */
  1066. static void fixup_u4_pcie(struct pci_dev* dev)
  1067. {
  1068. struct pci_controller *host = pci_bus_to_host(dev->bus);
  1069. struct resource *region = NULL;
  1070. u32 reg;
  1071. int i;
  1072. /* Only do that on PowerMac */
  1073. if (!machine_is(powermac))
  1074. return;
  1075. /* Find the largest MMIO region */
  1076. for (i = 0; i < 3; i++) {
  1077. struct resource *r = &host->mem_resources[i];
  1078. if (!(r->flags & IORESOURCE_MEM))
  1079. continue;
  1080. /* Skip the 0xf0xxxxxx..f2xxxxxx regions, we know they
  1081. * are reserved by HW for other things
  1082. */
  1083. if (r->start >= 0xf0000000 && r->start < 0xf3000000)
  1084. continue;
  1085. if (!region || resource_size(r) > resource_size(region))
  1086. region = r;
  1087. }
  1088. /* Nothing found, bail */
  1089. if (region == 0)
  1090. return;
  1091. /* Print things out */
  1092. printk(KERN_INFO "PCI: Fixup U4 PCIe bridge range: %pR\n", region);
  1093. /* Fixup bridge config space. We know it's a Mac, resource aren't
  1094. * offset so let's just blast them as-is. We also know that they
  1095. * fit in 32 bits
  1096. */
  1097. reg = ((region->start >> 16) & 0xfff0) | (region->end & 0xfff00000);
  1098. pci_write_config_dword(dev, PCI_MEMORY_BASE, reg);
  1099. pci_write_config_dword(dev, PCI_PREF_BASE_UPPER32, 0);
  1100. pci_write_config_dword(dev, PCI_PREF_LIMIT_UPPER32, 0);
  1101. pci_write_config_dword(dev, PCI_PREF_MEMORY_BASE, 0);
  1102. }
  1103. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_U4_PCIE, fixup_u4_pcie);
  1104. #ifdef CONFIG_PPC64
  1105. static int pmac_pci_probe_mode(struct pci_bus *bus)
  1106. {
  1107. struct device_node *node = pci_bus_to_OF_node(bus);
  1108. /* We need to use normal PCI probing for the AGP bus,
  1109. * since the device for the AGP bridge isn't in the tree.
  1110. * Same for the PCIe host on U4 and the HT host bridge.
  1111. */
  1112. if (bus->self == NULL && (of_device_is_compatible(node, "u3-agp") ||
  1113. of_device_is_compatible(node, "u4-pcie") ||
  1114. of_device_is_compatible(node, "u3-ht")))
  1115. return PCI_PROBE_NORMAL;
  1116. return PCI_PROBE_DEVTREE;
  1117. }
  1118. #endif /* CONFIG_PPC64 */
  1119. struct pci_controller_ops pmac_pci_controller_ops = {
  1120. #ifdef CONFIG_PPC64
  1121. .probe_mode = pmac_pci_probe_mode,
  1122. #endif
  1123. #ifdef CONFIG_PPC32
  1124. .enable_device_hook = pmac_pci_enable_device_hook,
  1125. #endif
  1126. };