qemu/kvm: E500 core emulation
PATCH 2/5 qemu/kvm: E500 core emulation
--- hw/ppce500.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppce500.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 0 deletions(-) create mode 100644 hw/ppce500.c create mode 100644 hw/ppce500.h
hw/ppce500.c new file +74 -0
@@ -0,0 +1,74 @@ +/* +* Qemu PowerPC E500 core emualtion +* +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. +* +* Author: Yu Liu, <[email protected]> +* +* This file is derived from hw/ppc440.c +* the copyright for that material belongs to the original owners. +* +* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include "hw.h" +#include "pc.h" +#include "hw/isa.h" +#include "ppce500.h" +#include "sysemu.h" + +#define PPCE500_SERIAL0_REGS 0x4500 +#define PPCE500_SERIAL1_REGS 0x4600 +#define PPCE500_MPIC_REGS 0x40000 +#define bytes_to_mb (a) (a>>20) + +CPUState *ppce500_init (ram_addr_t *ram_size, +qemu_irq **pic, +target_ulong ccsrbar_base) +{ +qemu_irq *mpic_irq, *irqs; +SerialState * serial[2 ]; +int ram_stick_sizes[] = {512 <<20 ,256 <<20 };/* in bytes */ +int i; +ram_addr_t tmp_ram_size; +CPUState *env; + +/* Setup Memory */ + tmp_ram_size = *ram_size; + +for (i=0 ; i<(sizeof (ram_stick_sizes)/sizeof (ram_stick_sizes[0 ])); i++) +while ((tmp_ram_size/ram_stick_sizes[i]) >0 ) + tmp_ram_size -= ram_stick_sizes[i]; + +if (tmp_ram_size) + *ram_size -= tmp_ram_size; + + env =cpu_ppc_init ("e500v2_v30" ); +if (!env) { +fprintf (stderr,"Unable to initilize CPU!\n" ); +exit (1 ); + } + +/* mpic */ + irqs =qemu_mallocz (sizeof (qemu_irq) *MPIC_OUTPUT_NB ); + irqs[MPIC_OUTPUT_INT ] = ((qemu_irq *)env->irq_inputs)[PPCE500_INPUT_INT ]; + irqs[MPIC_OUTPUT_CINT ] = ((qemu_irq *)env->irq_inputs)[PPCE500_INPUT_CINT ]; + mpic_irq =mpic_init (ccsrbar_base +PPCE500_MPIC_REGS ,1 , &irqs,NULL ); + *pic = mpic_irq; + +/* serial */ +if (serial_hds[0 ]) + serial[0 ] =serial_mm_init (ccsrbar_base +PPCE500_SERIAL0_REGS , +0 , mpic_irq[12 +26 ],399193 , + serial_hds[0 ],1 ); + +if (serial_hds[1 ]) + serial[0 ] =serial_mm_init (ccsrbar_base +PPCE500_SERIAL1_REGS , +0 , mpic_irq[12 +26 ],399193 , + serial_hds[0 ],1 ); + +return env; +}
hw/ppce500.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
1.5.4
Quoted 14 lines · Liu Yu
Signed-off-by Liu Yu <[email protected]>--- hw/ppce500.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppce500.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 0 deletions(-) create mode 100644 hw/ppce500.c create mode 100644 hw/ppce500.hhw/ppce500.c new file +0
-0
hw/ppce500.c line 9
Quoted 9 lines
hw/ppce500.c new file +9
-0@@ -0,0 +1,74 @@ +/* +* Qemu PowerPC E500 core emualtion +* +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. +* +* Author: Yu Liu, <[email protected]> +* +* This file is derived from hw/ppc440.c +* the copyright for that material belongs to the original owners.
I guess you based this off an old version of ppc440.c, which isn't good because I improved that code a lot when merging in to qemu.
Quoted 14 lines
hw/ppce500.c new file +14
-0+* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include "hw.h" +#include "pc.h" +#include "hw/isa.h" +#include "ppce500.h" +#include "sysemu.h" + +#define PPCE500_SERIAL0_REGS 0x4500 +#define PPCE500_SERIAL1_REGS 0x4600
hw/ppce500.c line 34
Quoted 10 lines
hw/ppce500.c new file +10
-0+#define PPCE500_MPIC_REGS 0x40000 +#define bytes_to_mb (a) (a>>20) + +CPUState *ppce500_init (ram_addr_t *ram_size, +qemu_irq **pic, +target_ulong ccsrbar_base) +{ +qemu_irq *mpic_irq, *irqs; +SerialState * serial[2 ]; +int ram_stick_sizes[] = {512 <<20 ,256 <<20 };/* in bytes */
Your memory controller only supports 512M and 256M?
hw/ppce500.c line 47
Quoted 13 lines
hw/ppce500.c new file +13
-0+int i; +ram_addr_t tmp_ram_size; +CPUState *env; + +/* Setup Memory */ + tmp_ram_size = *ram_size; + +for (i=0 ; i<(sizeof (ram_stick_sizes)/sizeof (ram_stick_sizes[0 ])); i++) +while ((tmp_ram_size/ram_stick_sizes[i]) >0 ) + tmp_ram_size -= ram_stick_sizes[i]; + +if (tmp_ram_size) + *ram_size -= tmp_ram_size;
This code was all refactored into a much nicer form. Look at ppc4xx_sdram_adjust(), and rename it if you need it too.
Quoted 16 lines
hw/ppce500.c new file +16
-0+ env =cpu_ppc_init ("e500v2_v30" ); +if (!env) { +fprintf (stderr,"Unable to initilize CPU!\n" ); +exit (1 ); + } + +/* mpic */ + irqs =qemu_mallocz (sizeof (qemu_irq) *MPIC_OUTPUT_NB ); + irqs[MPIC_OUTPUT_INT ] = ((qemu_irq *)env->irq_inputs)[PPCE500_INPUT_INT ]; + irqs[MPIC_OUTPUT_CINT ] = ((qemu_irq *)env->irq_inputs)[PPCE500_INPUT_CINT ]; + mpic_irq =mpic_init (ccsrbar_base +PPCE500_MPIC_REGS ,1 , &irqs,NULL ); + *pic = mpic_irq; + +/* serial */ +if (serial_hds[0 ]) + serial[0] = serial_mm_init(ccsrbar_base + PPCE500_SERIAL0_REGS,
hw/ppce500.c line 74
Quoted 10 lines
hw/ppce500.c new file +10
-0+0 , mpic_irq[12 +26 ],399193 , + serial_hds[0], 1); + +if (serial_hds[1 ]) + serial[0 ] =serial_mm_init (ccsrbar_base +PPCE500_SERIAL1_REGS , +0 , mpic_irq[12 +26 ],399193 , + serial_hds[0 ],1 ); + +return env; +}
e500 is a core, but the code you have here is initializing chip state. These should be separated.
Quoted 32 lines
hw/ppce500.h new file +26
-0@@ -0,0 +1,66 @@ +/* +* QEMU PowerPC E500 emulation shared definitions +* +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. +* +* Author: Yu Liu, <[email protected]> +* +* This file is derived from hw/ppc440.h +* the copyright for that material belongs to the original owners. +* +* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#if !defined(PPC_E500_H ) +#define PPC_E500_H + +#include "hw.h" +#include "pc.h" +#include "qemu-timer.h" +#include "sysemu.h" +#include "exec-all.h" +#include "boards.h" +
hw/ppce500.h line 36
Quoted 10 lines
hw/ppce500.h new file +10
-0+/* PowerPC E500 XXX initialization */ +extern CPUState *ppce500_init (ram_addr_t *ram_size, +qemu_irq **pic, +target_ulong ccsrbar_base); + +enum { +PPCUIC_OUTPUT_INT =0 , +PPCUIC_OUTPUT_CINT =1 , +PPCUIC_OUTPUT_NB , +};
UIC is the name of the 4xx interrupt controller, so I suspect this isn't actually used in you code.
Quoted 19 lines
hw/ppce500.h new file +19
-0+struct pci_outbound { +uint32_t potar; +uint32_t potear; +uint32_t powbar; +uint32_t powar; +}; + +struct pci_inbound { +uint32_t pitar; +uint32_t piwbar; +uint32_t piwbear; +uint32_t piwar; +}; + +PCIBus *ppce500_pci_init (qemu_irq *pic,target_phys_addr_t registers); + +/* mpic.c */ +/* MPIC have 5 outputs per CPU connected and one IRQ out single output */ +enum {
hw/ppce500.h line 66
Quoted 10 lines
hw/ppce500.h new file +10
-0+MPIC_OUTPUT_INT =0 ,/* IRQ */ +MPIC_OUTPUT_CINT ,/* critical IRQ */ +MPIC_OUTPUT_MCK ,/* Machine check event */ +MPIC_OUTPUT_DEBUG ,/* Inconditional debug event */ +MPIC_OUTPUT_RESET ,/* Core reset event */ + MPIC_OUTPUT_NB, +}; +qemu_irq *mpic_init (target_phys_addr_t base,int nb_cpus, +qemu_irq **irqs,qemu_irq irq_out); +#endif /* !defined(PPC_E500_H) */
PCI and MPIC stuff doesn't belong in a file for the e500 core.
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Quoted 61 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Saturday, January 10, 2009 4:16 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH 2/5] qemu/kvm: E500 core emulationQuoted 3 lines · Liu Yu
Signed-off-by Liu Yu <[email protected]>--- hw/ppce500.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/ppce500.h | 66+++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 10 lines
2 files changed, 140 insertions(+), 0 deletions(-) create mode 100644 hw/ppce500.c create mode 100644 hw/ppce500.hhw/ppce500.c new file +0
-0hw/ppce500.c line 4
Quoted 4 lines
hw/ppce500.c new file +4
-0@@ -0,0 +1,74 @@ +/* +* Qemu PowerPC E500 core emualtion +* +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
hw/ppce500.c line 9
Quoted 5 lines
hw/ppce500.c new file +5
-0+* +* Author: Yu Liu, <[email protected]> +* +* This file is derived from hw/ppc440.c +* the copyright for that material belongs to the original owners. I guess you based this off an old version of
ppc440.c, which isn't good
because I improved that code a lot when merging in to qemu.hw/ppce500.c line 11
Quoted 2 lines
hw/ppce500.c new file +2
-0+* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by
hw/ppce500.c line 12
Quoted 1 line
hw/ppce500.c new file +1
-0+* the Free Software Foundation; either version 2 of the License, or
Quoted 15 lines
hw/ppce500.c new file +15
-0+* (at your option) any later version. +*/ + +#include "hw.h" +#include "pc.h" +#include "hw/isa.h" +#include "ppce500.h" +#include "sysemu.h" + +#define PPCE500_SERIAL0_REGS 0x4500 +#define PPCE500_SERIAL1_REGS 0x4600 +#define PPCE500_MPIC_REGS 0x40000 +#define bytes_to_mb (a) (a>>20) + +CPUState *ppce500_init(ram_addr_t *ram_size,
Quoted 8 lines
hw/ppce500.c line 34
Quoted 6 lines
hw/ppce500.c new file +6
-0+ qemu_irq **pic, + target_ulong ccsrbar_base) +{ +qemu_irq *mpic_irq, *irqs; +SerialState * serial[2 ]; +int ram_stick_sizes[] = {512 <<20 ,256 <<20 };/* in bytes */ Your memory controller only supports 512M and 256M?
I don't emulate the memory controller, so I think qemu/e500 coulde support all kinds capacities.
Quoted 10 lines
hw/ppce500.c
Quoted 9 lines
hw/ppce500.c new file +8
-0+int i; +ram_addr_t tmp_ram_size; +CPUState *env; + +/* Setup Memory */ + tmp_ram_size = *ram_size; + + for (i=0;i<(sizeof(ram_stick_sizes)/sizeof(ram_stick_sizes[0])); i++)
Quoted 8 lines
hw/ppce500.c line 47
Quoted 5 lines
hw/ppce500.c new file +5
-0+while ((tmp_ram_size/ram_stick_sizes[i]) >0 ) + tmp_ram_size -= ram_stick_sizes[i]; + +if (tmp_ram_size) + *ram_size -= tmp_ram_size;This code was all refactored into a much nicer form. Look at
ppc4xx_sdram_adjust(), and rename it if you need it too.
As I haven't emulated memory controller, do I need to do this?
Quoted 25 lines
hw/ppce500.c
Quoted 10 lines
hw/ppce500.c new file +9
-0+ env =cpu_ppc_init ("e500v2_v30" ); +if (!env) { +fprintf (stderr,"Unable to initilize CPU!\n" ); +exit (1 ); + } + +/* mpic */ + irqs =qemu_mallocz (sizeof (qemu_irq) *MPIC_OUTPUT_NB ); + irqs[MPIC_OUTPUT_INT] = ((qemu_irq*)env->irq_inputs)[PPCE500_INPUT_INT];
hw/ppce500.c line 56
Quoted 1 line
hw/ppce500.c new file +1
-0+ irqs[MPIC_OUTPUT_CINT] = ((qemu_irq*)env->irq_inputs)[PPCE500_INPUT_CINT];
hw/ppce500.c line 57
Quoted 1 line
hw/ppce500.c new file +1
-0+ mpic_irq = mpic_init(ccsrbar_base + PPCE500_MPIC_REGS,1, &irqs, NULL);
Quoted 10 lines
hw/ppce500.c new file +10
-0+ *pic = mpic_irq; + +/* serial */ +if (serial_hds[0 ]) + serial[0 ] =serial_mm_init (ccsrbar_base +PPCE500_SERIAL0_REGS , +0 , mpic_irq[12 +26 ],399193 , + serial_hds[0 ],1 ); + +if (serial_hds[1 ]) + serial[0] = serial_mm_init(ccsrbar_base + PPCE500_SERIAL1_REGS,
Quoted 8 lines
hw/ppce500.c line 74
Quoted 5 lines
hw/ppce500.c new file +5
-0+0 , mpic_irq[12 +26 ],399193 , + serial_hds[0], 1); + +return env; +}e500 is a core, but the code you have here is initializing chip state. These should be separated.
Fixed. Thanks
Quoted 42 lines
hw/ppce500.h line 4
Quoted 11 lines
hw/ppce500.h new file +4
-0@@ -0,0 +1,66 @@ +/* +* QEMU PowerPC E500 emulation shared definitions +* +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
hw/ppce500.h
Quoted 8 lines
hw/ppce500.h new file +8
-0+* +* Author: Yu Liu, <[email protected]> +* +* This file is derived from hw/ppc440.h +* the copyright for that material belongs to the original owners. +* +* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by
hw/ppce500.h line 13
Quoted 1 line
hw/ppce500.h new file +1
-0+* the Free Software Foundation; either version 2 of the License, or
Quoted 19 lines
hw/ppce500.h new file +19
-0+* (at your option) any later version. +*/ + +#if !defined(PPC_E500_H ) +#define PPC_E500_H + +#include "hw.h" +#include "pc.h" +#include "qemu-timer.h" +#include "sysemu.h" +#include "exec-all.h" +#include "boards.h" + +/* PowerPC E500 XXX initialization */ +extern CPUState *ppce500_init (ram_addr_t *ram_size, +qemu_irq **pic, +target_ulong ccsrbar_base); + +enum {
Quoted 8 lines
hw/ppce500.h line 36
Quoted 4 lines
hw/ppce500.h new file +4
-0+PPCUIC_OUTPUT_INT =0 , +PPCUIC_OUTPUT_CINT =1 , + PPCUIC_OUTPUT_NB, +};UIC is the name of the 4xx interrupt controller, so I suspect this isn't
actually used in you code.
Fixed. Thanks.
Quoted 21 lines
Quoted 6 lines
hw/ppce500.h new file +5
-0+struct pci_outbound { +uint32_t potar; +uint32_t potear; +uint32_t powbar; +uint32_t powar;hw/ppce500.h
Quoted 10 lines
hw/ppce500.h new file +10
-0+}; + +struct pci_inbound { +uint32_t pitar; +uint32_t piwbar; +uint32_t piwbear; +uint32_t piwar; +}; + +PCIBus *ppce500_pci_init(qemu_irq *pic, target_phys_addr_tregisters);
hw/ppce500.h
Quoted 3 lines
hw/ppce500.h new file +3
-0+ +/* mpic.c */ +/* MPIC have 5 outputs per CPU connected and one IRQ out single output */
Quoted 14 lines
hw/ppce500.h line 66
Quoted 11 lines
hw/ppce500.h new file +11
-0+enum { +MPIC_OUTPUT_INT =0 ,/* IRQ */ +MPIC_OUTPUT_CINT ,/* critical IRQ */ +MPIC_OUTPUT_MCK ,/* Machine check event */ +MPIC_OUTPUT_DEBUG ,/* Inconditional debug event */ +MPIC_OUTPUT_RESET ,/* Core reset event */ +MPIC_OUTPUT_NB , +}; +qemu_irq *mpic_init (target_phys_addr_t base,int nb_cpus, +qemu_irq **irqs,qemu_irq irq_out); +#endif /* !defined(PPC_E500_H) */ PCI and MPIC stuff doesn't belong in a file for the e500 core.
Fixed. Thanks.
Quoted 89 lines · On Monday 12 January 2009 03:02:10 Liu Yu wrote:
Quoted 60 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Saturday, January 10, 2009 4:16 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH 2/5] qemu/kvm: E500 core emulationQuoted 3 lines · Liu Yu
Signed-off-by Liu Yu <[email protected]>---
hw/ppce500.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/ppce500.h | 66
+++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 10 lines
2 files changed, 140 insertions(+), 0 deletions(-)create mode 100644
hw/ppce500.c
create mode 100644hw/ppce500.hhw/ppce500.c new file +0
-0hw/ppce500.c line 4
Quoted 4 lines
hw/ppce500.c new file +4
-0@@ -0,0 +1,74 @@ +/* +* Qemu PowerPC E500 core emualtion +* +* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
hw/ppce500.c line 9
Quoted 5 lines
hw/ppce500.c new file +5
-0+* +* Author: Yu Liu, <[email protected]> +* +* This file is derived from hw/ppc440.c +* the copyright for that material belongs to the original owners. I guess you based this off an old version of
ppc440.c, which isn't good
because I improved that code a lot when merging in to qemu.hw/ppce500.c line 11
Quoted 2 lines
hw/ppce500.c new file +2
-0+* This is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by
hw/ppce500.c line 12
Quoted 1 line
hw/ppce500.c new file +1
-0+* the Free Software Foundation; either version 2 of the License, or
Quoted 15 lines
hw/ppce500.c new file +15
-0+* (at your option) any later version. +*/ + +#include "hw.h" +#include "pc.h" +#include "hw/isa.h" +#include "ppce500.h" +#include "sysemu.h" + +#define PPCE500_SERIAL0_REGS 0x4500 +#define PPCE500_SERIAL1_REGS 0x4600 +#define PPCE500_MPIC_REGS 0x40000 +#define bytes_to_mb (a) (a>>20) + +CPUState *ppce500_init(ram_addr_t *ram_size,Quoted 8 lines
hw/ppce500.c line 34
Quoted 6 lines
hw/ppce500.c new file +6
-0+ qemu_irq **pic, + target_ulong ccsrbar_base) +{ + qemu_irq *mpic_irq, *irqs; + SerialState * serial[2]; + int ram_stick_sizes[] = {512<<20, 256<<20}; /* in bytes */Your memory controller only supports 512M and 256M?
I don't emulate the memory controller, so I think qemu/e500 coulde support all kinds capacities.
Quoted 16 lines
hw/ppce500.c
Quoted 9 lines
hw/ppce500.c new file +8
-0+ int i; + ram_addr_t tmp_ram_size; + CPUState *env; + + /* Setup Memory */ + tmp_ram_size = *ram_size; + + for (i=0;i<(sizeof(ram_stick_sizes)/sizeof(ram_stick_sizes[0])); i++)
Quoted 5 lines
hw/ppce500.c new file +5
-0+ while ((tmp_ram_size/ram_stick_sizes[i]) > 0) + tmp_ram_size -= ram_stick_sizes[i]; + + if (tmp_ram_size) + *ram_size -= tmp_ram_size;
Quoted 4 lines
Quoted 2 lines
This code was all refactored into a much nicer form. Look at
ppc4xx_sdram_adjust(), and rename it if you need it too.As I haven't emulated memory controller, do I need to do this?
No, you don't. In that case you should remove this ram code entirely.
(The only reason we emulated the memory controller is because some of the early Linux bootwrapper code on 4xx uses it.)
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center