pcie_layerscape_fixup.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017-2021 NXP
  4. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  5. * Layerscape PCIe driver
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <init.h>
  10. #include <log.h>
  11. #include <pci.h>
  12. #include <asm/arch/fsl_serdes.h>
  13. #include <asm/io.h>
  14. #include <errno.h>
  15. #ifdef CONFIG_OF_BOARD_SETUP
  16. #include <linux/libfdt.h>
  17. #include <fdt_support.h>
  18. #ifdef CONFIG_ARM
  19. #include <asm/arch/clock.h>
  20. #endif
  21. #include <malloc.h>
  22. #include <env.h>
  23. #include "pcie_layerscape.h"
  24. #include "pcie_layerscape_fixup_common.h"
  25. int next_stream_id;
  26. static int fdt_pcie_get_nodeoffset(void *blob, struct ls_pcie_rc *pcie_rc)
  27. {
  28. int nodeoffset;
  29. uint svr;
  30. char *compat = NULL;
  31. /* find pci controller node */
  32. nodeoffset = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie",
  33. pcie_rc->dbi_res.start);
  34. if (nodeoffset < 0) {
  35. #ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */
  36. svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
  37. if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
  38. svr == SVR_LS2048A || svr == SVR_LS2044A ||
  39. svr == SVR_LS2081A || svr == SVR_LS2041A)
  40. compat = "fsl,ls2088a-pcie";
  41. else
  42. compat = CONFIG_FSL_PCIE_COMPAT;
  43. nodeoffset =
  44. fdt_node_offset_by_compat_reg(blob, compat,
  45. pcie_rc->dbi_res.start);
  46. #endif
  47. }
  48. return nodeoffset;
  49. }
  50. #if defined(CONFIG_FSL_LSCH3) || defined(CONFIG_FSL_LSCH2)
  51. /*
  52. * Return next available LUT index.
  53. */
  54. static int ls_pcie_next_lut_index(struct ls_pcie_rc *pcie_rc)
  55. {
  56. if (pcie_rc->next_lut_index < PCIE_LUT_ENTRY_COUNT)
  57. return pcie_rc->next_lut_index++;
  58. else
  59. return -ENOSPC; /* LUT is full */
  60. }
  61. static void lut_writel(struct ls_pcie_rc *pcie_rc, unsigned int value,
  62. unsigned int offset)
  63. {
  64. struct ls_pcie *pcie = pcie_rc->pcie;
  65. if (pcie->big_endian)
  66. out_be32(pcie->lut + offset, value);
  67. else
  68. out_le32(pcie->lut + offset, value);
  69. }
  70. /*
  71. * Program a single LUT entry
  72. */
  73. static void ls_pcie_lut_set_mapping(struct ls_pcie_rc *pcie_rc, int index,
  74. u32 devid, u32 streamid)
  75. {
  76. /* leave mask as all zeroes, want to match all bits */
  77. lut_writel(pcie_rc, devid << 16, PCIE_LUT_UDR(index));
  78. lut_writel(pcie_rc, streamid | PCIE_LUT_ENABLE, PCIE_LUT_LDR(index));
  79. }
  80. /*
  81. * An msi-map is a property to be added to the pci controller
  82. * node. It is a table, where each entry consists of 4 fields
  83. * e.g.:
  84. *
  85. * msi-map = <[devid] [phandle-to-msi-ctrl] [stream-id] [count]
  86. * [devid] [phandle-to-msi-ctrl] [stream-id] [count]>;
  87. */
  88. static void fdt_pcie_set_msi_map_entry_ls(void *blob,
  89. struct ls_pcie_rc *pcie_rc,
  90. u32 devid, u32 streamid)
  91. {
  92. u32 *prop;
  93. u32 phandle;
  94. int nodeoffset;
  95. uint svr;
  96. char *compat = NULL;
  97. struct ls_pcie *pcie = pcie_rc->pcie;
  98. /* find pci controller node */
  99. nodeoffset = fdt_node_offset_by_compat_reg(blob, "fsl,ls-pcie",
  100. pcie_rc->dbi_res.start);
  101. if (nodeoffset < 0) {
  102. #ifdef CONFIG_FSL_PCIE_COMPAT /* Compatible with older version of dts node */
  103. svr = (get_svr() >> SVR_VAR_PER_SHIFT) & 0xFFFFFE;
  104. if (svr == SVR_LS2088A || svr == SVR_LS2084A ||
  105. svr == SVR_LS2048A || svr == SVR_LS2044A ||
  106. svr == SVR_LS2081A || svr == SVR_LS2041A)
  107. compat = "fsl,ls2088a-pcie";
  108. else
  109. compat = CONFIG_FSL_PCIE_COMPAT;
  110. if (compat)
  111. nodeoffset = fdt_node_offset_by_compat_reg(blob,
  112. compat, pcie_rc->dbi_res.start);
  113. #endif
  114. if (nodeoffset < 0)
  115. return;
  116. }
  117. /* get phandle to MSI controller */
  118. prop = (u32 *)fdt_getprop(blob, nodeoffset, "msi-parent", 0);
  119. if (prop == NULL) {
  120. debug("\n%s: ERROR: missing msi-parent: PCIe%d\n",
  121. __func__, pcie->idx);
  122. return;
  123. }
  124. phandle = fdt32_to_cpu(*prop);
  125. /* set one msi-map row */
  126. fdt_appendprop_u32(blob, nodeoffset, "msi-map", devid);
  127. fdt_appendprop_u32(blob, nodeoffset, "msi-map", phandle);
  128. fdt_appendprop_u32(blob, nodeoffset, "msi-map", streamid);
  129. fdt_appendprop_u32(blob, nodeoffset, "msi-map", 1);
  130. }
  131. /*
  132. * An iommu-map is a property to be added to the pci controller
  133. * node. It is a table, where each entry consists of 4 fields
  134. * e.g.:
  135. *
  136. * iommu-map = <[devid] [phandle-to-iommu-ctrl] [stream-id] [count]
  137. * [devid] [phandle-to-iommu-ctrl] [stream-id] [count]>;
  138. */
  139. static void fdt_pcie_set_iommu_map_entry_ls(void *blob,
  140. struct ls_pcie_rc *pcie_rc,
  141. u32 devid, u32 streamid)
  142. {
  143. u32 *prop;
  144. u32 iommu_map[4];
  145. int nodeoffset;
  146. int lenp;
  147. struct ls_pcie *pcie = pcie_rc->pcie;
  148. nodeoffset = fdt_pcie_get_nodeoffset(blob, pcie_rc);
  149. if (nodeoffset < 0)
  150. return;
  151. /* get phandle to iommu controller */
  152. prop = fdt_getprop_w(blob, nodeoffset, "iommu-map", &lenp);
  153. if (prop == NULL) {
  154. debug("\n%s: ERROR: missing iommu-map: PCIe%d\n",
  155. __func__, pcie->idx);
  156. return;
  157. }
  158. /* set iommu-map row */
  159. iommu_map[0] = cpu_to_fdt32(devid);
  160. iommu_map[1] = *++prop;
  161. iommu_map[2] = cpu_to_fdt32(streamid);
  162. iommu_map[3] = cpu_to_fdt32(1);
  163. if (devid == 0) {
  164. fdt_setprop_inplace(blob, nodeoffset, "iommu-map",
  165. iommu_map, 16);
  166. } else {
  167. fdt_appendprop(blob, nodeoffset, "iommu-map", iommu_map, 16);
  168. }
  169. }
  170. static int fdt_fixup_pcie_device_ls(void *blob, pci_dev_t bdf,
  171. struct ls_pcie_rc *pcie_rc)
  172. {
  173. int streamid, index;
  174. streamid = pcie_next_streamid(pcie_rc->stream_id_cur,
  175. pcie_rc->pcie->idx);
  176. if (streamid < 0) {
  177. printf("ERROR: out of stream ids for BDF %d.%d.%d\n",
  178. PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
  179. return -ENOENT;
  180. }
  181. pcie_rc->stream_id_cur++;
  182. index = ls_pcie_next_lut_index(pcie_rc);
  183. if (index < 0) {
  184. printf("ERROR: out of LUT indexes for BDF %d.%d.%d\n",
  185. PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
  186. return -ENOENT;
  187. }
  188. /* map PCI b.d.f to streamID in LUT */
  189. ls_pcie_lut_set_mapping(pcie_rc, index, bdf >> 8, streamid);
  190. /* update msi-map in device tree */
  191. fdt_pcie_set_msi_map_entry_ls(blob, pcie_rc, bdf >> 8, streamid);
  192. /* update iommu-map in device tree */
  193. fdt_pcie_set_iommu_map_entry_ls(blob, pcie_rc, bdf >> 8, streamid);
  194. return 0;
  195. }
  196. struct extra_iommu_entry {
  197. int action;
  198. pci_dev_t bdf;
  199. int num_vfs;
  200. bool noari;
  201. };
  202. #define EXTRA_IOMMU_ENTRY_HOTPLUG 1
  203. #define EXTRA_IOMMU_ENTRY_VFS 2
  204. static struct extra_iommu_entry *get_extra_iommu_ents(void *blob,
  205. int nodeoffset,
  206. phys_addr_t addr,
  207. int *cnt)
  208. {
  209. const char *s, *p, *tok;
  210. struct extra_iommu_entry *entries;
  211. int i = 0, b, d, f;
  212. /*
  213. * Retrieve extra IOMMU configuration from env var or from device tree.
  214. * Env var is given priority.
  215. */
  216. s = env_get("pci_iommu_extra");
  217. if (!s) {
  218. s = fdt_getprop(blob, nodeoffset, "pci-iommu-extra", NULL);
  219. } else {
  220. phys_addr_t pci_base;
  221. char *endp;
  222. /*
  223. * In env var case the config string has "pci@0x..." in
  224. * addition. Parse this part and match it by address against
  225. * the input pci controller's registers base address.
  226. */
  227. tok = s;
  228. p = strchrnul(s + 1, ',');
  229. s = NULL;
  230. do {
  231. if (!strncmp(tok, "pci", 3)) {
  232. pci_base = simple_strtoul(tok + 4, &endp, 0);
  233. if (pci_base == addr) {
  234. s = endp + 1;
  235. break;
  236. }
  237. }
  238. p = strchrnul(p + 1, ',');
  239. tok = p + 1;
  240. } while (*p);
  241. }
  242. /*
  243. * If no env var or device tree property found or pci register base
  244. * address mismatches, bail out
  245. */
  246. if (!s)
  247. return NULL;
  248. /*
  249. * In order to find how many action entries to allocate, count number
  250. * of actions by interating through the pairs of bdfs and actions.
  251. */
  252. *cnt = 0;
  253. p = s;
  254. while (*p && strncmp(p, "pci", 3)) {
  255. if (*p == ',')
  256. (*cnt)++;
  257. p++;
  258. }
  259. if (!(*p))
  260. (*cnt)++;
  261. if (!(*cnt) || (*cnt) % 2) {
  262. printf("ERROR: invalid or odd extra iommu token count %d\n",
  263. *cnt);
  264. return NULL;
  265. }
  266. *cnt = (*cnt) / 2;
  267. entries = malloc((*cnt) * sizeof(*entries));
  268. if (!entries) {
  269. printf("ERROR: fail to allocate extra iommu entries\n");
  270. return NULL;
  271. }
  272. /*
  273. * Parse action entries one by one and store the information in the
  274. * newly allocated actions array.
  275. */
  276. p = s;
  277. while (p) {
  278. /* Extract BDF */
  279. b = simple_strtoul(p, (char **)&p, 0); p++;
  280. d = simple_strtoul(p, (char **)&p, 0); p++;
  281. f = simple_strtoul(p, (char **)&p, 0); p++;
  282. entries[i].bdf = PCI_BDF(b, d, f);
  283. /* Parse action */
  284. if (!strncmp(p, "hp", 2)) {
  285. /* Hot-plug entry */
  286. entries[i].action = EXTRA_IOMMU_ENTRY_HOTPLUG;
  287. p += 2;
  288. } else if (!strncmp(p, "vfs", 3) ||
  289. !strncmp(p, "noari_vfs", 9)) {
  290. /* VFs or VFs with ARI disabled entry */
  291. entries[i].action = EXTRA_IOMMU_ENTRY_VFS;
  292. entries[i].noari = !strncmp(p, "noari_vfs", 9);
  293. /*
  294. * Parse and store total number of VFs to allocate
  295. * IOMMU entries for.
  296. */
  297. p = strchr(p, '=');
  298. entries[i].num_vfs = simple_strtoul(p + 1, (char **)&p,
  299. 0);
  300. if (*p)
  301. p++;
  302. } else {
  303. printf("ERROR: invalid action in extra iommu entry\n");
  304. free(entries);
  305. return NULL;
  306. }
  307. if (!(*p) || !strncmp(p, "pci", 3))
  308. break;
  309. i++;
  310. }
  311. return entries;
  312. }
  313. static void get_vf_offset_and_stride(struct udevice *dev, int sriov_pos,
  314. struct extra_iommu_entry *entry,
  315. u16 *offset, u16 *stride)
  316. {
  317. u16 tmp16;
  318. u32 tmp32;
  319. bool have_ari = false;
  320. int pos;
  321. struct udevice *pf_dev;
  322. dm_pci_read_config16(dev, sriov_pos + PCI_SRIOV_TOTAL_VF, &tmp16);
  323. if (entry->num_vfs > tmp16) {
  324. printf("WARN: requested no. of VFs %d exceeds total of %d\n",
  325. entry->num_vfs, tmp16);
  326. }
  327. /*
  328. * The code below implements the VF Discovery recomandations specified
  329. * in PCIe base spec "9.2.1.2 VF Discovery", quoted below:
  330. *
  331. * VF Discovery
  332. *
  333. * The First VF Offset and VF Stride fields in the SR-IOV extended
  334. * capability are 16-bit Routing ID offsets. These offsets are used to
  335. * compute the Routing IDs for the VFs with the following restrictions:
  336. * - The value in NumVFs in a PF (Section 9.3.3.7) may affect the
  337. * values in First VF Offset (Section 9.3.3.9) and VF Stride
  338. * (Section 9.3.3.10) of that PF.
  339. * - The value in ARI Capable Hierarchy (Section 9.3.3.3.5) in the
  340. * lowest-numbered PF of the Device (for example PF0) may affect
  341. * the values in First VF Offset and VF Stride in all PFs of the
  342. * Device.
  343. * - NumVFs of a PF may only be changed when VF Enable
  344. * (Section 9.3.3.3.1) of that PF is Clear.
  345. * - ARI Capable Hierarchy (Section 9.3.3.3.5) may only be changed
  346. * when VF Enable is Clear in all PFs of a Device.
  347. */
  348. /* Clear VF enable for all PFs */
  349. device_foreach_child(pf_dev, dev->parent) {
  350. dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL,
  351. &tmp16);
  352. tmp16 &= ~PCI_SRIOV_CTRL_VFE;
  353. dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL,
  354. tmp16);
  355. }
  356. /* Obtain a reference to PF0 device */
  357. if (dm_pci_bus_find_bdf(PCI_BDF(PCI_BUS(entry->bdf),
  358. PCI_DEV(entry->bdf), 0), &pf_dev)) {
  359. printf("WARN: failed to get PF0\n");
  360. }
  361. if (entry->noari)
  362. goto skip_ari;
  363. /* Check that connected downstream port supports ARI Forwarding */
  364. pos = dm_pci_find_capability(dev->parent, PCI_CAP_ID_EXP);
  365. dm_pci_read_config32(dev->parent, pos + PCI_EXP_DEVCAP2, &tmp32);
  366. if (!(tmp32 & PCI_EXP_DEVCAP2_ARI))
  367. goto skip_ari;
  368. /* Check that PF supports Alternate Routing ID */
  369. if (!dm_pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI))
  370. goto skip_ari;
  371. /* Set ARI Capable Hierarcy for PF0 */
  372. dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, &tmp16);
  373. tmp16 |= PCI_SRIOV_CTRL_ARI;
  374. dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL, tmp16);
  375. have_ari = true;
  376. skip_ari:
  377. if (!have_ari) {
  378. /*
  379. * No ARI support or disabled so clear ARI Capable Hierarcy
  380. * for PF0
  381. */
  382. dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL,
  383. &tmp16);
  384. tmp16 &= ~PCI_SRIOV_CTRL_ARI;
  385. dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL,
  386. tmp16);
  387. }
  388. /* Set requested number of VFs */
  389. dm_pci_write_config16(dev, sriov_pos + PCI_SRIOV_NUM_VF,
  390. entry->num_vfs);
  391. /* Read VF stride and offset with the configs just made */
  392. dm_pci_read_config16(dev, sriov_pos + PCI_SRIOV_VF_OFFSET, offset);
  393. dm_pci_read_config16(dev, sriov_pos + PCI_SRIOV_VF_STRIDE, stride);
  394. if (have_ari) {
  395. /* Reset to default ARI Capable Hierarcy bit for PF0 */
  396. dm_pci_read_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL,
  397. &tmp16);
  398. tmp16 &= ~PCI_SRIOV_CTRL_ARI;
  399. dm_pci_write_config16(pf_dev, sriov_pos + PCI_SRIOV_CTRL,
  400. tmp16);
  401. }
  402. /* Reset to default the number of VFs */
  403. dm_pci_write_config16(dev, sriov_pos + PCI_SRIOV_NUM_VF, 0);
  404. }
  405. static int fdt_fixup_pci_vfs(void *blob, struct extra_iommu_entry *entry,
  406. struct ls_pcie_rc *pcie_rc)
  407. {
  408. struct udevice *dev, *bus;
  409. u16 vf_offset, vf_stride;
  410. int i, sriov_pos;
  411. pci_dev_t bdf;
  412. if (dm_pci_bus_find_bdf(entry->bdf, &dev)) {
  413. printf("ERROR: BDF %d.%d.%d not found\n", PCI_BUS(entry->bdf),
  414. PCI_DEV(entry->bdf), PCI_FUNC(entry->bdf));
  415. return 0;
  416. }
  417. sriov_pos = dm_pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV);
  418. if (!sriov_pos) {
  419. printf("WARN: trying to set VFs on non-SRIOV dev\n");
  420. return 0;
  421. }
  422. get_vf_offset_and_stride(dev, sriov_pos, entry, &vf_offset, &vf_stride);
  423. for (bus = dev; device_is_on_pci_bus(bus);)
  424. bus = bus->parent;
  425. bdf = entry->bdf - PCI_BDF(dev_seq(bus), 0, 0) + (vf_offset << 8);
  426. for (i = 0; i < entry->num_vfs; i++) {
  427. if (fdt_fixup_pcie_device_ls(blob, bdf, pcie_rc) < 0)
  428. return -1;
  429. bdf += vf_stride << 8;
  430. }
  431. printf("Added %d iommu VF mappings for PF %d.%d.%d\n",
  432. entry->num_vfs, PCI_BUS(entry->bdf),
  433. PCI_DEV(entry->bdf), PCI_FUNC(entry->bdf));
  434. return 0;
  435. }
  436. static void fdt_fixup_pcie_ls(void *blob)
  437. {
  438. struct udevice *dev, *bus;
  439. struct ls_pcie_rc *pcie_rc;
  440. pci_dev_t bdf;
  441. struct extra_iommu_entry *entries;
  442. int i, cnt, nodeoffset;
  443. /* Scan all known buses */
  444. for (pci_find_first_device(&dev);
  445. dev;
  446. pci_find_next_device(&dev)) {
  447. for (bus = dev; device_is_on_pci_bus(bus);)
  448. bus = bus->parent;
  449. /* Only do the fixups for layerscape PCIe controllers */
  450. if (!device_is_compatible(bus, "fsl,ls-pcie") &&
  451. !device_is_compatible(bus, CONFIG_FSL_PCIE_COMPAT))
  452. continue;
  453. pcie_rc = dev_get_priv(bus);
  454. /* the DT fixup must be relative to the hose first_busno */
  455. bdf = dm_pci_get_bdf(dev) - PCI_BDF(dev_seq(bus), 0, 0);
  456. if (fdt_fixup_pcie_device_ls(blob, bdf, pcie_rc) < 0)
  457. break;
  458. }
  459. if (!IS_ENABLED(CONFIG_PCI_IOMMU_EXTRA_MAPPINGS))
  460. return;
  461. list_for_each_entry(pcie_rc, &ls_pcie_list, list) {
  462. nodeoffset = fdt_pcie_get_nodeoffset(blob, pcie_rc);
  463. if (nodeoffset < 0) {
  464. printf("ERROR: couldn't find pci node\n");
  465. continue;
  466. }
  467. entries = get_extra_iommu_ents(blob, nodeoffset,
  468. pcie_rc->dbi_res.start, &cnt);
  469. if (!entries)
  470. continue;
  471. for (i = 0; i < cnt; i++) {
  472. if (entries[i].action == EXTRA_IOMMU_ENTRY_HOTPLUG) {
  473. bdf = entries[i].bdf;
  474. printf("Added iommu map for hotplug %d.%d.%d\n",
  475. PCI_BUS(bdf), PCI_DEV(bdf),
  476. PCI_FUNC(bdf));
  477. if (fdt_fixup_pcie_device_ls(blob, bdf,
  478. pcie_rc) < 0) {
  479. free(entries);
  480. return;
  481. }
  482. } else if (entries[i].action == EXTRA_IOMMU_ENTRY_VFS) {
  483. if (fdt_fixup_pci_vfs(blob, &entries[i],
  484. pcie_rc) < 0) {
  485. free(entries);
  486. return;
  487. }
  488. } else {
  489. printf("Invalid action %d for BDF %d.%d.%d\n",
  490. entries[i].action,
  491. PCI_BUS(entries[i].bdf),
  492. PCI_DEV(entries[i].bdf),
  493. PCI_FUNC(entries[i].bdf));
  494. }
  495. }
  496. free(entries);
  497. }
  498. }
  499. #endif
  500. static void ft_pcie_rc_fix(void *blob, struct ls_pcie_rc *pcie_rc)
  501. {
  502. int off;
  503. struct ls_pcie *pcie = pcie_rc->pcie;
  504. off = fdt_pcie_get_nodeoffset(blob, pcie_rc);
  505. if (off < 0)
  506. return;
  507. if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE)
  508. fdt_set_node_status(blob, off, FDT_STATUS_OKAY);
  509. else
  510. fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
  511. }
  512. static void ft_pcie_ep_fix(void *blob, struct ls_pcie_rc *pcie_rc)
  513. {
  514. int off;
  515. struct ls_pcie *pcie = pcie_rc->pcie;
  516. off = fdt_node_offset_by_compat_reg(blob, CONFIG_FSL_PCIE_EP_COMPAT,
  517. pcie_rc->dbi_res.start);
  518. if (off < 0)
  519. return;
  520. if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_NORMAL)
  521. fdt_set_node_status(blob, off, FDT_STATUS_OKAY);
  522. else
  523. fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
  524. }
  525. static void ft_pcie_ls_setup(void *blob, struct ls_pcie_rc *pcie_rc)
  526. {
  527. ft_pcie_ep_fix(blob, pcie_rc);
  528. ft_pcie_rc_fix(blob, pcie_rc);
  529. pcie_rc->stream_id_cur = 0;
  530. pcie_rc->next_lut_index = 0;
  531. }
  532. /* Fixup Kernel DT for PCIe */
  533. void ft_pci_setup_ls(void *blob, struct bd_info *bd)
  534. {
  535. struct ls_pcie_rc *pcie_rc;
  536. #if defined(CONFIG_FSL_LSCH3) || defined(CONFIG_FSL_LSCH2)
  537. pcie_board_fix_fdt(blob);
  538. #endif
  539. list_for_each_entry(pcie_rc, &ls_pcie_list, list)
  540. ft_pcie_ls_setup(blob, pcie_rc);
  541. #if defined(CONFIG_FSL_LSCH3) || defined(CONFIG_FSL_LSCH2)
  542. next_stream_id = FSL_PEX_STREAM_ID_START;
  543. fdt_fixup_pcie_ls(blob);
  544. #endif
  545. }
  546. #else /* !CONFIG_OF_BOARD_SETUP */
  547. void ft_pci_setup_ls(void *blob, struct bd_info *bd)
  548. {
  549. }
  550. #endif