driver_pci_host.c 17 KB

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