pci.c 36 KB

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