From patchwork Tue Mar 8 21:06:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 8537781 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4ED9BC0553 for ; Tue, 8 Mar 2016 21:10:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EEB8201FA for ; Tue, 8 Mar 2016 21:10:09 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 6F2D1201E4 for ; Tue, 8 Mar 2016 21:10:08 +0000 (UTC) Received: from localhost ([::1]:37401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adOtL-0005fH-NK for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Mar 2016 16:10:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adOt1-0005YM-EL for qemu-devel@nongnu.org; Tue, 08 Mar 2016 16:09:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adOsy-0002er-7u for qemu-devel@nongnu.org; Tue, 08 Mar 2016 16:09:47 -0500 Received: from mail-sn1nam02on0042.outbound.protection.outlook.com ([104.47.36.42]:57322 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adOsy-0002eW-0p for qemu-devel@nongnu.org; Tue, 08 Mar 2016 16:09:44 -0500 Received: from CY1NAM02FT050.eop-nam02.prod.protection.outlook.com (10.152.74.56) by CY1NAM02HT102.eop-nam02.prod.protection.outlook.com (10.152.74.159) with Microsoft SMTP Server (TLS) id 15.1.427.7; Tue, 8 Mar 2016 21:09:42 +0000 Authentication-Results: spf=fail (sender IP is 149.199.60.96) smtp.mailfrom=xilinx.com; linaro.org; dkim=none (message not signed) header.d=none; linaro.org; dmarc=none action=none header.from=xilinx.com; Received-SPF: Fail (protection.outlook.com: domain of xilinx.com does not designate 149.199.60.96 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.96; helo=xsj-tvapsmtpgw01; Received: from xsj-tvapsmtpgw01 (149.199.60.96) by CY1NAM02FT050.mail.protection.outlook.com (10.152.75.65) with Microsoft SMTP Server (TLS) id 15.1.434.11 via Frontend Transport; Tue, 8 Mar 2016 21:09:39 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:47515 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1adOss-0006CO-EX; Tue, 08 Mar 2016 13:09:38 -0800 Received: from [127.0.0.1] (port=48460 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1adOss-0000dj-AF; Tue, 08 Mar 2016 13:09:38 -0800 Received: from xsj-tvapsmtp02 (xsj-tvapsmtp02.xilinx.com [172.16.1.203]) by tsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u28L3lCY021867; Tue, 8 Mar 2016 13:03:48 -0800 Received: from [172.19.74.182] (port=56648 helo=xsjalistai50.xlnx.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1adOsr-0000dg-Gr; Tue, 08 Mar 2016 13:09:37 -0800 From: Alistair Francis To: , Date: Tue, 8 Mar 2016 13:06:37 -0800 Message-ID: <0250cbb0a6b9d18e12369720a47e96772347829c.1457470980.git.alistair.francis@xilinx.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: X-RCIS-Action: ALLOW X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22178.005 X-TM-AS-Result: No--10.486-7.0-31-10 X-imss-scan-details: No--10.486-7.0-31-10 X-TMASE-MatchedRID: MpG/zcNZUvGLwgJA7qJvFMnUT+eskUQPXs5nqGvDCfMTI3pLuil/foqN otXYNqA4kZ3T6ylBNAWvXn8ZlTtgDIRSqwm2ppCS3fn7n/ZHGqY7r2Gtb9iBYfFJXtgF4GFL3oz JRX7b4NnZo4bjogR4BhvcyOf/aYw3WU/fB/XFmJyHZXNSWjgdU+4dka7Cjortv8D7QPW2jo/JJm HlkMf/d9jrGJWvvRFdDncJmKUEXtPtgYgBGmF9nuTuT3JcmKqq75ETi8QGjNycFKOx6gFNeqPFj JEFr+olwXCBO/GKkVqOhzOa6g8KrSJBiatAPAMjzHcCMxZsmPp/RYbQbLX4aQ7mgGsbOFxPcqz5 gyR4Mx8= X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.96; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(106466001)(2906002)(105606002)(2950100001)(36756003)(5003940100001)(4326007)(64026002)(77096005)(586003)(71366001)(229853001)(1220700001)(19580395003)(50226001)(19580405001)(5003600100002)(48376002)(575784001)(86362001)(5008740100001)(87936001)(85426001)(6806005)(118296001)(50986999)(11100500001)(33646002)(1096002)(5001770100001)(81166005)(76176999)(50466002)(92566002)(47776003)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1NAM02HT102; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 942f9733-105f-4394-b41b-08d34795f79f X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1NAM02HT102; X-Microsoft-Antispam-PRVS: <623258ea36844a74a2a407e399630276@CY1NAM02HT102.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(13015025)(5005006)(13017025)(13018025)(13024025)(13023025)(3002001)(10201501046); SRVR:CY1NAM02HT102; BCL:0; PCL:0; RULEID:; SRVR:CY1NAM02HT102; X-Forefront-PRVS: 08756AC3C8 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2016 21:09:39.3415 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.96]; Helo=[xsj-tvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1NAM02HT102 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.42 Cc: edgar.iglesias@xilinx.com, alistair.francis@xilinx.com, crosthwaitepeter@gmail.com, edgar.iglesias@gmail.com, alex.bennee@linaro.org, afaerber@suse.de, fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v5 03/15] register: Add Memory API glue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add memory io handlers that glue the register API to the memory API. Just translation functions at this stage. Although it does allow for devices to be created without all-in-one mmio r/w handlers. This patch also adds the RegisterInfoArray struct, which allows all of the individual RegisterInfo structs to be grouped into a single memory region. Signed-off-by: Peter Crosthwaite Signed-off-by: Alistair Francis --- V5: - Convert to using only one memory region hw/core/register.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/hw/core/register.c b/hw/core/register.c index 1656f71..e1cd0c4 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -146,3 +146,73 @@ void register_reset(RegisterInfo *reg) register_write_val(reg, reg->access->reset); } + +static inline void register_write_memory(void *opaque, hwaddr addr, + uint64_t value, unsigned size, bool be) +{ + RegisterInfoArray *reg_array = opaque; + RegisterInfo *reg = NULL; + uint64_t we = ~0; + int i, shift = 0; + + for (i = 0; i < reg_array->num_elements; i++) { + if (reg_array->r[i]->access->decode.addr == addr) { + reg = reg_array->r[i]; + break; + } + } + assert(reg); + + /* Generate appropriate write enable mask and shift values */ + if (reg->data_size < size) { + we = MAKE_64BIT_MASK(0, reg->data_size * 8); + shift = 8 * (be ? reg->data_size - size : 0); + } else if (reg->data_size >= size) { + we = MAKE_64BIT_MASK(0, size * 8); + } + + register_write(reg, value << shift, we << shift); +} + +void register_write_memory_be(void *opaque, hwaddr addr, uint64_t value, + unsigned size) +{ + register_write_memory(opaque, addr, value, size, true); +} + + +void register_write_memory_le(void *opaque, hwaddr addr, uint64_t value, + unsigned size) +{ + register_write_memory(opaque, addr, value, size, false); +} + +static inline uint64_t register_read_memory(void *opaque, hwaddr addr, + unsigned size, bool be) +{ + RegisterInfoArray *reg_array = opaque; + RegisterInfo *reg = NULL; + int i, shift; + + for (i = 0; i < reg_array->num_elements; i++) { + if (reg_array->r[i]->access->decode.addr == addr) { + reg = reg_array->r[i]; + break; + } + } + assert(reg); + + shift = 8 * (be ? reg->data_size - size : 0); + + return (register_read(reg) >> shift) & MAKE_64BIT_MASK(0, size * 8); +} + +uint64_t register_read_memory_be(void *opaque, hwaddr addr, unsigned size) +{ + return register_read_memory(opaque, addr, size, true); +} + +uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size) +{ + return register_read_memory(opaque, addr, size, false); +} diff --git a/include/hw/register.h b/include/hw/register.h index baa08f5..726a914 100644 --- a/include/hw/register.h +++ b/include/hw/register.h @@ -15,6 +15,7 @@ typedef struct RegisterInfo RegisterInfo; typedef struct RegisterAccessInfo RegisterAccessInfo; +typedef struct RegisterInfoArray RegisterInfoArray; /** * Access description for a register that is part of guest accessible device @@ -51,6 +52,10 @@ struct RegisterAccessInfo { void (*post_write)(RegisterInfo *reg, uint64_t val); uint64_t (*post_read)(RegisterInfo *reg, uint64_t val); + + struct { + hwaddr addr; + } decode; }; /** @@ -82,6 +87,26 @@ struct RegisterInfo { }; /** + * This structure is used to group all of the individual registers which are + * modeled using the RegisterInfo strucutre. + * + * @r is an aray containing of all the relevent RegisterInfo structures. + * + * @num_elements is the number of elements in the array r + * + * @mem: optional Memory region for the register + */ + +struct RegisterInfoArray { + /* */ + MemoryRegion mem; + + /* */ + int num_elements; + RegisterInfo **r; +}; + +/** * write a value to a register, subject to its restrictions * @reg: register to write to * @val: value to write @@ -105,4 +130,30 @@ uint64_t register_read(RegisterInfo *reg); void register_reset(RegisterInfo *reg); +/** + * Memory API MMIO write handler that will write to a Register API register. + * _be for big endian variant and _le for little endian. + * @opaque: RegisterInfo to write to + * @addr: Address to write + * @value: Value to write + * @size: Number of bytes to write + */ + +void register_write_memory_be(void *opaque, hwaddr addr, uint64_t value, + unsigned size); +void register_write_memory_le(void *opaque, hwaddr addr, uint64_t value, + unsigned size); + +/** + * Memory API MMIO read handler that will read from a Register API register. + * _be for big endian variant and _le for little endian. + * @opaque: RegisterInfo to read from + * @addr: Address to read + * @size: Number of bytes to read + * returns: Value read from register + */ + +uint64_t register_read_memory_be(void *opaque, hwaddr addr, unsigned size); +uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size); + #endif