From patchwork Fri Jun 24 15:42:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 640265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rbjLQ0P0Yz9sC4 for ; Sat, 25 Jun 2016 01:44:14 +1000 (AEST) Received: from localhost ([::1]:44397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTH9-0003cx-Vy for incoming@patchwork.ozlabs.org; Fri, 24 Jun 2016 11:44:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTFl-00014b-1p for qemu-devel@nongnu.org; Fri, 24 Jun 2016 11:42:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGTFg-0002dA-Im for qemu-devel@nongnu.org; Fri, 24 Jun 2016 11:42:43 -0400 Received: from mail-cys01nam02on0058.outbound.protection.outlook.com ([104.47.37.58]:52304 helo=NAM02-CY1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTFg-0002d0-9z for qemu-devel@nongnu.org; Fri, 24 Jun 2016 11:42:40 -0400 Received: from CY1NAM02FT013.eop-nam02.prod.protection.outlook.com (10.152.74.57) by CY1NAM02HT020.eop-nam02.prod.protection.outlook.com (10.152.74.220) with Microsoft SMTP Server (TLS) id 15.1.523.9; Fri, 24 Jun 2016 15:42:38 +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 CY1NAM02FT013.mail.protection.outlook.com (10.152.75.162) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Fri, 24 Jun 2016 15:42:37 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:45519 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1bGTFd-0002SF-AR; Fri, 24 Jun 2016 08:42:37 -0700 Received: from [127.0.0.1] (port=54360 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1bGTFd-0004bF-6Y; Fri, 24 Jun 2016 08:42:37 -0700 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 u5OFa4B8022984; Fri, 24 Jun 2016 08:36:05 -0700 Received: from [172.19.74.182] (port=54344 helo=xsjalistai50.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1bGTFc-0004bC-As; Fri, 24 Jun 2016 08:42:36 -0700 From: Alistair Francis To: , Date: Fri, 24 Jun 2016 08:42:23 -0700 Message-ID: X-Mailer: git-send-email 2.7.4 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-22410.005 X-TM-AS-Result: No--8.918-7.0-31-10 X-imss-scan-details: No--8.918-7.0-31-10 X-TMASE-MatchedRID: gjHmqQ7feJb/uyguzMmOKFz+axQLnAVB5kzxLgNhSikKogmGusPLb9qE +670/uY7W7pnWgQdM83E2Ze23WGFFxNGrZ+8S29tzfqlpbtmcWghHWssEmb8zjaULO2AzDKgns7 fbmSSSa3Piwaw8bN2WHOJ+84SCqGXEuYl3YX/IW5Lc5N+0s1+DYfsPVs/8Vw6GepmY6Y3X4eSTV QJZzYEyCl9/0tJO78QN771ia5GkbtZT98H9cWYnHQIOMndeKgExKAxBgoYewkS+jFO7d+PW5j8G xLyYAHn1jShurgIBVcgvMMgzEy83h2J50HW8ezeQpxiLlDD9FXY6gjqh5AULpsoi2XrUn/Jn6Kd MrRsL14qtq5d3cxkNUle+SJ5STYltxlwFlRzQowKgyal2Coj7o6lmm7IiTGIUHSmLpN/cY4= X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.96; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(36756003)(48376002)(7846002)(81156014)(50986999)(76176999)(19580395003)(85426001)(8676002)(81166006)(8936002)(19580405001)(5003600100003)(50226002)(11100500001)(50466002)(305945005)(33646002)(92566002)(7696003)(9786002)(118296001)(2906002)(5003940100001)(4326007)(77096005)(86362001)(105606002)(106466001)(229853001)(6806005)(5001770100001)(189998001)(71366001)(47776003)(64026002)(586003)(356003)(2950100001)(87936001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1NAM02HT020; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; PTR:unknown-60-96.xilinx.com; A:1; MX:1; CAT:NONE; LANG:en; CAT:NONE; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: caeb8d45-44cd-438e-2ecd-08d39c462b9d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1NAM02HT020; X-Microsoft-Antispam-PRVS: <82d11c66bc784860b995f0b38473879c@CY1NAM02HT020.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)(13017025)(5005006)(8121501046)(13023025)(13024025)(13018025)(13015025)(10201501046)(3002001)(6055026); SRVR:CY1NAM02HT020; BCL:0; PCL:0; RULEID:; SRVR:CY1NAM02HT020; X-Forefront-PRVS: 0983EAD6B2 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jun 2016 15:42:37.8049 (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: CY1NAM02HT020 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.37.58 Subject: [Qemu-devel] [PATCH v8 6/8] register: Add block initialise helper 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: , 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 Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Peter Crosthwaite Add a helper that will scan a static RegisterAccessInfo Array and populate a container MemoryRegion with registers as defined. Signed-off-by: Peter Crosthwaite Signed-off-by: Alistair Francis --- The reason that I'm not using GArray is because the array needs to store the memory region that covers all of the registers. V8: - Add a finalise function used to free the allocated memory V7: - Return the memory region instead of adding it as a subregion V6: - Fixup the loop logic V5: - Convert to only using one memory region V3: - Fix typo V2: - Use memory_region_add_subregion_no_print() hw/core/register.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/register.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/hw/core/register.c b/hw/core/register.c index 058c998..7b73bf4 100644 --- a/hw/core/register.c +++ b/hw/core/register.c @@ -228,6 +228,50 @@ uint64_t register_read_memory(void *opaque, hwaddr addr, return extract64(read_val, 0, size * 8); } +RegisterInfoArray *register_init_block32(DeviceState *owner, + const RegisterAccessInfo *rae, + int num, RegisterInfo *ri, + uint32_t *data, + const MemoryRegionOps *ops, + bool debug_enabled, + uint64_t memory_size) +{ + const char *device_prefix = object_get_typename(OBJECT(owner)); + RegisterInfoArray *r_array = g_new0(RegisterInfoArray, 1); + int i; + + r_array->r = g_new0(RegisterInfo *, num); + r_array->num_elements = num; + r_array->debug = debug_enabled; + r_array->prefix = device_prefix; + + for (i = 0; i < num; i++) { + int index = rae[i].addr / 4; + RegisterInfo *r = &ri[index]; + + *r = (RegisterInfo) { + .data = &data[index], + .data_size = sizeof(uint32_t), + .access = &rae[i], + .opaque = owner, + }; + register_init(r); + + r_array->r[i] = r; + } + + memory_region_init_io(&r_array->mem, OBJECT(owner), ops, r_array, + device_prefix, memory_size); + + return r_array; +} + +void register_finlise_block(RegisterInfoArray *r_array) +{ + g_free(r_array->r); + g_free(r_array); +} + static const TypeInfo register_info = { .name = TYPE_REGISTER, .parent = TYPE_DEVICE, diff --git a/include/hw/register.h b/include/hw/register.h index 61c53fb..b8d464d 100644 --- a/include/hw/register.h +++ b/include/hw/register.h @@ -100,6 +100,8 @@ struct RegisterInfo { */ struct RegisterInfoArray { + MemoryRegion mem; + int num_elements; RegisterInfo **r; @@ -166,6 +168,40 @@ void register_write_memory(void *opaque, hwaddr addr, uint64_t value, uint64_t register_read_memory(void *opaque, hwaddr addr, unsigned size); +/** + * Init a block of registers into a container MemoryRegion. A + * number of constant register definitions are parsed to create a corresponding + * array of RegisterInfo's. + * + * @owner: device owning the registers + * @rae: Register definitions to init + * @num: number of registers to init (length of @rae) + * @ri: Register array to init, must already be allocated + * @data: Array to use for register data, must already be allocated + * @ops: Memory region ops to access registers. + * @debug enabled: turn on/off verbose debug information + * returns: An structure containing all of the registers and an initialized + memory region (r_array->mem) the caller should add to a container. + */ + +RegisterInfoArray *register_init_block32(DeviceState *owner, + const RegisterAccessInfo *rae, + int num, RegisterInfo *ri, + uint32_t *data, + const MemoryRegionOps *ops, + bool debug_enabled, + uint64_t memory_size); + +/** + * This function should be called to cleanup the registers that were initialized + * when calling register_init_block32() + * + * @r_array: An structure containing all of the registers. The caller is in + * charge of cleaning up the memory region (r_array->mem). + */ + +void register_finlise_block(RegisterInfoArray *r_array); + /* Define constants for a 32 bit register */ /* This macro will define A_FOO, for the byte address of a register