libqos support
cover libqos support
This is a not completely polished version of libqos that includes PCI support. I haven't gone through the patches thoroughly yet so I've got it marked as RFC. It works and is functionally complete. I know the files are missing copyrights though and the commit messages need some work. I also haven't run checkpatch on the patches yet.
I've included a test of the i440fx but not a virtio-blk test. There's a lot more infrastructure (block and virtio) needed for that. That has been what's been holding up this series. But since it's become a bottleneck for other people, I decided to split these bits off and save the virtio bits for another day.
Note that the pam test is pretty slow because it does a tremendous number of byte memory accesses. On my laptop, it comes in around two seconds which isn't that bad.
Regards,
Anthony Liguori
RFC PATCH 1/8 qtest: add libqos
This includes basic PCI support.
--- configure | 2 +- tests/Makefile | 2 +- tests/libqos/pci-pc.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/pci-pc.h | 8 ++ tests/libqos/pci.c | 108 +++++++++++++++++++++++++ tests/libqos/pci.h | 65 +++++++++++++++ 6 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 tests/libqos/pci-pc.c create mode 100644 tests/libqos/pci-pc.h create mode 100644 tests/libqos/pci.c create mode 100644 tests/libqos/pci.h
configure +1 -1
@@ -4354,7 +4354,7 @@ if [ "$pixman" = "internal" ]; then fi # build tree in object directory in case the source is not in the current directory -DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32" +DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas" DIRS="$DIRS roms/seabios roms/vgabios" DIRS="$DIRS qapi-generated"
tests/Makefile +1 -1
@@ -89,6 +89,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o $(test-obj-y): QEMU_INCLUDES += -Itests +QEMU_CFLAGS += -I$(SRC_PATH)/tests tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
@@ -117,7 +118,6 @@ tests/test-qmp-commands.h tests/test-qmp-marshal.c :\ $(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -o tests -p "test-" < $<, " GEN $@") - tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
tests/libqos/pci-pc.c new file +219 -0
219 lines not on this page · raw message
tests/libqos/pci-pc.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef LIBQOS_PCI_PC_H +#define LIBQOS_PCI_PC_H + +#include "libqos/pci.h" + +QPCIBus *qpci_init_pc (void ); + +#endif
tests/libqos/pci.c new file +108 -0
108 lines not on this page · raw message
tests/libqos/pci.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.8.0
Re: [Qemu-devel] [RFC PATCH 1/8] qtest: add libqos
Am 05.03.2013 um 14:53 hat Anthony Liguori geschrieben:
Quoted 12 lines
This includes basic PCI support.
Signed-off-by Anthony Liguori <[email protected]>tests/libqos/pci-pc.c new file +8
-0+static void *qpci_pc_iomap (QPCIBus *bus,QPCIDevice *dev,int barno) +{ +QPCIBusPC *s =container_of (bus, QPCIBusPC, bus); +static const int bar_reg_map[] = { +PCI_BASE_ADDRESS_0 ,PCI_BASE_ADDRESS_1 ,PCI_BASE_ADDRESS_2 , +PCI_BASE_ADDRESS_3 ,PCI_BASE_ADDRESS_4 ,PCI_BASE_ADDRESS_5 , + }; +int bar_reg;
tests/libqos/pci-pc.c line 152
Quoted 10 lines
tests/libqos/pci-pc.c new file +10
-0+uint32_t addr; +uint64_t size; + +g_assert (barno >=0 && barno <=5 ); + bar_reg = bar_reg_map[barno]; + +qpci_config_writel (dev, bar_reg,0xFFFFFFFF ); + addr =qpci_config_readl (dev, bar_reg); + + size = (1ULL <<ctol (addr));
This doesn't look right. It should be something like:
size = (1ULL << ctzl(addr & ~0x3));
In fact, what must be masked out differs for I/O (0x3) and memory (0xf).
Quoted 5 lines
tests/libqos/pci.c new file +2
-0@@ -0,0 +1,108 @@ +#include "libqos/pci.h" +
tests/libqos/pci.c line 12
Quoted 10 lines
tests/libqos/pci.c new file +10
-0+#include "hw/pci/pci_regs.h" +#include <glib.h> + +#include <stdio.h> + +QPCIDevice *qpci_device_find (QPCIBus *bus,int devfn) +{ +QPCIDevice *dev; + + dev =g_malloc0 (sizeof (*dev));
Where is the matching free? I can't seem to destroy a device I once queried.
Quoted 11 lines
tests/libqos/pci.c new file +11
-0+ dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("vendor id is %x\n" ,qpci_config_readw (dev,PCI_VENDOR_ID )); +g_free (dev); +return NULL ; + } + +return dev; +}
tests/libqos/pci.c line 33
Quoted 10 lines
tests/libqos/pci.c new file +10
-0+ +void qpci_device_enable (QPCIDevice *dev) +{ +uint16_t cmd; + +/* FIXME -- does this need to be a bus callout? */ + cmd =qpci_config_readw (dev,PCI_COMMAND ); + cmd |=PCI_COMMAND_IO |PCI_COMMAND_MEMORY ; +qpci_config_writew (dev,PCI_COMMAND , cmd); +}
Wouldn't it make sense to enable bus mastering here as well? Forgetting to do this manually is a trap that's easy to fall in...
Kevin
Re: [Qemu-devel] [RFC PATCH 1/8] qtest: add libqos
Quoted 26 lines · Kevin Wolf
Am 05.03.2013 um 14:53 hat Anthony Liguori geschrieben:
Quoted 12 lines
This includes basic PCI support.
Signed-off-by Anthony Liguori <[email protected]>tests/libqos/pci-pc.c new file +8
-0+static void *qpci_pc_iomap (QPCIBus *bus,QPCIDevice *dev,int barno) +{ +QPCIBusPC *s =container_of (bus, QPCIBusPC, bus); +static const int bar_reg_map[] = { +PCI_BASE_ADDRESS_0 ,PCI_BASE_ADDRESS_1 ,PCI_BASE_ADDRESS_2 , +PCI_BASE_ADDRESS_3 ,PCI_BASE_ADDRESS_4 ,PCI_BASE_ADDRESS_5 , + }; +int bar_reg;tests/libqos/pci-pc.c line 152
Quoted 10 lines
tests/libqos/pci-pc.c new file +10
-0+uint32_t addr; +uint64_t size; + +g_assert (barno >=0 && barno <=5 ); + bar_reg = bar_reg_map[barno]; + +qpci_config_writel (dev, bar_reg,0xFFFFFFFF ); + addr =qpci_config_readl (dev, bar_reg); + + size = (1ULL <<ctol (addr));This doesn't look right. It should be something like:
Quoted 4 lines
size = (1ULL << ctzl(addr & ~0x3));In fact, what must be masked out differs for I/O (
0x3) and memory (0xf).
You are correct, it should look something like:
if (addr & PCI_BASE_ADDRESS_SPACE_IO) {
size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_IO_MASK));
} else {
size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_MEM_MASK));
}This doesn't deal with 64-bit bars though.
I'll update in the next round. I think this has worked for me because I have only done single device testing. I did switch from ffz when I rebased but I think ffz would still have this problem.
Quoted 8 lines
tests/libqos/pci.c line 12
Quoted 5 lines
tests/libqos/pci.c new file +5
-0+QPCIDevice *qpci_device_find (QPCIBus *bus,int devfn) +{ +QPCIDevice *dev; + + dev =g_malloc0 (sizeof (*dev));Where is the matching free? I can't seem to destroy a device I once queried.
It's missing, I'll add it in the next round.
Quoted 16 lines
Quoted 16 lines
tests/libqos/pci.c new file +16
-0+ dev->bus = bus; + dev->devfn = devfn; + +if (qpci_config_readw (dev,PCI_VENDOR_ID ) ==0xFFFF ) { +printf ("vendor id is %x\n" ,qpci_config_readw (dev,PCI_VENDOR_ID )); +g_free (dev); +return NULL ; + } + +return dev; +} + +void qpci_device_enable (QPCIDevice *dev) +{ +uint16_t cmd; +
Quoted 8 lines
tests/libqos/pci.c line 33
Quoted 5 lines
tests/libqos/pci.c new file +5
-0+/* FIXME -- does this need to be a bus callout? */ + cmd =qpci_config_readw (dev,PCI_COMMAND ); + cmd |=PCI_COMMAND_IO |PCI_COMMAND_MEMORY ; +qpci_config_writew (dev,PCI_COMMAND , cmd); +}Wouldn't it make sense to enable bus mastering here as well? Forgetting to do this manually is a trap that's easy to fall in...
Indeed, thanks for pointing it out.
Regards,
Anthony Liguori
Quoted 2 lines
Kevin
Re: [Qemu-devel] [RFC PATCH 1/8] qtest: add libqos
Am 13.03.2013 um 15:03 hat Anthony Liguori geschrieben:
Quoted 8 lines
You are correct, it should look something like:
if (addr & PCI_BASE_ADDRESS_SPACE_IO) { size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_IO_MASK)); } else { size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_MEM_MASK)); }
Quoted 5 lines
This doesn't deal with 64-bit bars though.
I'll update in the next round. I think this has worked for me because I have only done single device testing. I did switch from ffz when I rebased but I think ffz would still have this problem.
For when are you planning the next round? Will we get this in time to make use of it in 1.5?
Kevin
Re: [Qemu-devel] [RFC PATCH 1/8] qtest: add libqos
Quoted 9 lines · Kevin Wolf
Am 13.03.2013 um 15:03 hat Anthony Liguori geschrieben:
Quoted 8 lines
You are correct, it should look something like:
if (addr & PCI_BASE_ADDRESS_SPACE_IO) { size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_IO_MASK)); } else { size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_MEM_MASK)); }
Quoted 7 lines
Quoted 5 lines
This doesn't deal with 64-bit bars though.
I'll update in the next round. I think this has worked for me because I have only done single device testing. I did switch from ffz when I rebased but I think ffz would still have this problem.
For when are you planning the next round?
I'll send one out soon. Perhaps tomorrow if all goes well.
Regards,
Anthony Liguori
Quoted 4 lines
Will we get this in time to make use of it in 1.5?
Kevin
Re: [Qemu-devel] [RFC PATCH 1/8] qtest: add libqos
Am 29.03.2013 um 03:26 hat Anthony Liguori geschrieben:
Quoted 13 lines
Quoted 11 lines · Kevin Wolf
Am 13.03.2013 um 15:03 hat Anthony Liguori geschrieben:
Quoted 10 lines
You are correct, it should look something like:
if (addr & PCI_BASE_ADDRESS_SPACE_IO) { size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_IO_MASK)); } else { size = (1ULL << ctzl(addr & PCI_BASE_ADDRESS_MEM_MASK)); }This doesn't deal with 64-bit bars though.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I'll update in the next round. I think this has worked for me because I have only done single device testing. I did switch from ffz when I rebased but I think ffz would still have this problem.
For when are you planning the next round?
I'll send one out soon. Perhaps tomorrow if all goes well.
I know, it's getting boring, but... which tomorrow?
Please just add the license headers and get the RFC committed. We'll get the rest fixed up on top. We've been waiting for over a year now. This is blocking any progress on the qtest coverage and probably already hurting the quality of our releases.
Kevin
Re: [Qemu-devel] [RFC PATCH 1/8] qtest: add libqos
In reply to Anthony LiguoriAm 05.03.2013 14:53, schrieb Anthony Liguori:
Quoted 15 lines
This includes basic PCI support.
Signed-off-by Anthony Liguori <[email protected]>--- configure | 2 +- tests/Makefile | 2 +- tests/libqos/pci-pc.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/pci-pc.h | 8 ++ tests/libqos/pci.c | 108 +++++++++++++++++++++++++ tests/libqos/pci.h | 65 +++++++++++++++ 6 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 tests/libqos/pci-pc.c create mode 100644 tests/libqos/pci-pc.h create mode 100644 tests/libqos/pci.c create mode 100644 tests/libqos/pci.h
This is missing a refactoring of existing I2C libqos:
tests/libi2c.[hc] -> tests/libqos/i2c.[hc]tests/libi2c-omap.c -> tests/libqos/i2c-omap.c
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
RFC PATCH 2/8 i440fx-test: add test to compare default register values against spec
In reply to Anthony LiguoriWe currently don't do so well...
--- tests/Makefile | 2 + tests/i440fx-test.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 tests/i440fx-test.c
tests/Makefile +2 -0
@@ -66,6 +66,7 @@ gcov-files-i386-y = hw/fdc.c check-qtest-i386-y += tests/hd-geo-test$(EXESUF) gcov-files-i386-y += hw/hd-geometry.c check-qtest-i386-y += tests/rtc-test$(EXESUF) +check-qtest-i386-y += tests/i440fx-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/mc146818rtc.c gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -133,6 +134,7 @@ tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/fdc-test$(EXESUF): tests/fdc-test.o tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/tmp105-test$(EXESUF): tests/tmp105-test.o +tests/i440fx-test$(EXESUF): tests/i440fx-test.o tests/libqos/pci.o tests/libqos/pci-pc.o # QTest rules
tests/i440fx-test.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
1.8.0
RFC PATCH 3/8 i440fx-test: add test for PAM functionality
In reply to Anthony Liguori--- tests/i440fx-test.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-)
tests/i440fx-test.c +138 -1
@@ -5,10 +5,12 @@#include "hw/pci/pci_regs.h" #include <glib.h> -#include <stdio.h> +#include <string.h> #define BROKEN 1 +#define ARRAY_SIZE (array) (sizeof(array) / sizeof((array)[0])) + typedef struct TestData { int num_cpus;
@@ -107,6 +109,139 @@ static void test_i440fx_defaults(gconstpointer opaque) g_assert_cmpint(qpci_config_readb(dev, 0x93), ==, 0x00); /* TRC */ } +#define PAM_RE 1 +#define PAM_WE 2 + +static void pam_set (QPCIDevice *dev,int index,int flags) +{ +int regno =0x59 + (index /2 ); +uint8_t reg; + + reg =qpci_config_readb (dev, regno); +if (index &1 ) { + reg = (reg &0x0F ) | (flags <<4 ); + }else { + reg = (reg &0xF0 ) | flags; + } +qpci_config_writeb (dev, regno, reg); +} + +static gboolean verify_area (uint32_t start,uint32_t end,uint8_t value) +{ +uint32_t size = end - start +1 ; +gboolean ret = TRUE; +uint8_t *data; +int i; + + data =g_malloc0 (size); +memread (start, data, size); + +g_test_message ("verify_area: data[0] = 0x%x" , data[0 ]); + +for (i =0 ; i < size; i++) { +if (data[i] != value) { + ret = FALSE; +break ; + } + } + +g_free (data); + +return ret; +} + +static void write_area (uint32_t start,uint32_t end,uint8_t value) +{ +uint32_t size = end - start +1 ; +uint8_t *data; + + data =g_malloc0 (size); +memset (data, value, size); +memwrite (start, data, size); + +g_free (data); +} + +static void test_i440fx_pam (gconstpointer opaque) +{ +const TestData *s = opaque; +QPCIDevice *dev; +int i; +static struct { +uint32_t start; +uint32_t end; + } pam_area[] = { + {0 ,0 },/* Reserved */ + {0xF0000 ,0xFFFFF },/* BIOS Area */ + {0xC0000 ,0xC3FFF },/* Option ROM */ + {0xC4000 ,0xC7FFF },/* Option ROM */ + {0xC8000 ,0xCBFFF },/* Option ROM */ + {0xCC000 ,0xCFFFF },/* Option ROM */ + {0xD0000 ,0xD3FFF },/* Option ROM */ + {0xD4000 ,0xD7FFF },/* Option ROM */ + {0xD8000 ,0xDBFFF },/* Option ROM */ + {0xDC000 ,0xDFFFF },/* Option ROM */ + {0xE0000 ,0xE3FFF },/* BIOS Extension */ + {0xE4000 ,0xE7FFF },/* BIOS Extension */ + {0xE8000 ,0xEBFFF },/* BIOS Extension */ + {0xEC000 ,0xEFFFF },/* BIOS Extension */ + }; + + dev =qpci_device_find (s->bus,QPCI_DEVFN (0 ,0 )); +g_assert (dev !=NULL ); + +for (i =0 ; i <ARRAY_SIZE (pam_area); i++) { +if (pam_area[i].start == pam_area[i].end) { +continue ; + } + +g_test_message ("Checking area 0x%05x..0x%05x" , + pam_area[i].start, pam_area[i].end); +/* Switch to RE for the area */ +pam_set (dev, i,PAM_RE ); +/* Verify the RAM is all zeros */ +g_assert (verify_area (pam_area[i].start, pam_area[i].end,0 )); + +/* Switch to WE for the area */ +pam_set (dev, i,PAM_RE |PAM_WE ); +/* Write out a non-zero mask to the full area */ +write_area (pam_area[i].start, pam_area[i].end,0x42 ); + +#ifndef BROKEN +/* QEMU only supports a limited form of PAM */ + +/* Switch to !RE for the area */ +pam_set (dev, i,PAM_WE ); +/* Verify the area is not our mask */ +g_assert (!verify_area (pam_area[i].start, pam_area[i].end,0x42 )); +#endif + +/* Verify the area is our new mask */ +g_assert (verify_area (pam_area[i].start, pam_area[i].end,0x42 )); + +/* Write out a new mask */ +write_area (pam_area[i].start, pam_area[i].end,0x82 ); + +#ifndef BROKEN +/* QEMU only supports a limited form of PAM */ + +/* Verify the area is not our mask */ +g_assert (!verify_area (pam_area[i].start, pam_area[i].end,0x82 )); + +/* Switch to RE for the area */ +pam_set (dev, i,PAM_RE |PAM_WE ); +#endif +/* Verify the area is our new mask */ +g_assert (verify_area (pam_area[i].start, pam_area[i].end,0x82 )); + +/* Reset area */ +pam_set (dev, i,0 ); + +/* Verify the area is not our new mask */ +g_assert (!verify_area (pam_area[i].start, pam_area[i].end,0x82 )); + } +} +int main (int argc,char **argv) {QTestState *s =NULL ;
@@ -125,6 +260,8 @@ int main(int argc, char **argv) data.bus =qpci_init_pc ();g_test_add_data_func ("/i440fx/defaults" , &data, test_i440fx_defaults); +g_test_add_data_func ("/i440fx/pam" , &data, test_i440fx_pam); + ret =g_test_run ();
Signature · 1 line
1.8.0
RFC PATCH 4/8 pci: foreach
In reply to Anthony Liguori--- tests/libqos/pci.c | 32 ++++++++++++++++++++++++++++++++ tests/libqos/pci.h | 3 +++ 2 files changed, 35 insertions(+)
tests/libqos/pci.c +32 -0
@@ -5,6 +5,38 @@#include <stdio.h> +void qpci_device_foreach (QPCIBus *bus,int vendor_id,int device_id, +void (*func)(QPCIDevice *dev,int devfn,void *data), +void *data) +{ +int slot; + +for (slot =0 ; slot <32 ; slot++) { +int fn; + +for (fn =0 ; fn <8 ; fn++) { +QPCIDevice *dev; + + dev =qpci_device_find (bus,QPCI_DEVFN (slot, fn)); +if (!dev) { +continue ; + } + +if (vendor_id !=-1 && +qpci_config_readw (dev,PCI_VENDOR_ID ) != vendor_id) { +continue ; + } + +if (device_id !=-1 && +qpci_config_readw (dev,PCI_DEVICE_ID ) != device_id) { +continue ; + } + +func (dev,QPCI_DEVFN (slot, fn), data); + } + } +} +QPCIDevice *qpci_device_find (QPCIBus *bus,int devfn) {QPCIDevice *dev;
tests/libqos/pci.h +3 -0
@@ -39,6 +39,9 @@ struct QPCIDeviceint devfn; }; +void qpci_device_foreach (QPCIBus *bus,int vendor_id,int device_id, +void (*func)(QPCIDevice *dev,int devfn,void *data), +void *data);QPCIDevice *qpci_device_find (QPCIBus *bus,int devfn);void qpci_device_enable (QPCIDevice *dev);
Signature · 1 line
1.8.0
RFC PATCH 5/8 fw_cfg: add qtest test harness
In reply to Anthony LiguoriWhile it's limited to PC support right now, the abstraction is there to support other platforms.
--- tests/Makefile | 7 +- tests/fw_cfg-test.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 tests/fw_cfg-test.c
tests/Makefile +6 -1
@@ -67,6 +67,7 @@ check-qtest-i386-y += tests/hd-geo-test$(EXESUF) gcov-files-i386-y += hw/hd-geometry.c check-qtest-i386-y += tests/rtc-test$(EXESUF) check-qtest-i386-y += tests/i440fx-test$(EXESUF) +check-qtest-i386-y += tests/fw_cfg-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/mc146818rtc.c gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -129,12 +130,16 @@ tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $( tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a +libqos-obj-y = tests/libqos/pci.o +libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o + tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/fdc-test$(EXESUF): tests/fdc-test.o tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/tmp105-test$(EXESUF): tests/tmp105-test.o -tests/i440fx-test$(EXESUF): tests/i440fx-test.o tests/libqos/pci.o tests/libqos/pci-pc.o +tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) +tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) # QTest rules
tests/fw_cfg-test.c new file +202 -0
202 lines not on this page · raw message
Signature · 1 line
1.8.0
RFC PATCH 6/8 libqos: fw_cfg
In reply to Anthony Liguori--- tests/Makefile | 2 +- tests/fw_cfg-test.c | 48 +----------------------------------------------- tests/libqos/fw_cfg.c | 39 +++++++++++++++++++++++++++++++++++++++ tests/libqos/fw_cfg.h | 22 ++++++++++++++++++++++ 4 files changed, 63 insertions(+), 48 deletions(-) create mode 100644 tests/libqos/fw_cfg.c create mode 100644 tests/libqos/fw_cfg.h
tests/Makefile +1 -1
@@ -130,7 +130,7 @@ tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $( tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a -libqos-obj-y = tests/libqos/pci.o +libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/rtc-test$(EXESUF): tests/rtc-test.o
tests/fw_cfg-test.c +1 -47
64 lines not on this page · raw message
tests/libqos/fw_cfg.c new file +39 -0
@@ -0,0 +1,39 @@ +#include "libqos/fw_cfg.h" + +void qfw_cfg_select (QFWCFG *fw_cfg,uint16_t key) +{ + fw_cfg->select (fw_cfg, key); +} + +void qfw_cfg_read_data (QFWCFG *fw_cfg,void *data,size_t len) +{ + fw_cfg->read (fw_cfg, data, len); +} + +void qfw_cfg_get (QFWCFG *fw_cfg,uint16_t key,void *data,size_t len) +{ +qfw_cfg_select (fw_cfg, key); +qfw_cfg_read_data (fw_cfg, data, len); +} + +uint16_t qfw_cfg_get_u16 (QFWCFG *fw_cfg,uint16_t key) +{ +uint16_t value; +qfw_cfg_get (fw_cfg, key, &value,sizeof (value)); +return value; +} + +uint32_t qfw_cfg_get_u32 (QFWCFG *fw_cfg,uint16_t key) +{ +uint32_t value; +qfw_cfg_get (fw_cfg, key, &value,sizeof (value)); +return value; +} + +uint64_t qfw_cfg_get_u64 (QFWCFG *fw_cfg,uint16_t key) +{ +uint64_t value; +qfw_cfg_get (fw_cfg, key, &value,sizeof (value)); +return value; +} +
tests/libqos/fw_cfg.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef LIBQOS_FW_CFG_H +#define LIBQOS_FW_CFG_H + +#include <stdint.h> +#include <sys/types.h> + +typedef struct QFWCFG QFWCFG ; + +struct QFWCFG +{ +void (*select)(QFWCFG *fw_cfg,uint16_t key); +void (*read)(QFWCFG *fw_cfg,void *data,size_t len); +}; + +void qfw_cfg_select (QFWCFG *fw_cfg,uint16_t key); +void qfw_cfg_read_data (QFWCFG *fw_cfg,void *data,size_t len); +void qfw_cfg_get (QFWCFG *fw_cfg,uint16_t key,void *data,size_t len); +uint16_t qfw_cfg_get_u16 (QFWCFG *fw_cfg,uint16_t key); +uint32_t qfw_cfg_get_u32 (QFWCFG *fw_cfg,uint16_t key); +uint64_t qfw_cfg_get_u64 (QFWCFG *fw_cfg,uint16_t key); + +#endif
Signature · 1 line
1.8.0
RFC PATCH 7/8 libqos: add fw_cfg-pc
In reply to Anthony Liguori--- tests/Makefile | 2 +- tests/fw_cfg-test.c | 29 +---------------------------- tests/libqos/fw_cfg-pc.c | 28 ++++++++++++++++++++++++++++ tests/libqos/fw_cfg-pc.h | 8 ++++++++ 4 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 tests/libqos/fw_cfg-pc.c create mode 100644 tests/libqos/fw_cfg-pc.h
tests/Makefile +1 -1
@@ -131,7 +131,7 @@ tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $( tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o -libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o +libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/libqos/fw_cfg-pc.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/fw_cfg-test.c +1 -28
@@ -2,38 +2,11 @@#include "libqtest.h" #include "hw/fw_cfg.h" -#include "libqos/fw_cfg.h" +#include "libqos/fw_cfg-pc.h" #include <string.h> #include <glib.h> -/* PC specific */ - -static void pc_fw_cfg_select (QFWCFG *fw_cfg,uint16_t key) -{ -outw (0x510 , key); -} - -static void pc_fw_cfg_read (QFWCFG *fw_cfg,void *data,size_t len) -{ -uint8_t *ptr = data; -int i; - -for (i =0 ; i < len; i++) { - ptr[i] =inb (0x511 ); - } -} - -static QFWCFG *pc_fw_cfg_init (void ) -{ -QFWCFG *fw_cfg =g_malloc0 (sizeof (*fw_cfg)); - - fw_cfg->select = pc_fw_cfg_select; - fw_cfg->read = pc_fw_cfg_read; - -return fw_cfg; -} -static uint64_t ram_size =128 <<20 ;static uint16_t nb_cpus =1 ;static uint16_t max_cpus =1 ;
tests/libqos/fw_cfg-pc.c new file +28 -0
@@ -0,0 +1,28 @@ +#include "libqos/fw_cfg-pc.h" +#include "libqtest.h" +#include <glib.h> + +static void pc_fw_cfg_select (QFWCFG *fw_cfg,uint16_t key) +{ +outw (0x510 , key); +} + +static void pc_fw_cfg_read (QFWCFG *fw_cfg,void *data,size_t len) +{ +uint8_t *ptr = data; +int i; + +for (i =0 ; i < len; i++) { + ptr[i] =inb (0x511 ); + } +} + +QFWCFG *pc_fw_cfg_init (void ) +{ +QFWCFG *fw_cfg =g_malloc0 (sizeof (*fw_cfg)); + + fw_cfg->select = pc_fw_cfg_select; + fw_cfg->read = pc_fw_cfg_read; + +return fw_cfg; +}
tests/libqos/fw_cfg-pc.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef LIBQOS_FW_CFG_PC_H +#define LIBQOS_FW_CFG_PC_H + +#include "libqos/fw_cfg.h" + +QFWCFG *pc_fw_cfg_init (void ); + +#endif
Signature · 1 line
1.8.0
RFC PATCH 8/8 libqos: add malloc
In reply to Anthony Liguori--- tests/Makefile | 1 + tests/libqos/malloc-pc.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/malloc-pc.h | 8 +++++++ tests/libqos/malloc.h | 26 +++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 tests/libqos/malloc-pc.c create mode 100644 tests/libqos/malloc-pc.h create mode 100644 tests/libqos/malloc.h
tests/Makefile +1 -0
@@ -132,6 +132,7 @@ tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/libqos/fw_cfg-pc.o +libqos-pc-obj-y += tests/libqos/malloc-pc.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/libqos/malloc-pc.c new file +59 -0
59 lines not on this page · raw message
tests/libqos/malloc-pc.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef LIBQOS_MALLOC_PC_H +#define LIBQOS_MALLOC_PC_H + +#include "libqos/malloc.h" + +QGuestAllocator *pc_alloc_init (void ); + +#endif
tests/libqos/malloc.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef LIBQOS_MALLOC_H +#define LIBQOS_MALLOC_H + +#include <stdint.h> +#include <sys/types.h> + +typedef struct QGuestAllocator QGuestAllocator ; + +struct QGuestAllocator +{ +uint64_t (*alloc)(QGuestAllocator *allocator,size_t size); +void (*free)(QGuestAllocator *allocator,uint64_t addr); +}; + +/* Always returns page aligned values */ +static inline uint64_t guest_alloc (QGuestAllocator *allocator,size_t size) +{ +return allocator->alloc (allocator, size); +} + +static inline void guest_free (QGuestAllocator *allocator,uint64_t addr) +{ + allocator->alloc (allocator, addr); +} + +#endif
Signature · 1 line
1.8.0
Re: [Qemu-devel] [RFC PATCH 8/8] libqos: add malloc
Am 05.03.2013 um 14:53 hat Anthony Liguori geschrieben:
Quoted 19 lines
Signed-off-by Anthony Liguori <[email protected]>tests/libqos/malloc.h new file +14
-0@@ -0,0 +1,26 @@ +#ifndef LIBQOS_MALLOC_H +#define LIBQOS_MALLOC_H + +#include <stdint.h> +#include <sys/types.h> + +typedef struct QGuestAllocator QGuestAllocator ; + +struct QGuestAllocator +{ +uint64_t (*alloc)(QGuestAllocator *allocator,size_t size); +void (*free)(QGuestAllocator *allocator,uint64_t addr); +}; +
tests/libqos/malloc.h line 24
Quoted 10 lines
tests/libqos/malloc.h new file +10
-0+/* Always returns page aligned values */ +static inline uint64_t guest_alloc (QGuestAllocator *allocator,size_t size) +{ +return allocator->alloc (allocator, size); +} + +static inline void guest_free (QGuestAllocator *allocator,uint64_t addr) +{ + allocator->alloc (allocator, addr); +}
I think the common case is using exactly one global allocator. Maybe worth convenience macros like in libqtest.h?
Kevin
Re: [Qemu-devel] [RFC PATCH 8/8] libqos: add malloc
Quoted 25 lines · Kevin Wolf
Am 05.03.2013 um 14:53 hat Anthony Liguori geschrieben:
Quoted 24 lines
Signed-off-by Anthony Liguori <[email protected]>tests/libqos/malloc.h new file +19
-0@@ -0,0 +1,26 @@ +#ifndef LIBQOS_MALLOC_H +#define LIBQOS_MALLOC_H + +#include <stdint.h> +#include <sys/types.h> + +typedef struct QGuestAllocator QGuestAllocator ; + +struct QGuestAllocator +{ +uint64_t (*alloc)(QGuestAllocator *allocator,size_t size); +void (*free)(QGuestAllocator *allocator,uint64_t addr); +}; + +/* Always returns page aligned values */ +static inline uint64_t guest_alloc (QGuestAllocator *allocator,size_t size) +{ +return allocator->alloc (allocator, size); +}
Quoted 8 lines
tests/libqos/malloc.h line 24
Quoted 5 lines
tests/libqos/malloc.h new file +5
-0+ +static inline void guest_free (QGuestAllocator *allocator,uint64_t addr) +{ + allocator->alloc (allocator, addr); +}I think the common case is using exactly one global allocator. Maybe worth convenience macros like in
libqtest.h?
Definitely.
Regard,
Anthony Liguori
Quoted 2 lines
Kevin
Quoted 5 lines · Anthony Liguori
This is a not completely polished version of libqos that includes PCI support. I haven't gone through the patches thoroughly yet so I've got it marked as RFC. It works and is functionally complete. I know the files are missing copyrights though and the commit messages need some work. I also haven't run checkpatch on the patches yet.
The PCI support looks pretty close. The minimum functionality that others can build on is the PCI support. Merging the PCI support should be uncontroversial.
The fw_cfg needs some patch reordering (best to introduce the fw_cfg pc code in a separate source file from the start instead of moving it later).
Stefan
Quoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · Anthony Liguori
This is a not completely polished version of libqos that includes PCI support. I haven't gone through the patches thoroughly yet so I've got it marked as RFC. It works and is functionally complete. I know the files are missing copyrights though and the commit messages need some work. I also haven't run checkpatch on the patches yet.
Quoted 7 lines
The PCI support looks pretty close. The minimum functionality that others can build on is the PCI support. Merging the PCI support should be uncontroversial.
The
fw_cfgneeds some patch reordering (best to introduce thefw_cfgpc code in a separate source file from the start instead of moving it later).
fw_cfg is needed in order to implement an alloc. Alloc is needed in order to do any form of DMA.
But I don't think it will be too hard to fix up this series into something mergable. The big issue was virtio support but now that that's dropped, the rest is pretty easy.
Regards,
Anthony Liguori
Quoted 2 lines
Stefan
Anthony Liguori
AppliedApplied. Thanks.
Regards,
Anthony Liguori