2018-01-26 21:50:27 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2017-04-10 16:55:10 +03:00
|
|
|
/**
|
|
|
|
* PCI Endpoint *Controller* (EPC) header file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Texas Instruments
|
|
|
|
* Author: Kishon Vijay Abraham I <kishon@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_PCI_EPC_H
|
|
|
|
#define __LINUX_PCI_EPC_H
|
|
|
|
|
|
|
|
#include <linux/pci-epf.h>
|
|
|
|
|
|
|
|
struct pci_epc;
|
|
|
|
|
2021-02-01 22:57:58 +03:00
|
|
|
enum pci_epc_interface_type {
|
|
|
|
UNKNOWN_INTERFACE = -1,
|
|
|
|
PRIMARY_INTERFACE,
|
|
|
|
SECONDARY_INTERFACE,
|
|
|
|
};
|
|
|
|
|
2017-04-10 16:55:10 +03:00
|
|
|
enum pci_epc_irq_type {
|
|
|
|
PCI_EPC_IRQ_UNKNOWN,
|
|
|
|
PCI_EPC_IRQ_LEGACY,
|
|
|
|
PCI_EPC_IRQ_MSI,
|
2018-07-19 11:32:12 +03:00
|
|
|
PCI_EPC_IRQ_MSIX,
|
2017-04-10 16:55:10 +03:00
|
|
|
};
|
|
|
|
|
2021-02-01 22:57:58 +03:00
|
|
|
static inline const char *
|
|
|
|
pci_epc_interface_string(enum pci_epc_interface_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case PRIMARY_INTERFACE:
|
|
|
|
return "primary";
|
|
|
|
case SECONDARY_INTERFACE:
|
|
|
|
return "secondary";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN interface";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 16:55:10 +03:00
|
|
|
/**
|
|
|
|
* struct pci_epc_ops - set of function pointers for performing EPC operations
|
|
|
|
* @write_header: ops to populate configuration space header
|
|
|
|
* @set_bar: ops to configure the BAR
|
|
|
|
* @clear_bar: ops to reset the BAR
|
|
|
|
* @map_addr: ops to map CPU address to PCI address
|
|
|
|
* @unmap_addr: ops to unmap CPU address and PCI address
|
|
|
|
* @set_msi: ops to set the requested number of MSI interrupts in the MSI
|
|
|
|
* capability register
|
|
|
|
* @get_msi: ops to get the number of MSI interrupts allocated by the RC from
|
|
|
|
* the MSI capability register
|
2018-07-19 11:32:12 +03:00
|
|
|
* @set_msix: ops to set the requested number of MSI-X interrupts in the
|
|
|
|
* MSI-X capability register
|
|
|
|
* @get_msix: ops to get the number of MSI-X interrupts allocated by the RC
|
|
|
|
* from the MSI-X capability register
|
2018-07-19 11:32:13 +03:00
|
|
|
* @raise_irq: ops to raise a legacy, MSI or MSI-X interrupt
|
2021-02-01 22:58:00 +03:00
|
|
|
* @map_msi_irq: ops to map physical address to MSI address and return MSI data
|
2017-04-10 16:55:10 +03:00
|
|
|
* @start: ops to start the PCI link
|
|
|
|
* @stop: ops to stop the PCI link
|
|
|
|
* @owner: the module owner containing the ops
|
|
|
|
*/
|
|
|
|
struct pci_epc_ops {
|
2018-01-30 23:56:56 +03:00
|
|
|
int (*write_header)(struct pci_epc *epc, u8 func_no,
|
2017-04-10 16:55:10 +03:00
|
|
|
struct pci_epf_header *hdr);
|
2018-01-30 23:56:56 +03:00
|
|
|
int (*set_bar)(struct pci_epc *epc, u8 func_no,
|
2018-03-28 14:50:07 +03:00
|
|
|
struct pci_epf_bar *epf_bar);
|
2018-01-30 23:56:56 +03:00
|
|
|
void (*clear_bar)(struct pci_epc *epc, u8 func_no,
|
2018-03-28 14:50:14 +03:00
|
|
|
struct pci_epf_bar *epf_bar);
|
2018-01-30 23:56:56 +03:00
|
|
|
int (*map_addr)(struct pci_epc *epc, u8 func_no,
|
|
|
|
phys_addr_t addr, u64 pci_addr, size_t size);
|
|
|
|
void (*unmap_addr)(struct pci_epc *epc, u8 func_no,
|
|
|
|
phys_addr_t addr);
|
|
|
|
int (*set_msi)(struct pci_epc *epc, u8 func_no, u8 interrupts);
|
|
|
|
int (*get_msi)(struct pci_epc *epc, u8 func_no);
|
2020-02-25 11:17:01 +03:00
|
|
|
int (*set_msix)(struct pci_epc *epc, u8 func_no, u16 interrupts,
|
|
|
|
enum pci_barno, u32 offset);
|
2018-07-19 11:32:12 +03:00
|
|
|
int (*get_msix)(struct pci_epc *epc, u8 func_no);
|
2018-01-30 23:56:56 +03:00
|
|
|
int (*raise_irq)(struct pci_epc *epc, u8 func_no,
|
2018-07-19 11:32:13 +03:00
|
|
|
enum pci_epc_irq_type type, u16 interrupt_num);
|
2021-02-01 22:58:00 +03:00
|
|
|
int (*map_msi_irq)(struct pci_epc *epc, u8 func_no,
|
|
|
|
phys_addr_t phys_addr, u8 interrupt_num,
|
|
|
|
u32 entry_size, u32 *msi_data,
|
|
|
|
u32 *msi_addr_offset);
|
2017-04-10 16:55:10 +03:00
|
|
|
int (*start)(struct pci_epc *epc);
|
|
|
|
void (*stop)(struct pci_epc *epc);
|
2019-01-14 14:14:59 +03:00
|
|
|
const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
|
|
|
|
u8 func_no);
|
2017-04-10 16:55:10 +03:00
|
|
|
struct module *owner;
|
|
|
|
};
|
|
|
|
|
2020-05-07 15:33:16 +03:00
|
|
|
/**
|
|
|
|
* struct pci_epc_mem_window - address window of the endpoint controller
|
|
|
|
* @phys_base: physical base address of the PCI address window
|
|
|
|
* @size: the size of the PCI address window
|
|
|
|
* @page_size: size of each page
|
|
|
|
*/
|
|
|
|
struct pci_epc_mem_window {
|
|
|
|
phys_addr_t phys_base;
|
|
|
|
size_t size;
|
|
|
|
size_t page_size;
|
|
|
|
};
|
|
|
|
|
2017-04-10 16:55:10 +03:00
|
|
|
/**
|
|
|
|
* struct pci_epc_mem - address space of the endpoint controller
|
2020-05-07 15:33:16 +03:00
|
|
|
* @window: address window of the endpoint controller
|
2017-04-10 16:55:10 +03:00
|
|
|
* @bitmap: bitmap to manage the PCI address space
|
|
|
|
* @pages: number of bits representing the address region
|
2020-02-24 12:53:36 +03:00
|
|
|
* @lock: mutex to protect bitmap
|
2017-04-10 16:55:10 +03:00
|
|
|
*/
|
|
|
|
struct pci_epc_mem {
|
2020-05-07 15:33:16 +03:00
|
|
|
struct pci_epc_mem_window window;
|
2017-04-10 16:55:10 +03:00
|
|
|
unsigned long *bitmap;
|
|
|
|
int pages;
|
2020-02-24 12:53:36 +03:00
|
|
|
/* mutex to protect against concurrent access for memory allocation*/
|
|
|
|
struct mutex lock;
|
2017-04-10 16:55:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct pci_epc - represents the PCI EPC device
|
|
|
|
* @dev: PCI EPC device
|
|
|
|
* @pci_epf: list of endpoint functions present in this EPC device
|
|
|
|
* @ops: function pointers for performing endpoint operations
|
2020-05-07 15:33:16 +03:00
|
|
|
* @windows: array of address space of the endpoint controller
|
|
|
|
* @mem: first window of the endpoint controller, which corresponds to
|
|
|
|
* default address space of the endpoint controller supporting
|
|
|
|
* single window.
|
|
|
|
* @num_windows: number of windows supported by device
|
2017-04-10 16:55:10 +03:00
|
|
|
* @max_functions: max number of functions that can be configured in this EPC
|
2017-03-27 12:45:01 +03:00
|
|
|
* @group: configfs group representing the PCI EPC device
|
2020-02-24 12:53:35 +03:00
|
|
|
* @lock: mutex to protect pci_epc ops
|
2020-02-24 12:53:38 +03:00
|
|
|
* @function_num_map: bitmap to manage physical function number
|
2020-02-24 12:53:34 +03:00
|
|
|
* @notifier: used to notify EPF of any EPC events (like linkup)
|
2017-04-10 16:55:10 +03:00
|
|
|
*/
|
|
|
|
struct pci_epc {
|
|
|
|
struct device dev;
|
|
|
|
struct list_head pci_epf;
|
|
|
|
const struct pci_epc_ops *ops;
|
2020-05-07 15:33:16 +03:00
|
|
|
struct pci_epc_mem **windows;
|
2017-04-10 16:55:10 +03:00
|
|
|
struct pci_epc_mem *mem;
|
2020-05-07 15:33:16 +03:00
|
|
|
unsigned int num_windows;
|
2017-04-10 16:55:10 +03:00
|
|
|
u8 max_functions;
|
2017-03-27 12:45:01 +03:00
|
|
|
struct config_group *group;
|
2020-02-24 12:53:35 +03:00
|
|
|
/* mutex to protect against concurrent access of EP controller */
|
|
|
|
struct mutex lock;
|
2020-02-24 12:53:38 +03:00
|
|
|
unsigned long function_num_map;
|
2020-02-24 12:53:34 +03:00
|
|
|
struct atomic_notifier_head notifier;
|
2017-04-10 16:55:10 +03:00
|
|
|
};
|
|
|
|
|
2019-01-14 14:14:59 +03:00
|
|
|
/**
|
|
|
|
* struct pci_epc_features - features supported by a EPC device per function
|
|
|
|
* @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
|
|
|
|
* @msi_capable: indicate if the endpoint function has MSI capability
|
|
|
|
* @msix_capable: indicate if the endpoint function has MSI-X capability
|
|
|
|
* @reserved_bar: bitmap to indicate reserved BAR unavailable to function driver
|
|
|
|
* @bar_fixed_64bit: bitmap to indicate fixed 64bit BARs
|
|
|
|
* @bar_fixed_size: Array specifying the size supported by each BAR
|
2019-03-25 12:39:39 +03:00
|
|
|
* @align: alignment size required for BAR buffer allocation
|
2019-01-14 14:14:59 +03:00
|
|
|
*/
|
|
|
|
struct pci_epc_features {
|
|
|
|
unsigned int linkup_notifier : 1;
|
2020-02-17 15:10:32 +03:00
|
|
|
unsigned int core_init_notifier : 1;
|
2019-01-14 14:14:59 +03:00
|
|
|
unsigned int msi_capable : 1;
|
|
|
|
unsigned int msix_capable : 1;
|
|
|
|
u8 reserved_bar;
|
|
|
|
u8 bar_fixed_64bit;
|
2019-09-28 02:43:08 +03:00
|
|
|
u64 bar_fixed_size[PCI_STD_NUM_BARS];
|
2019-03-25 12:39:39 +03:00
|
|
|
size_t align;
|
2019-01-14 14:14:59 +03:00
|
|
|
};
|
|
|
|
|
2017-04-10 16:55:10 +03:00
|
|
|
#define to_pci_epc(device) container_of((device), struct pci_epc, dev)
|
|
|
|
|
|
|
|
#define pci_epc_create(dev, ops) \
|
|
|
|
__pci_epc_create((dev), (ops), THIS_MODULE)
|
|
|
|
#define devm_pci_epc_create(dev, ops) \
|
|
|
|
__devm_pci_epc_create((dev), (ops), THIS_MODULE)
|
|
|
|
|
|
|
|
static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
|
|
|
|
{
|
|
|
|
dev_set_drvdata(&epc->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *epc_get_drvdata(struct pci_epc *epc)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(&epc->dev);
|
|
|
|
}
|
|
|
|
|
2020-02-24 12:53:34 +03:00
|
|
|
static inline int
|
|
|
|
pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return atomic_notifier_chain_register(&epc->notifier, nb);
|
|
|
|
}
|
|
|
|
|
2017-04-10 16:55:10 +03:00
|
|
|
struct pci_epc *
|
|
|
|
__devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
|
|
|
|
struct module *owner);
|
|
|
|
struct pci_epc *
|
|
|
|
__pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
|
|
|
|
struct module *owner);
|
|
|
|
void devm_pci_epc_destroy(struct device *dev, struct pci_epc *epc);
|
|
|
|
void pci_epc_destroy(struct pci_epc *epc);
|
2021-02-01 22:57:58 +03:00
|
|
|
int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,
|
|
|
|
enum pci_epc_interface_type type);
|
2017-04-10 16:55:10 +03:00
|
|
|
void pci_epc_linkup(struct pci_epc *epc);
|
2020-02-17 15:10:34 +03:00
|
|
|
void pci_epc_init_notify(struct pci_epc *epc);
|
2021-02-01 22:57:58 +03:00
|
|
|
void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
|
|
|
|
enum pci_epc_interface_type type);
|
2018-01-30 23:56:56 +03:00
|
|
|
int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
|
|
|
|
struct pci_epf_header *hdr);
|
|
|
|
int pci_epc_set_bar(struct pci_epc *epc, u8 func_no,
|
2018-03-28 14:50:07 +03:00
|
|
|
struct pci_epf_bar *epf_bar);
|
2018-03-28 14:50:14 +03:00
|
|
|
void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no,
|
|
|
|
struct pci_epf_bar *epf_bar);
|
2018-01-30 23:56:56 +03:00
|
|
|
int pci_epc_map_addr(struct pci_epc *epc, u8 func_no,
|
|
|
|
phys_addr_t phys_addr,
|
2017-04-10 16:55:10 +03:00
|
|
|
u64 pci_addr, size_t size);
|
2018-01-30 23:56:56 +03:00
|
|
|
void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no,
|
|
|
|
phys_addr_t phys_addr);
|
|
|
|
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts);
|
|
|
|
int pci_epc_get_msi(struct pci_epc *epc, u8 func_no);
|
2020-02-25 11:17:01 +03:00
|
|
|
int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts,
|
|
|
|
enum pci_barno, u32 offset);
|
2018-07-19 11:32:12 +03:00
|
|
|
int pci_epc_get_msix(struct pci_epc *epc, u8 func_no);
|
2021-02-01 22:58:00 +03:00
|
|
|
int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no,
|
|
|
|
phys_addr_t phys_addr, u8 interrupt_num,
|
|
|
|
u32 entry_size, u32 *msi_data, u32 *msi_addr_offset);
|
2018-01-30 23:56:56 +03:00
|
|
|
int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no,
|
2018-07-19 11:32:13 +03:00
|
|
|
enum pci_epc_irq_type type, u16 interrupt_num);
|
2017-04-10 16:55:10 +03:00
|
|
|
int pci_epc_start(struct pci_epc *epc);
|
|
|
|
void pci_epc_stop(struct pci_epc *epc);
|
2019-01-14 14:14:59 +03:00
|
|
|
const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
|
|
|
|
u8 func_no);
|
2021-02-01 22:57:56 +03:00
|
|
|
enum pci_barno
|
|
|
|
pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features);
|
|
|
|
enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features
|
|
|
|
*epc_features, enum pci_barno bar);
|
2017-04-10 16:55:10 +03:00
|
|
|
struct pci_epc *pci_epc_get(const char *epc_name);
|
|
|
|
void pci_epc_put(struct pci_epc *epc);
|
|
|
|
|
2020-05-07 15:33:15 +03:00
|
|
|
int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base,
|
|
|
|
size_t size, size_t page_size);
|
2020-05-07 15:33:16 +03:00
|
|
|
int pci_epc_multi_mem_init(struct pci_epc *epc,
|
|
|
|
struct pci_epc_mem_window *window,
|
|
|
|
unsigned int num_windows);
|
2017-04-10 16:55:10 +03:00
|
|
|
void pci_epc_mem_exit(struct pci_epc *epc);
|
|
|
|
void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
|
|
|
|
phys_addr_t *phys_addr, size_t size);
|
|
|
|
void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
|
|
|
|
void __iomem *virt_addr, size_t size);
|
|
|
|
#endif /* __LINUX_PCI_EPC_H */
|