pci.c 37 KB

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