From patchwork Fri Mar 31 16:48:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 9656833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BA88560351 for ; Fri, 31 Mar 2017 16:51:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACBB626223 for ; Fri, 31 Mar 2017 16:51:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0E1A286C7; Fri, 31 Mar 2017 16:51:20 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 22E8D26223 for ; Fri, 31 Mar 2017 16:51:20 +0000 (UTC) Received: from localhost ([::1]:42001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctzlf-0005zj-8J for patchwork-qemu-devel@patchwork.kernel.org; Fri, 31 Mar 2017 12:51:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctzjN-0004v8-CV for qemu-devel@nongnu.org; Fri, 31 Mar 2017 12:48:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctzjJ-0004qN-MX for qemu-devel@nongnu.org; Fri, 31 Mar 2017 12:48:57 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:36859) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ctzjJ-0004pv-I7 for qemu-devel@nongnu.org; Fri, 31 Mar 2017 12:48:53 -0400 Received: by mail-qt0-x243.google.com with SMTP id n37so10938424qtb.3 for ; Fri, 31 Mar 2017 09:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Aj3bU/Ec8aWm86Rhm/+QB/GfN936pEU1hbdVI1ZFy7A=; b=iIBbMm9VunAPiRVrvNkutQe8ihBD+QKoa45T/jTXkiDJ9Q0cygE1GrvRglsJWYBVfI IptzwKzCPclNw5xk6hwApbpSjiX7H4xWExZg/w4iEAdll3h3XAkLc6BEe4EzWOcw+pb5 mYAZr3ADoH9UCX/ETDgjlvCPg+Us40ZKyQ5e7Y7IBwQI5sHNiumSLVMJLXaz7ztYWAA3 fDEXq4fluFKnusI2x3wcYYTiInsYTffxdxqMJB7eC+jR05xNqY4jjxS3lO03ranAt6n/ 7YKA4Xu+ni95I6pXDoxf7D4Mj9MGPv0szWhpe33PPqQ568IS1T9j2rXSi0JZMlLC4u98 Wmwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Aj3bU/Ec8aWm86Rhm/+QB/GfN936pEU1hbdVI1ZFy7A=; b=L7cCcbPx1bNd3xWL4q8CQpZdQbjNm0NbrPhPbGoHHcHYUCRJ5kKCUiJYvlSbE4gN+V TlHgAhhqDCCMd1naOybMTxG47x2sHKwJmtNtYg/RmnbA9fKMPTGFB4NiUL8FZxmVwsQl AiE0XZuzwCGsy3OiDj488YsphonDkJLLM13MwH2bxAHfQ0RZNUFzrDlfSCQ9+ytu8Zs9 McaU2JzaX1BdZSoR/Dyp54Ip0Vq8riRdqNh6aOVBMcHiHB7B8alZY+bWOYJRGiTf1JAW aX9hD3SC89pS/psvm0eDFBlDNOlPPnVock6iTu21qM0JTD1muXRmz2H6umWR1+32FTHC I4Uw== X-Gm-Message-State: AFeK/H12w49BBEc7ty3PbWkUW3erTPYSTah3hmNgtUSHNLY7jIFNeavhvidQgfaWjZYQ/w== X-Received: by 10.237.33.240 with SMTP id m45mr4008610qtc.246.1490978932847; Fri, 31 Mar 2017 09:48:52 -0700 (PDT) Received: from HEDWIG.ini.cmu.edu (HEDWIG.INI.CMU.EDU. [128.2.16.51]) by smtp.gmail.com with ESMTPSA id z42sm3859371qtb.20.2017.03.31.09.48.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Mar 2017 09:48:52 -0700 (PDT) From: "Gabriel L. Somlo" To: qemu-devel@nongnu.org Date: Fri, 31 Mar 2017 12:48:40 -0400 Message-Id: <1490978921-3782-3-git-send-email-gsomlo@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490978921-3782-1-git-send-email-gsomlo@gmail.com> References: <1490978921-3782-1-git-send-email-gsomlo@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PATCH v1 2/3] applesmc: consolidate port i/o into single contiguous region 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: agraf@suse.de, eshelton@pobox.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Newer AppleSMC revisions support an error status (read) port in addition to the data and command ports currently supported. Register the full 32-bit region at once, and handle individual ports at various offsets within the region from the top-level applesmc_io_[write|read]() methods (ctual support for reading the error status port to be added by a subsequent patch). Originally proposed by Eric Shelton Signed-off-by: Gabriel Somlo --- hw/misc/applesmc.c | 56 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c index 986f2ac..e581e02 100644 --- a/hw/misc/applesmc.c +++ b/hw/misc/applesmc.c @@ -75,8 +75,7 @@ typedef struct AppleSMCState AppleSMCState; struct AppleSMCState { ISADevice parent_obj; - MemoryRegion io_data; - MemoryRegion io_cmd; + MemoryRegion io_reg; uint32_t iobase; uint8_t cmd; uint8_t status; @@ -207,19 +206,36 @@ static void qdev_applesmc_isa_reset(DeviceState *dev) applesmc_add_key(s, "MSSD", 1, "\0x3"); } -static const MemoryRegionOps applesmc_data_io_ops = { - .write = applesmc_io_data_write, - .read = applesmc_io_data_read, - .endianness = DEVICE_NATIVE_ENDIAN, - .impl = { - .min_access_size = 1, - .max_access_size = 1, - }, -}; +static void applesmc_io_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + switch (addr) { + case APPLESMC_DATA_PORT: + applesmc_io_data_write(opaque, addr, val, size); + break; + case APPLESMC_CMD_PORT: + applesmc_io_cmd_write(opaque, addr, val, size); + break; + default: + break; + } +} -static const MemoryRegionOps applesmc_cmd_io_ops = { - .write = applesmc_io_cmd_write, - .read = applesmc_io_cmd_read, +static uint64_t applesmc_io_read(void *opaque, hwaddr addr, unsigned size) +{ + switch (addr) { + case APPLESMC_DATA_PORT: + return applesmc_io_data_read(opaque, addr, size); + case APPLESMC_CMD_PORT: + return applesmc_io_cmd_read(opaque, addr, size); + default: + return 0xff; + } +} + +static const MemoryRegionOps applesmc_io_ops = { + .write = applesmc_io_write, + .read = applesmc_io_read, .endianness = DEVICE_NATIVE_ENDIAN, .impl = { .min_access_size = 1, @@ -231,15 +247,9 @@ static void applesmc_isa_realize(DeviceState *dev, Error **errp) { AppleSMCState *s = APPLE_SMC(dev); - memory_region_init_io(&s->io_data, OBJECT(s), &applesmc_data_io_ops, s, - "applesmc-data", 4); - isa_register_ioport(&s->parent_obj, &s->io_data, - s->iobase + APPLESMC_DATA_PORT); - - memory_region_init_io(&s->io_cmd, OBJECT(s), &applesmc_cmd_io_ops, s, - "applesmc-cmd", 4); - isa_register_ioport(&s->parent_obj, &s->io_cmd, - s->iobase + APPLESMC_CMD_PORT); + memory_region_init_io(&s->io_reg, OBJECT(s), &applesmc_io_ops, s, + "applesmc", APPLESMC_NUM_PORTS); + isa_register_ioport(&s->parent_obj, &s->io_reg, s->iobase); if (!s->osk || (strlen(s->osk) != 64)) { fprintf(stderr, "WARNING: Using AppleSMC with invalid key\n");