From patchwork Wed Aug 8 21:07:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)\" via" X-Patchwork-Id: 10560493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CB5913BB for ; Wed, 8 Aug 2018 21:12:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 301212AF4D for ; Wed, 8 Aug 2018 21:12:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 225052AF81; Wed, 8 Aug 2018 21:12:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A5EF92AF4D for ; Wed, 8 Aug 2018 21:12:08 +0000 (UTC) Received: from localhost ([::1]:45486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnVkV-00068x-TQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Aug 2018 17:12:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnVhd-0003Ek-Fy for qemu-devel@nongnu.org; Wed, 08 Aug 2018 17:09:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnVhY-0006iV-Qu for qemu-devel@nongnu.org; Wed, 08 Aug 2018 17:09:09 -0400 Received: from smtp20.mail.ru ([94.100.179.251]:39456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fnVhY-0006gu-IM for qemu-devel@nongnu.org; Wed, 08 Aug 2018 17:09:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=19D29lTyZ9YX5J8aRDYGXlSKwBspP7+Enqqzwn1MUE4=; b=Rcanuoo6/gXmCeE+cUt7RKtdns35sWMzD6u6w8fNKNiGx18dttrZySBJZfQQ0YGaXl5ggEcvyToizh0vdCbzRGJZb9MECZ0xOgJmWS3M1OnE9q5KqvmwhfOgrSHzPsxONZbwNiYWRgy/JOM4sHYoq57YjtvH4S/XuY37YhkGp6U=; Received: by smtp20.mail.ru with esmtpa (envelope-from ) id 1fnVhW-0002Hh-K2; Thu, 09 Aug 2018 00:09:02 +0300 To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2018 00:07:48 +0300 Message-Id: <20180808210750.3915-3-jusual@mail.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180808210750.3915-1-jusual@mail.ru> References: <20180808210750.3915-1-jusual@mail.ru> Authentication-Results: smtp20.mail.ru; auth=pass smtp.auth=jusual@mail.ru smtp.mailfrom=jusual@mail.ru X-7FA49CB5: 0D63561A33F958A54C8B9A410F8C7A2D6D2E4307B80EE54E534F12A45EB2B8BA8941B15DA834481F8AA50765F7900637F6B57BC7E6449061A352F6E88A58FB866BA297DBC24807EA76E601842F6C81A127C277FBC8AE2E8BCA3E976C47030043D81D268191BDAD3D4E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8B927CE0747365AA1D43DD3BDA1FFE7EB935872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C910FF24F588AC80D2BD9CCCA9EDD067B1EDA766A37F9254B7 X-Mailru-Sender: 7766D515518070DE138AAC7428EA760DBD9DE7C51E58D0066436CADAF6F1FC5F06F49D926679B5B77C4160E8B47E48163DDE9B364B0DF2898CB68AF7A628805D594FB4C9F0DBF412AE208404248635DF X-Mras: OK X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 94.100.179.251 Subject: [Qemu-devel] [PATCH v2 2/4] hw/arm/nrf51_soc: Connect UART to nRF51 SoC X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Julia Suvorova via Qemu-devel From: "Zhijian Li (Fujitsu)\" via" Reply-To: Julia Suvorova Cc: Peter Maydell , Jim Mussared , =?utf-8?q?Steffen_G=C3=B6rtz?= , Stefan Hajnoczi , Joel Stanley , Stefan Hajnoczi , Paolo Bonzini , Julia Suvorova Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Wire up nRF51 UART in the corresponding SoC using in-place init/realize. Based-on: <20180803052137.10602-1-joel@jms.id.au> Signed-off-by: Julia Suvorova --- hw/arm/nrf51_soc.c | 20 ++++++++++++++++++++ include/hw/arm/nrf51_soc.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c index 9f9649c780..8b5602f363 100644 --- a/hw/arm/nrf51_soc.c +++ b/hw/arm/nrf51_soc.c @@ -38,9 +38,12 @@ #define NRF51822_FLASH_SIZE (256 * 1024) #define NRF51822_SRAM_SIZE (16 * 1024) +#define BASE_TO_IRQ(base) ((base >> 12) & 0x1F) + static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) { NRF51State *s = NRF51_SOC(dev_soc); + MemoryRegion *mr = NULL; Error *err = NULL; if (!s->board_memory) { @@ -70,6 +73,19 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) } memory_region_add_subregion(&s->container, SRAM_BASE, &s->sram); + /* UART */ + qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hd(0)); + object_property_set_bool(OBJECT(&s->uart), true, "realized", &err); + if (err) { + error_propagate(errp, err); + return; + } + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->uart), 0); + memory_region_add_subregion_overlap(&s->container, UART_BASE, mr, 0); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart), 0, + qdev_get_gpio_in(DEVICE(&s->cpu), + BASE_TO_IRQ(UART_BASE))); + create_unimplemented_device("nrf51_soc.io", IOMEM_BASE, IOMEM_SIZE); create_unimplemented_device("nrf51_soc.ficr", FICR_BASE, FICR_SIZE); create_unimplemented_device("nrf51_soc.private", 0xF0000000, 0x10000000); @@ -86,6 +102,10 @@ static void nrf51_soc_init(Object *obj) qdev_set_parent_bus(DEVICE(&s->cpu), sysbus_get_default()); qdev_prop_set_string(DEVICE(&s->cpu), "cpu-type", ARM_CPU_TYPE_NAME("cortex-m0")); qdev_prop_set_uint32(DEVICE(&s->cpu), "num-irq", 32); + + object_initialize(&s->uart, sizeof(s->uart), TYPE_NRF51_UART); + object_property_add_child(obj, "uart", OBJECT(&s->uart), &error_abort); + qdev_set_parent_bus(DEVICE(&s->uart), sysbus_get_default()); } static Property nrf51_soc_properties[] = { diff --git a/include/hw/arm/nrf51_soc.h b/include/hw/arm/nrf51_soc.h index e380ec26b8..46a1c1a66c 100644 --- a/include/hw/arm/nrf51_soc.h +++ b/include/hw/arm/nrf51_soc.h @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "hw/sysbus.h" #include "hw/arm/armv7m.h" +#include "hw/char/nrf51_uart.h" #define TYPE_NRF51_SOC "nrf51-soc" #define NRF51_SOC(obj) \ @@ -25,6 +26,8 @@ typedef struct NRF51State { /*< public >*/ ARMv7MState cpu; + NRF51UARTState uart; + MemoryRegion iomem; MemoryRegion sram; MemoryRegion flash;