From patchwork Tue Jan 19 22:35:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 8065321 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 D7699BEEE5 for ; Tue, 19 Jan 2016 22:39:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27A502052A for ; Tue, 19 Jan 2016 22:39:46 +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 0F0D120456 for ; Tue, 19 Jan 2016 22:39:45 +0000 (UTC) Received: from localhost ([::1]:39476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLewC-0003b1-Dn for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jan 2016 17:39:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLeu7-0000AB-LW for qemu-devel@nongnu.org; Tue, 19 Jan 2016 17:37:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLeu4-0003nI-BC for qemu-devel@nongnu.org; Tue, 19 Jan 2016 17:37:35 -0500 Received: from mail-bl2nam02on0054.outbound.protection.outlook.com ([104.47.38.54]:30336 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLeu4-0003n5-6V for qemu-devel@nongnu.org; Tue, 19 Jan 2016 17:37:32 -0500 Received: from SN1NAM02FT022.eop-nam02.prod.protection.outlook.com (10.152.72.53) by SN1NAM02HT157.eop-nam02.prod.protection.outlook.com (10.152.73.87) with Microsoft SMTP Server (TLS) id 15.1.355.15; Tue, 19 Jan 2016 22:37:30 +0000 Authentication-Results: spf=fail (sender IP is 149.199.60.96) smtp.mailfrom=xilinx.com; suse.de; dkim=none (message not signed) header.d=none; suse.de; 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 SN1NAM02FT022.mail.protection.outlook.com (10.152.72.148) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Tue, 19 Jan 2016 22:37:30 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:34410 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1aLeu0-0008Qb-Uc; Tue, 19 Jan 2016 14:37:28 -0800 Received: from [127.0.0.1] (port=41629 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1aLeu0-0007g7-Oz; Tue, 19 Jan 2016 14:37:28 -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 u0JMVtkY015221; Tue, 19 Jan 2016 14:31:55 -0800 Received: from [172.19.74.182] (port=39706 helo=xsjalistai50.xlnx.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1aLeu0-0007g4-1F; Tue, 19 Jan 2016 14:37:28 -0800 From: Alistair Francis To: Date: Tue, 19 Jan 2016 14:35:01 -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.644-7.0-31-10 X-imss-scan-details: No--7.644-7.0-31-10 X-TMASE-MatchedRID: zYjuNubSscT/uyguzMmOKFz+axQLnAVBPZmbnY2qDInI9EDAP/dptgPa oyNK+Jv3U04tQnDKvayabl93ZYPKaEljyQrgpG/eA9lly13c/gGxIYWToTws904IqSdLdTKdHdu 4m3gbi+METAbnQIN9A3gscjoXnCecUW22dI8YBTrIOn6NK8S1a3Uh2OMdFI0JTl4aoBUEy2pdaO 8DxOlYWGpJmDs4lyyiUn2gzVSS+UpccQ8eam5EfRRFJJyf5BJe3QfwsVk0UbtuRXh7bFKB7tYhn 9VsjsrxiJf9uwr/aMDu7mP4mRQlJDCxLaPNk7yMvuvB6gAgryg= X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.96; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(979002)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(19580405001)(47776003)(50226001)(2351001)(2906002)(64026002)(106466001)(4326007)(5003940100001)(5003600100002)(36756003)(85426001)(1220700001)(76176999)(92566002)(87936001)(71366001)(50986999)(86362001)(77096005)(11100500001)(6806005)(2950100001)(189998001)(19580395003)(105606002)(48376002)(229853001)(5008740100001)(33646002)(586003)(50466002)(118296001)(81156007)(1096002)(5001960100002)(110136002)(107986001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1NAM02HT157; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; PTR:unknown-60-96.xilinx.com; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: ee653db6-a603-41bc-d0c1-08d321211d8f X-Exchange-Antispam-Report-Test: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:SN1NAM02HT157; UriScan:(192813158149592); X-Microsoft-Antispam-PRVS: <6872a000cfac494a877e2ed3720ff873@SN1NAM02HT157.eop-nam02.prod.protection.outlook.com> X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(13017025)(13024025)(13018025)(13015025)(13023025)(8121501046)(3002001)(10201501046); SRVR:SN1NAM02HT157; BCL:0; PCL:0; RULEID:; SRVR:SN1NAM02HT157; X-Forefront-PRVS: 0826B2F01B X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2016 22:37:30.0786 (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: SN1NAM02HT157 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.54 Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org, alistair.francis@xilinx.com, crosthwaitepeter@gmail.com, edgar.iglesias@gmail.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 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 --- changed from v2: Added fast path to register_write_memory to skip endianness bitbashing hw/core/register.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/hw/core/register.c b/hw/core/register.c index 02a4376..ca10cff 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -184,3 +184,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 249f458..a3c41db 100644 --- a/include/hw/register.h +++ b/include/hw/register.h @@ -86,6 +86,8 @@ 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 { @@ -103,6 +105,8 @@ struct RegisterInfo { bool read_lite; bool write_lite; + + MemoryRegion mem; }; /** @@ -129,4 +133,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