pci.c 36 KB

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