pci-ixp4xx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Support for Intel IXP4xx PCI host controller
  4. *
  5. * Copyright (C) 2017 Linus Walleij <[email protected]>
  6. *
  7. * Based on the IXP4xx arch/arm/mach-ixp4xx/common-pci.c driver
  8. * Copyright (C) 2002 Intel Corporation
  9. * Copyright (C) 2003 Greg Ungerer <[email protected]>
  10. * Copyright (C) 2003-2004 MontaVista Software, Inc.
  11. * Copyright (C) 2005 Deepak Saxena <[email protected]>
  12. * Copyright (C) 2005 Alessandro Zummo <[email protected]>
  13. *
  14. * TODO:
  15. * - Test IO-space access
  16. * - DMA support
  17. */
  18. #include <linux/init.h>
  19. #include <linux/io.h>
  20. #include <linux/kernel.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_device.h>
  23. #include <linux/of_pci.h>
  24. #include <linux/pci.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/slab.h>
  27. #include <linux/bits.h>
  28. /* Register offsets */
  29. #define IXP4XX_PCI_NP_AD 0x00
  30. #define IXP4XX_PCI_NP_CBE 0x04
  31. #define IXP4XX_PCI_NP_WDATA 0x08
  32. #define IXP4XX_PCI_NP_RDATA 0x0c
  33. #define IXP4XX_PCI_CRP_AD_CBE 0x10
  34. #define IXP4XX_PCI_CRP_WDATA 0x14
  35. #define IXP4XX_PCI_CRP_RDATA 0x18
  36. #define IXP4XX_PCI_CSR 0x1c
  37. #define IXP4XX_PCI_ISR 0x20
  38. #define IXP4XX_PCI_INTEN 0x24
  39. #define IXP4XX_PCI_DMACTRL 0x28
  40. #define IXP4XX_PCI_AHBMEMBASE 0x2c
  41. #define IXP4XX_PCI_AHBIOBASE 0x30
  42. #define IXP4XX_PCI_PCIMEMBASE 0x34
  43. #define IXP4XX_PCI_AHBDOORBELL 0x38
  44. #define IXP4XX_PCI_PCIDOORBELL 0x3c
  45. #define IXP4XX_PCI_ATPDMA0_AHBADDR 0x40
  46. #define IXP4XX_PCI_ATPDMA0_PCIADDR 0x44
  47. #define IXP4XX_PCI_ATPDMA0_LENADDR 0x48
  48. #define IXP4XX_PCI_ATPDMA1_AHBADDR 0x4c
  49. #define IXP4XX_PCI_ATPDMA1_PCIADDR 0x50
  50. #define IXP4XX_PCI_ATPDMA1_LENADDR 0x54
  51. /* CSR bit definitions */
  52. #define IXP4XX_PCI_CSR_HOST BIT(0)
  53. #define IXP4XX_PCI_CSR_ARBEN BIT(1)
  54. #define IXP4XX_PCI_CSR_ADS BIT(2)
  55. #define IXP4XX_PCI_CSR_PDS BIT(3)
  56. #define IXP4XX_PCI_CSR_ABE BIT(4)
  57. #define IXP4XX_PCI_CSR_DBT BIT(5)
  58. #define IXP4XX_PCI_CSR_ASE BIT(8)
  59. #define IXP4XX_PCI_CSR_IC BIT(15)
  60. #define IXP4XX_PCI_CSR_PRST BIT(16)
  61. /* ISR (Interrupt status) Register bit definitions */
  62. #define IXP4XX_PCI_ISR_PSE BIT(0)
  63. #define IXP4XX_PCI_ISR_PFE BIT(1)
  64. #define IXP4XX_PCI_ISR_PPE BIT(2)
  65. #define IXP4XX_PCI_ISR_AHBE BIT(3)
  66. #define IXP4XX_PCI_ISR_APDC BIT(4)
  67. #define IXP4XX_PCI_ISR_PADC BIT(5)
  68. #define IXP4XX_PCI_ISR_ADB BIT(6)
  69. #define IXP4XX_PCI_ISR_PDB BIT(7)
  70. /* INTEN (Interrupt Enable) Register bit definitions */
  71. #define IXP4XX_PCI_INTEN_PSE BIT(0)
  72. #define IXP4XX_PCI_INTEN_PFE BIT(1)
  73. #define IXP4XX_PCI_INTEN_PPE BIT(2)
  74. #define IXP4XX_PCI_INTEN_AHBE BIT(3)
  75. #define IXP4XX_PCI_INTEN_APDC BIT(4)
  76. #define IXP4XX_PCI_INTEN_PADC BIT(5)
  77. #define IXP4XX_PCI_INTEN_ADB BIT(6)
  78. #define IXP4XX_PCI_INTEN_PDB BIT(7)
  79. /* Shift value for byte enable on NP cmd/byte enable register */
  80. #define IXP4XX_PCI_NP_CBE_BESL 4
  81. /* PCI commands supported by NP access unit */
  82. #define NP_CMD_IOREAD 0x2
  83. #define NP_CMD_IOWRITE 0x3
  84. #define NP_CMD_CONFIGREAD 0xa
  85. #define NP_CMD_CONFIGWRITE 0xb
  86. #define NP_CMD_MEMREAD 0x6
  87. #define NP_CMD_MEMWRITE 0x7
  88. /* Constants for CRP access into local config space */
  89. #define CRP_AD_CBE_BESL 20
  90. #define CRP_AD_CBE_WRITE 0x00010000
  91. /* Special PCI configuration space registers for this controller */
  92. #define IXP4XX_PCI_RTOTTO 0x40
  93. struct ixp4xx_pci {
  94. struct device *dev;
  95. void __iomem *base;
  96. bool errata_hammer;
  97. bool host_mode;
  98. };
  99. /*
  100. * The IXP4xx has a peculiar address bus that will change the
  101. * byte order on SoC peripherals depending on whether the device
  102. * operates in big-endian or little-endian mode. That means that
  103. * readl() and writel() that always use little-endian access
  104. * will not work for SoC peripherals such as the PCI controller
  105. * when used in big-endian mode. The accesses to the individual
  106. * PCI devices on the other hand, are always little-endian and
  107. * can use readl() and writel().
  108. *
  109. * For local AHB bus access we need to use __raw_[readl|writel]()
  110. * to make sure that we access the SoC devices in the CPU native
  111. * endianness.
  112. */
  113. static inline u32 ixp4xx_readl(struct ixp4xx_pci *p, u32 reg)
  114. {
  115. return __raw_readl(p->base + reg);
  116. }
  117. static inline void ixp4xx_writel(struct ixp4xx_pci *p, u32 reg, u32 val)
  118. {
  119. __raw_writel(val, p->base + reg);
  120. }
  121. static int ixp4xx_pci_check_master_abort(struct ixp4xx_pci *p)
  122. {
  123. u32 isr = ixp4xx_readl(p, IXP4XX_PCI_ISR);
  124. if (isr & IXP4XX_PCI_ISR_PFE) {
  125. /* Make sure the master abort bit is reset */
  126. ixp4xx_writel(p, IXP4XX_PCI_ISR, IXP4XX_PCI_ISR_PFE);
  127. dev_dbg(p->dev, "master abort detected\n");
  128. return -EINVAL;
  129. }
  130. return 0;
  131. }
  132. static int ixp4xx_pci_read_indirect(struct ixp4xx_pci *p, u32 addr, u32 cmd, u32 *data)
  133. {
  134. ixp4xx_writel(p, IXP4XX_PCI_NP_AD, addr);
  135. if (p->errata_hammer) {
  136. int i;
  137. /*
  138. * PCI workaround - only works if NP PCI space reads have
  139. * no side effects. Hammer the register and read twice 8
  140. * times. last one will be good.
  141. */
  142. for (i = 0; i < 8; i++) {
  143. ixp4xx_writel(p, IXP4XX_PCI_NP_CBE, cmd);
  144. *data = ixp4xx_readl(p, IXP4XX_PCI_NP_RDATA);
  145. *data = ixp4xx_readl(p, IXP4XX_PCI_NP_RDATA);
  146. }
  147. } else {
  148. ixp4xx_writel(p, IXP4XX_PCI_NP_CBE, cmd);
  149. *data = ixp4xx_readl(p, IXP4XX_PCI_NP_RDATA);
  150. }
  151. return ixp4xx_pci_check_master_abort(p);
  152. }
  153. static int ixp4xx_pci_write_indirect(struct ixp4xx_pci *p, u32 addr, u32 cmd, u32 data)
  154. {
  155. ixp4xx_writel(p, IXP4XX_PCI_NP_AD, addr);
  156. /* Set up the write */
  157. ixp4xx_writel(p, IXP4XX_PCI_NP_CBE, cmd);
  158. /* Execute the write by writing to NP_WDATA */
  159. ixp4xx_writel(p, IXP4XX_PCI_NP_WDATA, data);
  160. return ixp4xx_pci_check_master_abort(p);
  161. }
  162. static u32 ixp4xx_config_addr(u8 bus_num, u16 devfn, int where)
  163. {
  164. /* Root bus is always 0 in this hardware */
  165. if (bus_num == 0) {
  166. /* type 0 */
  167. return BIT(32-PCI_SLOT(devfn)) | ((PCI_FUNC(devfn)) << 8) |
  168. (where & ~3);
  169. } else {
  170. /* type 1 */
  171. return (bus_num << 16) | ((PCI_SLOT(devfn)) << 11) |
  172. ((PCI_FUNC(devfn)) << 8) | (where & ~3) | 1;
  173. }
  174. }
  175. /*
  176. * CRP functions are "Controller Configuration Port" accesses
  177. * initiated from within this driver itself to read/write PCI
  178. * control information in the config space.
  179. */
  180. static u32 ixp4xx_crp_byte_lane_enable_bits(u32 n, int size)
  181. {
  182. if (size == 1)
  183. return (0xf & ~BIT(n)) << CRP_AD_CBE_BESL;
  184. if (size == 2)
  185. return (0xf & ~(BIT(n) | BIT(n+1))) << CRP_AD_CBE_BESL;
  186. if (size == 4)
  187. return 0;
  188. return 0xffffffff;
  189. }
  190. static int ixp4xx_crp_read_config(struct ixp4xx_pci *p, int where, int size,
  191. u32 *value)
  192. {
  193. u32 n, cmd, val;
  194. n = where % 4;
  195. cmd = where & ~3;
  196. dev_dbg(p->dev, "%s from %d size %d cmd %08x\n",
  197. __func__, where, size, cmd);
  198. ixp4xx_writel(p, IXP4XX_PCI_CRP_AD_CBE, cmd);
  199. val = ixp4xx_readl(p, IXP4XX_PCI_CRP_RDATA);
  200. val >>= (8*n);
  201. switch (size) {
  202. case 1:
  203. val &= U8_MAX;
  204. dev_dbg(p->dev, "%s read byte %02x\n", __func__, val);
  205. break;
  206. case 2:
  207. val &= U16_MAX;
  208. dev_dbg(p->dev, "%s read word %04x\n", __func__, val);
  209. break;
  210. case 4:
  211. val &= U32_MAX;
  212. dev_dbg(p->dev, "%s read long %08x\n", __func__, val);
  213. break;
  214. default:
  215. /* Should not happen */
  216. dev_err(p->dev, "%s illegal size\n", __func__);
  217. return PCIBIOS_DEVICE_NOT_FOUND;
  218. }
  219. *value = val;
  220. return PCIBIOS_SUCCESSFUL;
  221. }
  222. static int ixp4xx_crp_write_config(struct ixp4xx_pci *p, int where, int size,
  223. u32 value)
  224. {
  225. u32 n, cmd, val;
  226. n = where % 4;
  227. cmd = ixp4xx_crp_byte_lane_enable_bits(n, size);
  228. if (cmd == 0xffffffff)
  229. return PCIBIOS_BAD_REGISTER_NUMBER;
  230. cmd |= where & ~3;
  231. cmd |= CRP_AD_CBE_WRITE;
  232. val = value << (8*n);
  233. dev_dbg(p->dev, "%s to %d size %d cmd %08x val %08x\n",
  234. __func__, where, size, cmd, val);
  235. ixp4xx_writel(p, IXP4XX_PCI_CRP_AD_CBE, cmd);
  236. ixp4xx_writel(p, IXP4XX_PCI_CRP_WDATA, val);
  237. return PCIBIOS_SUCCESSFUL;
  238. }
  239. /*
  240. * Then follows the functions that read and write from the common PCI
  241. * configuration space.
  242. */
  243. static u32 ixp4xx_byte_lane_enable_bits(u32 n, int size)
  244. {
  245. if (size == 1)
  246. return (0xf & ~BIT(n)) << 4;
  247. if (size == 2)
  248. return (0xf & ~(BIT(n) | BIT(n+1))) << 4;
  249. if (size == 4)
  250. return 0;
  251. return 0xffffffff;
  252. }
  253. static int ixp4xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  254. int where, int size, u32 *value)
  255. {
  256. struct ixp4xx_pci *p = bus->sysdata;
  257. u32 n, addr, val, cmd;
  258. u8 bus_num = bus->number;
  259. int ret;
  260. *value = 0xffffffff;
  261. n = where % 4;
  262. cmd = ixp4xx_byte_lane_enable_bits(n, size);
  263. if (cmd == 0xffffffff)
  264. return PCIBIOS_BAD_REGISTER_NUMBER;
  265. addr = ixp4xx_config_addr(bus_num, devfn, where);
  266. cmd |= NP_CMD_CONFIGREAD;
  267. dev_dbg(p->dev, "read_config from %d size %d dev %d:%d:%d address: %08x cmd: %08x\n",
  268. where, size, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn), addr, cmd);
  269. ret = ixp4xx_pci_read_indirect(p, addr, cmd, &val);
  270. if (ret)
  271. return PCIBIOS_DEVICE_NOT_FOUND;
  272. val >>= (8*n);
  273. switch (size) {
  274. case 1:
  275. val &= U8_MAX;
  276. dev_dbg(p->dev, "%s read byte %02x\n", __func__, val);
  277. break;
  278. case 2:
  279. val &= U16_MAX;
  280. dev_dbg(p->dev, "%s read word %04x\n", __func__, val);
  281. break;
  282. case 4:
  283. val &= U32_MAX;
  284. dev_dbg(p->dev, "%s read long %08x\n", __func__, val);
  285. break;
  286. default:
  287. /* Should not happen */
  288. dev_err(p->dev, "%s illegal size\n", __func__);
  289. return PCIBIOS_DEVICE_NOT_FOUND;
  290. }
  291. *value = val;
  292. return PCIBIOS_SUCCESSFUL;
  293. }
  294. static int ixp4xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  295. int where, int size, u32 value)
  296. {
  297. struct ixp4xx_pci *p = bus->sysdata;
  298. u32 n, addr, val, cmd;
  299. u8 bus_num = bus->number;
  300. int ret;
  301. n = where % 4;
  302. cmd = ixp4xx_byte_lane_enable_bits(n, size);
  303. if (cmd == 0xffffffff)
  304. return PCIBIOS_BAD_REGISTER_NUMBER;
  305. addr = ixp4xx_config_addr(bus_num, devfn, where);
  306. cmd |= NP_CMD_CONFIGWRITE;
  307. val = value << (8*n);
  308. dev_dbg(p->dev, "write_config_byte %#x to %d size %d dev %d:%d:%d addr: %08x cmd %08x\n",
  309. value, where, size, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn), addr, cmd);
  310. ret = ixp4xx_pci_write_indirect(p, addr, cmd, val);
  311. if (ret)
  312. return PCIBIOS_DEVICE_NOT_FOUND;
  313. return PCIBIOS_SUCCESSFUL;
  314. }
  315. static struct pci_ops ixp4xx_pci_ops = {
  316. .read = ixp4xx_pci_read_config,
  317. .write = ixp4xx_pci_write_config,
  318. };
  319. static u32 ixp4xx_pci_addr_to_64mconf(phys_addr_t addr)
  320. {
  321. u8 base;
  322. base = ((addr & 0xff000000) >> 24);
  323. return (base << 24) | ((base + 1) << 16)
  324. | ((base + 2) << 8) | (base + 3);
  325. }
  326. static int ixp4xx_pci_parse_map_ranges(struct ixp4xx_pci *p)
  327. {
  328. struct device *dev = p->dev;
  329. struct pci_host_bridge *bridge = pci_host_bridge_from_priv(p);
  330. struct resource_entry *win;
  331. struct resource *res;
  332. phys_addr_t addr;
  333. win = resource_list_first_type(&bridge->windows, IORESOURCE_MEM);
  334. if (win) {
  335. u32 pcimembase;
  336. res = win->res;
  337. addr = res->start - win->offset;
  338. if (res->flags & IORESOURCE_PREFETCH)
  339. res->name = "IXP4xx PCI PRE-MEM";
  340. else
  341. res->name = "IXP4xx PCI NON-PRE-MEM";
  342. dev_dbg(dev, "%s window %pR, bus addr %pa\n",
  343. res->name, res, &addr);
  344. if (resource_size(res) != SZ_64M) {
  345. dev_err(dev, "memory range is not 64MB\n");
  346. return -EINVAL;
  347. }
  348. pcimembase = ixp4xx_pci_addr_to_64mconf(addr);
  349. /* Commit configuration */
  350. ixp4xx_writel(p, IXP4XX_PCI_PCIMEMBASE, pcimembase);
  351. } else {
  352. dev_err(dev, "no AHB memory mapping defined\n");
  353. }
  354. win = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
  355. if (win) {
  356. res = win->res;
  357. addr = pci_pio_to_address(res->start);
  358. if (addr & 0xff) {
  359. dev_err(dev, "IO mem at uneven address: %pa\n", &addr);
  360. return -EINVAL;
  361. }
  362. res->name = "IXP4xx PCI IO MEM";
  363. /*
  364. * Setup I/O space location for PCI->AHB access, the
  365. * upper 24 bits of the address goes into the lower
  366. * 24 bits of this register.
  367. */
  368. ixp4xx_writel(p, IXP4XX_PCI_AHBIOBASE, (addr >> 8));
  369. } else {
  370. dev_info(dev, "no IO space AHB memory mapping defined\n");
  371. }
  372. return 0;
  373. }
  374. static int ixp4xx_pci_parse_map_dma_ranges(struct ixp4xx_pci *p)
  375. {
  376. struct device *dev = p->dev;
  377. struct pci_host_bridge *bridge = pci_host_bridge_from_priv(p);
  378. struct resource_entry *win;
  379. struct resource *res;
  380. phys_addr_t addr;
  381. u32 ahbmembase;
  382. win = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
  383. if (win) {
  384. res = win->res;
  385. addr = res->start - win->offset;
  386. if (resource_size(res) != SZ_64M) {
  387. dev_err(dev, "DMA memory range is not 64MB\n");
  388. return -EINVAL;
  389. }
  390. dev_dbg(dev, "DMA MEM BASE: %pa\n", &addr);
  391. /*
  392. * 4 PCI-to-AHB windows of 16 MB each, write the 8 high bits
  393. * into each byte of the PCI_AHBMEMBASE register.
  394. */
  395. ahbmembase = ixp4xx_pci_addr_to_64mconf(addr);
  396. /* Commit AHB membase */
  397. ixp4xx_writel(p, IXP4XX_PCI_AHBMEMBASE, ahbmembase);
  398. } else {
  399. dev_err(dev, "no DMA memory range defined\n");
  400. }
  401. return 0;
  402. }
  403. /* Only used to get context for abort handling */
  404. static struct ixp4xx_pci *ixp4xx_pci_abort_singleton;
  405. static int ixp4xx_pci_abort_handler(unsigned long addr, unsigned int fsr,
  406. struct pt_regs *regs)
  407. {
  408. struct ixp4xx_pci *p = ixp4xx_pci_abort_singleton;
  409. u32 isr, status;
  410. int ret;
  411. isr = ixp4xx_readl(p, IXP4XX_PCI_ISR);
  412. ret = ixp4xx_crp_read_config(p, PCI_STATUS, 2, &status);
  413. if (ret) {
  414. dev_err(p->dev, "unable to read abort status\n");
  415. return -EINVAL;
  416. }
  417. dev_err(p->dev,
  418. "PCI: abort_handler addr = %#lx, isr = %#x, status = %#x\n",
  419. addr, isr, status);
  420. /* Make sure the Master Abort bit is reset */
  421. ixp4xx_writel(p, IXP4XX_PCI_ISR, IXP4XX_PCI_ISR_PFE);
  422. status |= PCI_STATUS_REC_MASTER_ABORT;
  423. ret = ixp4xx_crp_write_config(p, PCI_STATUS, 2, status);
  424. if (ret)
  425. dev_err(p->dev, "unable to clear abort status bit\n");
  426. /*
  427. * If it was an imprecise abort, then we need to correct the
  428. * return address to be _after_ the instruction.
  429. */
  430. if (fsr & (1 << 10)) {
  431. dev_err(p->dev, "imprecise abort\n");
  432. regs->ARM_pc += 4;
  433. }
  434. return 0;
  435. }
  436. static int __init ixp4xx_pci_probe(struct platform_device *pdev)
  437. {
  438. struct device *dev = &pdev->dev;
  439. struct device_node *np = dev->of_node;
  440. struct ixp4xx_pci *p;
  441. struct pci_host_bridge *host;
  442. int ret;
  443. u32 val;
  444. phys_addr_t addr;
  445. u32 basereg[4] = {
  446. PCI_BASE_ADDRESS_0,
  447. PCI_BASE_ADDRESS_1,
  448. PCI_BASE_ADDRESS_2,
  449. PCI_BASE_ADDRESS_3,
  450. };
  451. int i;
  452. host = devm_pci_alloc_host_bridge(dev, sizeof(*p));
  453. if (!host)
  454. return -ENOMEM;
  455. host->ops = &ixp4xx_pci_ops;
  456. p = pci_host_bridge_priv(host);
  457. host->sysdata = p;
  458. p->dev = dev;
  459. dev_set_drvdata(dev, p);
  460. /*
  461. * Set up quirk for erratic behaviour in the 42x variant
  462. * when accessing config space.
  463. */
  464. if (of_device_is_compatible(np, "intel,ixp42x-pci")) {
  465. p->errata_hammer = true;
  466. dev_info(dev, "activate hammering errata\n");
  467. }
  468. p->base = devm_platform_ioremap_resource(pdev, 0);
  469. if (IS_ERR(p->base))
  470. return PTR_ERR(p->base);
  471. val = ixp4xx_readl(p, IXP4XX_PCI_CSR);
  472. p->host_mode = !!(val & IXP4XX_PCI_CSR_HOST);
  473. dev_info(dev, "controller is in %s mode\n",
  474. p->host_mode ? "host" : "option");
  475. /* Hook in our fault handler for PCI errors */
  476. ixp4xx_pci_abort_singleton = p;
  477. hook_fault_code(16+6, ixp4xx_pci_abort_handler, SIGBUS, 0,
  478. "imprecise external abort");
  479. ret = ixp4xx_pci_parse_map_ranges(p);
  480. if (ret)
  481. return ret;
  482. ret = ixp4xx_pci_parse_map_dma_ranges(p);
  483. if (ret)
  484. return ret;
  485. /* This is only configured in host mode */
  486. if (p->host_mode) {
  487. addr = __pa(PAGE_OFFSET);
  488. /* This is a noop (0x00) but explains what is going on */
  489. addr |= PCI_BASE_ADDRESS_SPACE_MEMORY;
  490. for (i = 0; i < 4; i++) {
  491. /* Write this directly into the config space */
  492. ret = ixp4xx_crp_write_config(p, basereg[i], 4, addr);
  493. if (ret)
  494. dev_err(dev, "failed to set up PCI_BASE_ADDRESS_%d\n", i);
  495. else
  496. dev_info(dev, "set PCI_BASE_ADDR_%d to %pa\n", i, &addr);
  497. addr += SZ_16M;
  498. }
  499. /*
  500. * Enable CSR window at 64 MiB to allow PCI masters to continue
  501. * prefetching past the 64 MiB boundary, if all AHB to PCI
  502. * windows are consecutive.
  503. */
  504. ret = ixp4xx_crp_write_config(p, PCI_BASE_ADDRESS_4, 4, addr);
  505. if (ret)
  506. dev_err(dev, "failed to set up PCI_BASE_ADDRESS_4\n");
  507. else
  508. dev_info(dev, "set PCI_BASE_ADDR_4 to %pa\n", &addr);
  509. /*
  510. * Put the IO memory window at the very end of physical memory
  511. * at 0xfffffc00. This is when the system is trying to access IO
  512. * memory over AHB.
  513. */
  514. addr = 0xfffffc00;
  515. addr |= PCI_BASE_ADDRESS_SPACE_IO;
  516. ret = ixp4xx_crp_write_config(p, PCI_BASE_ADDRESS_5, 4, addr);
  517. if (ret)
  518. dev_err(dev, "failed to set up PCI_BASE_ADDRESS_5\n");
  519. else
  520. dev_info(dev, "set PCI_BASE_ADDR_5 to %pa\n", &addr);
  521. /*
  522. * Retry timeout to 0x80
  523. * Transfer ready timeout to 0xff
  524. */
  525. ret = ixp4xx_crp_write_config(p, IXP4XX_PCI_RTOTTO, 4,
  526. 0x000080ff);
  527. if (ret)
  528. dev_err(dev, "failed to set up TRDY limit\n");
  529. else
  530. dev_info(dev, "set TRDY limit to 0x80ff\n");
  531. }
  532. /* Clear interrupts */
  533. val = IXP4XX_PCI_ISR_PSE | IXP4XX_PCI_ISR_PFE | IXP4XX_PCI_ISR_PPE | IXP4XX_PCI_ISR_AHBE;
  534. ixp4xx_writel(p, IXP4XX_PCI_ISR, val);
  535. /*
  536. * Set Initialize Complete in PCI Control Register: allow IXP4XX to
  537. * generate PCI configuration cycles. Specify that the AHB bus is
  538. * operating in big-endian mode. Set up byte lane swapping between
  539. * little-endian PCI and the big-endian AHB bus.
  540. */
  541. val = IXP4XX_PCI_CSR_IC | IXP4XX_PCI_CSR_ABE;
  542. if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
  543. val |= (IXP4XX_PCI_CSR_PDS | IXP4XX_PCI_CSR_ADS);
  544. ixp4xx_writel(p, IXP4XX_PCI_CSR, val);
  545. ret = ixp4xx_crp_write_config(p, PCI_COMMAND, 2, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  546. if (ret)
  547. dev_err(dev, "unable to initialize master and command memory\n");
  548. else
  549. dev_info(dev, "initialized as master\n");
  550. pci_host_probe(host);
  551. return 0;
  552. }
  553. static const struct of_device_id ixp4xx_pci_of_match[] = {
  554. {
  555. .compatible = "intel,ixp42x-pci",
  556. },
  557. {
  558. .compatible = "intel,ixp43x-pci",
  559. },
  560. {},
  561. };
  562. /*
  563. * This driver needs to be a builtin module with suppressed bind
  564. * attributes since the probe() is initializing a hard exception
  565. * handler and this can only be done from __init-tagged code
  566. * sections. This module cannot be removed and inserted at all.
  567. */
  568. static struct platform_driver ixp4xx_pci_driver = {
  569. .driver = {
  570. .name = "ixp4xx-pci",
  571. .suppress_bind_attrs = true,
  572. .of_match_table = ixp4xx_pci_of_match,
  573. },
  574. };
  575. builtin_platform_driver_probe(ixp4xx_pci_driver, ixp4xx_pci_probe);