driver_pci_host.c 16 KB

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