Lines Matching +full:no +full:- +full:bar +full:- +full:match +full:- +full:nbits
1 // SPDX-License-Identifier: GPL-2.0
4 // Author: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
13 #include "pcie-cadence.h"
31 struct cdns_pcie *pcie = &rc->pcie; in cdns_pci_map_bus()
32 unsigned int busn = bus->number; in cdns_pci_map_bus()
44 return pcie->reg_base + (where & 0xfff); in cdns_pci_map_bus()
49 /* Clear AXI link-down status */ in cdns_pci_map_bus()
65 if (busn == bridge->busnr + 1) in cdns_pci_map_bus()
71 return rc->cfg_base + (where & 0xfff); in cdns_pci_map_bus()
82 struct device *dev = pcie->dev; in cdns_pcie_host_wait_for_link()
94 return -ETIMEDOUT; in cdns_pcie_host_wait_for_link()
128 struct cdns_pcie *pcie = &rc->pcie; in cdns_pcie_host_start_link()
137 if (!ret && rc->quirk_retrain_flag) in cdns_pcie_host_start_link()
145 struct cdns_pcie *pcie = &rc->pcie; in cdns_pcie_host_init_root_port()
150 * Set the root complex BAR configuration register: in cdns_pcie_host_init_root_port()
151 * - disable both BAR0 and BAR1. in cdns_pcie_host_init_root_port()
152 * - enable Prefetchable Memory Base and Limit registers in type 1 in cdns_pcie_host_init_root_port()
154 * - enable IO Base and Limit registers in type 1 config in cdns_pcie_host_init_root_port()
167 if (rc->vendor_id != 0xffff) { in cdns_pcie_host_init_root_port()
168 id = CDNS_PCIE_LM_ID_VENDOR(rc->vendor_id) | in cdns_pcie_host_init_root_port()
169 CDNS_PCIE_LM_ID_SUBSYS(rc->vendor_id); in cdns_pcie_host_init_root_port()
173 if (rc->device_id != 0xffff) in cdns_pcie_host_init_root_port()
174 cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id); in cdns_pcie_host_init_root_port()
184 enum cdns_pcie_rp_bar bar, in cdns_pcie_host_bar_ib_config() argument
188 struct cdns_pcie *pcie = &rc->pcie; in cdns_pcie_host_bar_ib_config()
191 if (!rc->avail_ib_bar[bar]) in cdns_pcie_host_bar_ib_config()
192 return -EBUSY; in cdns_pcie_host_bar_ib_config()
194 rc->avail_ib_bar[bar] = false; in cdns_pcie_host_bar_ib_config()
200 cdns_pcie_writel(pcie, CDNS_PCIE_AT_IB_RP_BAR_ADDR0(bar), addr0); in cdns_pcie_host_bar_ib_config()
201 cdns_pcie_writel(pcie, CDNS_PCIE_AT_IB_RP_BAR_ADDR1(bar), addr1); in cdns_pcie_host_bar_ib_config()
203 if (bar == RP_NO_BAR) in cdns_pcie_host_bar_ib_config()
207 value &= ~(LM_RC_BAR_CFG_CTRL_MEM_64BITS(bar) | in cdns_pcie_host_bar_ib_config()
208 LM_RC_BAR_CFG_CTRL_PREF_MEM_64BITS(bar) | in cdns_pcie_host_bar_ib_config()
209 LM_RC_BAR_CFG_CTRL_MEM_32BITS(bar) | in cdns_pcie_host_bar_ib_config()
210 LM_RC_BAR_CFG_CTRL_PREF_MEM_32BITS(bar) | in cdns_pcie_host_bar_ib_config()
211 LM_RC_BAR_CFG_APERTURE(bar, bar_aperture_mask[bar] + 2)); in cdns_pcie_host_bar_ib_config()
214 value |= LM_RC_BAR_CFG_CTRL_MEM_64BITS(bar); in cdns_pcie_host_bar_ib_config()
215 value |= LM_RC_BAR_CFG_CTRL_PREF_MEM_64BITS(bar); in cdns_pcie_host_bar_ib_config()
218 value |= LM_RC_BAR_CFG_CTRL_MEM_32BITS(bar); in cdns_pcie_host_bar_ib_config()
219 value |= LM_RC_BAR_CFG_CTRL_PREF_MEM_32BITS(bar); in cdns_pcie_host_bar_ib_config()
222 value |= LM_RC_BAR_CFG_APERTURE(bar, aperture); in cdns_pcie_host_bar_ib_config()
231 enum cdns_pcie_rp_bar bar, sel_bar; in cdns_pcie_host_find_min_bar() local
234 for (bar = RP_BAR0; bar <= RP_NO_BAR; bar++) { in cdns_pcie_host_find_min_bar()
235 if (!rc->avail_ib_bar[bar]) in cdns_pcie_host_find_min_bar()
238 if (size <= bar_max_size[bar]) { in cdns_pcie_host_find_min_bar()
240 sel_bar = bar; in cdns_pcie_host_find_min_bar()
244 if (bar_max_size[bar] < bar_max_size[sel_bar]) in cdns_pcie_host_find_min_bar()
245 sel_bar = bar; in cdns_pcie_host_find_min_bar()
255 enum cdns_pcie_rp_bar bar, sel_bar; in cdns_pcie_host_find_max_bar() local
258 for (bar = RP_BAR0; bar <= RP_NO_BAR; bar++) { in cdns_pcie_host_find_max_bar()
259 if (!rc->avail_ib_bar[bar]) in cdns_pcie_host_find_max_bar()
262 if (size >= bar_max_size[bar]) { in cdns_pcie_host_find_max_bar()
264 sel_bar = bar; in cdns_pcie_host_find_max_bar()
268 if (bar_max_size[bar] > bar_max_size[sel_bar]) in cdns_pcie_host_find_max_bar()
269 sel_bar = bar; in cdns_pcie_host_find_max_bar()
280 struct cdns_pcie *pcie = &rc->pcie; in cdns_pcie_host_bar_config()
281 struct device *dev = pcie->dev; in cdns_pcie_host_bar_config()
282 enum cdns_pcie_rp_bar bar; in cdns_pcie_host_bar_config() local
286 cpu_addr = entry->res->start; in cdns_pcie_host_bar_config()
287 pci_addr = entry->res->start - entry->offset; in cdns_pcie_host_bar_config()
288 flags = entry->res->flags; in cdns_pcie_host_bar_config()
289 size = resource_size(entry->res); in cdns_pcie_host_bar_config()
291 if (entry->offset) { in cdns_pcie_host_bar_config()
294 return -EINVAL; in cdns_pcie_host_bar_config()
299 * Try to find a minimum BAR whose size is greater than in cdns_pcie_host_bar_config()
303 * If a minimum BAR is found, IB ATU will be configured and in cdns_pcie_host_bar_config()
306 bar = cdns_pcie_host_find_min_bar(rc, size); in cdns_pcie_host_bar_config()
307 if (bar != RP_BAR_UNDEFINED) { in cdns_pcie_host_bar_config()
308 ret = cdns_pcie_host_bar_ib_config(rc, bar, cpu_addr, in cdns_pcie_host_bar_config()
311 dev_err(dev, "IB BAR: %d config failed\n", bar); in cdns_pcie_host_bar_config()
317 * resource_entry size cannot be fitted in a single BAR. So we in cdns_pcie_host_bar_config()
318 * find a maximum BAR whose size is less than or equal to the in cdns_pcie_host_bar_config()
321 * BAR. The remaining size would be fitted during the next in cdns_pcie_host_bar_config()
323 * If a maximum BAR is not found, there is no way we can fit in cdns_pcie_host_bar_config()
326 bar = cdns_pcie_host_find_max_bar(rc, size); in cdns_pcie_host_bar_config()
327 if (bar == RP_BAR_UNDEFINED) { in cdns_pcie_host_bar_config()
328 dev_err(dev, "No free BAR to map cpu_addr %llx\n", in cdns_pcie_host_bar_config()
330 return -EINVAL; in cdns_pcie_host_bar_config()
333 winsize = bar_max_size[bar]; in cdns_pcie_host_bar_config()
334 ret = cdns_pcie_host_bar_ib_config(rc, bar, cpu_addr, winsize, in cdns_pcie_host_bar_config()
337 dev_err(dev, "IB BAR: %d config failed\n", bar); in cdns_pcie_host_bar_config()
341 size -= winsize; in cdns_pcie_host_bar_config()
356 return resource_size(entry2->res) - resource_size(entry1->res); in cdns_pcie_host_dma_ranges_cmp()
361 struct cdns_pcie *pcie = &rc->pcie; in cdns_pcie_host_map_dma_ranges()
362 struct device *dev = pcie->dev; in cdns_pcie_host_map_dma_ranges()
363 struct device_node *np = dev->of_node; in cdns_pcie_host_map_dma_ranges()
371 return -ENOMEM; in cdns_pcie_host_map_dma_ranges()
373 if (list_empty(&bridge->dma_ranges)) { in cdns_pcie_host_map_dma_ranges()
374 of_property_read_u32(np, "cdns,no-bar-match-nbits", in cdns_pcie_host_map_dma_ranges()
379 dev_err(dev, "IB BAR: %d config failed\n", RP_NO_BAR); in cdns_pcie_host_map_dma_ranges()
383 list_sort(NULL, &bridge->dma_ranges, cdns_pcie_host_dma_ranges_cmp); in cdns_pcie_host_map_dma_ranges()
385 resource_list_for_each_entry(entry, &bridge->dma_ranges) { in cdns_pcie_host_map_dma_ranges()
388 dev_err(dev, "Fail to configure IB using dma-ranges\n"); in cdns_pcie_host_map_dma_ranges()
398 struct cdns_pcie *pcie = &rc->pcie; in cdns_pcie_host_init_address_translation()
400 struct resource *cfg_res = rc->cfg_res; in cdns_pcie_host_init_address_translation()
402 u64 cpu_addr = cfg_res->start; in cdns_pcie_host_init_address_translation()
406 entry = resource_list_first_type(&bridge->windows, IORESOURCE_BUS); in cdns_pcie_host_init_address_translation()
408 busnr = entry->res->start; in cdns_pcie_host_init_address_translation()
420 if (pcie->ops->cpu_addr_fixup) in cdns_pcie_host_init_address_translation()
421 cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr); in cdns_pcie_host_init_address_translation()
430 resource_list_for_each_entry(entry, &bridge->windows) { in cdns_pcie_host_init_address_translation()
431 struct resource *res = entry->res; in cdns_pcie_host_init_address_translation()
432 u64 pci_addr = res->start - entry->offset; in cdns_pcie_host_init_address_translation()
437 pci_pio_to_address(res->start), in cdns_pcie_host_init_address_translation()
443 res->start, in cdns_pcie_host_init_address_translation()
467 struct device *dev = rc->pcie.dev; in cdns_pcie_host_setup()
469 struct device_node *np = dev->of_node; in cdns_pcie_host_setup()
471 enum cdns_pcie_rp_bar bar; in cdns_pcie_host_setup() local
478 return -ENOMEM; in cdns_pcie_host_setup()
480 pcie = &rc->pcie; in cdns_pcie_host_setup()
481 pcie->is_rc = true; in cdns_pcie_host_setup()
483 rc->vendor_id = 0xffff; in cdns_pcie_host_setup()
484 of_property_read_u32(np, "vendor-id", &rc->vendor_id); in cdns_pcie_host_setup()
486 rc->device_id = 0xffff; in cdns_pcie_host_setup()
487 of_property_read_u32(np, "device-id", &rc->device_id); in cdns_pcie_host_setup()
489 pcie->reg_base = devm_platform_ioremap_resource_byname(pdev, "reg"); in cdns_pcie_host_setup()
490 if (IS_ERR(pcie->reg_base)) { in cdns_pcie_host_setup()
492 return PTR_ERR(pcie->reg_base); in cdns_pcie_host_setup()
496 rc->cfg_base = devm_pci_remap_cfg_resource(dev, res); in cdns_pcie_host_setup()
497 if (IS_ERR(rc->cfg_base)) in cdns_pcie_host_setup()
498 return PTR_ERR(rc->cfg_base); in cdns_pcie_host_setup()
499 rc->cfg_res = res; in cdns_pcie_host_setup()
501 if (rc->quirk_detect_quiet_flag) in cdns_pcie_host_setup()
502 cdns_pcie_detect_quiet_min_delay_set(&rc->pcie); in cdns_pcie_host_setup()
514 for (bar = RP_BAR0; bar <= RP_NO_BAR; bar++) in cdns_pcie_host_setup()
515 rc->avail_ib_bar[bar] = true; in cdns_pcie_host_setup()
521 if (!bridge->ops) in cdns_pcie_host_setup()
522 bridge->ops = &cdns_pcie_host_ops; in cdns_pcie_host_setup()