64 bit I/O support v7
PATCH 1/1 64 bit I/O support v7
This patch is a rebase on current svn of my previous patch.
This patch adds support for 64 bit I/O by essentially replacing an array of 4 function pointers with a structure containing 4 function pointers. The current array contains 4 pointers, one for 8, 16 and 32 bit function pointers which really support only 32 bits and a forth pointer which is unused but I assume is a place holder for a 64 bit function pointer. The current trick of passing 8, 16 or 32 bits in a 32 bit variable doesn't extend to passing 64 bits in a 32 bit bit variable and creating a 64 bit function would require casts to allow being saved in the array so a sutrcture is used that can take different function pointers.
Here are the relevant parts of the patch:
+typedef void CPUWriteMemoryFunc64(void *opaque, target_phys_addr_t addr, uint64_t value); +typedef uint64_t CPUReadMemoryFunc64(void *opaque, target_phys_addr_t addr); +
+typedef struct CPUWriteMemoryFuncs {
+ CPUWriteMemoryFunc *b;
+ CPUWriteMemoryFunc *w;
+ CPUWriteMemoryFunc *l;
+ CPUWriteMemoryFunc64 *q;
+} CPUWriteMemoryFuncs;
+
+typedef struct CPUReadMemoryFuncs {
+ CPUReadMemoryFunc *b;
+ CPUReadMemoryFunc *w;
+ CPUReadMemoryFunc *l;
+ CPUReadMemoryFunc64 *q;+} CPUReadMemoryFuncs;
-extern CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; -extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; +extern CPUWriteMemoryFuncs io_mem_write[IO_MEM_NB_ENTRIES]; +extern CPUReadMemoryFuncs io_mem_read[IO_MEM_NB_ENTRIES];
The rest of the patch just does the array to structure conversion and adds the 64 bit functions.
The old array function call is supported so no existing drivers need to be modified. They can continue to do 2 32 bit accesses because 2 helper functions have been added to break up the accesses automatically. However, the helper functions should only be used until all drivers are converted to use the structure and then can be removed along with the old array functions api. The replacement of the arrays with structures in the drivers is very straightforward for drivers that don't do 64 bit I/O and the few that do can be cleaned up to remove the work arounds for the lack of true 64 bit I/O by their maintainers.
softmmu_template.h +2 -22
@@ -65,17 +65,7 @@ } env->mem_io_vaddr = addr; -#if SHIFT <=2 - res = io_mem_read[index][SHIFT ](io_mem_opaque[index], physaddr); -#else -#ifdef TARGET_WORDS_BIGENDIAN - res = (uint64_t )io_mem_read[index][2 ](io_mem_opaque[index], physaddr) <<32 ; - res |= io_mem_read[index][2 ](io_mem_opaque[index], physaddr +4 ); -#else - res = io_mem_read[index][2 ](io_mem_opaque[index], physaddr); - res |= (uint64_t )io_mem_read[index][2 ](io_mem_opaque[index], physaddr +4 ) <<32 ; -#endif -#endif /* SHIFT > 2 */ + res = io_mem_read[index].SUFFIX (io_mem_opaque[index], physaddr);#ifdef CONFIG_KQEMU env->last_io_time =cpu_get_time_fast ();#endif
@@ -210,17 +200,7 @@ env->mem_io_vaddr = addr; env->mem_io_pc = (unsigned long )retaddr; -#if SHIFT <=2 - io_mem_write[index][SHIFT ](io_mem_opaque[index], physaddr, val); -#else -#ifdef TARGET_WORDS_BIGENDIAN - io_mem_write[index][2 ](io_mem_opaque[index], physaddr, val >>32 ); - io_mem_write[index][2 ](io_mem_opaque[index], physaddr +4 , val); -#else - io_mem_write[index][2 ](io_mem_opaque[index], physaddr, val); - io_mem_write[index][2 ](io_mem_opaque[index], physaddr +4 , val >>32 ); -#endif -#endif /* SHIFT > 2 */ + io_mem_write[index].SUFFIX (io_mem_opaque[index], physaddr, val);#ifdef CONFIG_KQEMU env->last_io_time =cpu_get_time_fast ();#endif
exec.c +277 -73
550 lines not on this page · raw message
exec-all.h +2 -2
@@ -265,8 +265,8 @@TranslationBlock *tb_find_pc (unsigned long pc_ptr); -extern CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES ][4 ]; -extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES ][4 ]; +extern CPUWriteMemoryFuncs io_mem_write[IO_MEM_NB_ENTRIES ]; +extern CPUReadMemoryFuncs io_mem_read[IO_MEM_NB_ENTRIES ];extern void *io_mem_opaque[IO_MEM_NB_ENTRIES ];#include "qemu-lock.h"
cpu-all.h +21 -0
@@ -891,6 +891,23 @@typedef void CPUWriteMemoryFunc (void *opaque,target_phys_addr_t addr,uint32_t value);typedef uint32_t CPUReadMemoryFunc (void *opaque,target_phys_addr_t addr); +typedef void CPUWriteMemoryFunc64 (void *opaque,target_phys_addr_t addr,uint64_t value); +typedef uint64_t CPUReadMemoryFunc64 (void *opaque,target_phys_addr_t addr); + +typedef struct CPUWriteMemoryFuncs { +CPUWriteMemoryFunc *b; +CPUWriteMemoryFunc *w; +CPUWriteMemoryFunc *l; +CPUWriteMemoryFunc64 *q; +}CPUWriteMemoryFuncs ; + +typedef struct CPUReadMemoryFuncs { +CPUReadMemoryFunc *b; +CPUReadMemoryFunc *w; +CPUReadMemoryFunc *l; +CPUReadMemoryFunc64 *q; +}CPUReadMemoryFuncs ; + void cpu_register_physical_memory_offset(target_phys_addr_t start_addr, ram_addr_t size, ram_addr_t phys_offset,
@@ -914,6 +931,10 @@ CPUReadMemoryFunc **mem_read, CPUWriteMemoryFunc **mem_write, void *opaque); +int cpu_register_io_memory64 (int io_index, +CPUReadMemoryFuncs *mem_read, +CPUWriteMemoryFuncs *mem_write, +void *opaque);void cpu_unregister_io_memory (int table_address);CPUWriteMemoryFunc **cpu_get_io_memory_write (int io_index);CPUReadMemoryFunc **cpu_get_io_memory_read (int io_index);
Quoted 9 lines
The old array function call is supported so no existing drivers need to be modified. They can continue to do 2 32 bit accesses because 2 helper functions have been added to break up the accesses automatically. However, the helper functions should only be used until all drivers are converted to use the structure and then can be removed along with the old array functions api. The replacement of the arrays with structures in the drivers is very straightforward for drivers that don't do 64 bit I/O and the few that do can be cleaned up to remove the work arounds for the lack of true 64 bit I/O by their maintainers.
This is going to be a bit of a pain, and a lot of duplication. My expectation is that most devices don't know/care about 64-bit accesses and want them to be automatically split into a pair of 32-bit accesses. I suggest pushing this down into the lower level dispatch routines. By my reading your mem_writeq helpers are broken if we happen to have multiple regions with the same opaque value (this effects at least lsi53c895a.c).
In the interests of avoiding duplication, I'd also implement cpu_register_io_memory in terms of cpu_register_io_memory64.
Quoted 2 lines
+ return ((CPUReadMemoryFunc64*)(*mmio->mem_read[idx][3])) (mmio->opaque[idx][0][3], addr + mmio->region_offset[idx][0][3]);
Eww. It would be a good idea to fix this at the same time.
Paul
Quoted 16 lines · Paul Brook
Quoted 10 lines
The old array function call is supported so no existing drivers need to be modified. They can continue to do 2 32 bit accesses because 2 helper functions have been added to break up the accesses automatically. However, the helper functions should only be used until all drivers are converted to use the structure and then can be removed along with the old array functions api. The replacement of the arrays with structures in the drivers is very straightforward for drivers that don't do 64 bit I/O and the few that do can be cleaned up to remove the work arounds for the lack of true 64 bit I/O by their maintainers.
This is going to be a bit of a pain, and a lot of duplication. My expectation is that most devices don't know/care about 64-bit accesses and want them to be automatically split into a pair of 32-bit accesses. I suggest pushing this down into the lower level dispatch routines. By my reading your
mem_writeqhelpers are broken if we happen to have multiple regions with the same opaque value (this effects at leastlsi53c895a.c).In the interests of avoiding duplication, I'd also implement
cpu_register_io_memoryin terms ofcpu_register_io_memory64.
Quoted 9 lines
Quoted 3 lines
+ return ((CPUReadMemoryFunc64*)(*mmio->mem_read[idx][3]))
(mmio->opaque[idx][0][3], addr + mmio->region_offset[idx][0][3]);Eww. It would be a good idea to fix this at the same time.
Paul
The right way to do this is to convert the whole tree at once so we don't need the helper functions and two versions of cpu_register_io_memory. Unfortunately people have written hardware drivers that rely on the current weird behavior by caching half of a 64 bit access so it can be accessed later. This doesn't work if the registers can also be accessed as 32 bits because the cache trick implies a specific order of access.
95% of the hardware drivers could be trivially converted and work fine. It's those few that play games that need to be looked at carefully and converted properly to do the right thing. I think the authors or maintainers of those drivers have the best knowledge to back out the current workarounds and do 64 bit I/O properly.
That's why I'm taking a 2 step approach using the helper functions and 2 cpu_register_io_memory functions. Once the entire tree is converted to use the structures, the helper functions and the second cpu_register_io_memory function would be removed. I can provide patches to convert sparc to the new API and also convert most of the simple drivers. However it's the ones that have workarounds for the current behavior that need careful scrutiny.
The ideal time for applying this patch would be at the start of a new development cycle. 95% of the drivers could be converted immediately and the problem ones could be identified and fixed afterwards. The issues with the helper functions doing a linear scan and not supporting overlapping regions for 64 bit accesses would only be a problem for a short period of time (maybe a week) and only for some of the drivers that have 64 bit access issues.
Quoted 5 lines
The right way to do this is to convert the whole tree at once so we don't need the helper functions and two versions of
cpu_register_io_memory.
95% of the hardware drivers could be trivially converted and work fine.
I think you're missing my point. It's the 95% of drivers that I don't want to have to "convert". I'm working on the assumption that devices that actually implement 64-bit transfers are the exception rather than the rule.
So we have three options:
1) Omit the 64-bit handler for most devices. This will trigger the subwith code and associated overhead for no good reason[1].
2) Implement a 64-bit handler for every single device. 90% of these are going to be identical trivial wrappers round the 32-bit function. Maybe 5% actually need 64-bit accesses, and 5% are broken because someone messed up a copy/paste.
3) Implement splitting of 64-bit accesses in generic code. Devices that actually care about 64-bit accesses can install a handler. Everything else indicates that it wants accesses split, either by a magic handler or a different registration function.
Your current patch implements a broken version of (3), with a vague hope that we'll switch to (2) at some time in the future.
I'm suggesting we implement (3) properly from the start.
Paul
[1] I still don't understand why the subwidth code exists, It's seems rather unlikely we'll have two different devices responding to different types of access the same address range. That's a separate argument though.
Quoted 16 lines · Paul Brook
Quoted 10 lines
The old array function call is supported so no existing drivers need to be modified. They can continue to do 2 32 bit accesses because 2 helper functions have been added to break up the accesses automatically. However, the helper functions should only be used until all drivers are converted to use the structure and then can be removed along with the old array functions api. The replacement of the arrays with structures in the drivers is very straightforward for drivers that don't do 64 bit I/O and the few that do can be cleaned up to remove the work arounds for the lack of true 64 bit I/O by their maintainers.
This is going to be a bit of a pain, and a lot of duplication. My expectation is that most devices don't know/care about 64-bit accesses and want them to be automatically split into a pair of 32-bit accesses. I suggest pushing this down into the lower level dispatch routines. By my reading your
mem_writeqhelpers are broken if we happen to have multiple regions with the same opaque value (this effects at leastlsi53c895a.c).In the interests of avoiding duplication, I'd also implement
cpu_register_io_memoryin terms ofcpu_register_io_memory64.
Quoted 11 lines
Quoted 3 lines
+ return ((CPUReadMemoryFunc64*)(*mmio->mem_read[idx][3]))
(mmio->opaque[idx][0][3], addr + mmio->region_offset[idx][0][3]);Eww. It would be a good idea to fix this at the same time.
Paul
The issue this patch is trying to address is not the case where software is trying to access 2 32 bit registers using a 64 bit access (because that should fault on sane hardware) but the case where we have a 64 bit counter and the 64 bit access is split up into 2 32 bit accesses and the counter ends up being read twice. Some drivers work around this by caching half of the 64 bit access so the cache is accessed for the second half rather than the hardware. However some hardware (like sparc) can access the timer as either 32 or 64 bits so this trick doesn't work.
Hardware that supports reading 2 32 bit registers with one 64 bit access can have the 64 callback do 2 32 bit accesses.
Quoted 2 lines
Hardware that supports reading 2 32 bit registers with one 64 bit access can have the 64 callback do 2 32 bit accesses.
Doesn't this include most PCI devices?
Paul
Quoted 15 lines · Paul Brook
Quoted 6 lines
The right way to do this is to convert the whole tree at once so we don't need the helper functions and two versions of
cpu_register_io_memory.
95% of the hardware drivers could be trivially converted and work fine.I think you're missing my point. It's the 95% of drivers that I don't want to have to "convert". I'm working on the assumption that devices that actually implement 64-bit transfers are the exception rather than the rule.
So we have three options:
1) Omit the 64-bit handler for most devices. This will trigger the subwith code and associated overhead for no good reason[1].
2) Implement a 64-bit handler for every single device. 90% of these are going to be identical trivial wrappers round the 32-bit function. Maybe 5% actually need 64-bit accesses, and 5% are broken because someone messed up a copy/paste.
3) Implement splitting of 64-bit accesses in generic code. Devices that actually care about 64-bit accesses can install a handler. Everything else indicates that it wants accesses split, either by a magic handler or a different registration function.
Quoted 9 lines
Your current patch implements a broken version of (3), with a vague hope that we'll switch to (2) at some time in the future.
I'm suggesting we implement (3) properly from the start.
Paul
[1] I still don't understand why the subwidth code exists, It's seems rather unlikely we'll have two different devices responding to different types of access the same address range. That's a separate argument though.
Here is a patch for most of the sparc32 hardware drivers. It's a very trivial and mechanical process for these drivers. The one driver that does 64 bit accesses just adds 64 bit access functions because it's broken now and has no workaround to remove. I don't think converting most other drivers will be much harder.
sparc32_dma.c +5 -3
@@ -199,16 +199,18 @@ s->dmaregs[saddr] = val; } -static CPUReadMemoryFunc *dma_mem_read[3 ] = { +static CPUReadMemoryFuncs dma_mem_read = {NULL ,NULL , dma_mem_readl, +NULL , }; -static CPUWriteMemoryFunc *dma_mem_write[3 ] = { +static CPUWriteMemoryFuncs dma_mem_write = {NULL ,NULL , dma_mem_writel, +NULL , };static void dma_reset (void *opaque)
@@ -252,7 +254,7 @@ s->irq = parent_irq; s->iommu = iommu; - dma_io_memory =cpu_register_io_memory (0 , dma_mem_read, dma_mem_write, s); + dma_io_memory =cpu_register_io_memory64 (0 , &dma_mem_read, &dma_mem_write, s);cpu_register_physical_memory (daddr,DMA_SIZE , dma_io_memory);register_savevm ("sparc32_dma" , daddr,2 , dma_save, dma_load, s);
slavio_intctl.c +16 -12
@@ -132,16 +132,18 @@ } } -static CPUReadMemoryFunc *slavio_intctl_mem_read[3 ] = { +static CPUReadMemoryFuncs slavio_intctl_mem_read = {NULL ,NULL , slavio_intctl_mem_readl, +NULL , }; -static CPUWriteMemoryFunc *slavio_intctl_mem_write[3 ] = { +static CPUWriteMemoryFuncs slavio_intctl_mem_write = {NULL ,NULL , slavio_intctl_mem_writel, +NULL , };// master system interrupt controller
@@ -206,16 +208,18 @@ } } -static CPUReadMemoryFunc *slavio_intctlm_mem_read[3 ] = { +static CPUReadMemoryFuncs slavio_intctlm_mem_read = {NULL ,NULL , slavio_intctlm_mem_readl, +NULL , }; -static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3 ] = { +static CPUWriteMemoryFuncs slavio_intctlm_mem_write = {NULL ,NULL , slavio_intctlm_mem_writel, +NULL , };void slavio_pic_info (Monitor *mon,void *opaque)
@@ -388,10 +392,10 @@ slave->cpu = i; slave->master = s; - slavio_intctl_io_memory =cpu_register_io_memory (0 , - slavio_intctl_mem_read, - slavio_intctl_mem_write, - slave); + slavio_intctl_io_memory =cpu_register_io_memory64 (0 , + &slavio_intctl_mem_read, + &slavio_intctl_mem_write, + slave);cpu_register_physical_memory (addr + i *TARGET_PAGE_SIZE ,INTCTL_SIZE , slavio_intctl_io_memory);
@@ -399,10 +403,10 @@ s->cpu_irqs[i] = parent_irq[i]; } - slavio_intctlm_io_memory =cpu_register_io_memory (0 , - slavio_intctlm_mem_read, - slavio_intctlm_mem_write, - s); + slavio_intctlm_io_memory =cpu_register_io_memory64 (0 , + &slavio_intctlm_mem_read, + &slavio_intctlm_mem_write, + s);cpu_register_physical_memory (addrg,INTCTLM_SIZE , slavio_intctlm_io_memory); register_savevm("slavio_intctl", addr, 1, slavio_intctl_save,
tcx.c +11 -7
@@ -463,16 +463,18 @@return ; } -static CPUReadMemoryFunc *tcx_dac_read[3 ] = { +static CPUReadMemoryFuncs tcx_dac_read = {NULL ,NULL , tcx_dac_readl, +NULL , }; -static CPUWriteMemoryFunc *tcx_dac_write[3 ] = { +static CPUWriteMemoryFuncs tcx_dac_write = {NULL ,NULL , tcx_dac_writel, +NULL , };static uint32_t tcx_dummy_readl (void *opaque,target_phys_addr_t addr)
@@ -485,16 +487,18 @@ { } -static CPUReadMemoryFunc *tcx_dummy_read[3 ] = { +static CPUReadMemoryFuncs tcx_dummy_read = {NULL ,NULL , tcx_dummy_readl, +NULL , }; -static CPUWriteMemoryFunc *tcx_dummy_write[3 ] = { +static CPUWriteMemoryFuncs tcx_dummy_write = {NULL ,NULL , tcx_dummy_writel, +NULL , }; void tcx_init(target_phys_addr_t addr, int vram_size, int width, int height,
@@ -523,12 +527,12 @@ vram_offset += size; vram_base += size; - io_memory =cpu_register_io_memory (0 , tcx_dac_read, tcx_dac_write, s); + io_memory =cpu_register_io_memory64 (0 , &tcx_dac_read, &tcx_dac_write, s);cpu_register_physical_memory (addr +0x00200000ULL ,TCX_DAC_NREGS , io_memory); - dummy_memory =cpu_register_io_memory (0 , tcx_dummy_read, tcx_dummy_write, - s); + dummy_memory =cpu_register_io_memory64 (0 , &tcx_dummy_read, + &tcx_dummy_write, s);cpu_register_physical_memory (addr +0x00700000ULL ,TCX_TEC_NREGS , dummy_memory);if (depth ==24 ) {
iommu.c +6 -4
@@ -236,16 +236,18 @@ } } -static CPUReadMemoryFunc *iommu_mem_read[3 ] = { +static CPUReadMemoryFuncs iommu_mem_read = {NULL ,NULL , iommu_mem_readl, +NULL , }; -static CPUWriteMemoryFunc *iommu_mem_write[3 ] = { +static CPUWriteMemoryFuncs iommu_mem_write = {NULL ,NULL , iommu_mem_writel, +NULL , };static uint32_t iommu_page_get_flags (IOMMUState *s,target_phys_addr_t addr)
@@ -375,8 +377,8 @@ s->version = version; s->irq = irq; - iommu_io_memory =cpu_register_io_memory (0 , iommu_mem_read, - iommu_mem_write, s); + iommu_io_memory =cpu_register_io_memory64 (0 , &iommu_mem_read, + &iommu_mem_write, s);cpu_register_physical_memory (addr,IOMMU_NREGS *4 , iommu_io_memory);register_savevm ("iommu" , addr,2 , iommu_save, iommu_load, s);
esp.c +6 -3
@@ -563,16 +563,18 @@ s->wregs[saddr] = val; } -static CPUReadMemoryFunc *esp_mem_read[3 ] = { +static CPUReadMemoryFuncs esp_mem_read = { esp_mem_readb,NULL ,NULL , +NULL , }; -static CPUWriteMemoryFunc *esp_mem_write[3 ] = { +static CPUWriteMemoryFuncs esp_mem_write = { esp_mem_writeb,NULL , esp_mem_writeb, +NULL , };static void esp_save (QEMUFile *f,void *opaque)
@@ -660,7 +662,8 @@ s->dma_memory_write = dma_memory_write; s->dma_opaque = dma_opaque; - esp_io_memory =cpu_register_io_memory (0 , esp_mem_read, esp_mem_write, s); + esp_io_memory =cpu_register_io_memory64 (0 , &esp_mem_read, &esp_mem_write, + s);cpu_register_physical_memory (espaddr,ESP_REGS << it_shift, esp_io_memory);esp_reset (s);
m48t59.c +12 -9
@@ -565,16 +565,18 @@return retval; } -static CPUWriteMemoryFunc *nvram_write[] = { - &nvram_writeb, - &nvram_writew, - &nvram_writel, +static CPUWriteMemoryFuncs nvram_write = { + nvram_writeb, + nvram_writew, + nvram_writel, +NULL , }; -static CPUReadMemoryFunc *nvram_read[] = { - &nvram_readb, - &nvram_readw, - &nvram_readl, +static CPUReadMemoryFuncs nvram_read = { + nvram_readb, + nvram_readw, + nvram_readl, +NULL , };static void m48t59_save (QEMUFile *f,void *opaque)
@@ -632,7 +634,8 @@register_ioport_write (io_base,0x04 ,1 , NVRAM_writeb, s); }if (mem_base !=0 ) { - s->mem_index =cpu_register_io_memory (0 , nvram_read, nvram_write, s); + s->mem_index =cpu_register_io_memory64 (0 , &nvram_read, &nvram_write, + s);cpu_register_physical_memory (mem_base, size, s->mem_index); }if (type ==59 ) {
slavio_misc.c +47 -31
225 lines not on this page · raw message
eccmemctl.c +12 -7
@@ -220,16 +220,18 @@return ret; } -static CPUReadMemoryFunc *ecc_mem_read[3 ] = { +static CPUReadMemoryFuncs ecc_mem_read = {NULL ,NULL , ecc_mem_readl, +NULL , }; -static CPUWriteMemoryFunc *ecc_mem_write[3 ] = { +static CPUWriteMemoryFuncs ecc_mem_write = {NULL ,NULL , ecc_mem_writel, +NULL , }; static void ecc_diag_mem_writeb(void *opaque, target_phys_addr_t addr,
@@ -250,16 +252,18 @@return ret; } -static CPUReadMemoryFunc *ecc_diag_mem_read[3 ] = { +static CPUReadMemoryFuncs ecc_diag_mem_read = { ecc_diag_mem_readb,NULL ,NULL , +NULL , }; -static CPUWriteMemoryFunc *ecc_diag_mem_write[3 ] = { +static CPUWriteMemoryFuncs ecc_diag_mem_write = { ecc_diag_mem_writeb,NULL ,NULL , +NULL , };static int ecc_load (QEMUFile *f,void *opaque,int version_id)
@@ -325,11 +329,12 @@ s->regs[0 ] = version; s->irq = irq; - ecc_io_memory =cpu_register_io_memory (0 , ecc_mem_read, ecc_mem_write, s); + ecc_io_memory =cpu_register_io_memory64 (0 , &ecc_mem_read, &ecc_mem_write, + s);cpu_register_physical_memory (base,ECC_SIZE , ecc_io_memory);if (version ==ECC_MCC ) {// SS-600MP only - ecc_io_memory =cpu_register_io_memory (0 , ecc_diag_mem_read, - ecc_diag_mem_write, s); + ecc_io_memory =cpu_register_io_memory64 (0 , &ecc_diag_mem_read, + &ecc_diag_mem_write, s);cpu_register_physical_memory (base +0x1000 ,ECC_DIAG_SIZE , ecc_io_memory); }
slavio_timer.c +66 -4
105 lines not on this page · raw message
Quoted 5 lines
Here is a patch for most of the sparc32 hardware drivers. It's a very trivial and mechanical process for these drivers. The one driver that does 64 bit accesses just adds 64 bit access functions because it's broken now and has no workaround to remove. I don't think converting most other drivers will be much harder.
sparc hardware is rather abnormal (for qemu at least) because it cares what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Paul
Quoted 7 lines · Paul Brook
Quoted 6 lines
Here is a patch for most of the sparc32 hardware drivers. It's a very trivial and mechanical process for these drivers. The one driver that does 64 bit accesses just adds 64 bit access functions because it's broken now and has no workaround to remove. I don't think converting most other drivers will be much harder.
Quoted 5 lines
sparc hardware is rather abnormal (for qemu at least) because it cares what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Paul
Ok, so that explains the curious code in m48t59.c:
static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t value) {
m48t59_t *NVRAM = opaque;
m48t59_write(NVRAM, addr, value & 0xff);
}
static void nvram_writew (void *opaque, target_phys_addr_t addr, uint32_t value) {
m48t59_t *NVRAM = opaque;
m48t59_write(NVRAM, addr, (value >> 8) & 0xff); m48t59_write(NVRAM, addr + 1, value & 0xff);
}
static void nvram_writel (void *opaque, target_phys_addr_t addr, uint32_t value) {
m48t59_t *NVRAM = opaque;
m48t59_write(NVRAM, addr, (value >> 24) & 0xff); m48t59_write(NVRAM, addr + 1, (value >> 16) & 0xff); m48t59_write(NVRAM, addr + 2, (value >> 8) & 0xff); m48t59_write(NVRAM, addr + 3, value & 0xff);
}
So nvram_writeq should be present on non sparc architectures and actually should be doing 8 byte accesses? How do we handle architecture differences like this? On sparc, it looks like the sbus controller does this because the actual hardware really only has an 8 bit bus.
Quoted 11 lines
Quoted 3 lines
sparc hardware is rather abnormal (for qemu at least) because it cares what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Ok, so that explains the curious code in
m48t59.c:
...
Sonvram_writeqshould be present on non sparc architectures and actually should be doing 8 byte accesses? How do we handle architecture differences like this? On sparc, it looks like the sbus controller does this because the actual hardware really only has an 8 bit bus.
Are there actually any cases where this matters?
My guess is that in pactice we only have certain SPARC devices that need to trap when you do a wrong sized access, and for everything else you're told not to do that, and qemu can happily return garbage.
If this is the case then the IO_MEM_SUBWIDTH code seems like complete overkill. I reccommend ripping it out, and maybe having the registration function replace NULL with the unassigned hander.
Paul
Quoted 18 lines · Paul Brook
Quoted 7 lines
Quoted 3 lines
sparc hardware is rather abnormal (for qemu at least) because it cares what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Ok, so that explains the curious code in
m48t59.c:Quoted 7 lines
...
So
nvram_writeqshould be present on non sparc architectures and actually should be doing 8 byte accesses? How do we handle architecture differences like this? On sparc, it looks like the sbus controller does this because the actual hardware really only has an 8 bit bus.Are there actually any cases where this matters?
Quoted 7 lines
My guess is that in pactice we only have certain SPARC devices that need to trap when you do a wrong sized access, and for everything else you're told not to do that, and qemu can happily return garbage.
If this is the case then the
IO_MEM_SUBWIDTHcode seems like complete overkill. I reccommend ripping it out, and maybe having the registration function replace NULL with the unassigned hander.
Maybe the registration could also be changed so that if the device only cares for (say) 16 bits (and does not want trapping for the wrong sized access), the 64, 32 and 8 bit cases are emulated at higher level. This would shrink the code base a bit and maybe fits to the bus model.
Quoted 27 lines · Blue Swirl
Quoted 18 lines · Paul Brook
Quoted 7 lines
Quoted 3 lines
sparc hardware is rather abnormal (for qemu at least) because it cares what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Ok, so that explains the curious code in
m48t59.c:Quoted 7 lines
...
So
nvram_writeqshould be present on non sparc architectures and actually should be doing 8 byte accesses? How do we handle architecture differences like this? On sparc, it looks like the sbus controller does this because the actual hardware really only has an 8 bit bus.Are there actually any cases where this matters?
Quoted 7 lines
My guess is that in pactice we only have certain SPARC devices that need to trap when you do a wrong sized access, and for everything else you're told not to do that, and qemu can happily return garbage.
If this is the case then the
IO_MEM_SUBWIDTHcode seems like complete overkill. I reccommend ripping it out, and maybe having the registration function replace NULL with the unassigned hander.
Quoted 5 lines
Maybe the registration could also be changed so that if the device only cares for (say) 16 bits (and does not want trapping for the wrong sized access), the 64, 32 and 8 bit cases are emulated at higher level. This would shrink the code base a bit and maybe fits to the bus model.
I'd appreciate something along these lines :)
Cheers
Quoted 32 lines · Blue Swirl
Quoted 21 lines · Paul Brook
Quoted 9 lines
Quoted 4 lines
sparc hardware is rather abnormal (for qemu at least) because it cares
what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Ok, so that explains the curious code in
m48t59.c:Quoted 8 lines
...
So
nvram_writeqshould be present on non sparc architecturesand actually should be doing 8 byte accesses? How do we handle architecture differences like this? On sparc, it looks like the sbus controller does this because the actual hardware really only has an 8 bit bus.
Are there actually any cases where this matters?
Quoted 8 lines
My guess is that in pactice we only have certain SPARC devices that need to trap when you do a wrong sized access, and for everything else you're told not to do that, and qemu can happily return garbage.
If this is the case then the
IO_MEM_SUBWIDTHcode seems like complete overkill. I reccommend ripping it out, and maybe having the registration function replace NULL with the unassigned hander.
Quoted 9 lines
Maybe the registration could also be changed so that if the device only cares for (say) 16 bits (and does not want trapping for the wrong sized access), the 64, 32 and 8 bit cases are emulated at higher level. This would shrink the code base a bit and maybe fits to the bus model.
This sounds like the way to go. The device would only need to support its natural bus width and a higher level bus driver would be responsible for doing the bus width conversion or faulting. This moves the bus width conversion code from each driver up to a specific bus driver. The bus driver could be a simple as converting NULL to helper functions.
Quoted 11 lines · Robert Reif
static void
nvram_writel(void *opaque,target_phys_addr_taddr,uint32_tvalue){ m48t59_t *NVRAM = opaque; m48t59_write(NVRAM, addr, (value >> 24) & 0xff); m48t59_write(NVRAM, addr + 1, (value >> 16) & 0xff); m48t59_write(NVRAM, addr + 2, (value >> 8) & 0xff); m48t59_write(NVRAM, addr + 3, value & 0xff); }
static void cirrus_vga_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) {
#ifdef TARGET_WORDS_BIGENDIAN
cirrus_vga_mem_writeb(opaque, addr, (val >> 24) & 0xff); cirrus_vga_mem_writeb(opaque, addr + 1, (val >> 16) & 0xff); cirrus_vga_mem_writeb(opaque, addr + 2, (val >> 8) & 0xff); cirrus_vga_mem_writeb(opaque, addr + 3, val & 0xff);
#else
cirrus_vga_mem_writeb(opaque, addr, val & 0xff); cirrus_vga_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff); cirrus_vga_mem_writeb(opaque, addr + 2, (val >> 16) & 0xff); cirrus_vga_mem_writeb(opaque, addr + 3, (val >> 24) & 0xff);
#endif
}
Should a new intermediate bus layer also do byte swapping?
Quoted 1 line
Should a new intermediate bus layer also do byte swapping?
Yes, though a bus layer isn't actually a necessary prerequisite.
As I mentioned in the recent "Smarter compilation for target devices" thread[1], having individual devices do byteswapping is bogus. A while ago I reworked the TLB handling, so there should now be spare bits that can be used for things like byteswapping.
Paul
[1] http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01820.html
Quoted 13 lines · Paul Brook
Quoted 4 lines
Quoted 4 lines
sparc hardware is rather abnormal (for qemu at least) because it cares what happens when you use the wrong width. Most devices don't care, and having any NULL functions is liable to introduce significant overhead.
Quoted 8 lines
Ok, so that explains the curious code in
m48t59.c:
...
Sonvram_writeqshould be present on non sparc architectures and actually should be doing 8 byte accesses? How do we handle architecture differences like this? On sparc, it looks like the sbus controller does this because the actual hardware really only has an 8 bit bus.
Quoted 11 lines
Are there actually any cases where this matters?
My guess is that in pactice we only have certain SPARC devices that need to trap when you do a wrong sized access, and for everything else you're told not to do that, and qemu can happily return garbage.
If this is the case then the
IO_MEM_SUBWIDTHcode seems like complete overkill. I reccommend ripping it out, and maybe having the registration function replace NULL with the unassigned hander.Paul
Wouldn't making a version of the subpage structure the default and getting rid of the multiple parallel arrays make more sense. Then there would only be one type of I/O memory and no special cases.
Quoted 4 lines
Quoted 4 lines
My guess is that in pactice we only have certain SPARC devices that need to trap when you do a wrong sized access, and for everything else you're told not to do that, and qemu can happily return garbage.
Quoted 8 lines
Quoted 3 lines
If this is the case then the
IO_MEM_SUBWIDTHcode seems like complete overkill. I reccommend ripping it out, and maybe having the registration function replace NULL with the unassigned hander.Wouldn't making a version of the subpage structure the default and getting rid of the multiple parallel arrays make more sense. Then there would only be one type of I/O memory and no special cases.
I'm not sure what you're suggesting. I've yet to see any actual use of the subwidth code, and the subpage stuff is fairly rare.
Trying to push the subpage code down into the TLB handler might be possible, but you'd have to be careful to avoid performance regressions in the common code.
Paul
Quoted 9 lines · Paul Brook
Quoted 1 line
Should a new intermediate bus layer also do byte swapping?
Yes, though a bus layer isn't actually a necessary prerequisite.
As I mentioned in the recent "Smarter compilation for target devices" thread[1], having individual devices do byteswapping is bogus. A while ago I reworked the TLB handling, so there should now be spare bits that can be used for things like byteswapping.
This version does the byte swapping and width translation in exec.c. Sparc32 OpenBIOS/Linux does not use the wrong sized accesses, so that part may be untested.
Some problems:
- Small writes cause a read-modify-write cycle, but I think that may happen with real devices too. Another solution is to write zero in other byte lanes without reading.
- The LE/BE distinction does not seem to be very obvious for devices. I think the board should give the is_le value to the device.
- There is a small performance hit for the native access case. This could be avoided by extending io_mem_opaque to cover all sizes.
Emulate non-native widths and optionally byte swap
From: Blue Swirl <[email protected]>
Currently the devices handle non-native I/O accesses by themselves. Handle them at higher level, so device code can be simplified.
---
cpu-all.h | 18 ++ exec.c | 713 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 731 insertions(+), 0 deletions(-)
cpu-all.h +18 -0
@@ -918,6 +918,24 @@ int cpu_register_io_memory(int io_index, void *opaque);void cpu_unregister_io_memory (int table_address); +/* Register IO memory with optional emulation for other bus widths +than native, optionally byte swapped */ +int cpu_register_8bit_io_memory (int io_index, +CPUReadMemoryFunc *mem_read, +CPUWriteMemoryFunc *mem_write, +void *opaque,int emulate_other_widths, +int is_le); +int cpu_register_16bit_io_memory (int io_index, +CPUReadMemoryFunc *mem_read, +CPUWriteMemoryFunc *mem_write, +void *opaque,int emulate_other_widths, +int is_le); +int cpu_register_32bit_io_memory (int io_index, +CPUReadMemoryFunc *mem_read, +CPUWriteMemoryFunc *mem_write, +void *opaque,int emulate_other_widths, +int is_le); +void cpu_physical_memory_rw (target_phys_addr_t addr,uint8_t *buf,int len,int is_write); static inline void cpu_physical_memory_read(target_phys_addr_t addr,
exec.c +713 -0
731 lines not on this page · raw message
Use new IO registration functions
From: Blue Swirl <[email protected]>
---
hw/m48t59.c | 56 +++--------------------------------------------------- hw/pcnet.c | 15 ++------------ hw/sparc32_dma.c | 15 ++------------ 3 files changed, 7 insertions(+), 79 deletions(-)
hw/m48t59.c +3 -53
74 lines not on this page · raw message
hw/pcnet.c +2 -13
@@ -2100,18 +2100,6 @@ static uint32_t lance_mem_readw(void *opaque, target_phys_addr_t addr)return val &0xffff ; } -static CPUReadMemoryFunc *lance_mem_read[3 ] = { -NULL , - lance_mem_readw, -NULL , -}; - -static CPUWriteMemoryFunc *lance_mem_write[3 ] = { -NULL , - lance_mem_writew, -NULL , -}; -static void lance_cleanup (VLANClientState *vc) {PCNetState *d = vc->opaque;
@@ -2135,7 +2123,8 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque, d =qemu_mallocz (sizeof (PCNetState)); d->mmio_index = -cpu_register_io_memory (0 , lance_mem_read, lance_mem_write, d); +cpu_register_16bit_io_memory (0 , lance_mem_readw, lance_mem_writew, d, +0 ,0 ); d->dma_opaque = dma_opaque;
hw/sparc32_dma.c +2 -13
@@ -199,18 +199,6 @@ static void dma_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) s->dmaregs[saddr] = val; } -static CPUReadMemoryFunc *dma_mem_read[3 ] = { -NULL , -NULL , - dma_mem_readl, -}; - -static CPUWriteMemoryFunc *dma_mem_write[3 ] = { -NULL , -NULL , - dma_mem_writel, -}; -static void dma_reset (void *opaque) {DMAState *s = opaque;
@@ -252,7 +240,8 @@ void *sparc32_dma_init(target_phys_addr_t daddr, qemu_irq parent_irq, s->irq = parent_irq; s->iommu = iommu; - dma_io_memory =cpu_register_io_memory (0 , dma_mem_read, dma_mem_write, s); + dma_io_memory =cpu_register_32bit_io_memory (0 , dma_mem_readl, dma_mem_writel, s, +0 ,1 );cpu_register_physical_memory (daddr,DMA_SIZE , dma_io_memory);register_savevm ("sparc32_dma" , daddr,2 , dma_save, dma_load, s);
Quoted 5 lines · Blue Swirl
Quoted 4 lines · Paul Brook
Quoted 1 line
Should a new intermediate bus layer also do byte swapping?
Yes, though a bus layer isn't actually a necessary prerequisite.
Quoted 8 lines
Quoted 4 lines
As I mentioned in the recent "Smarter compilation for target devices" thread[1], having individual devices do byteswapping is bogus. A while
ago I reworked the TLB handling, so there should now be spare bits that can be used for things like byteswapping.This version does the byte swapping and width translation in
exec.c. Sparc32 OpenBIOS/Linux does not use the wrong sized accesses, so that part may be untested.
This appears to be adding yet annother layer of indirection, which isn't really what I had inmind.
Paul
Quoted 3 lines · Blue Swirl
- Small writes cause a read-modify-write cycle, but I think that may happen with real devices too. Another solution is to write zero in other byte lanes without reading.
On PCI and I think most buses, there are separate byte-enable pins for writing each byte lane and the hardware can decide to ignore the unenabled bytes or not.
-- Jamie
Quoted 10 lines · Jamie Lokier
Quoted 3 lines · Blue Swirl
- Small writes cause a read-modify-write cycle, but I think that may happen with real devices too. Another solution is to write zero in other byte lanes without reading.
On PCI and I think most buses, there are separate byte-enable pins for writing each byte lane and the hardware can decide to ignore the unenabled bytes or not.
From my experience it is not uncommon for peripheral busses to
don't have the byte strobes. In fact, most (if not all) of the embedded ones I've worked with are purely 32bit.
Cheers