1 /* SPDX-License-Identifier: GPL-2.0 */
3 * PCI Backend - Common data structures for overriding the configuration space
5 * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
8 #ifndef __XEN_PCIBACK_CONF_SPACE_H__
9 #define __XEN_PCIBACK_CONF_SPACE_H__
11 #include <linux/list.h>
12 #include <linux/err.h>
14 /* conf_field_init can return an errno in a ptr with ERR_PTR() */
15 typedef void *(*conf_field_init) (struct pci_dev *dev, int offset);
16 typedef void (*conf_field_reset) (struct pci_dev *dev, int offset, void *data);
17 typedef void (*conf_field_free) (struct pci_dev *dev, int offset, void *data);
19 typedef int (*conf_dword_write) (struct pci_dev *dev, int offset, u32 value,
21 typedef int (*conf_word_write) (struct pci_dev *dev, int offset, u16 value,
23 typedef int (*conf_byte_write) (struct pci_dev *dev, int offset, u8 value,
25 typedef int (*conf_dword_read) (struct pci_dev *dev, int offset, u32 *value,
27 typedef int (*conf_word_read) (struct pci_dev *dev, int offset, u16 *value,
29 typedef int (*conf_byte_read) (struct pci_dev *dev, int offset, u8 *value,
32 /* These are the fields within the configuration space which we
33 * are interested in intercepting reads/writes to and changing their
41 conf_field_reset reset;
42 conf_field_free release;
43 void (*clean) (struct config_field *field);
46 conf_dword_write write;
50 conf_word_write write;
54 conf_byte_write write;
58 struct list_head list;
61 struct config_field_entry {
62 struct list_head list;
63 const struct config_field *field;
64 unsigned int base_offset;
68 #define INTERRUPT_TYPE_NONE (0)
69 #define INTERRUPT_TYPE_INTX (1<<0)
70 #define INTERRUPT_TYPE_MSI (1<<1)
71 #define INTERRUPT_TYPE_MSIX (1<<2)
73 extern bool xen_pcibk_permissive;
75 #define OFFSET(cfg_entry) ((cfg_entry)->base_offset+(cfg_entry)->field->offset)
77 /* Add fields to a device - the add_fields macro expects to get a pointer to
78 * the first entry in an array (of which the ending is marked by size==0)
80 int xen_pcibk_config_add_field_offset(struct pci_dev *dev,
81 const struct config_field *field,
84 static inline int xen_pcibk_config_add_field(struct pci_dev *dev,
85 const struct config_field *field)
87 return xen_pcibk_config_add_field_offset(dev, field, 0);
90 static inline int xen_pcibk_config_add_fields(struct pci_dev *dev,
91 const struct config_field *field)
94 for (i = 0; field[i].size != 0; i++) {
95 err = xen_pcibk_config_add_field(dev, &field[i]);
102 static inline int xen_pcibk_config_add_fields_offset(struct pci_dev *dev,
103 const struct config_field *field,
107 for (i = 0; field[i].size != 0; i++) {
108 err = xen_pcibk_config_add_field_offset(dev, &field[i], offset);
115 /* Read/Write the real configuration space */
116 int xen_pcibk_read_config_byte(struct pci_dev *dev, int offset, u8 *value,
118 int xen_pcibk_read_config_word(struct pci_dev *dev, int offset, u16 *value,
120 int xen_pcibk_read_config_dword(struct pci_dev *dev, int offset, u32 *value,
122 int xen_pcibk_write_config_byte(struct pci_dev *dev, int offset, u8 value,
124 int xen_pcibk_write_config_word(struct pci_dev *dev, int offset, u16 value,
126 int xen_pcibk_write_config_dword(struct pci_dev *dev, int offset, u32 value,
129 int xen_pcibk_config_capability_init(void);
131 int xen_pcibk_config_header_add_fields(struct pci_dev *dev);
132 int xen_pcibk_config_capability_add_fields(struct pci_dev *dev);
134 int xen_pcibk_get_interrupt_type(struct pci_dev *dev);
136 #endif /* __XEN_PCIBACK_CONF_SPACE_H__ */