pci.c 36 KB

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