pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2005-2007 Cavium Networks
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/pci.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/time.h>
  13. #include <linux/delay.h>
  14. #include <asm/time.h>
  15. #include <asm/octeon/octeon.h>
  16. #include <asm/octeon/cvmx-npi-defs.h>
  17. #include <asm/octeon/cvmx-pci-defs.h>
  18. #include "pci-common.h"
  19. #define USE_OCTEON_INTERNAL_ARBITER
  20. /*
  21. * Octeon's PCI controller uses did=3, subdid=2 for PCI IO
  22. * addresses. Use PCI endian swapping 1 so no address swapping is
  23. * necessary. The Linux io routines will endian swap the data.
  24. */
  25. #define OCTEON_PCI_IOSPACE_BASE 0x80011a0400000000ull
  26. #define OCTEON_PCI_IOSPACE_SIZE (1ull<<32)
  27. /* Octeon't PCI controller uses did=3, subdid=3 for PCI memory. */
  28. #define OCTEON_PCI_MEMSPACE_OFFSET (0x00011b0000000000ull)
  29. /**
  30. * This is the bit decoding used for the Octeon PCI controller addresses
  31. */
  32. union octeon_pci_address {
  33. uint64_t u64;
  34. struct {
  35. uint64_t upper:2;
  36. uint64_t reserved:13;
  37. uint64_t io:1;
  38. uint64_t did:5;
  39. uint64_t subdid:3;
  40. uint64_t reserved2:4;
  41. uint64_t endian_swap:2;
  42. uint64_t reserved3:10;
  43. uint64_t bus:8;
  44. uint64_t dev:5;
  45. uint64_t func:3;
  46. uint64_t reg:8;
  47. } s;
  48. };
  49. /**
  50. * Return the mapping of PCI device number to IRQ line. Each
  51. * character in the return string represents the interrupt
  52. * line for the device at that position. Device 1 maps to the
  53. * first character, etc. The characters A-D are used for PCI
  54. * interrupts.
  55. *
  56. * Returns PCI interrupt mapping
  57. */
  58. const char *octeon_get_pci_interrupts(void)
  59. {
  60. /*
  61. * Returning an empty string causes the interrupts to be
  62. * routed based on the PCI specification. From the PCI spec:
  63. *
  64. * INTA# of Device Number 0 is connected to IRQW on the system
  65. * board. (Device Number has no significance regarding being
  66. * located on the system board or in a connector.) INTA# of
  67. * Device Number 1 is connected to IRQX on the system
  68. * board. INTA# of Device Number 2 is connected to IRQY on the
  69. * system board. INTA# of Device Number 3 is connected to IRQZ
  70. * on the system board. The table below describes how each
  71. * agent's INTx# lines are connected to the system board
  72. * interrupt lines. The following equation can be used to
  73. * determine to which INTx# signal on the system board a given
  74. * device's INTx# line(s) is connected.
  75. *
  76. * MB = (D + I) MOD 4 MB = System board Interrupt (IRQW = 0,
  77. * IRQX = 1, IRQY = 2, and IRQZ = 3) D = Device Number I =
  78. * Interrupt Number (INTA# = 0, INTB# = 1, INTC# = 2, and
  79. * INTD# = 3)
  80. */
  81. switch (octeon_bootinfo->board_type) {
  82. case CVMX_BOARD_TYPE_NAO38:
  83. /* This is really the NAC38 */
  84. return "AAAAADABAAAAAAAAAAAAAAAAAAAAAAAA";
  85. case CVMX_BOARD_TYPE_THUNDER:
  86. return "";
  87. case CVMX_BOARD_TYPE_EBH3000:
  88. return "";
  89. case CVMX_BOARD_TYPE_EBH3100:
  90. case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
  91. case CVMX_BOARD_TYPE_CN3005_EVB_HS5:
  92. return "AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
  93. case CVMX_BOARD_TYPE_BBGW_REF:
  94. return "AABCD";
  95. default:
  96. return "";
  97. }
  98. }
  99. /**
  100. * Map a PCI device to the appropriate interrupt line
  101. *
  102. * @dev: The Linux PCI device structure for the device to map
  103. * @slot: The slot number for this device on __BUS 0__. Linux
  104. * enumerates through all the bridges and figures out the
  105. * slot on Bus 0 where this device eventually hooks to.
  106. * @pin: The PCI interrupt pin read from the device, then swizzled
  107. * as it goes through each bridge.
  108. * Returns Interrupt number for the device
  109. */
  110. int __init octeon_pci_pcibios_map_irq(const struct pci_dev *dev,
  111. u8 slot, u8 pin)
  112. {
  113. int irq_num;
  114. const char *interrupts;
  115. int dev_num;
  116. /* Get the board specific interrupt mapping */
  117. interrupts = octeon_get_pci_interrupts();
  118. dev_num = dev->devfn >> 3;
  119. if (dev_num < strlen(interrupts))
  120. irq_num = ((interrupts[dev_num] - 'A' + pin - 1) & 3) +
  121. OCTEON_IRQ_PCI_INT0;
  122. else
  123. irq_num = ((slot + pin - 3) & 3) + OCTEON_IRQ_PCI_INT0;
  124. return irq_num;
  125. }
  126. /**
  127. * Read a value from configuration space
  128. *
  129. */
  130. static int octeon_read_config(struct pci_bus *bus, unsigned int devfn,
  131. int reg, int size, u32 *val)
  132. {
  133. union octeon_pci_address pci_addr;
  134. pci_addr.u64 = 0;
  135. pci_addr.s.upper = 2;
  136. pci_addr.s.io = 1;
  137. pci_addr.s.did = 3;
  138. pci_addr.s.subdid = 1;
  139. pci_addr.s.endian_swap = 1;
  140. pci_addr.s.bus = bus->number;
  141. pci_addr.s.dev = devfn >> 3;
  142. pci_addr.s.func = devfn & 0x7;
  143. pci_addr.s.reg = reg;
  144. #if PCI_CONFIG_SPACE_DELAY
  145. udelay(PCI_CONFIG_SPACE_DELAY);
  146. #endif
  147. switch (size) {
  148. case 4:
  149. *val = le32_to_cpu(cvmx_read64_uint32(pci_addr.u64));
  150. return PCIBIOS_SUCCESSFUL;
  151. case 2:
  152. *val = le16_to_cpu(cvmx_read64_uint16(pci_addr.u64));
  153. return PCIBIOS_SUCCESSFUL;
  154. case 1:
  155. *val = cvmx_read64_uint8(pci_addr.u64);
  156. return PCIBIOS_SUCCESSFUL;
  157. }
  158. return PCIBIOS_FUNC_NOT_SUPPORTED;
  159. }
  160. /**
  161. * Write a value to PCI configuration space
  162. *
  163. * @bus:
  164. * @devfn:
  165. * @reg:
  166. * @size:
  167. * @val:
  168. * Returns
  169. */
  170. static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
  171. int reg, int size, u32 val)
  172. {
  173. union octeon_pci_address pci_addr;
  174. pci_addr.u64 = 0;
  175. pci_addr.s.upper = 2;
  176. pci_addr.s.io = 1;
  177. pci_addr.s.did = 3;
  178. pci_addr.s.subdid = 1;
  179. pci_addr.s.endian_swap = 1;
  180. pci_addr.s.bus = bus->number;
  181. pci_addr.s.dev = devfn >> 3;
  182. pci_addr.s.func = devfn & 0x7;
  183. pci_addr.s.reg = reg;
  184. #if PCI_CONFIG_SPACE_DELAY
  185. udelay(PCI_CONFIG_SPACE_DELAY);
  186. #endif
  187. switch (size) {
  188. case 4:
  189. cvmx_write64_uint32(pci_addr.u64, cpu_to_le32(val));
  190. return PCIBIOS_SUCCESSFUL;
  191. case 2:
  192. cvmx_write64_uint16(pci_addr.u64, cpu_to_le16(val));
  193. return PCIBIOS_SUCCESSFUL;
  194. case 1:
  195. cvmx_write64_uint8(pci_addr.u64, val);
  196. return PCIBIOS_SUCCESSFUL;
  197. }
  198. return PCIBIOS_FUNC_NOT_SUPPORTED;
  199. }
  200. static struct pci_ops octeon_pci_ops = {
  201. octeon_read_config,
  202. octeon_write_config,
  203. };
  204. static struct resource octeon_pci_mem_resource = {
  205. .start = 0,
  206. .end = 0,
  207. .name = "Octeon PCI MEM",
  208. .flags = IORESOURCE_MEM,
  209. };
  210. /*
  211. * PCI ports must be above 16KB so the ISA bus filtering in the PCI-X to PCI
  212. * bridge
  213. */
  214. static struct resource octeon_pci_io_resource = {
  215. .start = 0x4000,
  216. .end = OCTEON_PCI_IOSPACE_SIZE - 1,
  217. .name = "Octeon PCI IO",
  218. .flags = IORESOURCE_IO,
  219. };
  220. static struct pci_controller octeon_pci_controller = {
  221. .pci_ops = &octeon_pci_ops,
  222. .mem_resource = &octeon_pci_mem_resource,
  223. .mem_offset = OCTEON_PCI_MEMSPACE_OFFSET,
  224. .io_resource = &octeon_pci_io_resource,
  225. .io_offset = 0,
  226. .io_map_base = OCTEON_PCI_IOSPACE_BASE,
  227. };
  228. /**
  229. * Low level initialize the Octeon PCI controller
  230. *
  231. * Returns
  232. */
  233. static void octeon_pci_initialize(void)
  234. {
  235. union cvmx_pci_cfg01 cfg01;
  236. union cvmx_npi_ctl_status ctl_status;
  237. union cvmx_pci_ctl_status_2 ctl_status_2;
  238. union cvmx_pci_cfg19 cfg19;
  239. union cvmx_pci_cfg16 cfg16;
  240. union cvmx_pci_cfg22 cfg22;
  241. union cvmx_pci_cfg56 cfg56;
  242. /* Reset the PCI Bus */
  243. cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x1);
  244. cvmx_read_csr(CVMX_CIU_SOFT_PRST);
  245. udelay(2000); /* Hold PCI reset for 2 ms */
  246. ctl_status.u64 = 0; /* cvmx_read_csr(CVMX_NPI_CTL_STATUS); */
  247. ctl_status.s.max_word = 1;
  248. ctl_status.s.timer = 1;
  249. cvmx_write_csr(CVMX_NPI_CTL_STATUS, ctl_status.u64);
  250. /* Deassert PCI reset and advertize PCX Host Mode Device Capability
  251. (64b) */
  252. cvmx_write_csr(CVMX_CIU_SOFT_PRST, 0x4);
  253. cvmx_read_csr(CVMX_CIU_SOFT_PRST);
  254. udelay(2000); /* Wait 2 ms after deasserting PCI reset */
  255. ctl_status_2.u32 = 0;
  256. ctl_status_2.s.tsr_hwm = 1; /* Initializes to 0. Must be set
  257. before any PCI reads. */
  258. ctl_status_2.s.bar2pres = 1; /* Enable BAR2 */
  259. ctl_status_2.s.bar2_enb = 1;
  260. ctl_status_2.s.bar2_cax = 1; /* Don't use L2 */
  261. ctl_status_2.s.bar2_esx = 1;
  262. ctl_status_2.s.pmo_amod = 1; /* Round robin priority */
  263. if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {
  264. /* BAR1 hole */
  265. ctl_status_2.s.bb1_hole = OCTEON_PCI_BAR1_HOLE_BITS;
  266. ctl_status_2.s.bb1_siz = 1; /* BAR1 is 2GB */
  267. ctl_status_2.s.bb_ca = 1; /* Don't use L2 with big bars */
  268. ctl_status_2.s.bb_es = 1; /* Big bar in byte swap mode */
  269. ctl_status_2.s.bb1 = 1; /* BAR1 is big */
  270. ctl_status_2.s.bb0 = 1; /* BAR0 is big */
  271. }
  272. octeon_npi_write32(CVMX_NPI_PCI_CTL_STATUS_2, ctl_status_2.u32);
  273. udelay(2000); /* Wait 2 ms before doing PCI reads */
  274. ctl_status_2.u32 = octeon_npi_read32(CVMX_NPI_PCI_CTL_STATUS_2);
  275. pr_notice("PCI Status: %s %s-bit\n",
  276. ctl_status_2.s.ap_pcix ? "PCI-X" : "PCI",
  277. ctl_status_2.s.ap_64ad ? "64" : "32");
  278. if (OCTEON_IS_MODEL(OCTEON_CN58XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  279. union cvmx_pci_cnt_reg cnt_reg_start;
  280. union cvmx_pci_cnt_reg cnt_reg_end;
  281. unsigned long cycles, pci_clock;
  282. cnt_reg_start.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);
  283. cycles = read_c0_cvmcount();
  284. udelay(1000);
  285. cnt_reg_end.u64 = cvmx_read_csr(CVMX_NPI_PCI_CNT_REG);
  286. cycles = read_c0_cvmcount() - cycles;
  287. pci_clock = (cnt_reg_end.s.pcicnt - cnt_reg_start.s.pcicnt) /
  288. (cycles / (mips_hpt_frequency / 1000000));
  289. pr_notice("PCI Clock: %lu MHz\n", pci_clock);
  290. }
  291. /*
  292. * TDOMC must be set to one in PCI mode. TDOMC should be set to 4
  293. * in PCI-X mode to allow four oustanding splits. Otherwise,
  294. * should not change from its reset value. Don't write PCI_CFG19
  295. * in PCI mode (0x82000001 reset value), write it to 0x82000004
  296. * after PCI-X mode is known. MRBCI,MDWE,MDRE -> must be zero.
  297. * MRBCM -> must be one.
  298. */
  299. if (ctl_status_2.s.ap_pcix) {
  300. cfg19.u32 = 0;
  301. /*
  302. * Target Delayed/Split request outstanding maximum
  303. * count. [1..31] and 0=32. NOTE: If the user
  304. * programs these bits beyond the Designed Maximum
  305. * outstanding count, then the designed maximum table
  306. * depth will be used instead. No additional
  307. * Deferred/Split transactions will be accepted if
  308. * this outstanding maximum count is
  309. * reached. Furthermore, no additional deferred/split
  310. * transactions will be accepted if the I/O delay/ I/O
  311. * Split Request outstanding maximum is reached.
  312. */
  313. cfg19.s.tdomc = 4;
  314. /*
  315. * Master Deferred Read Request Outstanding Max Count
  316. * (PCI only). CR4C[26:24] Max SAC cycles MAX DAC
  317. * cycles 000 8 4 001 1 0 010 2 1 011 3 1 100 4 2 101
  318. * 5 2 110 6 3 111 7 3 For example, if these bits are
  319. * programmed to 100, the core can support 2 DAC
  320. * cycles, 4 SAC cycles or a combination of 1 DAC and
  321. * 2 SAC cycles. NOTE: For the PCI-X maximum
  322. * outstanding split transactions, refer to
  323. * CRE0[22:20].
  324. */
  325. cfg19.s.mdrrmc = 2;
  326. /*
  327. * Master Request (Memory Read) Byte Count/Byte Enable
  328. * select. 0 = Byte Enables valid. In PCI mode, a
  329. * burst transaction cannot be performed using Memory
  330. * Read command=4?h6. 1 = DWORD Byte Count valid
  331. * (default). In PCI Mode, the memory read byte
  332. * enables are automatically generated by the
  333. * core. Note: N3 Master Request transaction sizes are
  334. * always determined through the
  335. * am_attr[<35:32>|<7:0>] field.
  336. */
  337. cfg19.s.mrbcm = 1;
  338. octeon_npi_write32(CVMX_NPI_PCI_CFG19, cfg19.u32);
  339. }
  340. cfg01.u32 = 0;
  341. cfg01.s.msae = 1; /* Memory Space Access Enable */
  342. cfg01.s.me = 1; /* Master Enable */
  343. cfg01.s.pee = 1; /* PERR# Enable */
  344. cfg01.s.see = 1; /* System Error Enable */
  345. cfg01.s.fbbe = 1; /* Fast Back to Back Transaction Enable */
  346. octeon_npi_write32(CVMX_NPI_PCI_CFG01, cfg01.u32);
  347. #ifdef USE_OCTEON_INTERNAL_ARBITER
  348. /*
  349. * When OCTEON is a PCI host, most systems will use OCTEON's
  350. * internal arbiter, so must enable it before any PCI/PCI-X
  351. * traffic can occur.
  352. */
  353. {
  354. union cvmx_npi_pci_int_arb_cfg pci_int_arb_cfg;
  355. pci_int_arb_cfg.u64 = 0;
  356. pci_int_arb_cfg.s.en = 1; /* Internal arbiter enable */
  357. cvmx_write_csr(CVMX_NPI_PCI_INT_ARB_CFG, pci_int_arb_cfg.u64);
  358. }
  359. #endif /* USE_OCTEON_INTERNAL_ARBITER */
  360. /*
  361. * Preferrably written to 1 to set MLTD. [RDSATI,TRTAE,
  362. * TWTAE,TMAE,DPPMR -> must be zero. TILT -> must not be set to
  363. * 1..7.
  364. */
  365. cfg16.u32 = 0;
  366. cfg16.s.mltd = 1; /* Master Latency Timer Disable */
  367. octeon_npi_write32(CVMX_NPI_PCI_CFG16, cfg16.u32);
  368. /*
  369. * Should be written to 0x4ff00. MTTV -> must be zero.
  370. * FLUSH -> must be 1. MRV -> should be 0xFF.
  371. */
  372. cfg22.u32 = 0;
  373. /* Master Retry Value [1..255] and 0=infinite */
  374. cfg22.s.mrv = 0xff;
  375. /*
  376. * AM_DO_FLUSH_I control NOTE: This bit MUST BE ONE for proper
  377. * N3K operation.
  378. */
  379. cfg22.s.flush = 1;
  380. octeon_npi_write32(CVMX_NPI_PCI_CFG22, cfg22.u32);
  381. /*
  382. * MOST Indicates the maximum number of outstanding splits (in -1
  383. * notation) when OCTEON is in PCI-X mode. PCI-X performance is
  384. * affected by the MOST selection. Should generally be written
  385. * with one of 0x3be807, 0x2be807, 0x1be807, or 0x0be807,
  386. * depending on the desired MOST of 3, 2, 1, or 0, respectively.
  387. */
  388. cfg56.u32 = 0;
  389. cfg56.s.pxcid = 7; /* RO - PCI-X Capability ID */
  390. cfg56.s.ncp = 0xe8; /* RO - Next Capability Pointer */
  391. cfg56.s.dpere = 1; /* Data Parity Error Recovery Enable */
  392. cfg56.s.roe = 1; /* Relaxed Ordering Enable */
  393. cfg56.s.mmbc = 1; /* Maximum Memory Byte Count
  394. [0=512B,1=1024B,2=2048B,3=4096B] */
  395. cfg56.s.most = 3; /* Maximum outstanding Split transactions [0=1
  396. .. 7=32] */
  397. octeon_npi_write32(CVMX_NPI_PCI_CFG56, cfg56.u32);
  398. /*
  399. * Affects PCI performance when OCTEON services reads to its
  400. * BAR1/BAR2. Refer to Section 10.6.1. The recommended values are
  401. * 0x22, 0x33, and 0x33 for PCI_READ_CMD_6, PCI_READ_CMD_C, and
  402. * PCI_READ_CMD_E, respectively. Unfortunately due to errata DDR-700,
  403. * these values need to be changed so they won't possibly prefetch off
  404. * of the end of memory if PCI is DMAing a buffer at the end of
  405. * memory. Note that these values differ from their reset values.
  406. */
  407. octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_6, 0x21);
  408. octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_C, 0x31);
  409. octeon_npi_write32(CVMX_NPI_PCI_READ_CMD_E, 0x31);
  410. }
  411. /**
  412. * Initialize the Octeon PCI controller
  413. *
  414. * Returns
  415. */
  416. static int __init octeon_pci_setup(void)
  417. {
  418. union cvmx_npi_mem_access_subidx mem_access;
  419. int index;
  420. /* Only these chips have PCI */
  421. if (octeon_has_feature(OCTEON_FEATURE_PCIE))
  422. return 0;
  423. /* Point pcibios_map_irq() to the PCI version of it */
  424. octeon_pcibios_map_irq = octeon_pci_pcibios_map_irq;
  425. /* Only use the big bars on chips that support it */
  426. if (OCTEON_IS_MODEL(OCTEON_CN31XX) ||
  427. OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
  428. OCTEON_IS_MODEL(OCTEON_CN38XX_PASS1))
  429. octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_SMALL;
  430. else
  431. octeon_dma_bar_type = OCTEON_DMA_BAR_TYPE_BIG;
  432. /* PCI I/O and PCI MEM values */
  433. set_io_port_base(OCTEON_PCI_IOSPACE_BASE);
  434. ioport_resource.start = 0;
  435. ioport_resource.end = OCTEON_PCI_IOSPACE_SIZE - 1;
  436. if (!octeon_is_pci_host()) {
  437. pr_notice("Not in host mode, PCI Controller not initialized\n");
  438. return 0;
  439. }
  440. pr_notice("%s Octeon big bar support\n",
  441. (octeon_dma_bar_type ==
  442. OCTEON_DMA_BAR_TYPE_BIG) ? "Enabling" : "Disabling");
  443. octeon_pci_initialize();
  444. mem_access.u64 = 0;
  445. mem_access.s.esr = 1; /* Endian-Swap on read. */
  446. mem_access.s.esw = 1; /* Endian-Swap on write. */
  447. mem_access.s.nsr = 0; /* No-Snoop on read. */
  448. mem_access.s.nsw = 0; /* No-Snoop on write. */
  449. mem_access.s.ror = 0; /* Relax Read on read. */
  450. mem_access.s.row = 0; /* Relax Order on write. */
  451. mem_access.s.ba = 0; /* PCI Address bits [63:36]. */
  452. cvmx_write_csr(CVMX_NPI_MEM_ACCESS_SUBID3, mem_access.u64);
  453. /*
  454. * Remap the Octeon BAR 2 above all 32 bit devices
  455. * (0x8000000000ul). This is done here so it is remapped
  456. * before the readl()'s below. We don't want BAR2 overlapping
  457. * with BAR0/BAR1 during these reads.
  458. */
  459. octeon_npi_write32(CVMX_NPI_PCI_CFG08, 0);
  460. octeon_npi_write32(CVMX_NPI_PCI_CFG09, 0x80);
  461. /* Disable the BAR1 movable mappings */
  462. for (index = 0; index < 32; index++)
  463. octeon_npi_write32(CVMX_NPI_PCI_BAR1_INDEXX(index), 0);
  464. if (octeon_dma_bar_type == OCTEON_DMA_BAR_TYPE_BIG) {
  465. /* Remap the Octeon BAR 0 to 0-2GB */
  466. octeon_npi_write32(CVMX_NPI_PCI_CFG04, 0);
  467. octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);
  468. /*
  469. * Remap the Octeon BAR 1 to map 2GB-4GB (minus the
  470. * BAR 1 hole).
  471. */
  472. octeon_npi_write32(CVMX_NPI_PCI_CFG06, 2ul << 30);
  473. octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);
  474. /* Devices go after BAR1 */
  475. octeon_pci_mem_resource.start =
  476. OCTEON_PCI_MEMSPACE_OFFSET + (4ul << 30) -
  477. (OCTEON_PCI_BAR1_HOLE_SIZE << 20);
  478. octeon_pci_mem_resource.end =
  479. octeon_pci_mem_resource.start + (1ul << 30);
  480. } else {
  481. /* Remap the Octeon BAR 0 to map 128MB-(128MB+4KB) */
  482. octeon_npi_write32(CVMX_NPI_PCI_CFG04, 128ul << 20);
  483. octeon_npi_write32(CVMX_NPI_PCI_CFG05, 0);
  484. /* Remap the Octeon BAR 1 to map 0-128MB */
  485. octeon_npi_write32(CVMX_NPI_PCI_CFG06, 0);
  486. octeon_npi_write32(CVMX_NPI_PCI_CFG07, 0);
  487. /* Devices go after BAR0 */
  488. octeon_pci_mem_resource.start =
  489. OCTEON_PCI_MEMSPACE_OFFSET + (128ul << 20) +
  490. (4ul << 10);
  491. octeon_pci_mem_resource.end =
  492. octeon_pci_mem_resource.start + (1ul << 30);
  493. }
  494. register_pci_controller(&octeon_pci_controller);
  495. /*
  496. * Clear any errors that might be pending from before the bus
  497. * was setup properly.
  498. */
  499. cvmx_write_csr(CVMX_NPI_PCI_INT_SUM2, -1);
  500. return 0;
  501. }
  502. arch_initcall(octeon_pci_setup);