at v4.13 162 lines 4.9 kB view raw
1/** 2 * PCI Endpoint *Function* (EPF) header file 3 * 4 * Copyright (C) 2017 Texas Instruments 5 * Author: Kishon Vijay Abraham I <kishon@ti.com> 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 of 9 * the License as published by the Free Software Foundation. 10 */ 11 12#ifndef __LINUX_PCI_EPF_H 13#define __LINUX_PCI_EPF_H 14 15#include <linux/device.h> 16#include <linux/mod_devicetable.h> 17 18struct pci_epf; 19 20enum pci_interrupt_pin { 21 PCI_INTERRUPT_UNKNOWN, 22 PCI_INTERRUPT_INTA, 23 PCI_INTERRUPT_INTB, 24 PCI_INTERRUPT_INTC, 25 PCI_INTERRUPT_INTD, 26}; 27 28enum pci_barno { 29 BAR_0, 30 BAR_1, 31 BAR_2, 32 BAR_3, 33 BAR_4, 34 BAR_5, 35}; 36 37/** 38 * struct pci_epf_header - represents standard configuration header 39 * @vendorid: identifies device manufacturer 40 * @deviceid: identifies a particular device 41 * @revid: specifies a device-specific revision identifier 42 * @progif_code: identifies a specific register-level programming interface 43 * @subclass_code: identifies more specifically the function of the device 44 * @baseclass_code: broadly classifies the type of function the device performs 45 * @cache_line_size: specifies the system cacheline size in units of DWORDs 46 * @subsys_vendor_id: vendor of the add-in card or subsystem 47 * @subsys_id: id specific to vendor 48 * @interrupt_pin: interrupt pin the device (or device function) uses 49 */ 50struct pci_epf_header { 51 u16 vendorid; 52 u16 deviceid; 53 u8 revid; 54 u8 progif_code; 55 u8 subclass_code; 56 u8 baseclass_code; 57 u8 cache_line_size; 58 u16 subsys_vendor_id; 59 u16 subsys_id; 60 enum pci_interrupt_pin interrupt_pin; 61}; 62 63/** 64 * struct pci_epf_ops - set of function pointers for performing EPF operations 65 * @bind: ops to perform when a EPC device has been bound to EPF device 66 * @unbind: ops to perform when a binding has been lost between a EPC device 67 * and EPF device 68 * @linkup: ops to perform when the EPC device has established a connection with 69 * a host system 70 */ 71struct pci_epf_ops { 72 int (*bind)(struct pci_epf *epf); 73 void (*unbind)(struct pci_epf *epf); 74 void (*linkup)(struct pci_epf *epf); 75}; 76 77/** 78 * struct pci_epf_driver - represents the PCI EPF driver 79 * @probe: ops to perform when a new EPF device has been bound to the EPF driver 80 * @remove: ops to perform when the binding between the EPF device and EPF 81 * driver is broken 82 * @driver: PCI EPF driver 83 * @ops: set of function pointers for performing EPF operations 84 * @owner: the owner of the module that registers the PCI EPF driver 85 * @group: configfs group corresponding to the PCI EPF driver 86 * @id_table: identifies EPF devices for probing 87 */ 88struct pci_epf_driver { 89 int (*probe)(struct pci_epf *epf); 90 int (*remove)(struct pci_epf *epf); 91 92 struct device_driver driver; 93 struct pci_epf_ops *ops; 94 struct module *owner; 95 struct config_group *group; 96 const struct pci_epf_device_id *id_table; 97}; 98 99#define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \ 100 driver)) 101 102/** 103 * struct pci_epf_bar - represents the BAR of EPF device 104 * @phys_addr: physical address that should be mapped to the BAR 105 * @size: the size of the address space present in BAR 106 */ 107struct pci_epf_bar { 108 dma_addr_t phys_addr; 109 size_t size; 110}; 111 112/** 113 * struct pci_epf - represents the PCI EPF device 114 * @dev: the PCI EPF device 115 * @name: the name of the PCI EPF device 116 * @header: represents standard configuration header 117 * @bar: represents the BAR of EPF device 118 * @msi_interrupts: number of MSI interrupts required by this function 119 * @func_no: unique function number within this endpoint device 120 * @epc: the EPC device to which this EPF device is bound 121 * @driver: the EPF driver to which this EPF device is bound 122 * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc 123 */ 124struct pci_epf { 125 struct device dev; 126 const char *name; 127 struct pci_epf_header *header; 128 struct pci_epf_bar bar[6]; 129 u8 msi_interrupts; 130 u8 func_no; 131 132 struct pci_epc *epc; 133 struct pci_epf_driver *driver; 134 struct list_head list; 135}; 136 137#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev) 138 139#define pci_epf_register_driver(driver) \ 140 __pci_epf_register_driver((driver), THIS_MODULE) 141 142static inline void epf_set_drvdata(struct pci_epf *epf, void *data) 143{ 144 dev_set_drvdata(&epf->dev, data); 145} 146 147static inline void *epf_get_drvdata(struct pci_epf *epf) 148{ 149 return dev_get_drvdata(&epf->dev); 150} 151 152struct pci_epf *pci_epf_create(const char *name); 153void pci_epf_destroy(struct pci_epf *epf); 154int __pci_epf_register_driver(struct pci_epf_driver *driver, 155 struct module *owner); 156void pci_epf_unregister_driver(struct pci_epf_driver *driver); 157void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar); 158void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar); 159int pci_epf_bind(struct pci_epf *epf); 160void pci_epf_unbind(struct pci_epf *epf); 161void pci_epf_linkup(struct pci_epf *epf); 162#endif /* __LINUX_PCI_EPF_H */