Lines Matching defs:pcie
5 * Layerscape PCIe driver
25 static unsigned int dbi_readl(struct ls_pcie *pcie, unsigned int offset)
27 return in_le32(pcie->dbi + offset);
30 static void dbi_writel(struct ls_pcie *pcie, unsigned int value,
33 out_le32(pcie->dbi + offset, value);
36 static unsigned int ctrl_readl(struct ls_pcie *pcie, unsigned int offset)
38 if (pcie->big_endian)
39 return in_be32(pcie->ctrl + offset);
41 return in_le32(pcie->ctrl + offset);
44 static void ctrl_writel(struct ls_pcie *pcie, unsigned int value,
47 if (pcie->big_endian)
48 out_be32(pcie->ctrl + offset, value);
50 out_le32(pcie->ctrl + offset, value);
53 static int ls_pcie_ltssm(struct ls_pcie *pcie)
60 state = ctrl_readl(pcie, LS1021_PEXMSCPORTSR(pcie->idx));
63 state = ctrl_readl(pcie, PCIE_PF_DBG) & LTSSM_STATE_MASK;
69 static int ls_pcie_link_up(struct ls_pcie *pcie)
73 ltssm = ls_pcie_ltssm(pcie);
80 static void ls_pcie_cfg0_set_busdev(struct ls_pcie *pcie, u32 busdev)
82 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
84 dbi_writel(pcie, busdev, PCIE_ATU_LOWER_TARGET);
87 static void ls_pcie_cfg1_set_busdev(struct ls_pcie *pcie, u32 busdev)
89 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
91 dbi_writel(pcie, busdev, PCIE_ATU_LOWER_TARGET);
94 static void ls_pcie_atu_outbound_set(struct ls_pcie *pcie, int idx, int type,
97 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | idx, PCIE_ATU_VIEWPORT);
98 dbi_writel(pcie, (u32)phys, PCIE_ATU_LOWER_BASE);
99 dbi_writel(pcie, phys >> 32, PCIE_ATU_UPPER_BASE);
100 dbi_writel(pcie, (u32)phys + size - 1, PCIE_ATU_LIMIT);
101 dbi_writel(pcie, (u32)bus_addr, PCIE_ATU_LOWER_TARGET);
102 dbi_writel(pcie, bus_addr >> 32, PCIE_ATU_UPPER_TARGET);
103 dbi_writel(pcie, type, PCIE_ATU_CR1);
104 dbi_writel(pcie, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
108 static void ls_pcie_atu_inbound_set(struct ls_pcie *pcie, int idx,
111 dbi_writel(pcie, PCIE_ATU_REGION_INBOUND | idx, PCIE_ATU_VIEWPORT);
112 dbi_writel(pcie, (u32)phys, PCIE_ATU_LOWER_TARGET);
113 dbi_writel(pcie, phys >> 32, PCIE_ATU_UPPER_TARGET);
114 dbi_writel(pcie, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1);
115 dbi_writel(pcie, PCIE_ATU_ENABLE | PCIE_ATU_BAR_MODE_ENABLE |
119 static void ls_pcie_dump_atu(struct ls_pcie *pcie)
124 dbi_writel(pcie, PCIE_ATU_REGION_OUTBOUND | i,
128 dbi_readl(pcie, PCIE_ATU_LOWER_BASE));
130 dbi_readl(pcie, PCIE_ATU_UPPER_BASE));
132 dbi_readl(pcie, PCIE_ATU_LOWER_TARGET));
134 dbi_readl(pcie, PCIE_ATU_UPPER_TARGET));
136 readl(pcie->dbi + PCIE_ATU_LIMIT));
138 dbi_readl(pcie, PCIE_ATU_CR1));
140 dbi_readl(pcie, PCIE_ATU_CR2));
144 static void ls_pcie_setup_atu(struct ls_pcie *pcie)
154 LS1021_PCIE_SPACE_SIZE * pcie->idx;
158 ls_pcie_atu_outbound_set(pcie, PCIE_ATU_REGION_INDEX0,
160 pcie->cfg_res.start + offset,
162 fdt_resource_size(&pcie->cfg_res) / 2);
164 ls_pcie_atu_outbound_set(pcie, PCIE_ATU_REGION_INDEX1,
166 pcie->cfg_res.start + offset +
167 fdt_resource_size(&pcie->cfg_res) / 2,
169 fdt_resource_size(&pcie->cfg_res) / 2);
171 pci_get_regions(pcie->bus, &io, &mem, &pref);
174 /* Fix the pcie memory map for LS2088A series SoCs */
183 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
188 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
193 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
198 ls_pcie_atu_outbound_set(pcie, idx++,
206 ls_pcie_atu_outbound_set(pcie, idx++,
214 ls_pcie_atu_outbound_set(pcie, idx++,
220 ls_pcie_dump_atu(pcie);
224 static int ls_pcie_addr_valid(struct ls_pcie *pcie, pci_dev_t bdf)
226 struct udevice *bus = pcie->bus;
228 if (!pcie->enabled)
234 if ((PCI_BUS(bdf) > bus->seq) && (!ls_pcie_link_up(pcie)))
246 struct ls_pcie *pcie = dev_get_priv(bus);
249 if (ls_pcie_addr_valid(pcie, bdf))
253 *paddress = pcie->dbi + offset;
262 ls_pcie_cfg0_set_busdev(pcie, busdev);
263 *paddress = pcie->cfg0 + offset;
265 ls_pcie_cfg1_set_busdev(pcie, busdev);
266 *paddress = pcie->cfg1 + offset;
288 static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
290 writeb(PCI_HEADER_TYPE_BRIDGE, pcie->dbi + PCI_HEADER_TYPE);
294 static void ls_pcie_fix_class(struct ls_pcie *pcie)
296 writew(PCI_CLASS_BRIDGE_PCI, pcie->dbi + PCI_CLASS_DEVICE);
300 static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
304 val = dbi_readl(pcie, PCIE_STRFMR1);
306 dbi_writel(pcie, val, PCIE_STRFMR1);
310 static void ls_pcie_disable_bars(struct ls_pcie *pcie)
314 sriov = in_le32(pcie->dbi + PCIE_SRIOV);
317 * TODO: For PCIe controller with SRIOV, the method to disable bars
323 dbi_writel(pcie, 0, PCIE_CS2_OFFSET + PCI_BASE_ADDRESS_0);
324 dbi_writel(pcie, 0, PCIE_CS2_OFFSET + PCI_BASE_ADDRESS_1);
325 dbi_writel(pcie, 0, PCIE_CS2_OFFSET + PCI_ROM_ADDRESS1);
328 static void ls_pcie_setup_ctrl(struct ls_pcie *pcie)
330 ls_pcie_setup_atu(pcie);
332 dbi_writel(pcie, 1, PCIE_DBI_RO_WR_EN);
333 ls_pcie_fix_class(pcie);
334 ls_pcie_clear_multifunction(pcie);
335 ls_pcie_drop_msg_tlp(pcie);
336 dbi_writel(pcie, 0, PCIE_DBI_RO_WR_EN);
338 ls_pcie_disable_bars(pcie);
341 static void ls_pcie_ep_setup_atu(struct ls_pcie *pcie)
346 ls_pcie_atu_inbound_set(pcie, 0, 0, phys);
349 ls_pcie_atu_inbound_set(pcie, 1, 1, phys);
352 ls_pcie_atu_inbound_set(pcie, 2, 2, phys);
355 ls_pcie_atu_inbound_set(pcie, 3, 4, phys);
358 ls_pcie_atu_outbound_set(pcie, 0,
360 pcie->cfg_res.start,
404 static void ls_pcie_ep_enable_cfg(struct ls_pcie *pcie)
406 ctrl_writel(pcie, PCIE_CONFIG_READY, PCIE_PF_CONFIG);
409 static void ls_pcie_setup_ep(struct ls_pcie *pcie)
413 sriov = readl(pcie->dbi + PCIE_SRIOV);
419 ctrl_writel(pcie, PCIE_LCTRL0_VAL(pf, vf),
422 ls_pcie_ep_setup_bars(pcie->dbi);
423 ls_pcie_ep_setup_atu(pcie);
427 ctrl_writel(pcie, 0, PCIE_PF_VF_CTRL);
429 ls_pcie_ep_setup_bars(pcie->dbi + PCIE_NO_SRIOV_BAR_BASE);
430 ls_pcie_ep_setup_atu(pcie);
433 ls_pcie_ep_enable_cfg(pcie);
438 struct ls_pcie *pcie = dev_get_priv(dev);
448 pcie->bus = dev;
451 "dbi", &pcie->dbi_res);
453 printf("ls-pcie: resource \"dbi\" not found\n");
457 pcie->idx = (pcie->dbi_res.start - PCIE_SYS_BASE_ADDR) / PCIE_CCSR_SIZE;
459 list_add(&pcie->list, &ls_pcie_list);
461 pcie->enabled = is_serdes_configured(PCIE_SRDS_PRTCL(pcie->idx));
462 if (!pcie->enabled) {
463 printf("PCIe%d: %s disabled\n", pcie->idx, dev->name);
467 pcie->dbi = map_physmem(pcie->dbi_res.start,
468 fdt_resource_size(&pcie->dbi_res),
472 "lut", &pcie->lut_res);
474 pcie->lut = map_physmem(pcie->lut_res.start,
475 fdt_resource_size(&pcie->lut_res),
479 "ctrl", &pcie->ctrl_res);
481 pcie->ctrl = map_physmem(pcie->ctrl_res.start,
482 fdt_resource_size(&pcie->ctrl_res),
484 if (!pcie->ctrl)
485 pcie->ctrl = pcie->lut;
487 if (!pcie->ctrl) {
493 "config", &pcie->cfg_res);
500 * Fix the pcie memory map address and PF control registers address
508 cfg_size = fdt_resource_size(&pcie->cfg_res);
509 pcie->cfg_res.start = LS2088A_PCIE1_PHYS_ADDR +
510 LS2088A_PCIE_PHYS_SIZE * pcie->idx;
511 pcie->cfg_res.end = pcie->cfg_res.start + cfg_size;
512 pcie->ctrl = pcie->lut + 0x40000;
515 pcie->cfg0 = map_physmem(pcie->cfg_res.start,
516 fdt_resource_size(&pcie->cfg_res),
518 pcie->cfg1 = pcie->cfg0 + fdt_resource_size(&pcie->cfg_res) / 2;
520 pcie->big_endian = fdtdec_get_bool(fdt, node, "big-endian");
523 dev->name, (unsigned long)pcie->dbi, (unsigned long)pcie->lut,
524 (unsigned long)pcie->ctrl, (unsigned long)pcie->cfg0,
525 pcie->big_endian);
527 header_type = readb(pcie->dbi + PCI_HEADER_TYPE);
529 printf("PCIe%u: %s %s", pcie->idx, dev->name,
533 ls_pcie_setup_ep(pcie);
535 ls_pcie_setup_ctrl(pcie);
537 if (!ls_pcie_link_up(pcie)) {
538 /* Let the user know there's no PCIe link */
543 /* Print the negotiated PCIe link width */
544 link_sta = readw(pcie->dbi + PCIE_LINK_STA);
557 { .compatible = "fsl,ls-pcie" },