driver_pci_host.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * Broadcom specific AMBA
  3. * PCI Core in hostmode
  4. *
  5. * Copyright 2005 - 2011, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
  7. * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
  8. *
  9. * Licensed under the GNU/GPL. See COPYING for details.
  10. */
  11. #include "bcma_private.h"
  12. #include <linux/pci.h>
  13. #include <linux/export.h>
  14. #include <linux/bcma/bcma.h>
  15. #include <asm/paccess.h>
  16. /* Probe a 32bit value on the bus and catch bus exceptions.
  17. * Returns nonzero on a bus exception.
  18. * This is MIPS specific */
  19. #define mips_busprobe32(val, addr) get_dbe((val), ((u32 *)(addr)))
  20. /* Assume one-hot slot wiring */
  21. #define BCMA_PCI_SLOT_MAX 16
  22. #define PCI_CONFIG_SPACE_SIZE 256
  23. bool bcma_core_pci_is_in_hostmode(struct bcma_drv_pci *pc)
  24. {
  25. struct bcma_bus *bus = pc->core->bus;
  26. u16 chipid_top;
  27. u32 tmp;
  28. chipid_top = (bus->chipinfo.id & 0xFF00);
  29. if (chipid_top != 0x4700 &&
  30. chipid_top != 0x5300)
  31. return false;
  32. bcma_core_enable(pc->core, 0);
  33. return !mips_busprobe32(tmp, pc->core->io_addr);
  34. }
  35. static u32 bcma_pcie_read_config(struct bcma_drv_pci *pc, u32 address)
  36. {
  37. pcicore_write32(pc, BCMA_CORE_PCI_CONFIG_ADDR, address);
  38. pcicore_read32(pc, BCMA_CORE_PCI_CONFIG_ADDR);
  39. return pcicore_read32(pc, BCMA_CORE_PCI_CONFIG_DATA);
  40. }
  41. static void bcma_pcie_write_config(struct bcma_drv_pci *pc, u32 address,
  42. u32 data)
  43. {
  44. pcicore_write32(pc, BCMA_CORE_PCI_CONFIG_ADDR, address);
  45. pcicore_read32(pc, BCMA_CORE_PCI_CONFIG_ADDR);
  46. pcicore_write32(pc, BCMA_CORE_PCI_CONFIG_DATA, data);
  47. }
  48. static u32 bcma_get_cfgspace_addr(struct bcma_drv_pci *pc, unsigned int dev,
  49. unsigned int func, unsigned int off)
  50. {
  51. u32 addr = 0;
  52. /* Issue config commands only when the data link is up (atleast
  53. * one external pcie device is present).
  54. */
  55. if (dev >= 2 || !(bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_LSREG)
  56. & BCMA_CORE_PCI_DLLP_LSREG_LINKUP))
  57. goto out;
  58. /* Type 0 transaction */
  59. /* Slide the PCI window to the appropriate slot */
  60. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI1, BCMA_CORE_PCI_SBTOPCI_CFG0);
  61. /* Calculate the address */
  62. addr = pc->host_controller->host_cfg_addr;
  63. addr |= (dev << BCMA_CORE_PCI_CFG_SLOT_SHIFT);
  64. addr |= (func << BCMA_CORE_PCI_CFG_FUN_SHIFT);
  65. addr |= (off & ~3);
  66. out:
  67. return addr;
  68. }
  69. static int bcma_extpci_read_config(struct bcma_drv_pci *pc, unsigned int dev,
  70. unsigned int func, unsigned int off,
  71. void *buf, int len)
  72. {
  73. int err = -EINVAL;
  74. u32 addr, val;
  75. void __iomem *mmio = 0;
  76. WARN_ON(!pc->hostmode);
  77. if (unlikely(len != 1 && len != 2 && len != 4))
  78. goto out;
  79. if (dev == 0) {
  80. /* we support only two functions on device 0 */
  81. if (func > 1)
  82. goto out;
  83. /* accesses to config registers with offsets >= 256
  84. * requires indirect access.
  85. */
  86. if (off >= PCI_CONFIG_SPACE_SIZE) {
  87. addr = (func << 12);
  88. addr |= (off & 0x0FFC);
  89. val = bcma_pcie_read_config(pc, addr);
  90. } else {
  91. addr = BCMA_CORE_PCI_PCICFG0;
  92. addr |= (func << 8);
  93. addr |= (off & 0xFC);
  94. val = pcicore_read32(pc, addr);
  95. }
  96. } else {
  97. addr = bcma_get_cfgspace_addr(pc, dev, func, off);
  98. if (unlikely(!addr))
  99. goto out;
  100. err = -ENOMEM;
  101. mmio = ioremap_nocache(addr, sizeof(val));
  102. if (!mmio)
  103. goto out;
  104. if (mips_busprobe32(val, mmio)) {
  105. val = 0xFFFFFFFF;
  106. goto unmap;
  107. }
  108. }
  109. val >>= (8 * (off & 3));
  110. switch (len) {
  111. case 1:
  112. *((u8 *)buf) = (u8)val;
  113. break;
  114. case 2:
  115. *((u16 *)buf) = (u16)val;
  116. break;
  117. case 4:
  118. *((u32 *)buf) = (u32)val;
  119. break;
  120. }
  121. err = 0;
  122. unmap:
  123. if (mmio)
  124. iounmap(mmio);
  125. out:
  126. return err;
  127. }
  128. static int bcma_extpci_write_config(struct bcma_drv_pci *pc, unsigned int dev,
  129. unsigned int func, unsigned int off,
  130. const void *buf, int len)
  131. {
  132. int err = -EINVAL;
  133. u32 addr, val;
  134. void __iomem *mmio = 0;
  135. u16 chipid = pc->core->bus->chipinfo.id;
  136. WARN_ON(!pc->hostmode);
  137. if (unlikely(len != 1 && len != 2 && len != 4))
  138. goto out;
  139. if (dev == 0) {
  140. /* we support only two functions on device 0 */
  141. if (func > 1)
  142. goto out;
  143. /* accesses to config registers with offsets >= 256
  144. * requires indirect access.
  145. */
  146. if (off >= PCI_CONFIG_SPACE_SIZE) {
  147. addr = (func << 12);
  148. addr |= (off & 0x0FFC);
  149. val = bcma_pcie_read_config(pc, addr);
  150. } else {
  151. addr = BCMA_CORE_PCI_PCICFG0;
  152. addr |= (func << 8);
  153. addr |= (off & 0xFC);
  154. val = pcicore_read32(pc, addr);
  155. }
  156. } else {
  157. addr = bcma_get_cfgspace_addr(pc, dev, func, off);
  158. if (unlikely(!addr))
  159. goto out;
  160. err = -ENOMEM;
  161. mmio = ioremap_nocache(addr, sizeof(val));
  162. if (!mmio)
  163. goto out;
  164. if (mips_busprobe32(val, mmio)) {
  165. val = 0xFFFFFFFF;
  166. goto unmap;
  167. }
  168. }
  169. switch (len) {
  170. case 1:
  171. val &= ~(0xFF << (8 * (off & 3)));
  172. val |= *((const u8 *)buf) << (8 * (off & 3));
  173. break;
  174. case 2:
  175. val &= ~(0xFFFF << (8 * (off & 3)));
  176. val |= *((const u16 *)buf) << (8 * (off & 3));
  177. break;
  178. case 4:
  179. val = *((const u32 *)buf);
  180. break;
  181. }
  182. if (dev == 0) {
  183. /* accesses to config registers with offsets >= 256
  184. * requires indirect access.
  185. */
  186. if (off >= PCI_CONFIG_SPACE_SIZE)
  187. bcma_pcie_write_config(pc, addr, val);
  188. else
  189. pcicore_write32(pc, addr, val);
  190. } else {
  191. writel(val, mmio);
  192. if (chipid == BCMA_CHIP_ID_BCM4716 ||
  193. chipid == BCMA_CHIP_ID_BCM4748)
  194. readl(mmio);
  195. }
  196. err = 0;
  197. unmap:
  198. if (mmio)
  199. iounmap(mmio);
  200. out:
  201. return err;
  202. }
  203. static int bcma_core_pci_hostmode_read_config(struct pci_bus *bus,
  204. unsigned int devfn,
  205. int reg, int size, u32 *val)
  206. {
  207. unsigned long flags;
  208. int err;
  209. struct bcma_drv_pci *pc;
  210. struct bcma_drv_pci_host *pc_host;
  211. pc_host = container_of(bus->ops, struct bcma_drv_pci_host, pci_ops);
  212. pc = pc_host->pdev;
  213. spin_lock_irqsave(&pc_host->cfgspace_lock, flags);
  214. err = bcma_extpci_read_config(pc, PCI_SLOT(devfn),
  215. PCI_FUNC(devfn), reg, val, size);
  216. spin_unlock_irqrestore(&pc_host->cfgspace_lock, flags);
  217. return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  218. }
  219. static int bcma_core_pci_hostmode_write_config(struct pci_bus *bus,
  220. unsigned int devfn,
  221. int reg, int size, u32 val)
  222. {
  223. unsigned long flags;
  224. int err;
  225. struct bcma_drv_pci *pc;
  226. struct bcma_drv_pci_host *pc_host;
  227. pc_host = container_of(bus->ops, struct bcma_drv_pci_host, pci_ops);
  228. pc = pc_host->pdev;
  229. spin_lock_irqsave(&pc_host->cfgspace_lock, flags);
  230. err = bcma_extpci_write_config(pc, PCI_SLOT(devfn),
  231. PCI_FUNC(devfn), reg, &val, size);
  232. spin_unlock_irqrestore(&pc_host->cfgspace_lock, flags);
  233. return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  234. }
  235. /* return cap_offset if requested capability exists in the PCI config space */
  236. static u8 bcma_find_pci_capability(struct bcma_drv_pci *pc, unsigned int dev,
  237. unsigned int func, u8 req_cap_id,
  238. unsigned char *buf, u32 *buflen)
  239. {
  240. u8 cap_id;
  241. u8 cap_ptr = 0;
  242. u32 bufsize;
  243. u8 byte_val;
  244. /* check for Header type 0 */
  245. bcma_extpci_read_config(pc, dev, func, PCI_HEADER_TYPE, &byte_val,
  246. sizeof(u8));
  247. if ((byte_val & 0x7F) != PCI_HEADER_TYPE_NORMAL)
  248. return cap_ptr;
  249. /* check if the capability pointer field exists */
  250. bcma_extpci_read_config(pc, dev, func, PCI_STATUS, &byte_val,
  251. sizeof(u8));
  252. if (!(byte_val & PCI_STATUS_CAP_LIST))
  253. return cap_ptr;
  254. /* check if the capability pointer is 0x00 */
  255. bcma_extpci_read_config(pc, dev, func, PCI_CAPABILITY_LIST, &cap_ptr,
  256. sizeof(u8));
  257. if (cap_ptr == 0x00)
  258. return cap_ptr;
  259. /* loop thr'u the capability list and see if the requested capabilty
  260. * exists */
  261. bcma_extpci_read_config(pc, dev, func, cap_ptr, &cap_id, sizeof(u8));
  262. while (cap_id != req_cap_id) {
  263. bcma_extpci_read_config(pc, dev, func, cap_ptr + 1, &cap_ptr,
  264. sizeof(u8));
  265. if (cap_ptr == 0x00)
  266. return cap_ptr;
  267. bcma_extpci_read_config(pc, dev, func, cap_ptr, &cap_id,
  268. sizeof(u8));
  269. }
  270. /* found the caller requested capability */
  271. if ((buf != NULL) && (buflen != NULL)) {
  272. u8 cap_data;
  273. bufsize = *buflen;
  274. if (!bufsize)
  275. return cap_ptr;
  276. *buflen = 0;
  277. /* copy the cpability data excluding cap ID and next ptr */
  278. cap_data = cap_ptr + 2;
  279. if ((bufsize + cap_data) > PCI_CONFIG_SPACE_SIZE)
  280. bufsize = PCI_CONFIG_SPACE_SIZE - cap_data;
  281. *buflen = bufsize;
  282. while (bufsize--) {
  283. bcma_extpci_read_config(pc, dev, func, cap_data, buf,
  284. sizeof(u8));
  285. cap_data++;
  286. buf++;
  287. }
  288. }
  289. return cap_ptr;
  290. }
  291. /* If the root port is capable of returning Config Request
  292. * Retry Status (CRS) Completion Status to software then
  293. * enable the feature.
  294. */
  295. static void bcma_core_pci_enable_crs(struct bcma_drv_pci *pc)
  296. {
  297. struct bcma_bus *bus = pc->core->bus;
  298. u8 cap_ptr, root_ctrl, root_cap, dev;
  299. u16 val16;
  300. int i;
  301. cap_ptr = bcma_find_pci_capability(pc, 0, 0, PCI_CAP_ID_EXP, NULL,
  302. NULL);
  303. root_cap = cap_ptr + PCI_EXP_RTCAP;
  304. bcma_extpci_read_config(pc, 0, 0, root_cap, &val16, sizeof(u16));
  305. if (val16 & BCMA_CORE_PCI_RC_CRS_VISIBILITY) {
  306. /* Enable CRS software visibility */
  307. root_ctrl = cap_ptr + PCI_EXP_RTCTL;
  308. val16 = PCI_EXP_RTCTL_CRSSVE;
  309. bcma_extpci_read_config(pc, 0, 0, root_ctrl, &val16,
  310. sizeof(u16));
  311. /* Initiate a configuration request to read the vendor id
  312. * field of the device function's config space header after
  313. * 100 ms wait time from the end of Reset. If the device is
  314. * not done with its internal initialization, it must at
  315. * least return a completion TLP, with a completion status
  316. * of "Configuration Request Retry Status (CRS)". The root
  317. * complex must complete the request to the host by returning
  318. * a read-data value of 0001h for the Vendor ID field and
  319. * all 1s for any additional bytes included in the request.
  320. * Poll using the config reads for max wait time of 1 sec or
  321. * until we receive the successful completion status. Repeat
  322. * the procedure for all the devices.
  323. */
  324. for (dev = 1; dev < BCMA_PCI_SLOT_MAX; dev++) {
  325. for (i = 0; i < 100000; i++) {
  326. bcma_extpci_read_config(pc, dev, 0,
  327. PCI_VENDOR_ID, &val16,
  328. sizeof(val16));
  329. if (val16 != 0x1)
  330. break;
  331. udelay(10);
  332. }
  333. if (val16 == 0x1)
  334. bcma_err(bus, "PCI: Broken device in slot %d\n",
  335. dev);
  336. }
  337. }
  338. }
  339. void bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc)
  340. {
  341. struct bcma_bus *bus = pc->core->bus;
  342. struct bcma_drv_pci_host *pc_host;
  343. u32 tmp;
  344. u32 pci_membase_1G;
  345. unsigned long io_map_base;
  346. bcma_info(bus, "PCIEcore in host mode found\n");
  347. if (bus->sprom.boardflags_lo & BCMA_CORE_PCI_BFL_NOPCI) {
  348. bcma_info(bus, "This PCIE core is disabled and not working\n");
  349. return;
  350. }
  351. pc_host = kzalloc(sizeof(*pc_host), GFP_KERNEL);
  352. if (!pc_host) {
  353. bcma_err(bus, "can not allocate memory");
  354. return;
  355. }
  356. spin_lock_init(&pc_host->cfgspace_lock);
  357. pc->host_controller = pc_host;
  358. pc_host->pci_controller.io_resource = &pc_host->io_resource;
  359. pc_host->pci_controller.mem_resource = &pc_host->mem_resource;
  360. pc_host->pci_controller.pci_ops = &pc_host->pci_ops;
  361. pc_host->pdev = pc;
  362. pci_membase_1G = BCMA_SOC_PCI_DMA;
  363. pc_host->host_cfg_addr = BCMA_SOC_PCI_CFG;
  364. pc_host->pci_ops.read = bcma_core_pci_hostmode_read_config;
  365. pc_host->pci_ops.write = bcma_core_pci_hostmode_write_config;
  366. pc_host->mem_resource.name = "BCMA PCIcore external memory",
  367. pc_host->mem_resource.start = BCMA_SOC_PCI_DMA;
  368. pc_host->mem_resource.end = BCMA_SOC_PCI_DMA + BCMA_SOC_PCI_DMA_SZ - 1;
  369. pc_host->mem_resource.flags = IORESOURCE_MEM | IORESOURCE_PCI_FIXED;
  370. pc_host->io_resource.name = "BCMA PCIcore external I/O",
  371. pc_host->io_resource.start = 0x100;
  372. pc_host->io_resource.end = 0x7FF;
  373. pc_host->io_resource.flags = IORESOURCE_IO | IORESOURCE_PCI_FIXED;
  374. /* Reset RC */
  375. usleep_range(3000, 5000);
  376. pcicore_write32(pc, BCMA_CORE_PCI_CTL, BCMA_CORE_PCI_CTL_RST_OE);
  377. msleep(50);
  378. pcicore_write32(pc, BCMA_CORE_PCI_CTL, BCMA_CORE_PCI_CTL_RST |
  379. BCMA_CORE_PCI_CTL_RST_OE);
  380. /* 64 MB I/O access window. On 4716, use
  381. * sbtopcie0 to access the device registers. We
  382. * can't use address match 2 (1 GB window) region
  383. * as mips can't generate 64-bit address on the
  384. * backplane.
  385. */
  386. if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4716 ||
  387. bus->chipinfo.id == BCMA_CHIP_ID_BCM4748) {
  388. pc_host->mem_resource.start = BCMA_SOC_PCI_MEM;
  389. pc_host->mem_resource.end = BCMA_SOC_PCI_MEM +
  390. BCMA_SOC_PCI_MEM_SZ - 1;
  391. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
  392. BCMA_CORE_PCI_SBTOPCI_MEM | BCMA_SOC_PCI_MEM);
  393. } else if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  394. tmp = BCMA_CORE_PCI_SBTOPCI_MEM;
  395. tmp |= BCMA_CORE_PCI_SBTOPCI_PREF;
  396. tmp |= BCMA_CORE_PCI_SBTOPCI_BURST;
  397. if (pc->core->core_unit == 0) {
  398. pc_host->mem_resource.start = BCMA_SOC_PCI_MEM;
  399. pc_host->mem_resource.end = BCMA_SOC_PCI_MEM +
  400. BCMA_SOC_PCI_MEM_SZ - 1;
  401. pc_host->io_resource.start = 0x100;
  402. pc_host->io_resource.end = 0x47F;
  403. pci_membase_1G = BCMA_SOC_PCIE_DMA_H32;
  404. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
  405. tmp | BCMA_SOC_PCI_MEM);
  406. } else if (pc->core->core_unit == 1) {
  407. pc_host->mem_resource.start = BCMA_SOC_PCI1_MEM;
  408. pc_host->mem_resource.end = BCMA_SOC_PCI1_MEM +
  409. BCMA_SOC_PCI_MEM_SZ - 1;
  410. pc_host->io_resource.start = 0x480;
  411. pc_host->io_resource.end = 0x7FF;
  412. pci_membase_1G = BCMA_SOC_PCIE1_DMA_H32;
  413. pc_host->host_cfg_addr = BCMA_SOC_PCI1_CFG;
  414. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
  415. tmp | BCMA_SOC_PCI1_MEM);
  416. }
  417. } else
  418. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
  419. BCMA_CORE_PCI_SBTOPCI_IO);
  420. /* 64 MB configuration access window */
  421. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI1, BCMA_CORE_PCI_SBTOPCI_CFG0);
  422. /* 1 GB memory access window */
  423. pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI2,
  424. BCMA_CORE_PCI_SBTOPCI_MEM | pci_membase_1G);
  425. /* As per PCI Express Base Spec 1.1 we need to wait for
  426. * at least 100 ms from the end of a reset (cold/warm/hot)
  427. * before issuing configuration requests to PCI Express
  428. * devices.
  429. */
  430. msleep(100);
  431. bcma_core_pci_enable_crs(pc);
  432. if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706 ||
  433. bus->chipinfo.id == BCMA_CHIP_ID_BCM4716) {
  434. u16 val16;
  435. bcma_extpci_read_config(pc, 0, 0, BCMA_CORE_PCI_CFG_DEVCTRL,
  436. &val16, sizeof(val16));
  437. val16 |= (2 << 5); /* Max payload size of 512 */
  438. val16 |= (2 << 12); /* MRRS 512 */
  439. bcma_extpci_write_config(pc, 0, 0, BCMA_CORE_PCI_CFG_DEVCTRL,
  440. &val16, sizeof(val16));
  441. }
  442. /* Enable PCI bridge BAR0 memory & master access */
  443. tmp = PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  444. bcma_extpci_write_config(pc, 0, 0, PCI_COMMAND, &tmp, sizeof(tmp));
  445. /* Enable PCI interrupts */
  446. pcicore_write32(pc, BCMA_CORE_PCI_IMASK, BCMA_CORE_PCI_IMASK_INTA);
  447. /* Ok, ready to run, register it to the system.
  448. * The following needs change, if we want to port hostmode
  449. * to non-MIPS platform. */
  450. io_map_base = (unsigned long)ioremap_nocache(pc_host->mem_resource.start,
  451. resource_size(&pc_host->mem_resource));
  452. pc_host->pci_controller.io_map_base = io_map_base;
  453. set_io_port_base(pc_host->pci_controller.io_map_base);
  454. /* Give some time to the PCI controller to configure itself with the new
  455. * values. Not waiting at this point causes crashes of the machine. */
  456. usleep_range(10000, 15000);
  457. register_pci_controller(&pc_host->pci_controller);
  458. return;
  459. }
  460. /* Early PCI fixup for a device on the PCI-core bridge. */
  461. static void bcma_core_pci_fixup_pcibridge(struct pci_dev *dev)
  462. {
  463. if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
  464. /* This is not a device on the PCI-core bridge. */
  465. return;
  466. }
  467. if (PCI_SLOT(dev->devfn) != 0)
  468. return;
  469. pr_info("PCI: Fixing up bridge %s\n", pci_name(dev));
  470. /* Enable PCI bridge bus mastering and memory space */
  471. pci_set_master(dev);
  472. if (pcibios_enable_device(dev, ~0) < 0) {
  473. pr_err("PCI: BCMA bridge enable failed\n");
  474. return;
  475. }
  476. /* Enable PCI bridge BAR1 prefetch and burst */
  477. pci_write_config_dword(dev, BCMA_PCI_BAR1_CONTROL, 3);
  478. }
  479. DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, bcma_core_pci_fixup_pcibridge);
  480. /* Early PCI fixup for all PCI-cores to set the correct memory address. */
  481. static void bcma_core_pci_fixup_addresses(struct pci_dev *dev)
  482. {
  483. struct resource *res;
  484. int pos, err;
  485. if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
  486. /* This is not a device on the PCI-core bridge. */
  487. return;
  488. }
  489. if (PCI_SLOT(dev->devfn) == 0)
  490. return;
  491. pr_info("PCI: Fixing up addresses %s\n", pci_name(dev));
  492. for (pos = 0; pos < 6; pos++) {
  493. res = &dev->resource[pos];
  494. if (res->flags & (IORESOURCE_IO | IORESOURCE_MEM)) {
  495. err = pci_assign_resource(dev, pos);
  496. if (err)
  497. pr_err("PCI: Problem fixing up the addresses on %s\n",
  498. pci_name(dev));
  499. }
  500. }
  501. }
  502. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, bcma_core_pci_fixup_addresses);
  503. /* This function is called when doing a pci_enable_device().
  504. * We must first check if the device is a device on the PCI-core bridge. */
  505. int bcma_core_pci_plat_dev_init(struct pci_dev *dev)
  506. {
  507. struct bcma_drv_pci_host *pc_host;
  508. if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
  509. /* This is not a device on the PCI-core bridge. */
  510. return -ENODEV;
  511. }
  512. pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host,
  513. pci_ops);
  514. pr_info("PCI: Fixing up device %s\n", pci_name(dev));
  515. /* Fix up interrupt lines */
  516. dev->irq = bcma_core_irq(pc_host->pdev->core);
  517. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  518. return 0;
  519. }
  520. EXPORT_SYMBOL(bcma_core_pci_plat_dev_init);
  521. /* PCI device IRQ mapping. */
  522. int bcma_core_pci_pcibios_map_irq(const struct pci_dev *dev)
  523. {
  524. struct bcma_drv_pci_host *pc_host;
  525. if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
  526. /* This is not a device on the PCI-core bridge. */
  527. return -ENODEV;
  528. }
  529. pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host,
  530. pci_ops);
  531. return bcma_core_irq(pc_host->pdev->core);
  532. }
  533. EXPORT_SYMBOL(bcma_core_pci_pcibios_map_irq);