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 extern bool xen_pcibk_permissive
;
70 #define OFFSET(cfg_entry) ((cfg_entry)->base_offset+(cfg_entry)->field->offset)
72 /* Add fields to a device - the add_fields macro expects to get a pointer to
73 * the first entry in an array (of which the ending is marked by size==0)
75 int xen_pcibk_config_add_field_offset(struct pci_dev
*dev
,
76 const struct config_field
*field
,
79 static inline int xen_pcibk_config_add_field(struct pci_dev
*dev
,
80 const struct config_field
*field
)
82 return xen_pcibk_config_add_field_offset(dev
, field
, 0);
85 static inline int xen_pcibk_config_add_fields(struct pci_dev
*dev
,
86 const struct config_field
*field
)
89 for (i
= 0; field
[i
].size
!= 0; i
++) {
90 err
= xen_pcibk_config_add_field(dev
, &field
[i
]);
97 static inline int xen_pcibk_config_add_fields_offset(struct pci_dev
*dev
,
98 const struct config_field
*field
,
102 for (i
= 0; field
[i
].size
!= 0; i
++) {
103 err
= xen_pcibk_config_add_field_offset(dev
, &field
[i
], offset
);
110 /* Read/Write the real configuration space */
111 int xen_pcibk_read_config_byte(struct pci_dev
*dev
, int offset
, u8
*value
,
113 int xen_pcibk_read_config_word(struct pci_dev
*dev
, int offset
, u16
*value
,
115 int xen_pcibk_read_config_dword(struct pci_dev
*dev
, int offset
, u32
*value
,
117 int xen_pcibk_write_config_byte(struct pci_dev
*dev
, int offset
, u8 value
,
119 int xen_pcibk_write_config_word(struct pci_dev
*dev
, int offset
, u16 value
,
121 int xen_pcibk_write_config_dword(struct pci_dev
*dev
, int offset
, u32 value
,
124 int xen_pcibk_config_capability_init(void);
126 int xen_pcibk_config_header_add_fields(struct pci_dev
*dev
);
127 int xen_pcibk_config_capability_add_fields(struct pci_dev
*dev
);
129 #endif /* __XEN_PCIBACK_CONF_SPACE_H__ */