From patchwork Tue Feb 9 22:14:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 8266011 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 709D29F38B for ; Tue, 9 Feb 2016 22:17:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B3D6620218 for ; Tue, 9 Feb 2016 22:17:49 +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 C9FDA201F4 for ; Tue, 9 Feb 2016 22:17:48 +0000 (UTC) Received: from localhost ([::1]:32919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTGbU-0003kV-4M for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Feb 2016 17:17:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTGb8-0003aI-V2 for qemu-devel@nongnu.org; Tue, 09 Feb 2016 17:17:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTGb4-0000wj-3y for qemu-devel@nongnu.org; Tue, 09 Feb 2016 17:17:26 -0500 Received: from mail-sn1nam02on0040.outbound.protection.outlook.com ([104.47.36.40]:64992 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTGb3-0000wV-TI for qemu-devel@nongnu.org; Tue, 09 Feb 2016 17:17:22 -0500 Received: from SN1NAM02FT029.eop-nam02.prod.protection.outlook.com (10.152.72.55) by SN1NAM02HT217.eop-nam02.prod.protection.outlook.com (10.152.72.112) with Microsoft SMTP Server (TLS) id 15.1.409.7; Tue, 9 Feb 2016 22:17:20 +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 SN1NAM02FT029.mail.protection.outlook.com (10.152.72.110) with Microsoft SMTP Server (TLS) id 15.1.409.7 via Frontend Transport; Tue, 9 Feb 2016 22:17:20 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:35340 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1aTGb1-0002mR-Oc; Tue, 09 Feb 2016 14:17:19 -0800 Received: from [127.0.0.1] (port=42559 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1aTGb1-0007a4-Iq; Tue, 09 Feb 2016 14:17:19 -0800 Received: from xsj-tvapsmtp02 (smtptest.xilinx.com [172.16.1.203]) by tsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u19MBd0I011530; Tue, 9 Feb 2016 14:11:39 -0800 Received: from [172.19.74.182] (port=49716 helo=xsjalistai50.xlnx.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1aTGb0-0007a1-PV; Tue, 09 Feb 2016 14:17:18 -0800 From: Alistair Francis To: , Date: Tue, 9 Feb 2016 14:14:43 -0800 Message-ID: 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-22054.006 X-TM-AS-Result: No--7.930-7.0-31-10 X-imss-scan-details: No--7.930-7.0-31-10 X-TMASE-MatchedRID: TXpevnfF2xz/uyguzMmOKFz+axQLnAVBPZmbnY2qDInI9EDAP/dptibX zlOExFTakZ3T6ylBNAWvXn8ZlTtgDIRSqwm2ppCS3fn7n/ZHGqY7r2Gtb9iBYfFJXtgF4GFL3oz JRX7b4NmOACjEIVDcsUh/KIDtn07sgVDJ+NS/WkBQiFNNqFvt1cCY5/Mqi1OiwDR44lliPu1Wie 6ItM9+JwNmGucldpE6gDLqnrRlXrZ8nn9tnqel2DsAVzN+Ov/suyZMyfQ/qLACbi6wBqITNeX2K Psinew1OPRB+boXuxp2O3zHfFBkQA== X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.96; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(189998001)(1096002)(6806005)(11100500001)(19580405001)(87936001)(19580395003)(5003600100002)(77096005)(76176999)(2950100001)(92566002)(50466002)(5003940100001)(5001770100001)(85426001)(64026002)(48376002)(50986999)(5008740100001)(2906002)(118296001)(36756003)(105606002)(33646002)(106466001)(86362001)(1220700001)(50226001)(5001960100002)(47776003)(586003)(229853001)(4326007)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1NAM02HT217; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 9babf423-1cb1-422e-ac51-08d3319ec774 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1NAM02HT217; X-Microsoft-Antispam-PRVS: <9d8651189ced497497524eb21559afab@SN1NAM02HT217.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(13015025)(13017025)(13024025)(13018025)(13023025)(5005006)(10201501046)(3002001); SRVR:SN1NAM02HT217; BCL:0; PCL:0; RULEID:; SRVR:SN1NAM02HT217; X-Forefront-PRVS: 08476BC6EF X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2016 22:17:20.6840 (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: SN1NAM02HT217 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.40 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 v4 03/16] 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 From: Peter Crosthwaite 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. Signed-off-by: Peter Crosthwaite Signed-off-by: Alistair Francis --- hw/core/register.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/hw/core/register.c b/hw/core/register.c index 7e47df5..9cd50c8 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -150,3 +150,51 @@ 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) +{ + RegisterInfo *reg = opaque; + uint64_t we = ~0; + int shift = 0; + + if (reg->data_size != size) { + we = (size == 8) ? ~0ull : (1ull << size * 8) - 1; + shift = 8 * (be ? reg->data_size - size - addr : addr); + } + + assert(size + addr <= reg->data_size); + 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) +{ + RegisterInfo *reg = opaque; + int shift = 8 * (be ? reg->data_size - size - addr : addr); + + return register_read(reg) >> shift; +} + +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 444239c..9aa9cfc 100644 --- a/include/hw/register.h +++ b/include/hw/register.h @@ -69,9 +69,14 @@ struct RegisterAccessInfo { * @prefix: String prefix for log and debug messages * * @opaque: Opaque data for the register + * + * @mem: optional Memory region for the register */ struct RegisterInfo { + /* */ + MemoryRegion mem; + /* */ void *data; int data_size; @@ -108,4 +113,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