Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ly7MP-0003PJ-3q for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:37:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ly7MK-0003GJ-Oi for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:37:44 -0400 Received: from [199.232.76.173] (port=48785 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ly7MJ-0003Ft-TY for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:37:39 -0400 Received: from 30.mail-out.ovh.net ([213.186.62.213]:58278) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1Ly7MI-0008WQ-Ta for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:37:39 -0400 From: Jean-Christophe PLAGNIOL-VILLARD Date: Sun, 26 Apr 2009 18:36:12 +0200 Message-Id: <1240763772-22858-3-git-send-email-plagnioj@jcrosoft.com> In-Reply-To: <1240763772-22858-2-git-send-email-plagnioj@jcrosoft.com> References: <1240763772-22858-1-git-send-email-plagnioj@jcrosoft.com> <1240763772-22858-2-git-send-email-plagnioj@jcrosoft.com> Subject: [Qemu-devel] [PATCH 3/3] sh/serial: allow cpu regs definition List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jean-Christophe PLAGNIOL-VILLARD sh_serial_regs will allow to define the SCI/SCIF cpu regs need to add SH cpu other than sh7750 Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD --- hw/sh.h | 2 + hw/sh7750.c | 30 +++++++++++++++++++- hw/sh_serial.c | 86 ++++++++++++++++++++++++++----------------------------- hw/sh_serial.h | 42 +++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 46 deletions(-) create mode 100644 hw/sh_serial.h diff --git a/hw/sh.h b/hw/sh.h index 5e3c22b..c92fa8c 100644 --- a/hw/sh.h +++ b/hw/sh.h @@ -3,6 +3,7 @@ /* Definitions for SH board emulation. */ #include "sh_intc.h" +#include "sh_serial.h" #define A7ADDR(x) ((x) & 0x1fffffff) #define P4ADDR(x) ((x) | 0xe0000000) @@ -38,6 +39,7 @@ void tmu012_init(target_phys_addr_t base, int feat, uint32_t freq, /* sh_serial.c */ #define SH_SERIAL_FEAT_SCIF (1 << 0) void sh_serial_init (target_phys_addr_t base, int feat, + sh_serial_regs *regs, uint32_t freq, CharDriverState *chr, qemu_irq eri_source, qemu_irq rxi_source, diff --git a/hw/sh7750.c b/hw/sh7750.c index 423c43f..a43551d 100644 --- a/hw/sh7750.c +++ b/hw/sh7750.c @@ -30,6 +30,7 @@ #include "sh7750_regs.h" #include "sh7750_regnames.h" #include "sh_intc.h" +#include "sh_serial.h" #include "exec-all.h" #include "cpu.h" @@ -701,6 +702,31 @@ static CPUWriteMemoryFunc *sh7750_mmct_write[] = { sh7750_mmct_writel }; +sh_serial_regs sh7750_sci = { + .scsmr = 0x0, + .scbrr = 0x4, + .scscr = 0x8, + .scftdr = 0xc, /* AS TDR for SCI */ + .scfsr = 0x10, /* AS SSR for SCI */ + .scfrdr = 0x14, /* AS RDR for SCI */ + .scscmr = 0x18, + .scsptr = 0x1c, +}; + +sh_serial_regs sh7750_scif = { + .scsmr = 0x0, + .scbrr = 0x4, + .scscr = 0x8, + .scftdr = 0xc, + .scfsr = 0x10, + .scfrdr = 0x14, + .scfcr = 0x18, + .scfdr = 0x1c, + .scsptr = 0x20, + .sclsr = 0x24, +}; + + SH7750State *sh7750_init(CPUSH4State * cpu) { SH7750State *s; @@ -742,13 +768,15 @@ SH7750State *sh7750_init(CPUSH4State * cpu) cpu->intc_handle = &s->intc; - sh_serial_init(0x1fe00000, 0, s->periph_freq, serial_hds[0], + sh_serial_init(0x1fe00000, 0, &sh7750_sci, + s->periph_freq, serial_hds[0], s->intc.irqs[SCI1_ERI], s->intc.irqs[SCI1_RXI], s->intc.irqs[SCI1_TXI], s->intc.irqs[SCI1_TEI], NULL); sh_serial_init(0x1fe80000, SH_SERIAL_FEAT_SCIF, + &sh7750_scif, s->periph_freq, serial_hds[1], s->intc.irqs[SCIF_ERI], s->intc.irqs[SCIF_RXI], diff --git a/hw/sh_serial.c b/hw/sh_serial.c index c3eb146..7abbc49 100644 --- a/hw/sh_serial.c +++ b/hw/sh_serial.c @@ -26,6 +26,7 @@ */ #include "hw.h" #include "sh.h" +#include "sh_serial.h" #include "qemu-char.h" #include @@ -65,6 +66,8 @@ typedef struct { qemu_irq txi; qemu_irq tei; qemu_irq bri; + + sh_serial_regs *regs; } sh_serial_state; static void sh_serial_clear_fifo(sh_serial_state * s) @@ -78,20 +81,22 @@ static void sh_serial_clear_fifo(sh_serial_state * s) static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) { sh_serial_state *s = opaque; + sh_serial_regs *regs = s->regs; unsigned char ch; #ifdef DEBUG_SERIAL printf("sh_serial: write offs=0x%02x val=0x%02x\n", offs, val); #endif - switch(offs) { - case 0x00: /* SMR */ + if (offs == regs->scsmr) { /* SMR */ s->smr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff); return; - case 0x04: /* BRR */ + } + if (offs == regs->scbrr) { /* BRR */ s->brr = val; return; - case 0x08: /* SCR */ + } + if (offs == regs->scscr) { /* SCR */ /* TODO : For SH7751, SCIF mask should be 0xfb. */ s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff); if (!(val & (1 << 5))) @@ -103,7 +108,8 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) qemu_set_irq(s->rxi, 0); } return; - case 0x0c: /* FTDR / TDR */ + } + if (offs == regs->scftdr) { /* FTDR / TDR */ if (s->chr) { ch = val; qemu_chr_write(s->chr, &ch, 1); @@ -114,14 +120,13 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) else s->flags |= SH_SERIAL_FLAG_TDE; return; - case 0x14: /* FRDR / RDR */ + } + if (offs == regs->scfrdr) { /* FRDR / RDR */ /* do nothing */ return; - break; } if (s->feat & SH_SERIAL_FEAT_SCIF) { - switch(offs) { - case 0x10: /* FSR */ + if (offs == regs->scfsr) { /* FSR */ if (!(val & (1 << 6))) s->flags &= ~SH_SERIAL_FLAG_TEND; if (!(val & (1 << 5))) @@ -139,7 +144,8 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) } } return; - case 0x18: /* FCR */ + } + if (offs == regs->scfcr) { /* FCR */ s->fcr = val; switch ((val >> 6) & 3) { case 0: @@ -161,15 +167,16 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) } return; - case 0x20: /* SPTR */ + } + if (offs == regs->scsptr) { /* SPTR */ s->sptr = val & 0xf3; return; - case 0x24: /* LSR */ + } + if (offs == regs->sclsr) { /* LSR */ return; } } else { /* SCI */ - switch(offs) { - case 0x0c: /* TDR */ + if (offs == regs->scftdr) { /* TDR */ if (s->chr) { ch = val; qemu_chr_write(s->chr, &ch, 1); @@ -180,7 +187,8 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) qemu_set_irq(s->txi, 1); } return; - case 0x10: /* SSR */ + } + if (offs == regs->scfsr) { /* SSR */ /* * Ignore TDRE (1 << 7) bit because TDR is always * writable in this SCI emulation. @@ -194,7 +202,8 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) } } return; - case 0x1c: + } + if (offs == regs->scsptr) { s->sptr = val & 0x8f; return; } @@ -207,22 +216,18 @@ static void sh_serial_ioport_write(void *opaque, uint32_t offs, uint32_t val) static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs) { sh_serial_state *s = opaque; + sh_serial_regs *regs = s->regs; uint32_t ret = ~0; - switch(offs) { - case 0x00: /* SMR */ + if (offs == regs->scsmr) { /* SMR */ ret = s->smr; - break; - case 0x04: /* BRR */ + } else if (offs == regs->scbrr) { /* BRR */ ret = s->brr; - break; - case 0x08: /* SCR */ + } else if (offs == regs->scscr) { /* SCR */ ret = s->scr; - break; } if (s->feat & SH_SERIAL_FEAT_SCIF) { - switch(offs) { - case 0x10: /* FSR */ + if (offs == regs->scfsr) { /* FSR */ ret = 0; if (s->flags & SH_SERIAL_FLAG_TEND) ret |= (1 << 6); @@ -238,8 +243,7 @@ static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs) if (s->scr & (1 << 5)) s->flags |= SH_SERIAL_FLAG_TDE | SH_SERIAL_FLAG_TEND; - break; - case 0x14: + } else if (offs == regs->scfrdr) { if (s->rx_cnt > 0) { ret = s->rx_fifo[s->rx_tail++]; s->rx_cnt--; @@ -248,26 +252,19 @@ static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs) if (s->rx_cnt < s->rtrg) s->flags &= ~SH_SERIAL_FLAG_RDF; } - break; - case 0x18: + } else if (offs == regs->scfcr) { ret = s->fcr; - break; - case 0x1c: + } else if (offs == regs->scfdr) { ret = s->rx_cnt; - break; - case 0x20: + } else if (offs == regs->scsptr) { ret = s->sptr; - break; - case 0x24: + } else if (offs == regs->sclsr) { ret = 0; - break; } } else { - switch(offs) { - case 0x0c: /* TDR */ + if (offs == regs->scftdr) { /* TDR */ ret = s->dr; - break; - case 0x10: /* SSR */ + } else if (offs == regs->scfsr) { /* SSR */ ret = 0; if (s->flags & SH_SERIAL_FLAG_TDE) ret |= (1 << 7); @@ -276,14 +273,11 @@ static uint32_t sh_serial_ioport_read(void *opaque, uint32_t offs) if (s->flags & SH_SERIAL_FLAG_TEND) ret |= (1 << 2); /* TODO : handle bit MPBT */ - break; - case 0x14: /* RDR */ + } else if (offs == regs->scfrdr) { /* RDR */ ret = s->rx_fifo[0]; s->flags &= ~SH_SERIAL_FLAG_RDF; - break; - case 0x1c: /* SPTR */ + } else if (offs == regs->scsptr) { /* PTR */ ret = s->sptr; - break; } } #ifdef DEBUG_SERIAL @@ -379,6 +373,7 @@ static CPUWriteMemoryFunc *sh_serial_writefn[] = { }; void sh_serial_init (target_phys_addr_t base, int feat, + sh_serial_regs *regs, uint32_t freq, CharDriverState *chr, qemu_irq eri_source, qemu_irq rxi_source, @@ -392,6 +387,7 @@ void sh_serial_init (target_phys_addr_t base, int feat, s = qemu_mallocz(sizeof(sh_serial_state)); s->feat = feat; + s->regs = regs; s->flags = SH_SERIAL_FLAG_TEND | SH_SERIAL_FLAG_TDE; s->rtrg = 1; diff --git a/hw/sh_serial.h b/hw/sh_serial.h new file mode 100644 index 0000000..dc27ce9 --- /dev/null +++ b/hw/sh_serial.h @@ -0,0 +1,42 @@ +/* + * QEMU SH serial port emulation + * + * Copyright (c) 2009 Jean-Christophe PLAGNIOL-VILLARD + * + * 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. + */ + +#ifndef __SH_SERIAL_H__ +#define __SH_SERIAL_H__ + +typedef struct sh_serial_regs { + uint16_t scsmr; + uint16_t scbrr; + uint16_t scscr; + uint16_t scftdr; /* AS TDR for SCI */ + uint16_t scfsr; /* AS SSR for SCI */ + uint16_t scfrdr; /* AS RDR for SCI */ + uint16_t scfcr; /* SCIF only */ + uint16_t scfdr; /* SCIF only */ + uint16_t scsptr; + uint16_t scscmr; /* SCI only */ + uint16_t sclsr; /* SCIF only */ +} sh_serial_regs; + +#endif /* __SH_SERIAL_H__ */ -- 1.6.2.1