Altera NiosII support
Subsystems (2)
Re: [Qemu-devel] [PATCH 8/9] MicroBlaze: Add a config that is dynamically set up by a device tree file.
In reply to [email protected]Hi Chris,
This needs to be reviewed along with the petalogix implementation, but a few top level comments.
Regards,
Peter
Quoted 78 lines · On Sun, 2012-09-09 at 20:20 -0400, [email protected] wrote:
From: Chris Wulff <[email protected]>
Signed-off-by Chris Wulff <[email protected]>--- default-configs/microblaze-softmmu.mak | 1 + hw/labx_microblaze_devicetree.c | 597 ++++++++++++++++++++++++++++++++ hw/microblaze/Makefile.objs | 3 +- 3 files changed, 600 insertions(+), 1 deletion(-) create mode 100644 hw/labx_microblaze_devicetree.cdefault-configs/microblaze-softmmu.mak +1
-0@@ -5,3 +5,4 @@ CONFIG_PFLASH_CFI01=y CONFIG_SERIAL=y CONFIG_XILINX=y CONFIG_XILINX_AXI=y +CONFIG_LABX=yhw/labx_microblaze_devicetree.c new file +53
-0@@ -0,0 +1,597 @@ +/* +* Flexible model of microblaze designs that use a device-tree to determine +* the hardware configuration. +* +* Copyright (c) 2010 LabX Technologies, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#include "sysbus.h" +#include "hw.h" +#include "net.h" +#include "flash.h" +#include "sysemu.h" +#include "devices.h" +#include "boards.h" +#include "device_tree.h" +#include "xilinx.h" +#include "labx_devices.h" +#include "loader.h" +#include "elf.h" +#include "blockdev.h" +#include "exec-memory.h" +#include "microblaze_pic_cpu.h" + +#define LMB_BRAM_SIZE (128 * 1024) + +static struct +{ +uint32_t bootstrap_pc; +uint32_t cmdline; +uint32_t initrd; +uint32_t fdt; +} boot_info; + +/* Current ethernet device index for multiple network interfaces */ +static int eth_dev_index =-1 ; + +static void main_cpu_reset (void *opaque) +{ +MicroBlazeCPU *cpu = opaque;
hw/labx_microblaze_devicetree.c line 63
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+CPUMBState *env = &cpu->env; + +cpu_reset (CPU (cpu)); + + env->regs[5 ] = boot_info.cmdline; + env->regs[6 ] = boot_info.initrd; + env->regs[7 ] = boot_info.fdt; + env->sregs[SR_PC ] = boot_info.bootstrap_pc; +} +
Please use microblaze bootloader (hw/microblaze_boot.c). We need to consolidate bootloaders. If there is functionality missing from mb_boot, please add it there.
hw/labx_microblaze_devicetree.c line 67
Quoted 4 lines
hw/labx_microblaze_devicetree.c new file +4
-0+#ifndef CONFIG_FDT +#error "Device-tree support is required for this target to function" +#endif +
This should be handled by the make infrastructure. This machine model should be obj-(CONIFG_FDT)+= .. so this machine model just dissappears when QEMU is build without FDT.
Quoted 164 lines
hw/labx_microblaze_devicetree.c new file +164
-0+static uint32_t fdt_get_int_from_array (void *fdt,int node, +const char *name,int index) +{ +int array_length; +const void *array =qemu_devtree_getprop_offset (fdt, node, name, + &array_length); +if (index >= array_length) { +printf ("fdt_get_int_from_array: requesting %s from node %d, " +"index %d out of range (%d max)\n" , + name, node, index, array_length); +return 0 ; + }else { +return qemu_devtree_int_array_index (array, index); + } +} + +#define BINARY_DEVICE_TREE_FILE "labx-microblaze.dtb" +static void *get_device_tree (int *fdt_size) +{ +char *path; +void *fdt; + +/* Try the local "mb.dtb" override. */ + fdt =load_device_tree ("mb.dtb" , fdt_size); +if (!fdt) { + path =qemu_find_file (QEMU_FILE_TYPE_BIOS ,BINARY_DEVICE_TREE_FILE ); +if (path) { + fdt =load_device_tree (path, fdt_size); +g_free (path); + } + } + +return fdt; +} + +static int labx_microblaze_load_device_tree (target_phys_addr_t addr, +uint32_t ramsize, +target_phys_addr_t initrd_base, +target_phys_addr_t initrd_size, +const char *kernel_cmdline) +{ +int fdt_size; +void *fdt; +int r; + + fdt =get_device_tree (&fdt_size); + +if (!fdt) { +return 0 ; + } + +if (kernel_cmdline &&strlen (kernel_cmdline)) { + r =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , + kernel_cmdline); +if (r <0 ) { +fprintf (stderr,"couldn't set /chosen/bootargs\n" ); + } + } +cpu_physical_memory_write (addr, (void *)fdt, fdt_size); + +return fdt_size; +} + +static uint64_t translate_kernel_address (void *opaque,uint64_t addr) +{ +return addr -0x30000000LL ; +} + +static ram_addr_t get_dram_base (void *fdt) +{ +int root =qemu_devtree_node_offset (fdt,"/" ); +int memory =qemu_devtree_subnode_offset_namelen (fdt, root,"memory" ,6 ); +if (memory >0 ) { +int reglen; +const void *reg = +qemu_devtree_getprop_offset (fdt, memory,"reg" , ®len); + +if (reglen >=4 ) { +printf ("DRAM base %08X, size %08X\n" , +qemu_devtree_int_array_index (reg,0 ), +qemu_devtree_int_array_index (reg,1 )); +return qemu_devtree_int_array_index (reg,0 ); + } + } + +printf ("DRAM base not found. Defaulting to 0x88000000\n" ); + +return 0x88000000 ;/* Default to something reasonable */ +} + +typedef void (*device_init_func_t )(void *fdt,int node); + +typedef struct { +device_init_func_t probe; +int pass; +const char **compat; + +}devinfo_t ; + +/* +* Xilinx interrupt controller device +*/ +MicroBlazeCPU *g_cpu; +static qemu_irq irq[32 ] = {}; +static qemu_irq *cpu_irq; + +static void xilinx_interrupt_controller_probe (void *fdt,int node) +{ +int i; +DeviceState *dev; +int reglen; +const void *reg =qemu_devtree_getprop_offset (fdt, node,"reg" , ®len); +uint32_t irq_addr =qemu_devtree_int_array_index (reg,0 ); +int nrIrqLen; +const void *nrIrq = +qemu_devtree_getprop_offset (fdt, node,"xlnx,num-intr-inputs" , + &nrIrqLen); +uint32_t nrIrqs =qemu_devtree_int_array_index (nrIrq,0 ); + +printf (" IRQ BASE %08X NIRQS %d\n" , irq_addr, nrIrqs); + + cpu_irq =microblaze_pic_init_cpu (&g_cpu->env); + dev =xilinx_intc_create (irq_addr, cpu_irq[0 ],2 ); +for (i =0 ; i < nrIrqs; i++) { + irq[i] =qdev_get_gpio_in (dev, i); + } +} + +devinfo_t xilinx_interrupt_controller_device = { + .probe = &xilinx_interrupt_controller_probe, + .pass =0 , + .compat = (const char * []) {"xlnx,xps-intc-1.00.a" ,NULL } +}; + +/* +* Flash device +*/ +static void flash_probe (void *fdt,int node) +{ +int reglen; +const void *reg =qemu_devtree_getprop_offset (fdt, node,"reg" , ®len); +uint32_t flash_addr =qemu_devtree_int_array_index (reg,0 ); +uint32_t flash_size =qemu_devtree_int_array_index (reg,1 ); + +DriveInfo *dinfo =drive_get (IF_PFLASH ,0 ,0 ); +pflash_cfi01_register (flash_addr,NULL , +qemu_devtree_get_name (fdt, node,NULL ), flash_size, + dinfo ? dinfo->bdrv :NULL , (64 *1024 ), + flash_size >>16 , +1 ,0x89 ,0x18 ,0x0000 ,0x0 ,1 ); +printf ("-- loaded %d bytes to %08X\n" , +load_image_targphys (qemu_devtree_get_name (fdt, node,NULL ), + flash_addr, flash_size), + flash_addr); +} + +devinfo_t flash_device = { + .probe = &flash_probe, + .pass =1 , + .compat = (const char * []) {"cfi-flash" ,NULL } +}; + +/* +* Xilinx timer device
hw/labx_microblaze_devicetree.c line 241
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+*/ +static void xilinx_timer_probe (void *fdt,int node) +{ +uint32_t timer_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t timer_irq =fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); + +printf (" TIMER BASE %08X IRQ %d\n" , timer_addr, timer_irq); + +/* 2 timers at irq 2 @ 62 Mhz. */ +xilinx_timer_create (timer_addr, irq[timer_irq],0 ,62 *1000000 );
No check is made for the one_timer_only property.
Quoted 168 lines
hw/labx_microblaze_devicetree.c new file +168
-0+} + +devinfo_t xilinx_timer_device = { + .probe = &xilinx_timer_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,xps-timer-1.00.a" ,NULL } +}; + +/* +* Xilinx uartlite device +*/ +static void xilinx_uartlite_probe (void *fdt,int node) +{ +uint32_t uart_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t uart_irq =fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); + +printf (" UART BASE %08X IRQ %d\n" , uart_addr, uart_irq); + +sysbus_create_simple ("xlnx.xps-uartlite" , uart_addr, irq[uart_irq]); +} + +devinfo_t xilinx_uartlite_device = { + .probe = &xilinx_uartlite_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,xps-uartlite-1.00.a" ,NULL } +}; + +/* +* Xilinx ethernetlite device +*/ +static void xilinx_ethlite_probe (void *fdt,int node) +{ +uint32_t eth_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t eth_irq =fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); + +xilinx_ethlite_create (&nd_table[++eth_dev_index], eth_addr, + irq[eth_irq],0 ,0 ); +} + +devinfo_t xilinx_ethlite_device = { + .probe = &xilinx_ethlite_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,xps-ethernetlite-2.00.b" ,NULL } +}; + +/* +* LabX audio packetizer device +*/ +static void labx_audio_packetizer_probe (void *fdt,int node) +{ +uint32_t packetizer_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t packetizer_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); +uint32_t clock_domains = +fdt_get_int_from_array (fdt, node,"xlnx,num-clock-domains" ,0 ); +uint32_t cache_words = +fdt_get_int_from_array (fdt, node,"xlnx,cache-data-words" ,0 ); + +labx_audio_packetizer_create (packetizer_addr, irq[packetizer_irq], + clock_domains, cache_words); +} + +devinfo_t labx_audio_packetizer_device = { + .probe = &labx_audio_packetizer_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,labx-audio-packetizer-1.00.a" ,NULL } +}; + +/* +* LabX audio depacketizer device +*/ +static void labx_audio_depacketizer_probe (void *fdt,int node) +{ +uint32_t depacketizer_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t depacketizer_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); +uint32_t clock_domains = +fdt_get_int_from_array (fdt, node,"xlnx,num-clock-domains" ,0 ); +uint32_t cache_words = +fdt_get_int_from_array (fdt, node,"xlnx,cache-data-words" ,0 ); + +int ifLen; +const void *ifType = +qemu_devtree_getprop_offset (fdt, node,"xlnx,interface-type" , &ifLen); +int hasDMA = (0 !=strncmp ("CACHE_RAM" , (const char *)ifType, ifLen)); + +labx_audio_depacketizer_create (depacketizer_addr, irq[depacketizer_irq], + clock_domains, cache_words, hasDMA); +} + +devinfo_t labx_audio_depacketizer_device = { + .probe = &labx_audio_depacketizer_probe, + .pass =1 , + .compat = (const char * []) { +"xlnx,labx-audio-depacketizer-1.00.a" , +"xlnx,labx-audio-depacketizer-1.01.a" , +NULL + } +}; + +/* +* LabX dma device +*/ +static void labx_dma_probe (void *fdt,int node) +{ +uint32_t dma_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + +labx_dma_create (dma_addr,1024 ); +} + +devinfo_t labx_dma_device = { + .probe = &labx_dma_probe, + .pass =1 , + .compat = (const char * []) { +"xlnx,labx-dma-1.00.a" , +"xlnx,labx-dma-1.01.a" , +"xlnx,labx-local-audio-1.00.a" , +NULL + } +}; + +/* +* LabX ethernet device +*/ +static void labx_ethernet_probe (void *fdt,int node) +{ +uint32_t ethernet_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t host_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); +uint32_t fifo_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,2 ); +uint32_t phy_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,4 ); + +labx_ethernet_create (&nd_table[++eth_dev_index], ethernet_addr, + irq[host_irq], irq[fifo_irq], irq[phy_irq]); +} + +devinfo_t labx_ethernet_device = { + .probe = &labx_ethernet_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,labx-ethernet-1.00.a" ,NULL } +}; + +/* +* LabX ptp device +*/ +static void labx_ptp_probe (void *fdt,int node) +{ +uint32_t ptp_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + +labx_ptp_create (ptp_addr); +} + +devinfo_t labx_ptp_device = { + .probe = &labx_ptp_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,labx-ptp-1.00.a" ,NULL } +}; + +/* +* Table of available devices +*/ +devinfo_t *devices[] = { + &xilinx_interrupt_controller_device, + &flash_device, + &xilinx_timer_device, + &xilinx_uartlite_device,
hw/labx_microblaze_devicetree.c line 419
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ &xilinx_ethlite_device, + &labx_audio_packetizer_device, + &labx_audio_depacketizer_device, + &labx_dma_device, + &labx_ethernet_device, + &labx_ptp_device, + NULL +}; + +static int plb_device_probe (void *fdt,int node,int pass)
QEMU abstacts away interconnect implementations. You should probably also drive off the "simple-bus" compat rather than PLB for machine model compatibility. s/plb/bus/g or something like it.
Quoted 74 lines
hw/labx_microblaze_devicetree.c new file +74
-0+{ +devinfo_t **dev = &(devices[0 ]); + +while (*dev) { +const char **compat = &((*dev)->compat[0 ]); +while (*compat) { +if (0 ==qemu_devtree_node_check_compatible (fdt, node, *compat)) { +if (pass == (*dev)->pass) { +printf ("Adding a device for node %s\n" , +qemu_devtree_get_name (fdt, node,NULL )); + + (*dev)->probe (fdt, node); +return 0 ; + } + +if (pass < (*dev)->pass) { +/* Probe again on the next pass */ +return 1 ; + } + } + + compat++; + } + + dev++; + } + +return 0 ; +} + +static void plb_bus_probe (void *fdt) +{ +int root =qemu_devtree_node_offset (fdt,"/" ); +int plb =qemu_devtree_subnode_offset_namelen (fdt, root,"plb" ,3 ); +if (plb >0 ) { +/* Do multiple passes through the devices. Some have dependencies +on others being first */ +int pass =0 ; +int again =0 ; +do { +int child = plb; + again =0 ; +do { + child =qemu_devtree_next_child_offset (fdt, plb, child); +if (child <0 ) { +break ; + } + + again |=plb_device_probe (fdt, child, pass); + + }while (1 ); + + pass++; + + }while (again); + } +} + +static void +labx_microblaze_init (ram_addr_t ram_size, +const char *boot_device, +const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename, +const char *cpu_model) +{ +MemoryRegion *address_space_mem =get_system_memory (); + +int kernel_size; +int fdt_size; +void *fdt =get_device_tree (&fdt_size); +target_phys_addr_t ddr_base =get_dram_base (fdt); +MemoryRegion *phys_lmb_bram =g_new (MemoryRegion,1 ); +MemoryRegion *phys_ram =g_new (MemoryRegion,1 );
hw/labx_microblaze_devicetree.c line 503
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+CPUMBState *env; + +/* init CPUs */ +if (cpu_model ==NULL ) { + cpu_model ="microblaze" ; + } + g_cpu =cpu_mb_init (cpu_model); + env = &g_cpu->env; + + env->pvr.regs[10 ] =0x0c000000 ;/* spartan 3a dsp family. */
I have dtb driven solution for this.
Quoted 70 lines
hw/labx_microblaze_devicetree.c new file +70
-0+qemu_register_reset (main_cpu_reset, g_cpu); + +/* Attach emulated BRAM through the LMB. LMB size is not specified in the +device-tree but there must be one to hold the vector table. */ +memory_region_init_ram (phys_lmb_bram,"labx_microblaze.lmb_bram" , +LMB_BRAM_SIZE ); +vmstate_register_ram_global (phys_lmb_bram); +memory_region_add_subregion (address_space_mem,0x00000000 , phys_lmb_bram); + +memory_region_init_ram (phys_ram,"labx_microblaze.ram" , ram_size); +vmstate_register_ram_global (phys_ram); +memory_region_add_subregion (address_space_mem, ddr_base, phys_ram); + + +/* Create other devices listed in the device-tree */ +plb_bus_probe (fdt); + +if (kernel_filename) { +uint64_t entry, low, high; +uint32_t base32; + +/* Boots a kernel elf binary. */ + kernel_size =load_elf (kernel_filename,NULL ,NULL , + &entry, &low, &high, +1 ,ELF_MACHINE ,0 ); + base32 = entry; +if (base32 ==0xc0000000 ) { + kernel_size =load_elf (kernel_filename, translate_kernel_address, +NULL , &entry,NULL ,NULL , +1 ,ELF_MACHINE ,0 ); + } +/* Always boot into physical ram. */ + boot_info.bootstrap_pc = ddr_base + (entry &0x07ffffff ); + +/* If it wasn't an ELF image, try an u-boot image. */ +if (kernel_size <0 ) { +target_phys_addr_t uentry, loadaddr; + + kernel_size =load_uimage (kernel_filename, &uentry, &loadaddr,0 ); + boot_info.bootstrap_pc = uentry; + high = (loadaddr + kernel_size +3 ) & ~3 ; + } + +/* Not an ELF image nor an u-boot image, try a RAW image. */ +if (kernel_size <0 ) { + kernel_size =load_image_targphys (kernel_filename, ddr_base, + ram_size); + boot_info.bootstrap_pc = ddr_base; + high = (ddr_base + kernel_size +3 ) & ~3 ; + } + +if (initrd_filename) { +uint32_t initrd_base =0x88c00000 ; +uint32_t initrd_size = +load_image_targphys (initrd_filename, initrd_base, + ram_size - initrd_base); +if (initrd_size <=0 ) { +fprintf (stderr,"qemu: could not load initial ram disk '%s'\n" , + initrd_filename); +exit (1 ); + } + + boot_info.initrd = initrd_base; + }else { + boot_info.initrd =0x00000000 ; + } + + boot_info.cmdline = high +4096 ; +if (kernel_cmdline &&strlen (kernel_cmdline)) { +pstrcpy_targphys ("cmdline" , boot_info.cmdline,256 , kernel_cmdline);
hw/labx_microblaze_devicetree.c line 583
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ } +/* Provide a device-tree. */ + boot_info.fdt = boot_info.cmdline +4096 ; +labx_microblaze_load_device_tree (boot_info.fdt, ram_size, +0 ,0 , + kernel_cmdline); + } +} + +static QEMUMachine labx_microblaze_machine = {
Its a generic machine, so should it be badged as labx?
Quoted 20 lines
hw/labx_microblaze_devicetree.c new file +14
-0+ .name = "labx-microblaze-devicetree", + .desc ="Microblaze design based on the peripherals specified " + "in the device-tree.", + .init = labx_microblaze_init, + .is_default =1 +}; + +static void labx_microblaze_machine_init (void ) +{ +qemu_register_machine (&labx_microblaze_machine); +} + +machine_init (labx_microblaze_machine_init); +hw/microblaze/Makefile.objs +0
-0
hw/microblaze/Makefile.objs line 1
Quoted 2 lines
hw/microblaze/Makefile.objs +1
-1@@ -1,4 +1,5 @@ -obj-y = petalogix_s3adsp1800_mmu.o +obj-y = labx_microblaze_devicetree.o
obj-y += labx_microblaze_devicetree.(CONFIG-FDT)
Quoted 4 lines
hw/microblaze/Makefile.objs +1
-0+obj-y += petalogix_s3adsp1800_mmu.o obj-y += petalogix_ml605_mmu.o obj-y += microblaze_boot.o
Re: [Qemu-devel] [PATCH 5/9] FDT: Add additional access methods for array types and walking children.
In reply to [email protected]Quoted 14 lines · On Sun, 2012-09-09 at 20:20 -0400, [email protected] wrote:
From: Chris Wulff <[email protected]>
Signed-off-by Chris Wulff <[email protected]>--- device_tree.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ device_tree.h | 18 ++++++++++++ 2 files changed, 106 insertions(+)device_tree.c +0
-0@@ -27,6 +27,14 @@
device_tree.c line 37
Quoted 10 lines
device_tree.c +8
-0#include <libfdt.h> +#define CHECK_HEADER (fdt) \ + { \ + int err = fdt_check_header(fdt); \ + if (err != 0) { \ + return err; \ + } \ + } +
Im thinking the best way (and I have recently done some patches along this line) is to use the qemu error reporting mechanism. Rather than return 1, populate an Error ** with an error code. Not a blocker as this is out of scope of this series, but would make this macro foo go away with a nice inline function.
device_tree.c int qemu_devtree_add_subnode(void *fdt, const char *name) · line 319
Quoted 12 lines
device_tree.c +5
-0#define FDT_MAX_SIZE 0x10000void *create_device_tree (int *sizep)@@ -304,3 +312,83 @@ int qemu_devtree_add_subnode(void *fdt, const char *name)g_free (dupname);return retval; } + +int qemu_devtree_node_offset (void *fdt,const char *node_path) +{ +return fdt_path_offset (fdt, node_path); +}
device_tree so far has been able to insulate clients from dealing with offsets. Good to keep it that way and use node_paths instead. Offsets have the problem where they are globally invalidated as soon as the device tree is manipulated.
I have an alternate API extension that does a lot of what you are trying to do but nodepaths are used as handles to nodes rather than offsets. Will send patch.
device_tree.c int qemu_devtree_add_subnode(void *fdt, const char *name) · line 325
Quoted 6 lines
device_tree.c +6
-0+ +int qemu_devtree_subnode_offset_namelen (void *fdt,int parentoffset, +const char *name,int namelen) +{ +return fdt_subnode_offset_namelen (fdt, parentoffset, name, namelen); +}
No need for no-operation wrappers, just call into lib-fdt directly. Most device-tree api calls exit(1) on failure which is why we have these thin wrappers.
Quoted 81 lines
device_tree.c +69
-0+ +int qemu_devtree_next_child_offset (void *fdt,int parentoffset,int childoffset) +{ +int level =0 ; +uint32_t tag; +int offset, nextoffset; + +CHECK_HEADER (fdt); + tag =fdt_next_tag (fdt, parentoffset, &nextoffset); +if (tag !=FDT_BEGIN_NODE ) { +return -FDT_ERR_BADOFFSET ; + } + +do { + offset = nextoffset; + tag =fdt_next_tag (fdt, offset, &nextoffset); + +switch (tag) { +case FDT_END : +return -FDT_ERR_TRUNCATED ; + +case FDT_BEGIN_NODE : + level++; +if (level !=1 ) { +continue ; + } +if (offset > childoffset) { +return offset; + } +break ; + +case FDT_END_NODE : + level--; +break ; + +case FDT_PROP : +case FDT_NOP : +break ; + +default : +return -FDT_ERR_BADSTRUCTURE ; + } + }while (level >=0 ); + +return -FDT_ERR_NOTFOUND ; +} + +const char *qemu_devtree_get_name (const void *fdt,int nodeoffset,int *lenp) +{ +return fdt_get_name (fdt, nodeoffset, lenp); +} + +const void *qemu_devtree_getprop_offset (const void *fdt,int nodeoffset, +const char *name,int *lenp) +{ +return fdt_getprop (fdt, nodeoffset, name, lenp); +} + +uint32_t qemu_devtree_int_array_index (const void *propval,unsigned int index) +{ +return be32_to_cpu (((uint32_t *)propval)[index]); +} + +int qemu_devtree_node_check_compatible (const void *fdt,int nodeoffset, +const char *compatible) +{ +return fdt_node_check_compatible (fdt, nodeoffset, compatible); +} +device_tree.h +4
-0@@ -49,4 +49,22 @@ int qemu_devtree_add_subnode(void *fdt, const char *name); sizeof(qdt_tmp)); \ }while (0 ) +int qemu_devtree_node_offset(void *fdt, const char *node_path); + +int qemu_devtree_subnode_offset_namelen (void *fdt,int parentoffset, +const char *name,int namelen);
device_tree.h int qemu_devtree_add_subnode(void *fdt, const char *name); · line 65
Quoted 10 lines
device_tree.h +10
-0+ +int qemu_devtree_next_child_offset (void *fdt,int parentoffset, +int childoffset); + +const char *qemu_devtree_get_name (const void *fdt,int nodeoffset,int *lenp); + +const void *qemu_devtree_getprop_offset (const void *fdt,int nodeoffset, +const char *name,int *lenp); + +uint32_t qemu_devtree_int_array_index (const void *propval,unsigned int index);
This is get_prop_cell but with an index. We debated this on the list recently (cc PMM) that get_prop_cell should(nt) have an index field into it that lets you get the non-zeroth property. I have a patch in my tree that changes this that ill send you along with the rest.
device_tree.h int qemu_devtree_add_subnode(void *fdt, const char *name); · line 70
Quoted 5 lines
device_tree.h +4
-0+ +int qemu_devtree_node_check_compatible (const void *fdt,int nodeoffset, +const char *compatible); +#endif /* __DEVICE_TREE_H__ */
Regards,
Peter
Re: [Qemu-devel] [PATCH 8/9] MicroBlaze: Add a config that is dynamically set up by a device tree file.
In reply to Blue SwirlQuoted 16 lines · Blue Swirl
hw/labx_microblaze_devicetree.c line 278
Quoted 12 lines · On Mon, Sep 10, 2012 at 12:20 AM, <[email protected]> wrote:
From: Chris Wulff <[email protected]>
hw/labx_microblaze_devicetree.c new file +10
-0+/* +* Xilinx ethernetlite device +*/ +static void xilinx_ethlite_probe (void *fdt,int node) +{ +uint32_t eth_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t eth_irq =fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); + +xilinx_ethlite_create (&nd_table[++eth_dev_index], eth_addr, + irq[eth_irq],0 ,0 );The device should not access
nd_table, this should be handled at board level.
This is board level isn't it? This function calls xilinx_ethlite_create() which in turn does the qdev_create so this is pre device creation. Im open to suggestions on how to do this in a non-global hacking way however as I have the same problem in my tree.
Regards,
Peter
Quoted 8 lines
Quoted 8 lines
hw/labx_microblaze_devicetree.c new file +8
-0+} + +devinfo_t xilinx_ethlite_device = { + .probe = &xilinx_ethlite_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,xps-ethernetlite-2.00.b" ,NULL } +}; +
Re: [Qemu-devel] [PATCH 9/9] xilinx_timer: Fix a compile error if debug messages are enabled.
In reply to [email protected]Queued to microblaze-devs.
Thanks,
Peter
Quoted 3 lines · On Mon, Sep 10, 2012 at 10:20 AM, <[email protected]> wrote:
From: Chris Wulff <[email protected]>
Quoted 29 lines
--- hw/xilinx_timer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/xilinx_timer.c +2
-2@@ -24,6 +24,7 @@#include "sysbus.h" #include "ptimer.h" +#include "qemu-log.h" #define D (x)@@ -189,7 +190,7 @@ static void timer_hit(void *opaque) {struct xlx_timer *xt = opaque;struct timerblock *t = xt->parent; -D (printf ("%s %d\n" , __func__, timer)); +D (printf ("%s %d\n" , __func__, xt->nr)); xt->regs[R_TCSR ] |=TCSR_TINT ;if (xt->regs[R_TCSR ] &TCSR_ARHT ) --1.7.9.5
Re: [Qemu-devel] [PATCH 1/9] NiosII: Add support for the Altera NiosII soft-core CPU.
In reply to Blue SwirlThanks for the feedback. Nothing jumps out at me that I disagree with. I'll get it updated and another patch out once I get the chance to incorporate the info.
target-nios2/altera_iic.c line 25
Quoted 5 lines
target-nios2/altera_iic.c new file +5
-0+#include "hw/sysbus.h" +#include "dyngen-exec.h" +#include "cpu.h" + +struct altera_iic {
CamelCase
Yep. I missed that one in reviewing the coding standard and the checkpatch script apparently doesn't flag it. I'll clean up that one an the others like it.
target-nios2/cpu.h line 162
Quoted 11 lines
target-nios2/cpu.h new file +11
-0+ +#if !defined(CONFIG_USER_ONLY ) +struct nios2_mmu mmu; +#endif + + CPU_COMMON +} CPUNios2State; + +#include "cpu-qom.h" + +extern Nios2CPU *cpu_nios2_init (const char *cpu_model);
'extern' is useless for functions.
True. I will remove for consistency with other code.
target-nios2/cpu.h line 172
Quoted 10 lines
target-nios2/cpu.h new file +10
-0+extern int cpu_nios2_exec (CPUNios2State *s); +extern void cpu_nios2_close (CPUNios2State *s); +extern void do_interrupt (CPUNios2State *env); +extern int cpu_nios2_signal_handler (int host_signum,void *pinfo,void *puc); +extern void dump_mmu (FILE *f,fprintf_function cpu_fprintf,CPUNios2State *env); + +#define TARGET_PHYS_ADDR_SPACE_BITS 32 +#define TARGET_VIRT_ADDR_SPACE_BITS 32 + +extern Nios2CPU *g_cpu;
Just say no to globals.
target-nios2/exec.h line 24
Quoted 4 lines
target-nios2/exec.h new file +4
-0+#ifndef NIOS2_EXEC_H +#define NIOS2_EXEC_H + +#include "dyngen-exec.h"
Dyngen model is being obsoleted in coming days. Please make all helpers which need access to CPU state take the state as parameter.
target-nios2/exec.h line 26
Quoted 2 lines
target-nios2/exec.h new file +2
-0+ +register struct CPUNios2State *env asm(AREG0);
This is already defined in dyngen-exec.h, but see above. Maybe you are not using Git HEAD? No target uses exec.h anymore.
target-nios2/exec.h line 34
Quoted 8 lines
target-nios2/exec.h new file +8
-0+ +#include "cpu.h" +#include "exec-all.h" + +#if !defined(CONFIG_USER_ONLY ) +#include "softmmu_exec.h" +#endif +
The functions below should go to cpu.h.
I've been working on this on and off for months now so it is very well possible that I referenced older code that still did use some of this stuff. I'll review the latest to see how this is being done now. I agree that globals aren't good. I'll see if I can find how to get the information passed along to the appropriate places that need it.
target-nios2/helper.c line 54
Quoted 5 lines
target-nios2/helper.c new file +5
-0+void do_interrupt (CPUNios2State *env) +{ +switch (env->exception_index) { +case EXCP_IRQ : +assert (env->regs[CR_STATUS ] &CR_STATUS_PIE );
I hope this is not a guest triggerable assert.
It shouldn't be. But maybe this should just be a debug message and not trigger an exception if this is the case. We should never be trying to send an IRQ exception to the guest if interrupts are globally disabled.
target-nios2/helper.c line 281
Quoted 7 lines
target-nios2/helper.c new file +7
-0+if (has_mmu && (addr <0xC0000000 )) { + hit =mmu_translate (env, &lu, addr,0 ,0 ); +if (hit) { + vaddr = addr &TARGET_PAGE_MASK ; + paddr = lu.paddr + vaddr - lu.vaddr; + }else { +cpu_abort (env,"cpu_get_phys_page debug MISS: %08X\n" , addr);
cpu_get_phys_page_debug is used for memory access from monitor. Aborting because user specified a bad address is rather draconian.
I was seeing this come from the disassembly code when I had a mismatch between the TLB in the processor emulation and the one that QEMU knows about (due to improper removal of QEMU tlb entries when they were overwritten in the NiosII TLB.) I can make this into a debug message though instead. I'm not seeing this come out at all now that I've fixed my TLB implementation.
Review
Quoted 2 lines
(quoted diff) +2
-0+ default: + cpu_abort(dc->env, "Incorrect load size %d\n", size);
Maybe assert instead.
target-nios2/instruction.c
Quoted 10 lines
target-nios2/instruction.c new file +7
-0+break; +} +} +*/ + +/* I-Type instruction */ +struct i_type {
IType
target-nios2/instruction.h line 40
Quoted 5 lines
target-nios2/instruction.h new file +5
-0+ uint32_t op:6; + uint32_t imm16:16; + uint32_t b:5; + uint32_t a:5; +} __attribute__((packed));
QEMU_PACKED
Yep. I will change this and any others.
target-nios2/instruction.h line 271
Quoted 2 lines
target-nios2/instruction.h new file +2
-0+#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x)
We already have glue and stringify, no need to add another.
Ok, didn't see those. This was some of the bits I originally got from nios2sim-ng, but I can easily clean that up.
target-nios2/op_helper.c line 22
Quoted 2 lines
target-nios2/op_helper.c new file +2
-0+#include "cpu.h" +#include "dyngen-exec.h"
Remove.
target-nios2/op_helper.c line 45
Quoted 10 lines
target-nios2/op_helper.c new file +10
-0+ +void tlb_fill (CPUNios2State *env1,target_ulong addr,int is_write,int mmu_idx, +uintptr_t retaddr) +{ +TranslationBlock *tb; +CPUNios2State *saved_env; +int ret; + + saved_env = env; + env = env1;
References to global env should be removed, the CPU state should be passed around instead. Please check for example Sparc or recent commits to s390x.
Ok, I'll take a look at that example. Definitely good to get rid of globals.
-- Chris Wulff
Re: [Qemu-devel] [PATCH 1/9] NiosII: Add support for the Altera NiosII soft-core CPU.
In reply to Aurelien JarnoThanks for the feedback. I'll see about getting things updated once I have the chance. I wasn't too terribly concerned with performance as the target processor being emulated is much slower than the host (about 100MHz). Even the way things are now, Linux runs several times faster in emulation that it does on the actual target CPU.
Many of the optimizations you point out look pretty simple to incorporate so I will definitely see about doing that. I'll review the places you've pointed out where the translation vs. execution time CPU state is being mis-handled. It seems to be working, but those are definitely the types of things that will introduce hard to find bugs.
-- Chris Wulff
Quoted 267 lines
Quoted 6 lines
target-nios2/instruction.c new file +6
-0+static void gen_check_supervisor (DisasContext *dc,int label) +{ +int l1 =gen_new_label (); + +TCGv_i32 tmp =tcg_temp_new (); +tcg_gen_andi_tl (tmp, dc->cpu_R[CR_STATUS ],CR_STATUS_U );target-nios2/instruction.c line 86
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+tcg_gen_brcond_tl (TCG_COND_EQ , dc->cpu_R[R_ZERO ], tmp, l1); +t_gen_helper_raise_exception (dc,EXCP_SUPERI ); +tcg_gen_br (label); + +gen_set_label (l1); +tcg_temp_free_i32 (tmp); + +/* If we aren't taking the exception, update the PC to the +* next instruction */ +tcg_gen_movi_tl (dc->cpu_R[R_PC ], dc->pc+4 );You probably don't want to do that. It's quite expensive to have a branch in every priviledged instruction.
Given that
CR_STATUS_Uis use for the flags incpu_get_tb_cpu_state(), for a given value ofCR_STATUS_U, only TB with a correspondingCR_STATUS_Uwill be reused.For that you should copy
tb->flagsin DisasContext and use that instead.target-nios2/instruction.c line 92
Quoted 6 lines
target-nios2/instruction.c new file +6
-0+} + +static inline void gen_load_u (DisasContext *dc,TCGv dst,TCGv addr, +unsigned int size) +{ +int mem_index =cpu_mmu_index (dc->env);In general you should not use env in
instructions.c, unless it is for accessing a value that doesn't change during the execution (for example CPU features/capabilities), as there is no guarantee that the value will be the same when the TB is actually executed.In this case it should work correctly because
cpu_mmu_index()only accessCR_STATUS_Uwhich is in the TB flags, but it is technically wrong. Either makecpu_mmu_indexcheck the tb flags (see above to add them in DisasContext), or add amem_indexflag in DisasContext, computed from TB flags at the beginning ofgen_intermediate_code_internal.In the latter case, you might even remove these functions and directly call
tcg_gen_qemu_ldXXu(dst, addr, ctx->mem_index)when needed.Quoted 12 lines
target-nios2/instruction.c new file +12
-0+ +switch (size) { +case 1 : +tcg_gen_qemu_ld8u (dst, addr, mem_index); +break ; +case 2 : +tcg_gen_qemu_ld16u (dst, addr, mem_index); +break ; +case 4 : +tcg_gen_qemu_ld32u (dst, addr, mem_index); +break ; +default :target-nios2/instruction.c line 114
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+cpu_abort (dc->env,"Incorrect load size %d\n" , size); +break ; + } +} + +static inline void gen_load_s (DisasContext *dc,TCGv dst,TCGv addr, +unsigned int size) +{ +int mem_index =cpu_mmu_index (dc->env); +Ditto
Quoted 11 lines
target-nios2/instruction.c new file +11
-0+switch (size) { +case 1 : +tcg_gen_qemu_ld8s (dst, addr, mem_index); +break ; +case 2 : +tcg_gen_qemu_ld16s (dst, addr, mem_index); +break ; +case 4 : +tcg_gen_qemu_ld32s (dst, addr, mem_index); +break ; +default :target-nios2/instruction.c line 135
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+cpu_abort (dc->env,"Incorrect load size %d\n" , size); +break ; + } +} + +static inline void gen_store (DisasContext *dc,TCGv val,TCGv addr, +unsigned int size) +{ +int mem_index =cpu_mmu_index (dc->env); +Ditto
Quoted 8 lines
target-nios2/instruction.c new file +8
-0+switch (size) { +case 1 : +tcg_gen_qemu_st8 (val, addr, mem_index); +break ; +case 2 : +tcg_gen_qemu_st16 (val, addr, mem_index); +break ; +case 4 :target-nios2/instruction.c
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+tcg_gen_qemu_st32 (val, addr, mem_index); +break ; +default : +cpu_abort (dc->env,"Incorrect load size %d\n" , size); +break ; + } +} + +/* +* Used as a placeholder for all instructions which do not have an effect on the
Quoted 13 lines
+ * simulator (e.g. flush, sync)
+ */target-nios2/instruction.c new file +11
-0+static void nop (DisasContext *dc __attribute__((unused)), +uint32_t code __attribute__((unused))) +{ +/* Nothing to do here */ +} + +/* +* J-Type instructions +*/ + +/* target-nios2/instruction.c
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+* ra <- PC + 4 +* PC <- (PC(31..28) : IMM26 * 4) +*/ +static void call (DisasContext *dc,uint32_t code) +{ +J_TYPE (instr, code); + +#ifdef CALL_TRACING +TCGv_i32 tmp =tcg_const_i32 (dc->pc); + TCGv_i32 tmp2 = tcg_const_i32((dc->pc & 0xF0000000) | (instr->imm26* 4));
target-nios2/instruction.c line 188
Quoted 12 lines
target-nios2/instruction.c new file +12
-0+gen_helper_call_status (tmp, tmp2); +tcg_temp_free_i32 (tmp); +tcg_temp_free_i32 (tmp2); +#endif + +tcg_gen_movi_tl (dc->cpu_R[R_RA ], dc->pc +4 ); +tcg_gen_movi_tl (dc->cpu_R[R_PC ], + (dc->pc &0xF0000000 ) | (instr->imm26 *4 )); + + dc->is_jmp =DISAS_JUMP ; +} +You probably want to add some
tcg_gen_goto_tb()for static jumps, so that TB linking is possible. It greatly improves the speed of the emulation.Quoted 13 lines
target-nios2/instruction.c new file +13
-0+/* PC <- (PC(31..28) : IMM26 * 4) */ +static void jmpi (DisasContext *dc,uint32_t code) +{ +J_TYPE (instr, code); + +tcg_gen_movi_tl (dc->cpu_R[R_PC ], + (dc->pc &0xF0000000 ) | (instr->imm26 *4 )); + + dc->is_jmp =DISAS_JUMP ; +} + +/* +* I-Type instructions target-nios2/instruction.c line 211
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+*/ + +/* rB <- 0x000000 : Mem8[rA + @(IMM16)] */ +static void ldbu (DisasContext *dc,uint32_t code) +{ +I_TYPE (instr, code); + +TCGv addr =tcg_temp_new (); +tcg_gen_movi_tl (addr, (int32_t )((int16_t )instr->imm16)); +tcg_gen_add_tl (addr, dc->cpu_R[instr->a], addr);Minor nitpick: it's better to write:
tcg_gen_add_tl(addr, addr, dc->cpu_R[instr->a]);as the code generator on non-RISC hosts usually generate a slightly tiny better code.
Quoted 6 lines
target-nios2/instruction.c new file +6
-0+ +gen_load_u (dc, dc->cpu_R[instr->b], addr,1 ); + +tcg_temp_free (addr); +} +target-nios2/instruction.c line 227
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+/* rB <- rA + IMM16 */ +static void addi (DisasContext *dc,uint32_t code) +{ +I_TYPE (instr, code); + +TCGv imm =tcg_temp_new (); +tcg_gen_movi_tl (imm, (int32_t )((int16_t )instr->imm16)); + +tcg_gen_add_tl (dc->cpu_R[instr->b], dc->cpu_R[instr->a], imm); +You can also call
tcg_gen_addi_tl()instead, so that you don't need to load the constant by yourself. As a bonus the immediate = 0 case is optimized earlier in the code generation.target-nios2/instruction.c line 238
Quoted 11 lines
target-nios2/instruction.c new file +11
-0+tcg_temp_free (imm); +} + +/* Mem8[rA + @(IMM16)] <- rB(7..0) */ +static void stb (DisasContext *dc,uint32_t code) +{ +I_TYPE (instr, code); + +TCGv addr =tcg_temp_new (); +tcg_gen_movi_tl (addr, (int32_t )((int16_t )instr->imm16)); +tcg_gen_add_tl (addr, dc->cpu_R[instr->a], addr);Ditto
target-nios2/instruction.c
Quoted 9 lines
target-nios2/instruction.c new file +9
-0+/* rC <- rA rotated left IMM5 bit positions */ +static void roli (DisasContext *dc,uint32_t code) +{ +R_TYPE (instr, code); + +TCGv t0 =tcg_temp_new (); + +tcg_gen_shri_tl (t0, dc->cpu_R[instr->a],32 - instr->imm5); + tcg_gen_shli_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a],
instr->imm5);target-nios2/instruction.c line 845
Quoted 2 lines
target-nios2/instruction.c new file +2
-0+tcg_gen_or_tl (dc->cpu_R[instr->c], dc->cpu_R[instr->c], t0); +Looks like you want to use
tcg_gen_rotli, which is optimized on some hosts (like x86).Quoted 8 lines
target-nios2/instruction.c new file +8
-0+tcg_temp_free (t0); +} + +/* rC <- rA rotated left rB(4..0) bit positions */ +static void rol (DisasContext *dc,uint32_t code) +{ +R_TYPE (instr, code); +target-nios2/instruction.c line 863
Quoted 10 lines
target-nios2/instruction.c new file +10
-0+TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); + +tcg_gen_andi_tl (t0, dc->cpu_R[instr->b],31 ); +tcg_gen_movi_tl (t1,32 ); +tcg_gen_sub_tl (t1, t1, t0); +tcg_gen_shri_tl (t1, dc->cpu_R[instr->a], t1); +tcg_gen_shli_tl (dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0); +tcg_gen_or_tl (dc->cpu_R[instr->c], dc->cpu_R[instr->c], t1); +Same,
tcg_gen_rotlexists.--
Aurelien Jarno GPG: 1024D/F1BCDB73
[email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH 8/9] MicroBlaze: Add a config that is dynamically set up by a device tree file.
In reply to Peter CrosthwaiteI'm all for consolidating the different device-tree based "boards" as much as possible. This, the petalogix variant, and the NiosII one that I created as part of this patch set too, are all very similar. We just need some generic way to register the set of devices that can be created and then the walking of the device tree itself could probably be generic. I'd be happy to work with you to move in that direction.
The only thing that I ran into that is a bit different is that the NiosII declares the type of attached interrupt controller inside the CPU block and I ended up enumerating that as if the cpu were itself a bus.
-- Chris Wulff
Quoted 700 lines · Peter Crosthwaite
Hi Chris,
This needs to be reviewed along with the petalogix implementation, but a few top level comments.
Regards,
PeterQuoted 6 lines · On Sun, 2012-09-09 at 20:20 -0400, [email protected] wrote:
From: Chris Wulff <[email protected]>
Signed-off-by Chris Wulff <[email protected]>--- default-configs/microblaze-softmmu.mak | 1 + hw/labx_microblaze_devicetree.c | 597++++++++++++++++++++++++++++++++
Review
Quoted 5 lines
hw/microblaze/Makefile.objs | 3 +- 3 files changed, 600 insertions(+), 1 deletion(-) create mode 100644 hw/labx_microblaze_devicetree.c(quoted diff) +0
-0b/default-configs/microblaze-softmmu.mak
Review
Quoted 9 lines
index 64c9485..7e4cab8 100644
default-configs/microblaze-softmmu.mak +1
-0@@ -5,3 +5,4 @@ CONFIG_PFLASH_CFI01=y CONFIG_SERIAL=y CONFIG_XILINX=y CONFIG_XILINX_AXI=y +CONFIG_LABX=y(quoted diff) +0
-0
b/hw/labx_microblaze_devicetree.chw/labx_microblaze_devicetree.c line 2
Quoted 7 lines
new file mode 100644
index 0000000..581ad14hw/labx_microblaze_devicetree.c new file +2
-0@@ -0,0 +1,597 @@ +/* +* Flexible model of microblaze designs that use a device-tree to determine
Quoted 51 lines
hw/labx_microblaze_devicetree.c new file +51
-0+* the hardware configuration. +* +* Copyright (c) 2010 LabX Technologies, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#include "sysbus.h" +#include "hw.h" +#include "net.h" +#include "flash.h" +#include "sysemu.h" +#include "devices.h" +#include "boards.h" +#include "device_tree.h" +#include "xilinx.h" +#include "labx_devices.h" +#include "loader.h" +#include "elf.h" +#include "blockdev.h" +#include "exec-memory.h" +#include "microblaze_pic_cpu.h" + +#define LMB_BRAM_SIZE (128 * 1024) + +static struct +{ +uint32_t bootstrap_pc; +uint32_t cmdline; +uint32_t initrd; +uint32_t fdt; +} boot_info; + +/* Current ethernet device index for multiple network interfaces */ +static int eth_dev_index =-1 ; + +static void main_cpu_reset (void *opaque) +{ +MicroBlazeCPU *cpu = opaque;hw/labx_microblaze_devicetree.c line 63
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+CPUMBState *env = &cpu->env; + +cpu_reset (CPU (cpu)); + + env->regs[5 ] = boot_info.cmdline; + env->regs[6 ] = boot_info.initrd; + env->regs[7 ] = boot_info.fdt; + env->sregs[SR_PC ] = boot_info.bootstrap_pc; +} +Please use microblaze bootloader (
hw/microblaze_boot.c). We need to consolidate bootloaders. If there is functionality missing frommb_boot, please add it there.hw/labx_microblaze_devicetree.c line 67
Quoted 4 lines
hw/labx_microblaze_devicetree.c new file +4
-0+#ifndef CONFIG_FDT +#error "Device-tree support is required for this target to function" +#endif +This should be handled by the make infrastructure. This machine model should be obj-(CONIFG_FDT)+= .. so this machine model just dissappears when QEMU is build without FDT.
Quoted 16 lines
hw/labx_microblaze_devicetree.c new file +16
-0+static uint32_t fdt_get_int_from_array (void *fdt,int node, +const char *name,int index) +{ +int array_length; +const void *array =qemu_devtree_getprop_offset (fdt, node, name, + &array_length); +if (index >= array_length) { +printf ("fdt_get_int_from_array: requesting %s from node %d, " +"index %d out of range (%d max)\n" , + name, node, index, array_length); +return 0 ; + }else { +return qemu_devtree_int_array_index (array, index); + } +} +hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+#define BINARY_DEVICE_TREE_FILE "labx-microblaze.dtb" +static void *get_device_tree (int *fdt_size) +{ +char *path; +void *fdt; + +/* Try the local "mb.dtb" override. */ + fdt =load_device_tree ("mb.dtb" , fdt_size); +if (!fdt) { + path = qemu_find_file(QEMU_FILE_TYPE_BIOS,
BINARY_DEVICE_TREE_FILE);Quoted 36 lines
hw/labx_microblaze_devicetree.c new file +36
-0+if (path) { + fdt =load_device_tree (path, fdt_size); +g_free (path); + } + } + +return fdt; +} + +static int labx_microblaze_load_device_tree (target_phys_addr_t addr, +uint32_t ramsize, +target_phys_addr_t initrd_base, +target_phys_addr_t initrd_size, +const char *kernel_cmdline) +{ +int fdt_size; +void *fdt; +int r; + + fdt =get_device_tree (&fdt_size); + +if (!fdt) { +return 0 ; + } + +if (kernel_cmdline &&strlen (kernel_cmdline)) { + r =qemu_devtree_setprop_string (fdt,"/chosen" ,"bootargs" , + kernel_cmdline); +if (r <0 ) { +fprintf (stderr,"couldn't set /chosen/bootargs\n" ); + } + } +cpu_physical_memory_write (addr, (void *)fdt, fdt_size); + +return fdt_size; +}hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ +static uint64_t translate_kernel_address (void *opaque,uint64_t addr) +{ +return addr -0x30000000LL ; +} + +static ram_addr_t get_dram_base (void *fdt) +{ +int root =qemu_devtree_node_offset (fdt,"/" ); + int memory = qemu_devtree_subnode_offset_namelen(fdt, root,"memory", 6);
Quoted 30 lines
hw/labx_microblaze_devicetree.c new file +30
-0+if (memory >0 ) { +int reglen; +const void *reg = +qemu_devtree_getprop_offset (fdt, memory,"reg" , ®len); + +if (reglen >=4 ) { +printf ("DRAM base %08X, size %08X\n" , +qemu_devtree_int_array_index (reg,0 ), +qemu_devtree_int_array_index (reg,1 )); +return qemu_devtree_int_array_index (reg,0 ); + } + } + +printf ("DRAM base not found. Defaulting to 0x88000000\n" ); + +return 0x88000000 ;/* Default to something reasonable */ +} + +typedef void (*device_init_func_t )(void *fdt,int node); + +typedef struct { +device_init_func_t probe; +int pass; +const char **compat; + +}devinfo_t ; + +/* +* Xilinx interrupt controller device +*/ hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+MicroBlazeCPU *g_cpu; +static qemu_irq irq[32 ] = {}; +static qemu_irq *cpu_irq; + +static void xilinx_interrupt_controller_probe (void *fdt,int node) +{ +int i; +DeviceState *dev; +int reglen; + const void *reg = qemu_devtree_getprop_offset(fdt, node, "reg",®len);
Quoted 19 lines
hw/labx_microblaze_devicetree.c new file +19
-0+uint32_t irq_addr =qemu_devtree_int_array_index (reg,0 ); +int nrIrqLen; +const void *nrIrq = +qemu_devtree_getprop_offset (fdt, node,"xlnx,num-intr-inputs" , + &nrIrqLen); +uint32_t nrIrqs =qemu_devtree_int_array_index (nrIrq,0 ); + +printf (" IRQ BASE %08X NIRQS %d\n" , irq_addr, nrIrqs); + + cpu_irq =microblaze_pic_init_cpu (&g_cpu->env); + dev =xilinx_intc_create (irq_addr, cpu_irq[0 ],2 ); +for (i =0 ; i < nrIrqs; i++) { + irq[i] =qdev_get_gpio_in (dev, i); + } +} + +devinfo_t xilinx_interrupt_controller_device = { + .probe = &xilinx_interrupt_controller_probe, + .pass =0 ,hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ .compat = (const char * []) { "xlnx,xps-intc-1.00.a", NULL } +}; + +/* +* Flash device +*/ +static void flash_probe (void *fdt,int node) +{ +int reglen; + const void *reg = qemu_devtree_getprop_offset(fdt, node, "reg",®len);
hw/labx_microblaze_devicetree.c
Quoted 6 lines
hw/labx_microblaze_devicetree.c new file +6
-0+uint32_t flash_addr =qemu_devtree_int_array_index (reg,0 ); +uint32_t flash_size =qemu_devtree_int_array_index (reg,1 ); + +DriveInfo *dinfo =drive_get (IF_PFLASH ,0 ,0 ); + pflash_cfi01_register(flash_addr, NULL, + qemu_devtree_get_name(fdt, node, NULL),
flash_size,Quoted 12 lines
hw/labx_microblaze_devicetree.c new file +12
-0+ dinfo ? dinfo->bdrv :NULL , (64 *1024 ), + flash_size >>16 , + 1, 0x89, 0x18, 0x0000, 0x0, 1); +printf ("-- loaded %d bytes to %08X\n" , +load_image_targphys (qemu_devtree_get_name (fdt, node,NULL ), + flash_addr, flash_size), + flash_addr); +} + +devinfo_t flash_device = { + .probe = &flash_probe, + .pass =1 ,hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ .compat = (const char * []) { "cfi-flash", NULL } +}; + +/* +* Xilinx timer device +*/ +static void xilinx_timer_probe (void *fdt,int node) +{ +uint32_t timer_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + uint32_t timer_irq = fdt_get_int_from_array(fdt, node,"interrupts", 0);
hw/labx_microblaze_devicetree.c line 241
Quoted 5 lines
hw/labx_microblaze_devicetree.c new file +5
-0+ +printf (" TIMER BASE %08X IRQ %d\n" , timer_addr, timer_irq); + +/* 2 timers at irq 2 @ 62 Mhz. */ +xilinx_timer_create (timer_addr, irq[timer_irq],0 ,62 *1000000 );No check is made for the
one_timer_onlyproperty.Quoted 5 lines
hw/labx_microblaze_devicetree.c new file +5
-0+} + +devinfo_t xilinx_timer_device = { + .probe = &xilinx_timer_probe, + .pass =1 ,hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ .compat = (const char * []) { "xlnx,xps-timer-1.00.a", NULL } +}; + +/* +* Xilinx uartlite device +*/ +static void xilinx_uartlite_probe (void *fdt,int node) +{ +uint32_t uart_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + uint32_t uart_irq = fdt_get_int_from_array(fdt, node, "interrupts",0);
Quoted 9 lines
hw/labx_microblaze_devicetree.c new file +9
-0+ +printf (" UART BASE %08X IRQ %d\n" , uart_addr, uart_irq); + +sysbus_create_simple ("xlnx.xps-uartlite" , uart_addr, irq[uart_irq]); +} + +devinfo_t xilinx_uartlite_device = { + .probe = &xilinx_uartlite_probe, + .pass =1 ,hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ .compat = (const char * []) { "xlnx,xps-uartlite-1.00.a", NULL } +}; + +/* +* Xilinx ethernetlite device +*/ +static void xilinx_ethlite_probe (void *fdt,int node) +{ +uint32_t eth_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + uint32_t eth_irq = fdt_get_int_from_array(fdt, node, "interrupts",0);
Quoted 7 lines
hw/labx_microblaze_devicetree.c new file +7
-0+ +xilinx_ethlite_create (&nd_table[++eth_dev_index], eth_addr, + irq[eth_irq],0 ,0 ); +} + +devinfo_t xilinx_ethlite_device = { + .probe = &xilinx_ethlite_probe,hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ .pass = 1, + .compat = (const char * []) { "xlnx,xps-ethernetlite-2.00.b", NULL } +}; + +/* +* LabX audio packetizer device +*/ +static void labx_audio_packetizer_probe (void *fdt,int node) +{ + uint32_t packetizer_addr = fdt_get_int_from_array(fdt, node, "reg",0);
Quoted 5 lines
hw/labx_microblaze_devicetree.c new file +5
-0+uint32_t packetizer_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); +uint32_t clock_domains = +fdt_get_int_from_array (fdt, node,"xlnx,num-clock-domains" ,0 ); + uint32_t cache_words =hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+fdt_get_int_from_array (fdt, node,"xlnx,cache-data-words" ,0 ); + +labx_audio_packetizer_create (packetizer_addr, irq[packetizer_irq], + clock_domains, cache_words); +} + +devinfo_t labx_audio_packetizer_device = { + .probe = &labx_audio_packetizer_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,labx-audio-packetizer-1.00.a" ,NULL }
hw/labx_microblaze_devicetree.c
Quoted 8 lines
hw/labx_microblaze_devicetree.c new file +8
-0+}; + +/* +* LabX audio depacketizer device +*/ +static void labx_audio_depacketizer_probe (void *fdt,int node) +{ + uint32_t depacketizer_addr = fdt_get_int_from_array(fdt, node,"reg", 0);
hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+uint32_t depacketizer_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); +uint32_t clock_domains = +fdt_get_int_from_array (fdt, node,"xlnx,num-clock-domains" ,0 ); +uint32_t cache_words = +fdt_get_int_from_array (fdt, node,"xlnx,cache-data-words" ,0 ); + +int ifLen; +const void *ifType = + qemu_devtree_getprop_offset(fdt, node, "xlnx,interface-type",&ifLen);
hw/labx_microblaze_devicetree.c line 326
Quoted 1 line
hw/labx_microblaze_devicetree.c new file +1
-0+ int hasDMA = (0 != strncmp("CACHE_RAM", (const char *)ifType,ifLen));
hw/labx_microblaze_devicetree.c line 328
Quoted 2 lines
hw/labx_microblaze_devicetree.c new file +2
-0+ + labx_audio_depacketizer_create(depacketizer_addr,irq[depacketizer_irq],
Quoted 30 lines
hw/labx_microblaze_devicetree.c new file +30
-0+ clock_domains, cache_words, hasDMA); +} + +devinfo_t labx_audio_depacketizer_device = { + .probe = &labx_audio_depacketizer_probe, + .pass =1 , + .compat = (const char * []) { +"xlnx,labx-audio-depacketizer-1.00.a" , +"xlnx,labx-audio-depacketizer-1.01.a" , +NULL + } +}; + +/* +* LabX dma device +*/ +static void labx_dma_probe (void *fdt,int node) +{ +uint32_t dma_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + +labx_dma_create (dma_addr,1024 ); +} + +devinfo_t labx_dma_device = { + .probe = &labx_dma_probe, + .pass =1 , + .compat = (const char * []) { +"xlnx,labx-dma-1.00.a" , +"xlnx,labx-dma-1.01.a" , +"xlnx,labx-local-audio-1.00.a" ,hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ NULL + } +}; + +/* +* LabX ethernet device +*/ +static void labx_ethernet_probe (void *fdt,int node) +{ + uint32_t ethernet_addr = fdt_get_int_from_array(fdt, node, "reg",0);
Quoted 41 lines
hw/labx_microblaze_devicetree.c new file +41
-0+uint32_t host_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); +uint32_t fifo_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,2 ); +uint32_t phy_irq = +fdt_get_int_from_array (fdt, node,"interrupts" ,4 ); + +labx_ethernet_create (&nd_table[++eth_dev_index], ethernet_addr, + irq[host_irq], irq[fifo_irq], irq[phy_irq]); +} + +devinfo_t labx_ethernet_device = { + .probe = &labx_ethernet_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,labx-ethernet-1.00.a" ,NULL } +}; + +/* +* LabX ptp device +*/ +static void labx_ptp_probe (void *fdt,int node) +{ +uint32_t ptp_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); + +labx_ptp_create (ptp_addr); +} + +devinfo_t labx_ptp_device = { + .probe = &labx_ptp_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,labx-ptp-1.00.a" ,NULL } +}; + +/* +* Table of available devices +*/ +devinfo_t *devices[] = { + &xilinx_interrupt_controller_device, + &flash_device, + &xilinx_timer_device, + &xilinx_uartlite_device,hw/labx_microblaze_devicetree.c line 419
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ &xilinx_ethlite_device, + &labx_audio_packetizer_device, + &labx_audio_depacketizer_device, + &labx_dma_device, + &labx_ethernet_device, + &labx_ptp_device, + NULL +}; + +static int plb_device_probe (void *fdt,int node,int pass)QEMU abstacts away interconnect implementations. You should probably also drive off the "simple-bus" compat rather than PLB for machine model compatibility. s/plb/bus/g or something like it.
hw/labx_microblaze_devicetree.c
Quoted 7 lines
hw/labx_microblaze_devicetree.c new file +7
-0+{ + devinfo_t **dev = &(devices[0]); + + while (*dev) { + const char **compat = &((*dev)->compat[0]); + while (*compat) { + if (0 == qemu_devtree_node_check_compatible(fdt, node,*compat)) {
Quoted 19 lines
hw/labx_microblaze_devicetree.c new file +19
-0+if (pass == (*dev)->pass) { +printf ("Adding a device for node %s\n" , +qemu_devtree_get_name (fdt, node,NULL )); + + (*dev)->probe (fdt, node); +return 0 ; + } + +if (pass < (*dev)->pass) { +/* Probe again on the next pass */ +return 1 ; + } + } + + compat++; + } + + dev++; + }hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ +return 0 ; +} + +static void plb_bus_probe (void *fdt) +{ +int root =qemu_devtree_node_offset (fdt,"/" ); +int plb =qemu_devtree_subnode_offset_namelen (fdt, root,"plb" ,3 ); +if (plb >0 ) { +/* Do multiple passes through the devices. Some have dependencies
Quoted 38 lines
hw/labx_microblaze_devicetree.c new file +38
-0+on others being first */ +int pass =0 ; +int again =0 ; +do { +int child = plb; + again =0 ; +do { + child =qemu_devtree_next_child_offset (fdt, plb, child); +if (child <0 ) { +break ; + } + + again |=plb_device_probe (fdt, child, pass); + + }while (1 ); + + pass++; + + }while (again); + } +} + +static void +labx_microblaze_init (ram_addr_t ram_size, +const char *boot_device, +const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename, +const char *cpu_model) +{ +MemoryRegion *address_space_mem =get_system_memory (); + +int kernel_size; +int fdt_size; +void *fdt =get_device_tree (&fdt_size); +target_phys_addr_t ddr_base =get_dram_base (fdt); +MemoryRegion *phys_lmb_bram =g_new (MemoryRegion,1 ); +MemoryRegion *phys_ram =g_new (MemoryRegion,1 );hw/labx_microblaze_devicetree.c line 503
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+CPUMBState *env; + +/* init CPUs */ +if (cpu_model ==NULL ) { + cpu_model ="microblaze" ; + } + g_cpu =cpu_mb_init (cpu_model); + env = &g_cpu->env; + + env->pvr.regs[10 ] =0x0c000000 ;/* spartan 3a dsp family. */ I have dtb driven solution for this.
hw/labx_microblaze_devicetree.c
Quoted 3 lines
hw/labx_microblaze_devicetree.c new file +3
-0+qemu_register_reset (main_cpu_reset, g_cpu); + +/* Attach emulated BRAM through the LMB. LMB size is not specified in the
hw/labx_microblaze_devicetree.c
Quoted 5 lines
hw/labx_microblaze_devicetree.c new file +5
-0+device-tree but there must be one to hold the vector table. */ +memory_region_init_ram (phys_lmb_bram,"labx_microblaze.lmb_bram" , +LMB_BRAM_SIZE ); +vmstate_register_ram_global (phys_lmb_bram); + memory_region_add_subregion(address_space_mem, 0x00000000,
phys_lmb_bram);Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ +memory_region_init_ram (phys_ram,"labx_microblaze.ram" , ram_size); +vmstate_register_ram_global (phys_ram); +memory_region_add_subregion (address_space_mem, ddr_base, phys_ram); + + +/* Create other devices listed in the device-tree */ +plb_bus_probe (fdt); + +if (kernel_filename) {hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+uint64_t entry, low, high; +uint32_t base32; + +/* Boots a kernel elf binary. */ + kernel_size =load_elf (kernel_filename,NULL ,NULL , + &entry, &low, &high, +1 ,ELF_MACHINE ,0 ); + base32 = entry; +if (base32 ==0xc0000000 ) { + kernel_size = load_elf(kernel_filename,
translate_kernel_address,hw/labx_microblaze_devicetree.c
Quoted 11 lines
hw/labx_microblaze_devicetree.c new file +11
-0+NULL , &entry,NULL ,NULL , + 1, ELF_MACHINE, 0); + } +/* Always boot into physical ram. */ + boot_info.bootstrap_pc = ddr_base + (entry &0x07ffffff ); + +/* If it wasn't an ELF image, try an u-boot image. */ +if (kernel_size <0 ) { +target_phys_addr_t uentry, loadaddr; + + kernel_size = load_uimage(kernel_filename, &uentry,&loadaddr, 0);
Quoted 9 lines
hw/labx_microblaze_devicetree.c new file +9
-0+ boot_info.bootstrap_pc = uentry; + high = (loadaddr + kernel_size +3 ) & ~3 ; + } + +/* Not an ELF image nor an u-boot image, try a RAW image. */ +if (kernel_size <0 ) { + kernel_size =load_image_targphys (kernel_filename, ddr_base, + ram_size); + boot_info.bootstrap_pc = ddr_base;hw/labx_microblaze_devicetree.c
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ high = (ddr_base + kernel_size +3 ) & ~3 ; + } + +if (initrd_filename) { +uint32_t initrd_base =0x88c00000 ; +uint32_t initrd_size = +load_image_targphys (initrd_filename, initrd_base, + ram_size - initrd_base); +if (initrd_size <=0 ) { + fprintf(stderr, "qemu: could not load initial ram disk'%s'\n",
hw/labx_microblaze_devicetree.c
Quoted 12 lines
hw/labx_microblaze_devicetree.c new file +12
-0+ initrd_filename); +exit (1 ); + } + + boot_info.initrd = initrd_base; + }else { + boot_info.initrd =0x00000000 ; + } + + boot_info.cmdline = high +4096 ; +if (kernel_cmdline &&strlen (kernel_cmdline)) { + pstrcpy_targphys("cmdline", boot_info.cmdline, 256,
kernel_cmdline);hw/labx_microblaze_devicetree.c line 583
Quoted 10 lines
hw/labx_microblaze_devicetree.c new file +10
-0+ } +/* Provide a device-tree. */ + boot_info.fdt = boot_info.cmdline +4096 ; +labx_microblaze_load_device_tree (boot_info.fdt, ram_size, +0 ,0 , + kernel_cmdline); + } +} + +static QEMUMachine labx_microblaze_machine = {Its a generic machine, so should it be badged as labx?
Quoted 20 lines
hw/labx_microblaze_devicetree.c new file +14
-0+ .name = "labx-microblaze-devicetree", + .desc ="Microblaze design based on the peripherals specified " + "in the device-tree.", + .init = labx_microblaze_init, + .is_default =1 +}; + +static void labx_microblaze_machine_init (void ) +{ +qemu_register_machine (&labx_microblaze_machine); +} + +machine_init (labx_microblaze_machine_init); +hw/microblaze/Makefile.objs +0
-0hw/microblaze/Makefile.objs line 1
Quoted 2 lines
hw/microblaze/Makefile.objs +1
-1@@ -1,4 +1,5 @@ -obj-y = petalogix_s3adsp1800_mmu.o +obj-y = labx_microblaze_devicetree.oobj-y += labx_microblaze_devicetree.(CONFIG-FDT)
Quoted 4 lines
hw/microblaze/Makefile.objs +1
-0+obj-y += petalogix_s3adsp1800_mmu.o obj-y += petalogix_ml605_mmu.o obj-y += microblaze_boot.o
Re: [Qemu-devel] [PATCH 8/9] MicroBlaze: Add a config that is dynamically set up by a device tree file.
In reply to Peter CrosthwaiteQuoted 18 lines · Peter Crosthwaite
Quoted 16 lines · Blue Swirl
hw/labx_microblaze_devicetree.c line 278
Quoted 12 lines · On Mon, Sep 10, 2012 at 12:20 AM, <[email protected]> wrote:
From: Chris Wulff <[email protected]>
hw/labx_microblaze_devicetree.c new file +10
-0+/* +* Xilinx ethernetlite device +*/ +static void xilinx_ethlite_probe (void *fdt,int node) +{ +uint32_t eth_addr =fdt_get_int_from_array (fdt, node,"reg" ,0 ); +uint32_t eth_irq =fdt_get_int_from_array (fdt, node,"interrupts" ,0 ); + +xilinx_ethlite_create (&nd_table[++eth_dev_index], eth_addr, + irq[eth_irq],0 ,0 );The device should not access
nd_table, this should be handled at board level.
Quoted 4 lines
This is board level isn't it? This function calls
xilinx_ethlite_create()which in turn does theqdev_createso this is pre device creation. Im open to suggestions on how to do this in a non-global hacking way however as I have the same problem in my tree.
OK, the device code is mixed with the board code and that was confusing me. It could be better to move the device part to a separate file.
Quoted 14 lines
Regards,
PeterQuoted 8 lines
Quoted 8 lines
hw/labx_microblaze_devicetree.c new file +8
-0+} + +devinfo_t xilinx_ethlite_device = { + .probe = &xilinx_ethlite_probe, + .pass =1 , + .compat = (const char * []) {"xlnx,xps-ethernetlite-2.00.b" ,NULL } +}; +
Re: [Qemu-devel] [PATCH 1/9] NiosII: Add support for the Altera NiosII soft-core CPU.
In reply to [email protected]Am 10.09.2012 02:19, schrieb [email protected]:
Quoted 12 lines
From: Chris Wulff <[email protected]>
Signed-off-by Chris Wulff <[email protected]>--- target-nios2/Makefile.objs | 5 + target-nios2/altera_iic.c | 100 +++ target-nios2/cpu-qom.h | 69 +++ target-nios2/cpu.c | 83 +++ target-nios2/cpu.h | 259 ++++++++ target-nios2/exec.h | 60 ++ target-nios2/helper.c | 291 +++++++++ target-nios2/helper.h | 45 ++
Quoted 8 lines
target-nios2/instruction.c | 1463 ++++++++++++++++++++++++++++++++++++++++++++ target-nios2/instruction.h | 290 +++++++++ target-nios2/machine.c | 33 + target-nios2/mmu.c | 273 +++++++++ target-nios2/mmu.h | 49 ++ target-nios2/op_helper.c | 125 ++++ target-nios2/translate.c | 252 ++++++++ 15 files changed, 3397 insertions(+)
Some general comments: You're introducing a new target here, so if you design your API cleanly (using Nios2CPU where possible) you don't really need a separate cpu-qom.h file in addition to cpu.h, cf. target-or32.
Please prefer passing Nios2CPU as opaque rather than CPUNios2State (e.g., 3/9; cf. target-arm). Reason is that fields are being moved from CPUxxxState to CPUState and this will simplify the migration.
Thanks,
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
Re: [Qemu-devel] [PATCH 3/9] Altera: Add support for Altera devices required to boot linux on NiosII.
In reply to Blue SwirlAm 11.09.2012 21:53, schrieb Blue Swirl:
Quoted 29 lines · On Mon, Sep 10, 2012 at 12:20 AM, <[email protected]> wrote:
Quoted 27 lines
hw/nios2_pic_cpu.c new file +21
-0@@ -0,0 +1,48 @@ +/* +* QEMU Altera Nios II CPU interrupt wrapper logic. +* +* Copyright (c) 2012 Chris Wulff <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +* <http://www.gnu.org/licenses/lgpl-2.1.html> +*/ + +#include "hw.h"
Quoted 1 line
hw/nios2_pic_cpu.c line 22
Quoted 1 line
hw/nios2_pic_cpu.c new file +1
-0+#include "pc.h"
Why?
Quoted 9 lines
hw/nios2_pic_cpu.c line 31
Quoted 9 lines
hw/nios2_pic_cpu.c new file +9
-0+#include "nios2.h" + +void pic_info (Monitor *mon) +{ +} + +void irq_info (Monitor *mon) +{ +}
Thought these stubs were no longer necessary...
Quoted 6 lines
hw/nios2_pic_cpu.c line 35
Quoted 4 lines
hw/nios2_pic_cpu.c new file +4
-0+ +static void nios2_pic_cpu_handler (void *opaque,int irq,int level) +{ +CPUNios2State *env = (CPUNios2State *)opaque;Useless cast in C.
Please use Nios2CPU so that we can more easily make cpu_interrupt() and cpu_reset_interrupt() take a CPUState argument in the future.
Please also split this patch up per device and always cc the appropriate maintainers to facilitate review (e.g., --cc-cmd="scripts/get_maintainer.pl --nogit-fallback").
Regards,
Andreas
Quoted 14 lines
Quoted 14 lines
hw/nios2_pic_cpu.c new file +13
-0+int type = irq ?CPU_INTERRUPT_NMI :CPU_INTERRUPT_HARD ; + +if (level) { +cpu_interrupt (env, type); + }else { +cpu_reset_interrupt (env, type); + } +} + +qemu_irq *nios2_pic_init_cpu (CPUNios2State *env) +{ +return qemu_allocate_irqs (nios2_pic_cpu_handler, env,2 ); +}
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
Re: [Qemu-devel] [PATCH 1/9] NiosII: Add support for the Altera NiosII soft-core CPU.
In reply to Aurelien JarnoQuoted 5 lines · Aurelien Jarno
Quoted 3 lines · On Sun, Sep 09, 2012 at 08:19:59PM -0400, [email protected] wrote:
From: Chris Wulff <[email protected]>
Signed-off-by Chris Wulff <[email protected]>
Quoted 14 lines
target-nios2/instruction.c line 188
Quoted 7 lines
target-nios2/instruction.c new file +7
-0+tcg_gen_movi_tl (dc->cpu_R[R_RA ], dc->pc +4 ); +tcg_gen_movi_tl (dc->cpu_R[R_PC ], + (dc->pc &0xF0000000 ) | (instr->imm26 *4 )); + + dc->is_jmp =DISAS_JUMP ; +} +You probably want to add some
tcg_gen_goto_tb()for static jumps, so that TB linking is possible. It greatly improves the speed of the emulation.
Doing this actually made quite a big difference. The reported bogomips from linux went up 15x and the observable speed by about 2x. The rest of your suggested changes didn't have much noticeable effect but were at least good things to clean up anyway.
-- Chris Wulff