From 783753fd53fe513d37fbbfe6694c0c1ab9701fd1 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 13 Jul 2010 13:01:39 +0900 Subject: pci/bridge: split out pci bridge code into pci_bridge.c from pci.c Move pci bridge related code into pci_bridge.c from pci.c for further enhancement. pci.c is big enough now, so split it out. No code change but exporting some accesser functions. In fact, few pci bridge functions stays in pci.c. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 1eab7e7dda..c551f9661c 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -233,10 +233,7 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp, void do_pci_info_print(Monitor *mon, const QObject *data); void do_pci_info(Monitor *mon, QObject **ret_data); -PCIBus *pci_bridge_init(PCIBus *bus, int devfn, bool multifunction, - uint16_t vid, uint16_t did, - pci_map_irq_fn map_irq, const char *name); -PCIDevice *pci_bridge_get_device(PCIBus *bus); +void pci_bridge_update_mappings(PCIBus *b); static inline void pci_set_byte(uint8_t *config, uint8_t val) -- cgit v1.2.3 From ca77089d2d8e73283bfc73f03d954504561e1ce8 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Mon, 6 Sep 2010 16:46:16 +0900 Subject: pci: consolidate pci_add_capability_at_offset() into pci_add_capability(). By making pci_add_capability() the special case of pci_add_capability_at_offset() of offset = 0, consolidate pci_add_capability_at_offset() into pci_add_capability(). Cc: Stefan Weil Cc: Michael S. Tsirkin Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index c551f9661c..2ddba59589 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -183,9 +183,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, pcibus_t size, int type, PCIMapIORegionFunc *map_func); -int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size); -int pci_add_capability_at_offset(PCIDevice *pci_dev, uint8_t cap_id, - uint8_t cap_offset, uint8_t cap_size); +int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, + uint8_t offset, uint8_t size); void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size); -- cgit v1.2.3 From 43c945f16a172f07145ca1f30abb958070228690 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Mon, 6 Sep 2010 16:46:19 +0900 Subject: pci: make pci_parse_devfn() aware of func. make pci_parse_devfn() aware of func. With func = NULL it behave as before. This will be used later. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 2ddba59589..2b4c318898 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -227,6 +227,8 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num); PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function); PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr); +int pci_parse_devaddr(const char *addr, int *domp, int *busp, + unsigned int *slotp, unsigned int *funcp); int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp, unsigned *slotp); -- cgit v1.2.3 From 0bb750ef9e897ba5f4d9899ddc7e222e809bcbbd Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 9 Sep 2010 11:48:57 +0900 Subject: pci: improve signature of pci_register_bar(). Make type uint8_t from int because PCIIORegion::type is uint8_t. Signed-off-by: Isaku Yamahata --- hw/pci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 2b4c318898..1c6075eb40 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -180,7 +180,7 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name, PCIConfigWriteFunc *config_write); void pci_register_bar(PCIDevice *pci_dev, int region_num, - pcibus_t size, int type, + pcibus_t size, uint8_t type, PCIMapIORegionFunc *map_func); int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, -- cgit v1.2.3 From 92ba5f51c305911cbfc0fcff9f259b0604681222 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Wed, 15 Sep 2010 14:38:15 +0900 Subject: pci: implement RW1C register framework. Implement RW1C register framework. With this patch, it would be easy to implement W1C(Write 1 to Clear) register by just setting w1cmask. Later RW1C register will be used by pcie. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 1c6075eb40..d8b399f4d5 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -129,6 +129,9 @@ struct PCIDevice { /* Used to implement R/W bytes */ uint8_t *wmask; + /* Used to implement RW1C(Write 1 to Clear) bytes */ + uint8_t *w1cmask; + /* Used to allocate config space for capabilities. */ uint8_t *used; -- cgit v1.2.3 From aabcf5266f94e637afd4c38d46d1fc1d1381d99e Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 19 Oct 2010 18:06:28 +0900 Subject: pci: introduce helper functions to test-and-{clear, set} mask in configuration space This patch introduces helper functions to test-and-{clear, set} mask in configuration space. pci_{byte, word, long, quad}_test_and_{clear, set}_mask(). They will be used later. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index d8b399f4d5..752e652eca 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -323,6 +323,76 @@ pci_config_set_interrupt_pin(uint8_t *pci_config, uint8_t val) pci_set_byte(&pci_config[PCI_INTERRUPT_PIN], val); } +/* + * helper functions to do bit mask operation on configuration space. + * Just to set bit, use test-and-set and discard returned value. + * Just to clear bit, use test-and-clear and discard returned value. + * NOTE: They aren't atomic. + */ +static inline uint8_t +pci_byte_test_and_clear_mask(uint8_t *config, uint8_t mask) +{ + uint8_t val = pci_get_byte(config); + pci_set_byte(config, val & ~mask); + return val & mask; +} + +static inline uint8_t +pci_byte_test_and_set_mask(uint8_t *config, uint8_t mask) +{ + uint8_t val = pci_get_byte(config); + pci_set_byte(config, val | mask); + return val & mask; +} + +static inline uint16_t +pci_word_test_and_clear_mask(uint8_t *config, uint16_t mask) +{ + uint16_t val = pci_get_word(config); + pci_set_word(config, val & ~mask); + return val & mask; +} + +static inline uint16_t +pci_word_test_and_set_mask(uint8_t *config, uint16_t mask) +{ + uint16_t val = pci_get_word(config); + pci_set_word(config, val | mask); + return val & mask; +} + +static inline uint32_t +pci_long_test_and_clear_mask(uint8_t *config, uint32_t mask) +{ + uint32_t val = pci_get_long(config); + pci_set_long(config, val & ~mask); + return val & mask; +} + +static inline uint32_t +pci_long_test_and_set_mask(uint8_t *config, uint32_t mask) +{ + uint32_t val = pci_get_long(config); + pci_set_long(config, val | mask); + return val & mask; +} + +static inline uint64_t +pci_quad_test_and_clear_mask(uint8_t *config, uint64_t mask) +{ + uint64_t val = pci_get_quad(config); + pci_set_quad(config, val & ~mask); + return val & mask; +} + +static inline uint64_t +pci_quad_test_and_set_mask(uint8_t *config, uint64_t mask) +{ + uint64_t val = pci_get_quad(config); + pci_set_quad(config, val | mask); + return val & mask; +} + typedef int (*pci_qdev_initfn)(PCIDevice *dev); typedef struct { DeviceInfo qdev; -- cgit v1.2.3 From a5d1fd20ccfd1fbe840729378e4adbc3eb0f8306 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 19 Oct 2010 18:06:29 +0900 Subject: pci: introduce helper function to handle msi-x and msi. this patch implements helper functions to handle msi-x and msi uniformly. They will be used later. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 752e652eca..3072a5f854 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -239,6 +239,9 @@ void do_pci_info_print(Monitor *mon, const QObject *data); void do_pci_info(Monitor *mon, QObject **ret_data); void pci_bridge_update_mappings(PCIBus *b); +bool pci_msi_enabled(PCIDevice *dev); +void pci_msi_notify(PCIDevice *dev, unsigned int vector); + static inline void pci_set_byte(uint8_t *config, uint8_t val) { -- cgit v1.2.3 From e4c7d2aef899780f9b9b86343bca4ac34c9e252f Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 19 Oct 2010 18:06:32 +0900 Subject: msi: implements msi implements msi related functions. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 3072a5f854..9e2f27d372 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -109,11 +109,12 @@ typedef struct PCIIORegion { /* Bits in cap_present field. */ enum { - QEMU_PCI_CAP_MSIX = 0x1, - QEMU_PCI_CAP_EXPRESS = 0x2, + QEMU_PCI_CAP_MSI = 0x1, + QEMU_PCI_CAP_MSIX = 0x2, + QEMU_PCI_CAP_EXPRESS = 0x4, /* multifunction capable device */ -#define QEMU_PCI_CAP_MULTIFUNCTION_BITNR 2 +#define QEMU_PCI_CAP_MULTIFUNCTION_BITNR 3 QEMU_PCI_CAP_MULTIFUNCTION = (1 << QEMU_PCI_CAP_MULTIFUNCTION_BITNR), }; @@ -171,6 +172,9 @@ struct PCIDevice { /* Version id needed for VMState */ int32_t version_id; + /* Offset of MSI capability in config space */ + uint8_t msi_cap; + /* Location of option rom */ char *romfile; ram_addr_t rom_offset; -- cgit v1.2.3 From 0428527c621c3edfd258b4d34fc178ef5df41071 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 19 Oct 2010 18:06:34 +0900 Subject: pcie: helper functions for pcie capability and extended capability This patch implements helper functions for pci express capability and pci express extended capability allocation. NOTE: presence detection depends on pci_qdev_init() change. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'hw/pci.h') diff --git a/hw/pci.h b/hw/pci.h index 9e2f27d372..d6c522b8dd 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -9,6 +9,8 @@ /* PCI includes legacy ISA access. */ #include "isa.h" +#include "pcie.h" + /* PCI bus */ #define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) @@ -175,6 +177,9 @@ struct PCIDevice { /* Offset of MSI capability in config space */ uint8_t msi_cap; + /* PCI Express */ + PCIExpressDevice exp; + /* Location of option rom */ char *romfile; ram_addr_t rom_offset; -- cgit v1.2.3