pci.c 35 KB

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