driver_pci_host.c 17 KB

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