From patchwork Thu Feb 17 22:45:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 83501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2A096B7127 for ; Fri, 18 Feb 2011 10:30:32 +1100 (EST) Received: from localhost ([127.0.0.1]:33070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PqDF7-00052S-4b for incoming@patchwork.ozlabs.org; Thu, 17 Feb 2011 18:26:37 -0500 Received: from [140.186.70.92] (port=36870 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PqCcN-0006Xx-DN for qemu-devel@nongnu.org; Thu, 17 Feb 2011 17:47:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PqCbZ-0000WM-IS for qemu-devel@nongnu.org; Thu, 17 Feb 2011 17:45:53 -0500 Received: from mail.serverraum.org ([78.47.150.89]:40270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PqCbZ-0000Vp-7w for qemu-devel@nongnu.org; Thu, 17 Feb 2011 17:45:45 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.serverraum.org (Postfix) with ESMTP id B7C9D3EEFB; Thu, 17 Feb 2011 23:45:41 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.serverraum.org Received: from mail.serverraum.org ([127.0.0.1]) by localhost (web.serverraum.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uxQs1FbejAi9; Thu, 17 Feb 2011 23:45:41 +0100 (CET) Received: from thanatos.fritz.box (91-66-128-56-dynip.superkabel.de [91.66.128.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.serverraum.org (Postfix) with ESMTPSA id 4743F3EEFD; Thu, 17 Feb 2011 23:45:38 +0100 (CET) From: Michael Walle To: qemu-devel@nongnu.org Date: Thu, 17 Feb 2011 23:45:08 +0100 Message-Id: <1297982718-21865-8-git-send-email-michael@walle.cc> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1297982718-21865-1-git-send-email-michael@walle.cc> References: <1297982718-21865-1-git-send-email-michael@walle.cc> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 78.47.150.89 Cc: Blue Swirl , "Edgar E. Iglesias" , Michael Walle , Alexander Graf , Richard Henderson Subject: [Qemu-devel] [PATCH 07/17] lm32: juart model X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds the JTAG UART model. It is accessed through special control registers and opcodes. Therefore the translation uses callbacks to this model. Signed-off-by: Michael Walle --- Makefile.target | 1 + hw/lm32_juart.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/lm32_juart.h | 11 ++++ trace-events | 6 ++ 4 files changed, 168 insertions(+), 0 deletions(-) create mode 100644 hw/lm32_juart.c create mode 100644 hw/lm32_juart.h diff --git a/Makefile.target b/Makefile.target index d9b1cc7..11531e2 100644 --- a/Makefile.target +++ b/Makefile.target @@ -249,6 +249,7 @@ obj-ppc-y += xilinx_ethlite.o # LM32 peripherals obj-lm32-y += lm32_pic.o +obj-lm32-y += lm32_juart.o obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o obj-mips-y += mips_addr.o mips_timer.o mips_int.o diff --git a/hw/lm32_juart.c b/hw/lm32_juart.c new file mode 100644 index 0000000..fddcf7e --- /dev/null +++ b/hw/lm32_juart.c @@ -0,0 +1,150 @@ +/* + * LatticeMico32 JTAG UART model. + * + * Copyright (c) 2010 Michael Walle + * + * 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 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 . + */ + +#include "hw.h" +#include "sysbus.h" +#include "trace.h" +#include "qemu-char.h" + +#include "lm32_juart.h" + +enum { + LM32_JUART_MIN_SAVE_VERSION = 0, + LM32_JUART_CURRENT_SAVE_VERSION = 0, + LM32_JUART_MAX_SAVE_VERSION = 0, +}; + +enum { + JTX_FULL = (1<<8), +}; + +enum { + JRX_FULL = (1<<8), +}; + +struct LM32JuartState { + SysBusDevice busdev; + CharDriverState *chr; + + uint32_t jtx; + uint32_t jrx; +}; +typedef struct LM32JuartState LM32JuartState; + +uint32_t lm32_juart_get_jtx(DeviceState *d) +{ + LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); + + trace_lm32_juart_get_jtx(s->jtx); + return s->jtx; +} + +uint32_t lm32_juart_get_jrx(DeviceState *d) +{ + LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); + + trace_lm32_juart_get_jrx(s->jrx); + return s->jrx; +} + +void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx) +{ + LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); + unsigned char ch = jtx & 0xff; + + trace_lm32_juart_set_jtx(s->jtx); + + s->jtx = jtx; + if (s->chr) { + qemu_chr_write(s->chr, &ch, 1); + } +} + +void lm32_juart_set_jrx(DeviceState *d, uint32_t jtx) +{ + LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); + + trace_lm32_juart_set_jrx(s->jrx); + s->jrx &= ~JRX_FULL; +} + +static void juart_rx(void *opaque, const uint8_t *buf, int size) +{ + LM32JuartState *s = opaque; + + s->jrx = *buf | JRX_FULL; +} + +static int juart_can_rx(void *opaque) +{ + LM32JuartState *s = opaque; + + return !(s->jrx & JRX_FULL); +} + +static void juart_event(void *opaque, int event) +{ +} + +static void juart_reset(DeviceState *d) +{ + LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); + + s->jtx = 0; + s->jrx = 0; +} + +static int lm32_juart_init(SysBusDevice *dev) +{ + LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev); + + s->chr = qdev_init_chardev(&dev->qdev); + if (s->chr) { + qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s); + } + + return 0; +} + +static const VMStateDescription vmstate_lm32_juart = { + .name = "lm32-juart", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(jtx, LM32JuartState), + VMSTATE_UINT32(jrx, LM32JuartState), + VMSTATE_END_OF_LIST() + } +}; + +static SysBusDeviceInfo lm32_juart_info = { + .init = lm32_juart_init, + .qdev.name = "lm32-juart", + .qdev.size = sizeof(LM32JuartState), + .qdev.vmsd = &vmstate_lm32_juart, + .qdev.reset = juart_reset, +}; + +static void lm32_juart_register(void) +{ + sysbus_register_withprop(&lm32_juart_info); +} + +device_init(lm32_juart_register) diff --git a/hw/lm32_juart.h b/hw/lm32_juart.h new file mode 100644 index 0000000..67fc586 --- /dev/null +++ b/hw/lm32_juart.h @@ -0,0 +1,11 @@ +#ifndef QEMU_HW_LM32_JUART_H +#define QEMU_HW_LM32_JUART_H + +#include "qemu-common.h" + +uint32_t lm32_juart_get_jtx(DeviceState *d); +uint32_t lm32_juart_get_jrx(DeviceState *d); +void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx); +void lm32_juart_set_jrx(DeviceState *d, uint32_t jrx); + +#endif /* QEMU_HW_LM32_JUART_H */ diff --git a/trace-events b/trace-events index 557375e..966099f 100644 --- a/trace-events +++ b/trace-events @@ -263,3 +263,9 @@ disable lm32_pic_set_im(uint32_t im) "im 0x%08x" disable lm32_pic_set_ip(uint32_t ip) "ip 0x%08x" disable lm32_pic_get_im(uint32_t im) "im 0x%08x" disable lm32_pic_get_ip(uint32_t ip) "ip 0x%08x" + +# hw/lm32_juart.c +disable lm32_juart_get_jtx(uint32_t value) "jtx 0x%08x" +disable lm32_juart_set_jtx(uint32_t value) "jtx 0x%08x" +disable lm32_juart_get_jrx(uint32_t value) "jrx 0x%08x" +disable lm32_juart_set_jrx(uint32_t value) "jrx 0x%08x"