Lines Matching +full:pci +full:- +full:dev
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
28 iounmap(ipc_pcie->scratchpad); in ipc_pcie_resources_release()
31 iounmap(ipc_pcie->ipc_regs); in ipc_pcie_resources_release()
33 /* Releases all PCI I/O and memory resources previously reserved by a in ipc_pcie_resources_release()
35 * after all use of the PCI regions has ceased. in ipc_pcie_resources_release()
37 pci_release_regions(ipc_pcie->pci); in ipc_pcie_resources_release()
43 ipc_imem_cleanup(ipc_pcie->imem); in ipc_pcie_cleanup()
47 /* Signal to the system that the PCI device is not in use. */ in ipc_pcie_cleanup()
48 pci_disable_device(ipc_pcie->pci); in ipc_pcie_cleanup()
53 kfree(ipc_pcie->imem); in ipc_pcie_deinit()
57 static void ipc_pcie_remove(struct pci_dev *pci) in ipc_pcie_remove() argument
59 struct iosm_pcie *ipc_pcie = pci_get_drvdata(pci); in ipc_pcie_remove()
68 struct pci_dev *pci = ipc_pcie->pci; in ipc_pcie_resources_request() local
72 /* Reserved PCI I/O and memory resources. in ipc_pcie_resources_request()
73 * Mark all PCI regions associated with PCI device pci as in ipc_pcie_resources_request()
76 ret = pci_request_regions(pci, "IOSM_IPC"); in ipc_pcie_resources_request()
78 dev_err(ipc_pcie->dev, "failed pci request regions"); in ipc_pcie_resources_request()
87 ipc_pcie->ipc_regs = pci_ioremap_bar(pci, ipc_pcie->ipc_regs_bar_nr); in ipc_pcie_resources_request()
89 if (!ipc_pcie->ipc_regs) { in ipc_pcie_resources_request()
90 dev_err(ipc_pcie->dev, "IPC REGS ioremap error"); in ipc_pcie_resources_request()
91 ret = -EBUSY; in ipc_pcie_resources_request()
100 ipc_pcie->scratchpad = in ipc_pcie_resources_request()
101 pci_ioremap_bar(pci, ipc_pcie->scratchpad_bar_nr); in ipc_pcie_resources_request()
103 if (!ipc_pcie->scratchpad) { in ipc_pcie_resources_request()
104 dev_err(ipc_pcie->dev, "doorbell scratchpad ioremap error"); in ipc_pcie_resources_request()
105 ret = -EBUSY; in ipc_pcie_resources_request()
112 dev_err(ipc_pcie->dev, "acquiring MSI irq failed!"); in ipc_pcie_resources_request()
116 /* Enable bus-mastering for the IOSM IPC device. */ in ipc_pcie_resources_request()
117 pci_set_master(pci); in ipc_pcie_resources_request()
122 pcie_capability_read_dword(ipc_pcie->pci, PCI_EXP_DEVCAP2, &cap); in ipc_pcie_resources_request()
124 pcie_capability_set_word(ipc_pcie->pci, PCI_EXP_DEVCTL2, in ipc_pcie_resources_request()
127 dev_dbg(ipc_pcie->dev, "link between AP and CP is fully on"); in ipc_pcie_resources_request()
132 iounmap(ipc_pcie->scratchpad); in ipc_pcie_resources_request()
134 iounmap(ipc_pcie->ipc_regs); in ipc_pcie_resources_request()
136 pci_release_regions(pci); in ipc_pcie_resources_request()
149 pdev = ipc_pcie->pci->bus->self; in ipc_pcie_check_aspm_enabled()
151 pdev = ipc_pcie->pci; in ipc_pcie_check_aspm_enabled()
155 dev_dbg(ipc_pcie->dev, "ASPM L1: 0x%04X 0x%03X", pdev->device, value); in ipc_pcie_check_aspm_enabled()
166 if (!ipc_pcie->pci->bus || !ipc_pcie->pci->bus->self) { in ipc_pcie_check_data_link_active()
167 dev_err(ipc_pcie->dev, "root port not found"); in ipc_pcie_check_data_link_active()
171 parent = ipc_pcie->pci->bus->self; in ipc_pcie_check_data_link_active()
174 dev_dbg(ipc_pcie->dev, "Link status: 0x%04X", link_status); in ipc_pcie_check_data_link_active()
187 pdev = ipc_pcie->pci->bus->self; in ipc_pcie_check_aspm_supported()
189 pdev = ipc_pcie->pci; in ipc_pcie_check_aspm_supported()
193 dev_dbg(ipc_pcie->dev, "ASPM L1 not supported: 0x%04X", in ipc_pcie_check_aspm_supported()
194 pdev->device); in ipc_pcie_check_aspm_supported()
212 dev_dbg(ipc_pcie->dev, "ASPM parent: %s device: %s", in ipc_pcie_config_aspm()
221 ipc_pcie->ipc_regs_bar_nr = IPC_DOORBELL_BAR0; in ipc_pcie_config_init()
224 ipc_pcie->scratchpad_bar_nr = IPC_SCRATCHPAD_BAR2; in ipc_pcie_config_init()
225 ipc_pcie->doorbell_reg_offset = IPC_DOORBELL_CH_OFFSET; in ipc_pcie_config_init()
226 ipc_pcie->doorbell_write = IPC_WRITE_PTR_REG_0; in ipc_pcie_config_init()
227 ipc_pcie->doorbell_capture = IPC_CAPTURE_PTR_REG_0; in ipc_pcie_config_init()
233 static enum ipc_pcie_sleep_state ipc_pcie_read_bios_cfg(struct device *dev) in ipc_pcie_read_bios_cfg() argument
239 handle_acpi = ACPI_HANDLE(dev); in ipc_pcie_read_bios_cfg()
241 pr_debug("pci device is NOT ACPI supporting device\n"); in ipc_pcie_read_bios_cfg()
249 if (object->integer.value == 3) in ipc_pcie_read_bios_cfg()
258 static int ipc_pcie_probe(struct pci_dev *pci, in ipc_pcie_probe() argument
264 pr_debug("Probing device 0x%X from the vendor 0x%X", pci_id->device, in ipc_pcie_probe()
265 pci_id->vendor); in ipc_pcie_probe()
271 ipc_pcie->dev = &pci->dev; in ipc_pcie_probe()
274 pci_set_drvdata(pci, ipc_pcie); in ipc_pcie_probe()
276 /* Save the address of the PCI device configuration. */ in ipc_pcie_probe()
277 ipc_pcie->pci = pci; in ipc_pcie_probe()
282 /* Initialize the device before it is used. Ask low-level code in ipc_pcie_probe()
285 if (pci_enable_device(pci)) { in ipc_pcie_probe()
286 dev_err(ipc_pcie->dev, "failed to enable the AP PCIe device"); in ipc_pcie_probe()
295 ret = dma_set_mask(ipc_pcie->dev, DMA_BIT_MASK(64)); in ipc_pcie_probe()
297 dev_err(ipc_pcie->dev, "Could not set PCI DMA mask: %d", ret); in ipc_pcie_probe()
302 dev_dbg(ipc_pcie->dev, "PCIe device enabled."); in ipc_pcie_probe()
306 ipc_pcie->d3l2_support = ipc_pcie_read_bios_cfg(&pci->dev); in ipc_pcie_probe()
308 ipc_pcie->suspend = 0; in ipc_pcie_probe()
314 ipc_pcie->imem = ipc_imem_init(ipc_pcie, pci->device, in ipc_pcie_probe()
315 ipc_pcie->scratchpad, ipc_pcie->dev); in ipc_pcie_probe()
316 if (!ipc_pcie->imem) { in ipc_pcie_probe()
317 dev_err(ipc_pcie->dev, "failed to init imem"); in ipc_pcie_probe()
327 pci_disable_device(pci); in ipc_pcie_probe()
331 return -EIO; in ipc_pcie_probe()
339 MODULE_DEVICE_TABLE(pci, iosm_ipc_ids);
350 set_bit(0, &ipc_pcie->suspend); in ipc_pcie_suspend_s2idle()
355 ipc_imem_pm_s2idle_sleep(ipc_pcie->imem, true); in ipc_pcie_suspend_s2idle()
366 ipc_imem_pm_s2idle_sleep(ipc_pcie->imem, false); in ipc_pcie_resume_s2idle()
371 clear_bit(0, &ipc_pcie->suspend); in ipc_pcie_resume_s2idle()
381 ipc_imem_pm_suspend(ipc_pcie->imem); in ipc_pcie_suspend()
383 dev_dbg(ipc_pcie->dev, "SUSPEND done"); in ipc_pcie_suspend()
392 ipc_imem_pm_resume(ipc_pcie->imem); in ipc_pcie_resume()
394 dev_dbg(ipc_pcie->dev, "RESUME done"); in ipc_pcie_resume()
398 static int __maybe_unused ipc_pcie_suspend_cb(struct device *dev) in ipc_pcie_suspend_cb() argument
403 pdev = to_pci_dev(dev); in ipc_pcie_suspend_cb()
407 switch (ipc_pcie->d3l2_support) { in ipc_pcie_suspend_cb()
419 static int __maybe_unused ipc_pcie_resume_cb(struct device *dev) in ipc_pcie_resume_cb() argument
424 pdev = to_pci_dev(dev); in ipc_pcie_resume_cb()
428 switch (ipc_pcie->d3l2_support) { in ipc_pcie_resume_cb()
456 if (ipc_pcie->pci) { in ipc_pcie_addr_map()
457 *mapping = dma_map_single(&ipc_pcie->pci->dev, data, size, in ipc_pcie_addr_map()
459 if (dma_mapping_error(&ipc_pcie->pci->dev, *mapping)) { in ipc_pcie_addr_map()
460 dev_err(ipc_pcie->dev, "dma mapping failed"); in ipc_pcie_addr_map()
461 return -EINVAL; in ipc_pcie_addr_map()
472 if (ipc_pcie->pci) in ipc_pcie_addr_unmap()
473 dma_unmap_single(&ipc_pcie->pci->dev, mapping, size, direction); in ipc_pcie_addr_unmap()
490 IPC_CB(skb)->op_type = (u8)UL_DEFAULT; in ipc_pcie_alloc_local_skb()
491 IPC_CB(skb)->mapping = 0; in ipc_pcie_alloc_local_skb()
508 if (ipc_pcie_addr_map(ipc_pcie, skb->data, size, mapping, direction)) { in ipc_pcie_alloc_skb()
513 BUILD_BUG_ON(sizeof(*IPC_CB(skb)) > sizeof(skb->cb)); in ipc_pcie_alloc_skb()
516 IPC_CB(skb)->mapping = *mapping; in ipc_pcie_alloc_skb()
517 IPC_CB(skb)->direction = direction; in ipc_pcie_alloc_skb()
518 IPC_CB(skb)->len = size; in ipc_pcie_alloc_skb()
528 ipc_pcie_addr_unmap(ipc_pcie, IPC_CB(skb)->len, IPC_CB(skb)->mapping, in ipc_pcie_kfree_skb()
529 IPC_CB(skb)->direction); in ipc_pcie_kfree_skb()
530 IPC_CB(skb)->mapping = 0; in ipc_pcie_kfree_skb()