Patch: Sparc system support (2/3)
Hi,
Contents: IOMMU, TCX frame buffer (basic), interrupt controllers, timers (incomplete), and Lance Ethernet emulation. Bound together to emulate Sun4m architecture.
hw/iommu.c +141 -0
@@ -0,0 +1,141 @@ +/* +* QEMU iommu emulation +* +* Copyright (c) 2003 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#include "vl.h" +#include "iommu.h" + +/* debug iommu */ +//#define DEBUG_IOMMU + +#define PHYS_JJ_IOMMU 0x10000000/* First page of sun4m IOMMU */ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +typedef struct IOMMUState { +uint32_t regs[sizeof (struct iommu_regs )]; +}IOMMUState ; + +static IOMMUState *ps; + +static int iommu_io_memory; + +static void iommu_reset (IOMMUState *s) +{ +} + +static uint32_t iommu_mem_readw (void *opaque,target_phys_addr_t addr) +{ +IOMMUState *s = opaque; +uint32_t saddr; + + saddr = (addr -PHYS_JJ_IOMMU ) >>2 ; +switch (saddr) { +default : +return s->regs[saddr]; +break ; + } +return 0 ; +} + +static void iommu_mem_writew (void *opaque,target_phys_addr_t addr,uint32_t val) +{ +IOMMUState *s = opaque; +uint32_t saddr; + + saddr = (addr -PHYS_JJ_IOMMU ) >>2 ; +switch (saddr) { +default : + s->regs[saddr] = val; +break ; + } +} + +static CPUReadMemoryFunc *iommu_mem_read[3 ] = { + iommu_mem_readw, + iommu_mem_readw, + iommu_mem_readw, +}; + +static CPUWriteMemoryFunc *iommu_mem_write[3 ] = { + iommu_mem_writew, + iommu_mem_writew, + iommu_mem_writew, +}; + +uint32_t iommu_translate (uint32_t addr) +{ +uint32_t *iopte = (void *)(ps->regs[1 ] <<4 ), pa, iostart; + +switch (ps->regs[0 ] &IOMMU_CTRL_RNGE ) { +case IOMMU_RNGE_16MB : + iostart =0xff000000 ; +break ; +case IOMMU_RNGE_32MB : + iostart =0xfe000000 ; +break ; +case IOMMU_RNGE_64MB : + iostart =0xfc000000 ; +break ; +case IOMMU_RNGE_128MB : + iostart =0xf8000000 ; +break ; +case IOMMU_RNGE_256MB : + iostart =0xf0000000 ; +break ; +case IOMMU_RNGE_512MB : + iostart =0xe0000000 ; +break ; +case IOMMU_RNGE_1GB : + iostart =0xc0000000 ; +break ; +default : +case IOMMU_RNGE_2GB : + iostart =0x80000000 ; +break ; + } + + iopte += ((addr - iostart) >>PAGE_SHIFT ); +cpu_physical_memory_rw ((uint32_t )iopte, (void *) &pa,4 ,0 ); +bswap32s (&pa); + pa = (pa &IOPTE_PAGE ) <<4 ;/* Loose higher bits of 36 */ +//return pa + PAGE_SIZE; +return pa + (addr &PAGE_MASK ); +} + +void iommu_init () +{ +IOMMUState *s; + + s =qemu_mallocz (sizeof (IOMMUState)); +if (!s) +return ; + + iommu_io_memory =cpu_register_io_memory (0 , iommu_mem_read, iommu_mem_write, s); +cpu_register_physical_memory (PHYS_JJ_IOMMU ,sizeof (struct iommu_regs ), + iommu_io_memory); + +iommu_reset (s); + ps = s; +} +
hw/iommu.h +97 -0
97 lines not on this page · raw message
hw/lance.c +446 -0
446 lines not on this page · raw message
hw/sched.c +346 -0
346 lines not on this page · raw message
hw/sun4m.c +127 -0
127 lines not on this page · raw message
hw/tcx.c +176 -0
176 lines not on this page · raw message
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail