mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 00:48:50 +00:00
ac08b1c68d
-----BEGIN PGP SIGNATURE----- iQJIBAABCgAyFiEEgMe7l+5h9hnxdsnuWYigwDrT+vwFAmE3jjYUHGJoZWxnYWFz QGdvb2dsZS5jb20ACgkQWYigwDrT+vwrIA/8DYHYRQ6tR3lY0ZxVeBdnd/ryp/ag z35N8RFLPaFlifLWSldwDV/8dylXnRjS57WS9sppp5gKsLl6xYySvTeMpt5QHdXd gJw27sBqiBmecUGFHWVp9B3yF2LvgrtItjd9RadYaHhWEfWyB5AFK7qwxx02fzvo hoGA2XbpI/Hb1BvSOi1avmPYgly1BRu8RFvKMwB2cxQNv3TZOnekT/iFK5WVR1o2 Z5BA+0nj9PrDO/axS0Vh+TqXhU+hOGox7bkOMcNmbDV7Yo8hgot5SsxddbZqJX+O BNNrRv72pbHGIwT/vOP7OQ49sRXledHYeyEGIixjLylBcROk9t8M1z1sfgJ6obVy 1eM3TIx/+7OS5dxC+gTNMVgUiL1NQIdA1LVIBb0BrXm6yNqNxBlj3o/gQ+VGEiNI 0lATmpe4P/N0/cOSI7tK9O2zsX3qzbLnJxsseGrwtK1L+GRYMUPhP4ciblhB0CIf BmK9j0ROmCBGN0Pz/5wIaQgkTro74dqO1BPX8n84M8KWByNZwTrJo/rCBdD4DGaJ eJvyt3hoYxhSxRQ1rp3zqZ9ytm4dJBGcZBKeO1IvKvJHEzfZBIqqq3M/hlNIaSDP v+8I9HaS1kI4SDB1Ia0LFRqKqvpN+WVLB+EoGkeDQozPO42tYSb43lYe83sEnZ+T KY0a/5feu975eLs= =g1WT -----END PGP SIGNATURE----- Merge tag 'pci-v5.15-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci Pull PCI updates from Bjorn Helgaas: "Enumeration: - Convert controller drivers to generic_handle_domain_irq() (Marc Zyngier) - Simplify VPD (Vital Product Data) access and search (Heiner Kallweit) - Update bnx2, bnx2x, bnxt, cxgb4, cxlflash, sfc, tg3 drivers to use simplified VPD interfaces (Heiner Kallweit) - Run Max Payload Size quirks before configuring MPS; work around ASMedia ASM1062 SATA MPS issue (Marek Behún) Resource management: - Refactor pci_ioremap_bar() and pci_ioremap_wc_bar() (Krzysztof Wilczyński) - Optimize pci_resource_len() to reduce kernel size (Zhen Lei) PCI device hotplug: - Fix a double unmap in ibmphp (Vishal Aslot) PCIe port driver: - Enable Bandwidth Notification only if port supports it (Stuart Hayes) Sysfs/proc/syscalls: - Add schedule point in proc_bus_pci_read() (Krzysztof Wilczyński) - Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure (Krzysztof Wilczyński) - Return "int" from pciconfig_read() syscall (Krzysztof Wilczyński) Virtualization: - Extend "pci=noats" to also turn on Translation Blocking to protect against some DMA attacks (Alex Williamson) - Add sysfs mechanism to control the type of reset used between device assignments to VMs (Amey Narkhede) - Add support for ACPI _RST reset method (Shanker Donthineni) - Add ACS quirks for Cavium multi-function devices (George Cherian) - Add ACS quirks for NXP LX2xx0 and LX2xx2 platforms (Wasim Khan) - Allow HiSilicon AMBA devices that appear as fake PCI devices to use PASID and SVA (Zhangfei Gao) Endpoint framework: - Add support for SR-IOV Endpoint devices (Kishon Vijay Abraham I) - Zero-initialize endpoint test tool parameters so we don't use random parameters (Shunyong Yang) APM X-Gene PCIe controller driver: - Remove redundant dev_err() call in xgene_msi_probe() (ErKun Yang) Broadcom iProc PCIe controller driver: - Don't fail devm_pci_alloc_host_bridge() on missing 'ranges' because it's optional on BCMA devices (Rob Herring) - Fix BCMA probe resource handling (Rob Herring) Cadence PCIe driver: - Work around J7200 Link training electrical issue by increasing delays in LTSSM (Nadeem Athani) Intel IXP4xx PCI controller driver: - Depend on ARCH_IXP4XX to avoid useless config questions (Geert Uytterhoeven) Intel Keembay PCIe controller driver: - Add Intel Keem Bay PCIe controller (Srikanth Thokala) Marvell Aardvark PCIe controller driver: - Work around config space completion handling issues (Evan Wang) - Increase timeout for config access completions (Pali Rohár) - Emulate CRS Software Visibility bit (Pali Rohár) - Configure resources from DT 'ranges' property to fix I/O space access (Pali Rohár) - Serialize INTx mask/unmask (Pali Rohár) MediaTek PCIe controller driver: - Add MT7629 support in DT (Chuanjia Liu) - Fix an MSI issue (Chuanjia Liu) - Get syscon regmap ("mediatek,generic-pciecfg"), IRQ number ("pci_irq"), PCI domain ("linux,pci-domain") from DT properties if present (Chuanjia Liu) Microsoft Hyper-V host bridge driver: - Add ARM64 support (Boqun Feng) - Support "Create Interrupt v3" message (Sunil Muthuswamy) NVIDIA Tegra PCIe controller driver: - Use seq_puts(), move err_msg from stack to static, fix OF node leak (Christophe JAILLET) NVIDIA Tegra194 PCIe driver: - Disable suspend when in Endpoint mode (Om Prakash Singh) - Fix MSI-X address programming error (Om Prakash Singh) - Disable interrupts during suspend to avoid spurious AER link down (Om Prakash Singh) Renesas R-Car PCIe controller driver: - Work around hardware issue that prevents Link L1->L0 transition (Marek Vasut) - Fix runtime PM refcount leak (Dinghao Liu) Rockchip DesignWare PCIe controller driver: - Add Rockchip RK356X host controller driver (Simon Xue) TI J721E PCIe driver: - Add support for J7200 and AM64 (Kishon Vijay Abraham I) Toshiba Visconti PCIe controller driver: - Add Toshiba Visconti PCIe host controller driver (Nobuhiro Iwamatsu) Xilinx NWL PCIe controller driver: - Enable PCIe reference clock via CCF (Hyun Kwon) Miscellaneous: - Convert sta2x11 from 'pci_' to 'dma_' API (Christophe JAILLET) - Fix pci_dev_str_match_path() alloc while atomic bug (used for kernel parameters that specify devices) (Dan Carpenter) - Remove pointless Precision Time Management warning when PTM is present but not enabled (Jakub Kicinski) - Remove surplus "break" statements (Krzysztof Wilczyński)" * tag 'pci-v5.15-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: (132 commits) PCI: ibmphp: Fix double unmap of io_mem x86/PCI: sta2x11: switch from 'pci_' to 'dma_' API PCI/VPD: Use unaligned access helpers PCI/VPD: Clean up public VPD defines and inline functions cxgb4: Use pci_vpd_find_id_string() to find VPD ID string PCI/VPD: Add pci_vpd_find_id_string() PCI/VPD: Include post-processing in pci_vpd_find_tag() PCI/VPD: Stop exporting pci_vpd_find_info_keyword() PCI/VPD: Stop exporting pci_vpd_find_tag() PCI: Set dma-can-stall for HiSilicon chips PCI: rockchip-dwc: Add Rockchip RK356X host controller driver PCI: dwc: Remove surplus break statement after return PCI: artpec6: Remove local code block from switch statement PCI: artpec6: Remove surplus break statement after return MAINTAINERS: Add entries for Toshiba Visconti PCIe controller PCI: visconti: Add Toshiba Visconti PCIe host controller driver PCI/portdrv: Enable Bandwidth Notification only if port supports it PCI: Allow PASID on fake PCIe devices without TLP prefixes PCI: mediatek: Use PCI domain to handle ports detection PCI: mediatek: Add new method to get irq number ...
571 lines
13 KiB
C
571 lines
13 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* PCI Endpoint *Function* (EPF) library
|
|
*
|
|
* Copyright (C) 2017 Texas Instruments
|
|
* Author: Kishon Vijay Abraham I <kishon@ti.com>
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci-epc.h>
|
|
#include <linux/pci-epf.h>
|
|
#include <linux/pci-ep-cfs.h>
|
|
|
|
static DEFINE_MUTEX(pci_epf_mutex);
|
|
|
|
static struct bus_type pci_epf_bus_type;
|
|
static const struct device_type pci_epf_type;
|
|
|
|
/**
|
|
* pci_epf_type_add_cfs() - Help function drivers to expose function specific
|
|
* attributes in configfs
|
|
* @epf: the EPF device that has to be configured using configfs
|
|
* @group: the parent configfs group (corresponding to entries in
|
|
* pci_epf_device_id)
|
|
*
|
|
* Invoke to expose function specific attributes in configfs. If the function
|
|
* driver does not have anything to expose (attributes configured by user),
|
|
* return NULL.
|
|
*/
|
|
struct config_group *pci_epf_type_add_cfs(struct pci_epf *epf,
|
|
struct config_group *group)
|
|
{
|
|
struct config_group *epf_type_group;
|
|
|
|
if (!epf->driver) {
|
|
dev_err(&epf->dev, "epf device not bound to driver\n");
|
|
return NULL;
|
|
}
|
|
|
|
if (!epf->driver->ops->add_cfs)
|
|
return NULL;
|
|
|
|
mutex_lock(&epf->lock);
|
|
epf_type_group = epf->driver->ops->add_cfs(epf, group);
|
|
mutex_unlock(&epf->lock);
|
|
|
|
return epf_type_group;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_type_add_cfs);
|
|
|
|
/**
|
|
* pci_epf_unbind() - Notify the function driver that the binding between the
|
|
* EPF device and EPC device has been lost
|
|
* @epf: the EPF device which has lost the binding with the EPC device
|
|
*
|
|
* Invoke to notify the function driver that the binding between the EPF device
|
|
* and EPC device has been lost.
|
|
*/
|
|
void pci_epf_unbind(struct pci_epf *epf)
|
|
{
|
|
struct pci_epf *epf_vf;
|
|
|
|
if (!epf->driver) {
|
|
dev_WARN(&epf->dev, "epf device not bound to driver\n");
|
|
return;
|
|
}
|
|
|
|
mutex_lock(&epf->lock);
|
|
list_for_each_entry(epf_vf, &epf->pci_vepf, list) {
|
|
if (epf_vf->is_bound)
|
|
epf_vf->driver->ops->unbind(epf_vf);
|
|
}
|
|
if (epf->is_bound)
|
|
epf->driver->ops->unbind(epf);
|
|
mutex_unlock(&epf->lock);
|
|
module_put(epf->driver->owner);
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_unbind);
|
|
|
|
/**
|
|
* pci_epf_bind() - Notify the function driver that the EPF device has been
|
|
* bound to a EPC device
|
|
* @epf: the EPF device which has been bound to the EPC device
|
|
*
|
|
* Invoke to notify the function driver that it has been bound to a EPC device
|
|
*/
|
|
int pci_epf_bind(struct pci_epf *epf)
|
|
{
|
|
struct device *dev = &epf->dev;
|
|
struct pci_epf *epf_vf;
|
|
u8 func_no, vfunc_no;
|
|
struct pci_epc *epc;
|
|
int ret;
|
|
|
|
if (!epf->driver) {
|
|
dev_WARN(dev, "epf device not bound to driver\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (!try_module_get(epf->driver->owner))
|
|
return -EAGAIN;
|
|
|
|
mutex_lock(&epf->lock);
|
|
list_for_each_entry(epf_vf, &epf->pci_vepf, list) {
|
|
vfunc_no = epf_vf->vfunc_no;
|
|
|
|
if (vfunc_no < 1) {
|
|
dev_err(dev, "Invalid virtual function number\n");
|
|
ret = -EINVAL;
|
|
goto ret;
|
|
}
|
|
|
|
epc = epf->epc;
|
|
func_no = epf->func_no;
|
|
if (!IS_ERR_OR_NULL(epc)) {
|
|
if (!epc->max_vfs) {
|
|
dev_err(dev, "No support for virt function\n");
|
|
ret = -EINVAL;
|
|
goto ret;
|
|
}
|
|
|
|
if (vfunc_no > epc->max_vfs[func_no]) {
|
|
dev_err(dev, "PF%d: Exceeds max vfunc number\n",
|
|
func_no);
|
|
ret = -EINVAL;
|
|
goto ret;
|
|
}
|
|
}
|
|
|
|
epc = epf->sec_epc;
|
|
func_no = epf->sec_epc_func_no;
|
|
if (!IS_ERR_OR_NULL(epc)) {
|
|
if (!epc->max_vfs) {
|
|
dev_err(dev, "No support for virt function\n");
|
|
ret = -EINVAL;
|
|
goto ret;
|
|
}
|
|
|
|
if (vfunc_no > epc->max_vfs[func_no]) {
|
|
dev_err(dev, "PF%d: Exceeds max vfunc number\n",
|
|
func_no);
|
|
ret = -EINVAL;
|
|
goto ret;
|
|
}
|
|
}
|
|
|
|
epf_vf->func_no = epf->func_no;
|
|
epf_vf->sec_epc_func_no = epf->sec_epc_func_no;
|
|
epf_vf->epc = epf->epc;
|
|
epf_vf->sec_epc = epf->sec_epc;
|
|
ret = epf_vf->driver->ops->bind(epf_vf);
|
|
if (ret)
|
|
goto ret;
|
|
epf_vf->is_bound = true;
|
|
}
|
|
|
|
ret = epf->driver->ops->bind(epf);
|
|
if (ret)
|
|
goto ret;
|
|
epf->is_bound = true;
|
|
|
|
mutex_unlock(&epf->lock);
|
|
return 0;
|
|
|
|
ret:
|
|
mutex_unlock(&epf->lock);
|
|
pci_epf_unbind(epf);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_bind);
|
|
|
|
/**
|
|
* pci_epf_add_vepf() - associate virtual EP function to physical EP function
|
|
* @epf_pf: the physical EP function to which the virtual EP function should be
|
|
* associated
|
|
* @epf_vf: the virtual EP function to be added
|
|
*
|
|
* A physical endpoint function can be associated with multiple virtual
|
|
* endpoint functions. Invoke pci_epf_add_epf() to add a virtual PCI endpoint
|
|
* function to a physical PCI endpoint function.
|
|
*/
|
|
int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf)
|
|
{
|
|
u32 vfunc_no;
|
|
|
|
if (IS_ERR_OR_NULL(epf_pf) || IS_ERR_OR_NULL(epf_vf))
|
|
return -EINVAL;
|
|
|
|
if (epf_pf->epc || epf_vf->epc || epf_vf->epf_pf)
|
|
return -EBUSY;
|
|
|
|
if (epf_pf->sec_epc || epf_vf->sec_epc)
|
|
return -EBUSY;
|
|
|
|
mutex_lock(&epf_pf->lock);
|
|
vfunc_no = find_first_zero_bit(&epf_pf->vfunction_num_map,
|
|
BITS_PER_LONG);
|
|
if (vfunc_no >= BITS_PER_LONG) {
|
|
mutex_unlock(&epf_pf->lock);
|
|
return -EINVAL;
|
|
}
|
|
|
|
set_bit(vfunc_no, &epf_pf->vfunction_num_map);
|
|
epf_vf->vfunc_no = vfunc_no;
|
|
|
|
epf_vf->epf_pf = epf_pf;
|
|
epf_vf->is_vf = true;
|
|
|
|
list_add_tail(&epf_vf->list, &epf_pf->pci_vepf);
|
|
mutex_unlock(&epf_pf->lock);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_add_vepf);
|
|
|
|
/**
|
|
* pci_epf_remove_vepf() - remove virtual EP function from physical EP function
|
|
* @epf_pf: the physical EP function from which the virtual EP function should
|
|
* be removed
|
|
* @epf_vf: the virtual EP function to be removed
|
|
*
|
|
* Invoke to remove a virtual endpoint function from the physcial endpoint
|
|
* function.
|
|
*/
|
|
void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf)
|
|
{
|
|
if (IS_ERR_OR_NULL(epf_pf) || IS_ERR_OR_NULL(epf_vf))
|
|
return;
|
|
|
|
mutex_lock(&epf_pf->lock);
|
|
clear_bit(epf_vf->vfunc_no, &epf_pf->vfunction_num_map);
|
|
list_del(&epf_vf->list);
|
|
mutex_unlock(&epf_pf->lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_remove_vepf);
|
|
|
|
/**
|
|
* pci_epf_free_space() - free the allocated PCI EPF register space
|
|
* @epf: the EPF device from whom to free the memory
|
|
* @addr: the virtual address of the PCI EPF register space
|
|
* @bar: the BAR number corresponding to the register space
|
|
* @type: Identifies if the allocated space is for primary EPC or secondary EPC
|
|
*
|
|
* Invoke to free the allocated PCI EPF register space.
|
|
*/
|
|
void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar,
|
|
enum pci_epc_interface_type type)
|
|
{
|
|
struct device *dev;
|
|
struct pci_epf_bar *epf_bar;
|
|
struct pci_epc *epc;
|
|
|
|
if (!addr)
|
|
return;
|
|
|
|
if (type == PRIMARY_INTERFACE) {
|
|
epc = epf->epc;
|
|
epf_bar = epf->bar;
|
|
} else {
|
|
epc = epf->sec_epc;
|
|
epf_bar = epf->sec_epc_bar;
|
|
}
|
|
|
|
dev = epc->dev.parent;
|
|
dma_free_coherent(dev, epf_bar[bar].size, addr,
|
|
epf_bar[bar].phys_addr);
|
|
|
|
epf_bar[bar].phys_addr = 0;
|
|
epf_bar[bar].addr = NULL;
|
|
epf_bar[bar].size = 0;
|
|
epf_bar[bar].barno = 0;
|
|
epf_bar[bar].flags = 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_free_space);
|
|
|
|
/**
|
|
* pci_epf_alloc_space() - allocate memory for the PCI EPF register space
|
|
* @epf: the EPF device to whom allocate the memory
|
|
* @size: the size of the memory that has to be allocated
|
|
* @bar: the BAR number corresponding to the allocated register space
|
|
* @align: alignment size for the allocation region
|
|
* @type: Identifies if the allocation is for primary EPC or secondary EPC
|
|
*
|
|
* Invoke to allocate memory for the PCI EPF register space.
|
|
*/
|
|
void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
|
|
size_t align, enum pci_epc_interface_type type)
|
|
{
|
|
struct pci_epf_bar *epf_bar;
|
|
dma_addr_t phys_addr;
|
|
struct pci_epc *epc;
|
|
struct device *dev;
|
|
void *space;
|
|
|
|
if (size < 128)
|
|
size = 128;
|
|
|
|
if (align)
|
|
size = ALIGN(size, align);
|
|
else
|
|
size = roundup_pow_of_two(size);
|
|
|
|
if (type == PRIMARY_INTERFACE) {
|
|
epc = epf->epc;
|
|
epf_bar = epf->bar;
|
|
} else {
|
|
epc = epf->sec_epc;
|
|
epf_bar = epf->sec_epc_bar;
|
|
}
|
|
|
|
dev = epc->dev.parent;
|
|
space = dma_alloc_coherent(dev, size, &phys_addr, GFP_KERNEL);
|
|
if (!space) {
|
|
dev_err(dev, "failed to allocate mem space\n");
|
|
return NULL;
|
|
}
|
|
|
|
epf_bar[bar].phys_addr = phys_addr;
|
|
epf_bar[bar].addr = space;
|
|
epf_bar[bar].size = size;
|
|
epf_bar[bar].barno = bar;
|
|
epf_bar[bar].flags |= upper_32_bits(size) ?
|
|
PCI_BASE_ADDRESS_MEM_TYPE_64 :
|
|
PCI_BASE_ADDRESS_MEM_TYPE_32;
|
|
|
|
return space;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_alloc_space);
|
|
|
|
static void pci_epf_remove_cfs(struct pci_epf_driver *driver)
|
|
{
|
|
struct config_group *group, *tmp;
|
|
|
|
if (!IS_ENABLED(CONFIG_PCI_ENDPOINT_CONFIGFS))
|
|
return;
|
|
|
|
mutex_lock(&pci_epf_mutex);
|
|
list_for_each_entry_safe(group, tmp, &driver->epf_group, group_entry)
|
|
pci_ep_cfs_remove_epf_group(group);
|
|
list_del(&driver->epf_group);
|
|
mutex_unlock(&pci_epf_mutex);
|
|
}
|
|
|
|
/**
|
|
* pci_epf_unregister_driver() - unregister the PCI EPF driver
|
|
* @driver: the PCI EPF driver that has to be unregistered
|
|
*
|
|
* Invoke to unregister the PCI EPF driver.
|
|
*/
|
|
void pci_epf_unregister_driver(struct pci_epf_driver *driver)
|
|
{
|
|
pci_epf_remove_cfs(driver);
|
|
driver_unregister(&driver->driver);
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_unregister_driver);
|
|
|
|
static int pci_epf_add_cfs(struct pci_epf_driver *driver)
|
|
{
|
|
struct config_group *group;
|
|
const struct pci_epf_device_id *id;
|
|
|
|
if (!IS_ENABLED(CONFIG_PCI_ENDPOINT_CONFIGFS))
|
|
return 0;
|
|
|
|
INIT_LIST_HEAD(&driver->epf_group);
|
|
|
|
id = driver->id_table;
|
|
while (id->name[0]) {
|
|
group = pci_ep_cfs_add_epf_group(id->name);
|
|
if (IS_ERR(group)) {
|
|
pci_epf_remove_cfs(driver);
|
|
return PTR_ERR(group);
|
|
}
|
|
|
|
mutex_lock(&pci_epf_mutex);
|
|
list_add_tail(&group->group_entry, &driver->epf_group);
|
|
mutex_unlock(&pci_epf_mutex);
|
|
id++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* __pci_epf_register_driver() - register a new PCI EPF driver
|
|
* @driver: structure representing PCI EPF driver
|
|
* @owner: the owner of the module that registers the PCI EPF driver
|
|
*
|
|
* Invoke to register a new PCI EPF driver.
|
|
*/
|
|
int __pci_epf_register_driver(struct pci_epf_driver *driver,
|
|
struct module *owner)
|
|
{
|
|
int ret;
|
|
|
|
if (!driver->ops)
|
|
return -EINVAL;
|
|
|
|
if (!driver->ops->bind || !driver->ops->unbind)
|
|
return -EINVAL;
|
|
|
|
driver->driver.bus = &pci_epf_bus_type;
|
|
driver->driver.owner = owner;
|
|
|
|
ret = driver_register(&driver->driver);
|
|
if (ret)
|
|
return ret;
|
|
|
|
pci_epf_add_cfs(driver);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__pci_epf_register_driver);
|
|
|
|
/**
|
|
* pci_epf_destroy() - destroy the created PCI EPF device
|
|
* @epf: the PCI EPF device that has to be destroyed.
|
|
*
|
|
* Invoke to destroy the PCI EPF device created by invoking pci_epf_create().
|
|
*/
|
|
void pci_epf_destroy(struct pci_epf *epf)
|
|
{
|
|
device_unregister(&epf->dev);
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_destroy);
|
|
|
|
/**
|
|
* pci_epf_create() - create a new PCI EPF device
|
|
* @name: the name of the PCI EPF device. This name will be used to bind the
|
|
* the EPF device to a EPF driver
|
|
*
|
|
* Invoke to create a new PCI EPF device by providing the name of the function
|
|
* device.
|
|
*/
|
|
struct pci_epf *pci_epf_create(const char *name)
|
|
{
|
|
int ret;
|
|
struct pci_epf *epf;
|
|
struct device *dev;
|
|
int len;
|
|
|
|
epf = kzalloc(sizeof(*epf), GFP_KERNEL);
|
|
if (!epf)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
len = strchrnul(name, '.') - name;
|
|
epf->name = kstrndup(name, len, GFP_KERNEL);
|
|
if (!epf->name) {
|
|
kfree(epf);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
|
|
/* VFs are numbered starting with 1. So set BIT(0) by default */
|
|
epf->vfunction_num_map = 1;
|
|
INIT_LIST_HEAD(&epf->pci_vepf);
|
|
|
|
dev = &epf->dev;
|
|
device_initialize(dev);
|
|
dev->bus = &pci_epf_bus_type;
|
|
dev->type = &pci_epf_type;
|
|
mutex_init(&epf->lock);
|
|
|
|
ret = dev_set_name(dev, "%s", name);
|
|
if (ret) {
|
|
put_device(dev);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
ret = device_add(dev);
|
|
if (ret) {
|
|
put_device(dev);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
return epf;
|
|
}
|
|
EXPORT_SYMBOL_GPL(pci_epf_create);
|
|
|
|
static void pci_epf_dev_release(struct device *dev)
|
|
{
|
|
struct pci_epf *epf = to_pci_epf(dev);
|
|
|
|
kfree(epf->name);
|
|
kfree(epf);
|
|
}
|
|
|
|
static const struct device_type pci_epf_type = {
|
|
.release = pci_epf_dev_release,
|
|
};
|
|
|
|
static int
|
|
pci_epf_match_id(const struct pci_epf_device_id *id, const struct pci_epf *epf)
|
|
{
|
|
while (id->name[0]) {
|
|
if (strcmp(epf->name, id->name) == 0)
|
|
return true;
|
|
id++;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static int pci_epf_device_match(struct device *dev, struct device_driver *drv)
|
|
{
|
|
struct pci_epf *epf = to_pci_epf(dev);
|
|
struct pci_epf_driver *driver = to_pci_epf_driver(drv);
|
|
|
|
if (driver->id_table)
|
|
return pci_epf_match_id(driver->id_table, epf);
|
|
|
|
return !strcmp(epf->name, drv->name);
|
|
}
|
|
|
|
static int pci_epf_device_probe(struct device *dev)
|
|
{
|
|
struct pci_epf *epf = to_pci_epf(dev);
|
|
struct pci_epf_driver *driver = to_pci_epf_driver(dev->driver);
|
|
|
|
if (!driver->probe)
|
|
return -ENODEV;
|
|
|
|
epf->driver = driver;
|
|
|
|
return driver->probe(epf);
|
|
}
|
|
|
|
static void pci_epf_device_remove(struct device *dev)
|
|
{
|
|
struct pci_epf *epf = to_pci_epf(dev);
|
|
struct pci_epf_driver *driver = to_pci_epf_driver(dev->driver);
|
|
|
|
if (driver->remove)
|
|
driver->remove(epf);
|
|
epf->driver = NULL;
|
|
}
|
|
|
|
static struct bus_type pci_epf_bus_type = {
|
|
.name = "pci-epf",
|
|
.match = pci_epf_device_match,
|
|
.probe = pci_epf_device_probe,
|
|
.remove = pci_epf_device_remove,
|
|
};
|
|
|
|
static int __init pci_epf_init(void)
|
|
{
|
|
int ret;
|
|
|
|
ret = bus_register(&pci_epf_bus_type);
|
|
if (ret) {
|
|
pr_err("failed to register pci epf bus --> %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
module_init(pci_epf_init);
|
|
|
|
static void __exit pci_epf_exit(void)
|
|
{
|
|
bus_unregister(&pci_epf_bus_type);
|
|
}
|
|
module_exit(pci_epf_exit);
|
|
|
|
MODULE_DESCRIPTION("PCI EPF Library");
|
|
MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
|
|
MODULE_LICENSE("GPL v2");
|