xref: /kvmtool/pci.c (revision 4c797ebc31e1ac6ebe13807c293f4e0c747953e1)
160742802SPekka Enberg #include "kvm/pci.h"
260742802SPekka Enberg 
360742802SPekka Enberg #include "kvm/ioport.h"
460742802SPekka Enberg 
560742802SPekka Enberg #include <stdint.h>
660742802SPekka Enberg 
74402a581SPekka Enberg static struct pci_config_address pci_config_address;
860742802SPekka Enberg 
9305b72ceSCyrill Gorcunov static bool pci_config_address_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
1060742802SPekka Enberg {
114402a581SPekka Enberg 	struct pci_config_address *addr = data;
1260742802SPekka Enberg 
13dad5bc09SCyrill Gorcunov 	pci_config_address	= *addr;
1460742802SPekka Enberg 
1560742802SPekka Enberg 	return true;
1660742802SPekka Enberg }
1760742802SPekka Enberg 
18305b72ceSCyrill Gorcunov static bool pci_config_address_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
1960742802SPekka Enberg {
204402a581SPekka Enberg 	struct pci_config_address *addr = data;
2160742802SPekka Enberg 
22305b72ceSCyrill Gorcunov 	*addr		=  pci_config_address;
2360742802SPekka Enberg 
2460742802SPekka Enberg 	return true;
2560742802SPekka Enberg }
2660742802SPekka Enberg 
27305b72ceSCyrill Gorcunov static struct ioport_operations pci_config_address_ops = {
28305b72ceSCyrill Gorcunov 	.io_in		= pci_config_address_in,
29305b72ceSCyrill Gorcunov 	.io_out		= pci_config_address_out,
3060742802SPekka Enberg };
3160742802SPekka Enberg 
32305b72ceSCyrill Gorcunov static bool pci_config_data_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
3360742802SPekka Enberg {
3460742802SPekka Enberg 	return true;
3560742802SPekka Enberg }
3660742802SPekka Enberg 
37305b72ceSCyrill Gorcunov static bool pci_config_data_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
3860742802SPekka Enberg {
39*4c797ebcSCyrill Gorcunov 	uint32_t *value = data;
40*4c797ebcSCyrill Gorcunov 
41*4c797ebcSCyrill Gorcunov 	*value = PCI_NO_DEVICE;
42*4c797ebcSCyrill Gorcunov 
4360742802SPekka Enberg 	return true;
4460742802SPekka Enberg }
4560742802SPekka Enberg 
46305b72ceSCyrill Gorcunov static struct ioport_operations pci_config_data_ops = {
47305b72ceSCyrill Gorcunov 	.io_in		= pci_config_data_in,
48305b72ceSCyrill Gorcunov 	.io_out		= pci_config_data_out,
4960742802SPekka Enberg };
5060742802SPekka Enberg 
5160742802SPekka Enberg void pci__init(void)
5260742802SPekka Enberg {
53305b72ceSCyrill Gorcunov 	ioport__register(PCI_CONFIG_DATA,    &pci_config_data_ops);
54305b72ceSCyrill Gorcunov 	ioport__register(PCI_CONFIG_ADDRESS, &pci_config_address_ops);
5560742802SPekka Enberg }
56