4xx_pci.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /*-----------------------------------------------------------------------------+
  2. * This source code is dual-licensed. You may use it under the terms of
  3. * the GNU General Public license version 2, or under the license below.
  4. *
  5. * This source code has been made available to you by IBM on an AS-IS
  6. * basis. Anyone receiving this source is licensed under IBM
  7. * copyrights to use it in any way he or she deems fit, including
  8. * copying it, modifying it, compiling it, and redistributing it either
  9. * with or without modifications. No license under IBM patents or
  10. * patent applications is to be implied by the copyright license.
  11. *
  12. * Any user of this software should understand that IBM cannot provide
  13. * technical support for this software and will not be responsible for
  14. * any consequences resulting from the use of this software.
  15. *
  16. * Any person who transfers this source code or any derivative work
  17. * must include the IBM copyright notice, this paragraph, and the
  18. * preceding two paragraphs in the transferred software.
  19. *
  20. * COPYRIGHT I B M CORPORATION 1995
  21. * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  22. *-----------------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------------+
  24. *
  25. * File Name: 405gp_pci.c
  26. *
  27. * Function: Initialization code for the 405GP PCI Configuration regs.
  28. *
  29. * Author: Mark Game
  30. *
  31. * Change Activity-
  32. *
  33. * Date Description of Change BY
  34. * --------- --------------------- ---
  35. * 09-Sep-98 Created MCG
  36. * 02-Nov-98 Removed External arbiter selected message JWB
  37. * 27-Nov-98 Zero out PTMBAR2 and disable in PTM2MS JWB
  38. * 04-Jan-99 Zero out other unused PMM and PTM regs. Change bus scan MCG
  39. * from (0 to n) to (1 to n).
  40. * 17-May-99 Port to Walnut JWB
  41. * 17-Jun-99 Updated for VGA support JWB
  42. * 21-Jun-99 Updated to allow SRAM region to be a target from PCI bus JWB
  43. * 19-Jul-99 Updated for 405GP pass 1 errata #26 (Low PCI subsequent MCG
  44. * target latency timer values are not supported).
  45. * Should be fixed in pass 2.
  46. * 09-Sep-99 Removed use of PTM2 since the SRAM region no longer needs JWB
  47. * to be a PCI target. Zero out PTMBAR2 and disable in PTM2MS.
  48. * 10-Dec-99 Updated PCI_Write_CFG_Reg for pass2 errata #6 JWB
  49. * 11-Jan-00 Ensure PMMxMAs disabled before setting PMMxLAs. This is not
  50. * really required after a reset since PMMxMAs are already
  51. * disabled but is a good practice nonetheless. JWB
  52. * 12-Jun-01 stefan.roese@esd-electronics.com
  53. * - PCI host/adapter handling reworked
  54. * 09-Jul-01 stefan.roese@esd-electronics.com
  55. * - PCI host now configures from device 0 (not 1) to max_dev,
  56. * (host configures itself)
  57. * - On CPCI-405 pci base address and size is generated from
  58. * SDRAM and FLASH size (CFG regs not used anymore)
  59. * - Some minor changes for CPCI-405-A (adapter version)
  60. * 14-Sep-01 stefan.roese@esd-electronics.com
  61. * - CONFIG_PCI_SCAN_SHOW added to print pci devices upon startup
  62. * 28-Sep-01 stefan.roese@esd-electronics.com
  63. * - Changed pci master configuration for linux compatibility
  64. * (no need for bios_fixup() anymore)
  65. * 26-Feb-02 stefan.roese@esd-electronics.com
  66. * - Bug fixed in pci configuration (Andrew May)
  67. * - Removed pci class code init for CPCI405 board
  68. * 15-May-02 stefan.roese@esd-electronics.com
  69. * - New vga device handling
  70. * 29-May-02 stefan.roese@esd-electronics.com
  71. * - PCI class code init added (if defined)
  72. *----------------------------------------------------------------------------*/
  73. #include <common.h>
  74. #include <command.h>
  75. #include <asm/4xx_pci.h>
  76. #include <asm/processor.h>
  77. #include <asm/io.h>
  78. #include <pci.h>
  79. #ifdef CONFIG_PCI
  80. DECLARE_GLOBAL_DATA_PTR;
  81. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  82. #if defined(CONFIG_PMC405)
  83. ushort pmc405_pci_subsys_deviceid(void);
  84. #endif
  85. /*#define DEBUG*/
  86. /*
  87. * Board-specific pci initialization
  88. * Platform code can reimplement pci_pre_init() if needed
  89. */
  90. int __pci_pre_init(struct pci_controller *hose)
  91. {
  92. #if defined(CONFIG_405EP)
  93. /*
  94. * Enable the internal PCI arbiter by default.
  95. *
  96. * On 405EP CPUs the internal arbiter can be controlled
  97. * by the I2C strapping EEPROM. If you want to do so
  98. * or if you want to disable the arbiter pci_pre_init()
  99. * must be reimplemented without enabling the arbiter.
  100. * The arbiter is enabled in this place because of
  101. * compatibility reasons.
  102. */
  103. mtdcr(CPC0_PCI, mfdcr(CPC0_PCI) | CPC0_PCI_ARBIT_EN);
  104. #endif /* CONFIG_405EP */
  105. return 1;
  106. }
  107. int pci_pre_init(struct pci_controller *hose)
  108. __attribute__((weak, alias("__pci_pre_init")));
  109. int __is_pci_host(struct pci_controller *hose)
  110. {
  111. #if defined(CONFIG_405GP)
  112. if (mfdcr(CPC0_PSR) & PSR_PCI_ARBIT_EN)
  113. return 1;
  114. #elif defined (CONFIG_405EP)
  115. if (mfdcr(CPC0_PCI) & CPC0_PCI_ARBIT_EN)
  116. return 1;
  117. #endif
  118. return 0;
  119. }
  120. int is_pci_host(struct pci_controller *hose) __attribute__((weak, alias("__is_pci_host")));
  121. /*-----------------------------------------------------------------------------+
  122. * pci_init. Initializes the 405GP PCI Configuration regs.
  123. *-----------------------------------------------------------------------------*/
  124. void pci_405gp_init(struct pci_controller *hose)
  125. {
  126. int i, reg_num = 0;
  127. bd_t *bd = gd->bd;
  128. unsigned short temp_short;
  129. unsigned long ptmpcila[2] = {CONFIG_SYS_PCI_PTM1PCI, CONFIG_SYS_PCI_PTM2PCI};
  130. #if defined(CONFIG_PCI_4xx_PTM_OVERWRITE)
  131. char *ptmla_str, *ptmms_str;
  132. #endif
  133. unsigned long ptmla[2] = {CONFIG_SYS_PCI_PTM1LA, CONFIG_SYS_PCI_PTM2LA};
  134. unsigned long ptmms[2] = {CONFIG_SYS_PCI_PTM1MS, CONFIG_SYS_PCI_PTM2MS};
  135. #if defined(CONFIG_PIP405) || defined (CONFIG_MIP405)
  136. unsigned long pmmla[3] = {0x80000000, 0xA0000000, 0};
  137. unsigned long pmmma[3] = {0xE0000001, 0xE0000001, 0};
  138. unsigned long pmmpcila[3] = {0x80000000, 0x00000000, 0};
  139. unsigned long pmmpciha[3] = {0x00000000, 0x00000000, 0};
  140. #else
  141. unsigned long pmmla[3] = {0x80000000, 0,0};
  142. unsigned long pmmma[3] = {0xC0000001, 0,0};
  143. unsigned long pmmpcila[3] = {0x80000000, 0,0};
  144. unsigned long pmmpciha[3] = {0x00000000, 0,0};
  145. #endif
  146. #ifdef CONFIG_PCI_PNP
  147. #if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
  148. char *s;
  149. #endif
  150. #endif
  151. #if defined(CONFIG_PCI_4xx_PTM_OVERWRITE)
  152. ptmla_str = getenv("ptm1la");
  153. ptmms_str = getenv("ptm1ms");
  154. if(NULL != ptmla_str && NULL != ptmms_str ) {
  155. ptmla[0] = simple_strtoul (ptmla_str, NULL, 16);
  156. ptmms[0] = simple_strtoul (ptmms_str, NULL, 16);
  157. }
  158. ptmla_str = getenv("ptm2la");
  159. ptmms_str = getenv("ptm2ms");
  160. if(NULL != ptmla_str && NULL != ptmms_str ) {
  161. ptmla[1] = simple_strtoul (ptmla_str, NULL, 16);
  162. ptmms[1] = simple_strtoul (ptmms_str, NULL, 16);
  163. }
  164. #endif
  165. /*
  166. * Register the hose
  167. */
  168. hose->first_busno = 0;
  169. hose->last_busno = 0xff;
  170. /* ISA/PCI I/O space */
  171. pci_set_region(hose->regions + reg_num++,
  172. MIN_PCI_PCI_IOADDR,
  173. MIN_PLB_PCI_IOADDR,
  174. 0x10000,
  175. PCI_REGION_IO);
  176. /* PCI I/O space */
  177. pci_set_region(hose->regions + reg_num++,
  178. 0x00800000,
  179. 0xe8800000,
  180. 0x03800000,
  181. PCI_REGION_IO);
  182. reg_num = 2;
  183. /* Memory spaces */
  184. for (i=0; i<2; i++)
  185. if (ptmms[i] & 1)
  186. {
  187. if (!i) hose->pci_fb = hose->regions + reg_num;
  188. pci_set_region(hose->regions + reg_num++,
  189. ptmpcila[i], ptmla[i],
  190. ~(ptmms[i] & 0xfffff000) + 1,
  191. PCI_REGION_MEM |
  192. PCI_REGION_SYS_MEMORY);
  193. }
  194. /* PCI memory spaces */
  195. for (i=0; i<3; i++)
  196. if (pmmma[i] & 1)
  197. {
  198. pci_set_region(hose->regions + reg_num++,
  199. pmmpcila[i], pmmla[i],
  200. ~(pmmma[i] & 0xfffff000) + 1,
  201. PCI_REGION_MEM);
  202. }
  203. hose->region_count = reg_num;
  204. pci_setup_indirect(hose,
  205. PCICFGADR,
  206. PCICFGDATA);
  207. if (hose->pci_fb)
  208. pciauto_region_init(hose->pci_fb);
  209. /* Let board change/modify hose & do initial checks */
  210. if (pci_pre_init(hose) == 0) {
  211. printf("PCI: Board-specific initialization failed.\n");
  212. printf("PCI: Configuration aborted.\n");
  213. return;
  214. }
  215. pci_register_hose(hose);
  216. /*--------------------------------------------------------------------------+
  217. * 405GP PCI Master configuration.
  218. * Map one 512 MB range of PLB/processor addresses to PCI memory space.
  219. * PLB address 0x80000000-0xBFFFFFFF ==> PCI address 0x80000000-0xBFFFFFFF
  220. * Use byte reversed out routines to handle endianess.
  221. *--------------------------------------------------------------------------*/
  222. out32r(PMM0MA, (pmmma[0]&~0x1)); /* disable, configure PMMxLA, PMMxPCILA first */
  223. out32r(PMM0LA, pmmla[0]);
  224. out32r(PMM0PCILA, pmmpcila[0]);
  225. out32r(PMM0PCIHA, pmmpciha[0]);
  226. out32r(PMM0MA, pmmma[0]);
  227. /*--------------------------------------------------------------------------+
  228. * PMM1 is not used. Initialize them to zero.
  229. *--------------------------------------------------------------------------*/
  230. out32r(PMM1MA, (pmmma[1]&~0x1));
  231. out32r(PMM1LA, pmmla[1]);
  232. out32r(PMM1PCILA, pmmpcila[1]);
  233. out32r(PMM1PCIHA, pmmpciha[1]);
  234. out32r(PMM1MA, pmmma[1]);
  235. /*--------------------------------------------------------------------------+
  236. * PMM2 is not used. Initialize them to zero.
  237. *--------------------------------------------------------------------------*/
  238. out32r(PMM2MA, (pmmma[2]&~0x1));
  239. out32r(PMM2LA, pmmla[2]);
  240. out32r(PMM2PCILA, pmmpcila[2]);
  241. out32r(PMM2PCIHA, pmmpciha[2]);
  242. out32r(PMM2MA, pmmma[2]);
  243. /*--------------------------------------------------------------------------+
  244. * 405GP PCI Target configuration. (PTM1)
  245. * Note: PTM1MS is hardwire enabled but we set the enable bit anyway.
  246. *--------------------------------------------------------------------------*/
  247. out32r(PTM1LA, ptmla[0]); /* insert address */
  248. out32r(PTM1MS, ptmms[0]); /* insert size, enable bit is 1 */
  249. pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_1, ptmpcila[0]);
  250. /*--------------------------------------------------------------------------+
  251. * 405GP PCI Target configuration. (PTM2)
  252. *--------------------------------------------------------------------------*/
  253. out32r(PTM2LA, ptmla[1]); /* insert address */
  254. pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, ptmpcila[1]);
  255. if (ptmms[1] == 0)
  256. {
  257. out32r(PTM2MS, 0x00000001); /* set enable bit */
  258. pci_write_config_dword(PCIDEVID_405GP, PCI_BASE_ADDRESS_2, 0x00000000);
  259. out32r(PTM2MS, 0x00000000); /* disable */
  260. }
  261. else
  262. {
  263. out32r(PTM2MS, ptmms[1]); /* insert size, enable bit is 1 */
  264. }
  265. /*
  266. * Insert Subsystem Vendor and Device ID
  267. */
  268. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_VENDOR_ID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
  269. #ifdef CONFIG_CPCI405
  270. if (is_pci_host(hose))
  271. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
  272. else
  273. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID2);
  274. #else
  275. pci_write_config_word(PCIDEVID_405GP, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
  276. #endif
  277. /*
  278. * Insert Class-code
  279. */
  280. #ifdef CONFIG_SYS_PCI_CLASSCODE
  281. pci_write_config_word(PCIDEVID_405GP, PCI_CLASS_SUB_CODE, CONFIG_SYS_PCI_CLASSCODE);
  282. #endif /* CONFIG_SYS_PCI_CLASSCODE */
  283. /*--------------------------------------------------------------------------+
  284. * If PCI speed = 66MHz, set 66MHz capable bit.
  285. *--------------------------------------------------------------------------*/
  286. if (bd->bi_pci_busfreq >= 66000000) {
  287. pci_read_config_word(PCIDEVID_405GP, PCI_STATUS, &temp_short);
  288. pci_write_config_word(PCIDEVID_405GP,PCI_STATUS,(temp_short|PCI_STATUS_66MHZ));
  289. }
  290. #if (CONFIG_PCI_HOST != PCI_HOST_ADAPTER)
  291. #if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
  292. if (is_pci_host(hose) ||
  293. (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
  294. #endif
  295. {
  296. /*--------------------------------------------------------------------------+
  297. * Write the 405GP PCI Configuration regs.
  298. * Enable 405GP to be a master on the PCI bus (PMM).
  299. * Enable 405GP to act as a PCI memory target (PTM).
  300. *--------------------------------------------------------------------------*/
  301. pci_read_config_word(PCIDEVID_405GP, PCI_COMMAND, &temp_short);
  302. pci_write_config_word(PCIDEVID_405GP, PCI_COMMAND, temp_short |
  303. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  304. }
  305. #endif
  306. #if defined(CONFIG_405EP)
  307. /*
  308. * on ppc405ep vendor/device id is not set
  309. * The user manual says 0x1014 (IBM) / 0x0156 (405GP!)
  310. * are the correct values.
  311. */
  312. pci_write_config_word(PCIDEVID_405GP, PCI_VENDOR_ID, PCI_VENDOR_ID_IBM);
  313. pci_write_config_word(PCIDEVID_405GP,
  314. PCI_DEVICE_ID, PCI_DEVICE_ID_IBM_405GP);
  315. #endif
  316. /*
  317. * Set HCE bit (Host Configuration Enabled)
  318. */
  319. pci_read_config_word(PCIDEVID_405GP, PCIBRDGOPT2, &temp_short);
  320. pci_write_config_word(PCIDEVID_405GP, PCIBRDGOPT2, (temp_short | 0x0001));
  321. #ifdef CONFIG_PCI_PNP
  322. /*--------------------------------------------------------------------------+
  323. * Scan the PCI bus and configure devices found.
  324. *--------------------------------------------------------------------------*/
  325. #if (CONFIG_PCI_HOST == PCI_HOST_AUTO)
  326. if (is_pci_host(hose) ||
  327. (((s = getenv("pciscan")) != NULL) && (strcmp(s, "yes") == 0)))
  328. #endif
  329. {
  330. #ifdef CONFIG_PCI_SCAN_SHOW
  331. printf("PCI: Bus Dev VenId DevId Class Int\n");
  332. #endif
  333. hose->last_busno = pci_hose_scan(hose);
  334. }
  335. #endif /* CONFIG_PCI_PNP */
  336. }
  337. /*
  338. * drivers/pci/pci.c skips every host bridge but the 405GP since it could
  339. * be set as an Adapter.
  340. *
  341. * I (Andrew May) don't know what we should do here, but I don't want
  342. * the auto setup of a PCI device disabling what is done pci_405gp_init
  343. * as has happened before.
  344. */
  345. void pci_405gp_setup_bridge(struct pci_controller *hose, pci_dev_t dev,
  346. struct pci_config_table *entry)
  347. {
  348. #ifdef DEBUG
  349. printf("405gp_setup_bridge\n");
  350. #endif
  351. }
  352. /*
  353. *
  354. */
  355. void pci_405gp_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  356. {
  357. unsigned char int_line = 0xff;
  358. /*
  359. * Write pci interrupt line register (cpci405 specific)
  360. */
  361. switch (PCI_DEV(dev) & 0x03)
  362. {
  363. case 0:
  364. int_line = 27 + 2;
  365. break;
  366. case 1:
  367. int_line = 27 + 3;
  368. break;
  369. case 2:
  370. int_line = 27 + 0;
  371. break;
  372. case 3:
  373. int_line = 27 + 1;
  374. break;
  375. }
  376. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
  377. }
  378. void pci_405gp_setup_vga(struct pci_controller *hose, pci_dev_t dev,
  379. struct pci_config_table *entry)
  380. {
  381. unsigned int cmdstat = 0;
  382. pciauto_setup_device(hose, dev, 6, hose->pci_mem, hose->pci_prefetch, hose->pci_io);
  383. /* always enable io space on vga boards */
  384. pci_hose_read_config_dword(hose, dev, PCI_COMMAND, &cmdstat);
  385. cmdstat |= PCI_COMMAND_IO;
  386. pci_hose_write_config_dword(hose, dev, PCI_COMMAND, cmdstat);
  387. }
  388. #if !(defined(CONFIG_PIP405) || defined (CONFIG_MIP405)) && !(defined (CONFIG_SC3))
  389. /*
  390. *As is these functs get called out of flash Not a horrible
  391. *thing, but something to keep in mind. (no statics?)
  392. */
  393. static struct pci_config_table pci_405gp_config_table[] = {
  394. /*if VendID is 0 it terminates the table search (ie Walnut)*/
  395. #ifdef CONFIG_SYS_PCI_SUBSYS_VENDORID
  396. {CONFIG_SYS_PCI_SUBSYS_VENDORID, PCI_ANY_ID, PCI_CLASS_BRIDGE_HOST,
  397. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_bridge},
  398. #endif
  399. {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA,
  400. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
  401. {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA,
  402. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, pci_405gp_setup_vga},
  403. { }
  404. };
  405. static struct pci_controller hose = {
  406. fixup_irq: pci_405gp_fixup_irq,
  407. config_table: pci_405gp_config_table,
  408. };
  409. void pci_init_board(void)
  410. {
  411. /*we want the ptrs to RAM not flash (ie don't use init list)*/
  412. hose.fixup_irq = pci_405gp_fixup_irq;
  413. hose.config_table = pci_405gp_config_table;
  414. pci_405gp_init(&hose);
  415. }
  416. #endif
  417. #endif /* CONFIG_405GP */
  418. /*-----------------------------------------------------------------------------+
  419. * CONFIG_440
  420. *-----------------------------------------------------------------------------*/
  421. #if defined(CONFIG_440)
  422. #if defined(CONFIG_SYS_PCI_MASTER_INIT) || defined(CONFIG_SYS_PCI_TARGET_INIT)
  423. static struct pci_controller ppc440_hose = {0};
  424. #endif
  425. /*
  426. * This routine is called to determine if a pci scan should be
  427. * performed. With various hardware environments (especially cPCI and
  428. * PPMC) it's insufficient to depend on the state of the arbiter enable
  429. * bit in the strap register, or generic host/adapter assumptions.
  430. *
  431. * Rather than hard-code a bad assumption in the general 440 code, the
  432. * 440 pci code requires the board to decide at runtime.
  433. *
  434. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  435. *
  436. * Weak default implementation: "Normal" boards implement the PCI
  437. * host functionality. This can be overridden for PCI adapter boards.
  438. */
  439. int __is_pci_host(struct pci_controller *hose)
  440. {
  441. return 1;
  442. }
  443. int is_pci_host(struct pci_controller *hose)
  444. __attribute__((weak, alias("__is_pci_host")));
  445. #if defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
  446. defined(CONFIG_440GR) || defined(CONFIG_440GRX)
  447. #if defined(CONFIG_SYS_PCI_TARGET_INIT)
  448. /*
  449. * pci_target_init
  450. *
  451. * The bootstrap configuration provides default settings for the pci
  452. * inbound map (PIM). But the bootstrap config choices are limited and
  453. * may not be sufficient for a given board.
  454. */
  455. void __pci_target_init(struct pci_controller *hose)
  456. {
  457. /*
  458. * Set up Direct MMIO registers
  459. */
  460. /*
  461. * PowerPC440 EP PCI Master configuration.
  462. * Map one 1Gig range of PLB/processor addresses to PCI memory space.
  463. * PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  464. * Use byte reversed out routines to handle endianess.
  465. * Make this region non-prefetchable.
  466. */
  467. /* PMM0 Mask/Attribute - disabled b4 setting */
  468. out_le32((void *)PCIL0_PMM0MA, 0x00000000);
  469. /* PMM0 Local Address */
  470. out_le32((void *)PCIL0_PMM0LA, CONFIG_SYS_PCI_MEMBASE);
  471. /* PMM0 PCI Low Address */
  472. out_le32((void *)PCIL0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE);
  473. /* PMM0 PCI High Address */
  474. out_le32((void *)PCIL0_PMM0PCIHA, 0x00000000);
  475. /* 512M + No prefetching, and enable region */
  476. out_le32((void *)PCIL0_PMM0MA, 0xE0000001);
  477. /* PMM1 Mask/Attribute - disabled b4 setting */
  478. out_le32((void *)PCIL0_PMM1MA, 0x00000000);
  479. /* PMM1 Local Address */
  480. out_le32((void *)PCIL0_PMM1LA, CONFIG_SYS_PCI_MEMBASE2);
  481. /* PMM1 PCI Low Address */
  482. out_le32((void *)PCIL0_PMM1PCILA, CONFIG_SYS_PCI_MEMBASE2);
  483. /* PMM1 PCI High Address */
  484. out_le32((void *)PCIL0_PMM1PCIHA, 0x00000000);
  485. /* 512M + No prefetching, and enable region */
  486. out_le32((void *)PCIL0_PMM1MA, 0xE0000001);
  487. out_le32((void *)PCIL0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  488. out_le32((void *)PCIL0_PTM1LA, 0); /* Local Addr. Reg */
  489. out_le32((void *)PCIL0_PTM2MS, 0); /* Memory Size/Attribute */
  490. out_le32((void *)PCIL0_PTM2LA, 0); /* Local Addr. Reg */
  491. /*
  492. * Set up Configuration registers
  493. */
  494. /* Program the board's subsystem id/vendor id */
  495. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  496. CONFIG_SYS_PCI_SUBSYS_VENDORID);
  497. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
  498. /* Configure command register as bus master */
  499. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  500. /* 240nS PCI clock */
  501. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  502. /* No error reporting */
  503. pci_write_config_word(0, PCI_ERREN, 0);
  504. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  505. }
  506. #endif /* CONFIG_SYS_PCI_TARGET_INIT */
  507. /*
  508. * pci_pre_init
  509. *
  510. * This routine is called just prior to registering the hose and gives
  511. * the board the opportunity to check things. Returning a value of zero
  512. * indicates that things are bad & PCI initialization should be aborted.
  513. *
  514. * Different boards may wish to customize the pci controller structure
  515. * (add regions, override default access routines, etc) or perform
  516. * certain pre-initialization actions.
  517. *
  518. */
  519. int __pci_pre_init(struct pci_controller *hose)
  520. {
  521. u32 reg;
  522. /*
  523. * Set priority for all PLB3 devices to 0.
  524. * Set PLB3 arbiter to fair mode.
  525. */
  526. mfsdr(SDR0_AMP1, reg);
  527. mtsdr(SDR0_AMP1, (reg & 0x000000FF) | 0x0000FF00);
  528. reg = mfdcr(PLB3A0_ACR);
  529. mtdcr(PLB3A0_ACR, reg | 0x80000000);
  530. /*
  531. * Set priority for all PLB4 devices to 0.
  532. */
  533. mfsdr(SDR0_AMP0, reg);
  534. mtsdr(SDR0_AMP0, (reg & 0x000000FF) | 0x0000FF00);
  535. reg = mfdcr(PLB4A0_ACR) | 0xa0000000;
  536. mtdcr(PLB4A0_ACR, reg);
  537. /*
  538. * Set Nebula PLB4 arbiter to fair mode.
  539. */
  540. /* Segment0 */
  541. reg = (mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_PPM_MASK) | PLB4Ax_ACR_PPM_FAIR;
  542. reg = (reg & ~PLB4Ax_ACR_HBU_MASK) | PLB4Ax_ACR_HBU_ENABLED;
  543. reg = (reg & ~PLB4Ax_ACR_RDP_MASK) | PLB4Ax_ACR_RDP_4DEEP;
  544. reg = (reg & ~PLB4Ax_ACR_WRP_MASK) | PLB4Ax_ACR_WRP_2DEEP;
  545. mtdcr(PLB4A0_ACR, reg);
  546. /* Segment1 */
  547. reg = (mfdcr(PLB4A1_ACR) & ~PLB4Ax_ACR_PPM_MASK) | PLB4Ax_ACR_PPM_FAIR;
  548. reg = (reg & ~PLB4Ax_ACR_HBU_MASK) | PLB4Ax_ACR_HBU_ENABLED;
  549. reg = (reg & ~PLB4Ax_ACR_RDP_MASK) | PLB4Ax_ACR_RDP_4DEEP;
  550. reg = (reg & ~PLB4Ax_ACR_WRP_MASK) | PLB4Ax_ACR_WRP_2DEEP;
  551. mtdcr(PLB4A1_ACR, reg);
  552. #if defined(CONFIG_SYS_PCI_BOARD_FIXUP_IRQ)
  553. hose->fixup_irq = board_pci_fixup_irq;
  554. #endif
  555. return 1;
  556. }
  557. #else /* defined(CONFIG_440EP) ... */
  558. #if defined(CONFIG_SYS_PCI_TARGET_INIT)
  559. void __pci_target_init(struct pci_controller * hose)
  560. {
  561. /*
  562. * Disable everything
  563. */
  564. out_le32((void *)PCIL0_PIM0SA, 0); /* disable */
  565. out_le32((void *)PCIL0_PIM1SA, 0); /* disable */
  566. out_le32((void *)PCIL0_PIM2SA, 0); /* disable */
  567. out_le32((void *)PCIL0_EROMBA, 0); /* disable expansion rom */
  568. /*
  569. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440
  570. * strapping options do not support sizes such as 128/256 MB.
  571. */
  572. out_le32((void *)PCIL0_PIM0LAL, CONFIG_SYS_SDRAM_BASE);
  573. out_le32((void *)PCIL0_PIM0LAH, 0);
  574. out_le32((void *)PCIL0_PIM0SA, ~(gd->ram_size - 1) | 1);
  575. out_le32((void *)PCIL0_BAR0, 0);
  576. /*
  577. * Program the board's subsystem id/vendor id
  578. */
  579. out_le16((void *)PCIL0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID);
  580. out_le16((void *)PCIL0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_DEVICEID);
  581. out_le16((void *)PCIL0_CMD, in_le16((void *)PCIL0_CMD) |
  582. PCI_COMMAND_MEMORY);
  583. }
  584. #endif /* CONFIG_SYS_PCI_TARGET_INIT */
  585. int __pci_pre_init(struct pci_controller *hose)
  586. {
  587. /*
  588. * This board is always configured as the host & requires the
  589. * PCI arbiter to be enabled.
  590. */
  591. if (!pci_arbiter_enabled()) {
  592. printf("PCI: PCI Arbiter disabled!\n");
  593. return 0;
  594. }
  595. return 1;
  596. }
  597. #endif /* defined(CONFIG_440EP) ... */
  598. #if defined(CONFIG_SYS_PCI_TARGET_INIT)
  599. void pci_target_init(struct pci_controller * hose)
  600. __attribute__((weak, alias("__pci_target_init")));
  601. #endif /* CONFIG_SYS_PCI_TARGET_INIT */
  602. int pci_pre_init(struct pci_controller *hose)
  603. __attribute__((weak, alias("__pci_pre_init")));
  604. #if defined(CONFIG_SYS_PCI_MASTER_INIT)
  605. void __pci_master_init(struct pci_controller *hose)
  606. {
  607. u16 reg;
  608. /*
  609. * Write the PowerPC440 EP PCI Configuration regs.
  610. * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  611. * Enable PowerPC440 EP to act as a PCI memory target (PTM).
  612. */
  613. pci_read_config_word(0, PCI_COMMAND, &reg);
  614. pci_write_config_word(0, PCI_COMMAND, reg |
  615. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  616. }
  617. void pci_master_init(struct pci_controller *hose)
  618. __attribute__((weak, alias("__pci_master_init")));
  619. #endif /* CONFIG_SYS_PCI_MASTER_INIT */
  620. #if defined(CONFIG_SYS_PCI_MASTER_INIT) || defined(CONFIG_SYS_PCI_TARGET_INIT)
  621. static int pci_440_init (struct pci_controller *hose)
  622. {
  623. int reg_num = 0;
  624. #ifndef CONFIG_DISABLE_PISE_TEST
  625. /*--------------------------------------------------------------------------+
  626. * The PCI initialization sequence enable bit must be set ... if not abort
  627. * pci setup since updating the bit requires chip reset.
  628. *--------------------------------------------------------------------------*/
  629. #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  630. unsigned long strap;
  631. mfsdr(SDR0_SDSTP1,strap);
  632. if ((strap & SDR0_SDSTP1_PISE_MASK) == 0) {
  633. printf("PCI: SDR0_STRP1[PISE] not set.\n");
  634. printf("PCI: Configuration aborted.\n");
  635. return -1;
  636. }
  637. #elif defined(CONFIG_440GP)
  638. unsigned long strap;
  639. strap = mfdcr(CPC0_STRP1);
  640. if ((strap & CPC0_STRP1_PISE_MASK) == 0) {
  641. printf("PCI: CPC0_STRP1[PISE] not set.\n");
  642. printf("PCI: Configuration aborted.\n");
  643. return -1;
  644. }
  645. #endif
  646. #endif /* CONFIG_DISABLE_PISE_TEST */
  647. /*--------------------------------------------------------------------------+
  648. * PCI controller init
  649. *--------------------------------------------------------------------------*/
  650. hose->first_busno = 0;
  651. hose->last_busno = 0;
  652. /* PCI I/O space */
  653. pci_set_region(hose->regions + reg_num++,
  654. 0x00000000,
  655. PCIL0_IOBASE,
  656. 0x10000,
  657. PCI_REGION_IO);
  658. /* PCI memory space */
  659. pci_set_region(hose->regions + reg_num++,
  660. CONFIG_SYS_PCI_TARGBASE,
  661. CONFIG_SYS_PCI_MEMBASE,
  662. #ifdef CONFIG_SYS_PCI_MEMSIZE
  663. CONFIG_SYS_PCI_MEMSIZE,
  664. #else
  665. 0x10000000,
  666. #endif
  667. PCI_REGION_MEM );
  668. #if defined(CONFIG_PCI_SYS_MEM_BUS) && defined(CONFIG_PCI_SYS_MEM_PHYS) && \
  669. defined(CONFIG_PCI_SYS_MEM_SIZE)
  670. /* System memory space */
  671. pci_set_region(hose->regions + reg_num++,
  672. CONFIG_PCI_SYS_MEM_BUS,
  673. CONFIG_PCI_SYS_MEM_PHYS,
  674. CONFIG_PCI_SYS_MEM_SIZE,
  675. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY );
  676. #endif
  677. hose->region_count = reg_num;
  678. pci_setup_indirect(hose, PCIL0_CFGADR, PCIL0_CFGDATA);
  679. /* Let board change/modify hose & do initial checks */
  680. if (pci_pre_init(hose) == 0) {
  681. printf("PCI: Board-specific initialization failed.\n");
  682. printf("PCI: Configuration aborted.\n");
  683. return -1;
  684. }
  685. pci_register_hose( hose );
  686. /*--------------------------------------------------------------------------+
  687. * PCI target init
  688. *--------------------------------------------------------------------------*/
  689. #if defined(CONFIG_SYS_PCI_TARGET_INIT)
  690. pci_target_init(hose); /* Let board setup pci target */
  691. #else
  692. out16r( PCIL0_SBSYSVID, CONFIG_SYS_PCI_SUBSYS_VENDORID );
  693. out16r( PCIL0_SBSYSID, CONFIG_SYS_PCI_SUBSYS_ID );
  694. out16r( PCIL0_CLS, 0x00060000 ); /* Bridge, host bridge */
  695. #endif
  696. #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
  697. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  698. out32r( PCIL0_BRDGOPT1, 0x04000060 ); /* PLB Rq pri highest */
  699. out32r( PCIL0_BRDGOPT2, in32(PCIL0_BRDGOPT2) | 0x83 ); /* Enable host config, clear Timeout, ensure int src1 */
  700. #elif defined(PCIL0_BRDGOPT1)
  701. out32r( PCIL0_BRDGOPT1, 0x10000060 ); /* PLB Rq pri highest */
  702. out32r( PCIL0_BRDGOPT2, in32(PCIL0_BRDGOPT2) | 1 ); /* Enable host config */
  703. #endif
  704. /*--------------------------------------------------------------------------+
  705. * PCI master init: default is one 256MB region for PCI memory:
  706. * 0x3_00000000 - 0x3_0FFFFFFF ==> CONFIG_SYS_PCI_MEMBASE
  707. *--------------------------------------------------------------------------*/
  708. #if defined(CONFIG_SYS_PCI_MASTER_INIT)
  709. pci_master_init(hose); /* Let board setup pci master */
  710. #else
  711. out32r( PCIL0_POM0SA, 0 ); /* disable */
  712. out32r( PCIL0_POM1SA, 0 ); /* disable */
  713. out32r( PCIL0_POM2SA, 0 ); /* disable */
  714. #if defined(CONFIG_440SPE)
  715. out32r( PCIL0_POM0LAL, 0x10000000 );
  716. out32r( PCIL0_POM0LAH, 0x0000000c );
  717. #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
  718. out32r( PCIL0_POM0LAL, 0x20000000 );
  719. out32r( PCIL0_POM0LAH, 0x0000000c );
  720. #else
  721. out32r( PCIL0_POM0LAL, 0x00000000 );
  722. out32r( PCIL0_POM0LAH, 0x00000003 );
  723. #endif
  724. out32r( PCIL0_POM0PCIAL, CONFIG_SYS_PCI_MEMBASE );
  725. out32r( PCIL0_POM0PCIAH, 0x00000000 );
  726. out32r( PCIL0_POM0SA, 0xf0000001 ); /* 256MB, enabled */
  727. out32r( PCIL0_STS, in32r( PCIL0_STS ) & ~0x0000fff8 );
  728. #endif
  729. /*--------------------------------------------------------------------------+
  730. * PCI host configuration -- we don't make any assumptions here ... the
  731. * _board_must_indicate_ what to do -- there's just too many runtime
  732. * scenarios in environments like cPCI, PPMC, etc. to make a determination
  733. * based on hard-coded values or state of arbiter enable.
  734. *--------------------------------------------------------------------------*/
  735. if (is_pci_host(hose)) {
  736. #ifdef CONFIG_PCI_SCAN_SHOW
  737. printf("PCI: Bus Dev VenId DevId Class Int\n");
  738. #endif
  739. #if !defined(CONFIG_440EP) && !defined(CONFIG_440GR) && \
  740. !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
  741. out16r( PCIL0_CMD, in16r( PCIL0_CMD ) | PCI_COMMAND_MASTER);
  742. #endif
  743. hose->last_busno = pci_hose_scan(hose);
  744. }
  745. return hose->last_busno;
  746. }
  747. #endif
  748. void pci_init_board(void)
  749. {
  750. int busno = 0;
  751. /*
  752. * Only init PCI when either master or target functionality
  753. * is selected.
  754. */
  755. #if defined(CONFIG_SYS_PCI_MASTER_INIT) || defined(CONFIG_SYS_PCI_TARGET_INIT)
  756. busno = pci_440_init(&ppc440_hose);
  757. if (busno < 0)
  758. return;
  759. #endif
  760. #if (defined(CONFIG_440SPE) || \
  761. defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
  762. !defined(CONFIG_PCI_DISABLE_PCIE)
  763. pcie_setup_hoses(busno + 1);
  764. #endif
  765. }
  766. #endif /* CONFIG_440 */
  767. #if defined(CONFIG_405EX)
  768. void pci_init_board(void)
  769. {
  770. #ifdef CONFIG_PCI_SCAN_SHOW
  771. printf("PCI: Bus Dev VenId DevId Class Int\n");
  772. #endif
  773. pcie_setup_hoses(0);
  774. }
  775. #endif /* CONFIG_405EX */
  776. #endif /* CONFIG_PCI */