From patchwork Fri Mar 31 16:48:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 9656835 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 7C66560351 for ; Fri, 31 Mar 2017 16:51:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EDFA26223 for ; Fri, 31 Mar 2017 16:51:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63833286C7; Fri, 31 Mar 2017 16:51:21 +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 DAF2926223 for ; Fri, 31 Mar 2017 16:51:20 +0000 (UTC) Received: from localhost ([::1]:42002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctzlg-00060A-0D for patchwork-qemu-devel@patchwork.kernel.org; Fri, 31 Mar 2017 12:51:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctzjN-0004v6-Bn 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 1ctzjI-0004pQ-Td for qemu-devel@nongnu.org; Fri, 31 Mar 2017 12:48:57 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:34451) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ctzjI-0004p1-Op for qemu-devel@nongnu.org; Fri, 31 Mar 2017 12:48:52 -0400 Received: by mail-qk0-x241.google.com with SMTP id 10so11177620qkh.1 for ; Fri, 31 Mar 2017 09:48:52 -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=ZPhWmDTXfisxCGzkpiXOTV0rcEsfkfwpDkE8mDdQLtY=; b=riG7U5lLHgWrLm/ZAI+3wv65AYBvWZml1X9mTsEeY/XaqozjFNyIIQMkwpFpLLKPy6 BG4A43DGYsr+Gek/9uYwD7xJFDvslIgizCbRtiJbGkQK78mCzkLcmBxj7FF+VYFof4Q9 2xFM+Gm7PKRPMSiuuqqkN42YyfESJoKpkR50BD9UbUabdGUiJoYn10+RF3+0V0YwWYXF lwVHbUfpSuWAbY9dzNDmwXTWxTe8zh9L2nIziAgKfzD4obAkmMUAIdHYmPfT1hvG4P0M LckD2D+wZ0JvdFpOpJX76n5s4O2cEm5ZcxRjXs6ARgGKbIBCZ4adrX41mTHV2fgNW/c6 87TQ== 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=ZPhWmDTXfisxCGzkpiXOTV0rcEsfkfwpDkE8mDdQLtY=; b=QRRAhuOuWlF1gaWlzoah02fWTcKiavoYKdBZvF9c4a57o0812Y0N3DaoguH2yt+wAV 2BQIlyFkTM/nOOP2wvG7FiOLilUjfUXLs4t1oMBTtTFWZfehn1TE5TZds7hL3aC6u+/r p3nJonbOSgPy42L65F1YYv6oK9gHW6D2GYHxWOvEyijUtjE10aCBHJFh/fLRpDwkNL/c VDG7fbScZ5tekLE7jhsU0XI5OktmI8J7MdWvybocYUkgDJHP3lkSWQWQ0ipE4HEW4Pxv Fb+172GS+BFLsJfdGpUbWQ5q5rijmrUsx4o7RCozTKh9K5cVgwbG22OlV3waVHZkdbDq eMgg== X-Gm-Message-State: AFeK/H1K0VP6BAMfHDZGkWRLLNz+y4Rgdan071Sri+fzNAkDQLkK6CHXmbXW1c+5C6sObQ== X-Received: by 10.55.19.83 with SMTP id d80mr3893672qkh.196.1490978932160; 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.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Mar 2017 09:48:51 -0700 (PDT) From: "Gabriel L. Somlo" To: qemu-devel@nongnu.org Date: Fri, 31 Mar 2017 12:48:39 -0400 Message-Id: <1490978921-3782-2-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: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PATCH v1 1/3] applesmc: cosmetic whitespace and indentation cleanup 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 Signed-off-by: Gabriel Somlo Reviewed-by: Alexander Graf Reviewed-by: Philippe Mathieu-Daudé --- hw/misc/applesmc.c | 100 +++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c index 77fab5b..986f2ac 100644 --- a/hw/misc/applesmc.c +++ b/hw/misc/applesmc.c @@ -39,24 +39,27 @@ /* #define DEBUG_SMC */ #define APPLESMC_DEFAULT_IOBASE 0x300 -/* data port used by Apple SMC */ -#define APPLESMC_DATA_PORT 0x0 -/* command/status port used by Apple SMC */ -#define APPLESMC_CMD_PORT 0x4 -#define APPLESMC_NR_PORTS 32 -#define APPLESMC_READ_CMD 0x10 -#define APPLESMC_WRITE_CMD 0x11 -#define APPLESMC_GET_KEY_BY_INDEX_CMD 0x12 -#define APPLESMC_GET_KEY_TYPE_CMD 0x13 +enum { + APPLESMC_DATA_PORT = 0x00, + APPLESMC_CMD_PORT = 0x04, + APPLESMC_NUM_PORTS = 0x20, +}; + +enum { + APPLESMC_READ_CMD = 0x10, + APPLESMC_WRITE_CMD = 0x11, + APPLESMC_GET_KEY_BY_INDEX_CMD = 0x12, + APPLESMC_GET_KEY_TYPE_CMD = 0x13, +}; #ifdef DEBUG_SMC #define smc_debug(...) fprintf(stderr, "AppleSMC: " __VA_ARGS__) #else -#define smc_debug(...) do { } while(0) +#define smc_debug(...) do { } while (0) #endif -static char default_osk[64] = "This is a dummy key. Enter the real key " +static char default_osk[65] = "This is a dummy key. Enter the real key " "using the -osk parameter"; struct AppleSMCData { @@ -77,12 +80,11 @@ struct AppleSMCState { uint32_t iobase; uint8_t cmd; uint8_t status; - uint8_t key[4]; + char key[4]; uint8_t read_pos; uint8_t data_len; uint8_t data_pos; uint8_t data[255]; - uint8_t charactic[4]; char *osk; QLIST_HEAD(, AppleSMCData) data_def; }; @@ -93,10 +95,10 @@ static void applesmc_io_cmd_write(void *opaque, hwaddr addr, uint64_t val, AppleSMCState *s = opaque; smc_debug("CMD Write B: %#x = %#x\n", addr, val); - switch(val) { - case APPLESMC_READ_CMD: - s->status = 0x0c; - break; + switch (val) { + case APPLESMC_READ_CMD: + s->status = 0x0c; + break; } s->cmd = val; s->read_pos = 0; @@ -123,54 +125,54 @@ static void applesmc_io_data_write(void *opaque, hwaddr addr, uint64_t val, AppleSMCState *s = opaque; smc_debug("DATA Write B: %#x = %#x\n", addr, val); - switch(s->cmd) { - case APPLESMC_READ_CMD: - if(s->read_pos < 4) { - s->key[s->read_pos] = val; - s->status = 0x04; - } else if(s->read_pos == 4) { - s->data_len = val; - s->status = 0x05; - s->data_pos = 0; - smc_debug("Key = %c%c%c%c Len = %d\n", s->key[0], - s->key[1], s->key[2], s->key[3], val); - applesmc_fill_data(s); - } - s->read_pos++; - break; + switch (s->cmd) { + case APPLESMC_READ_CMD: + if (s->read_pos < 4) { + s->key[s->read_pos] = val; + s->status = 0x04; + } else if (s->read_pos == 4) { + s->data_len = val; + s->status = 0x05; + s->data_pos = 0; + smc_debug("Key = %c%c%c%c Len = %d\n", s->key[0], + s->key[1], s->key[2], s->key[3], val); + applesmc_fill_data(s); + } + s->read_pos++; + break; } } -static uint64_t applesmc_io_data_read(void *opaque, hwaddr addr1, - unsigned size) +static uint64_t applesmc_io_data_read(void *opaque, hwaddr addr, unsigned size) { AppleSMCState *s = opaque; uint8_t retval = 0; - switch(s->cmd) { - case APPLESMC_READ_CMD: - if(s->data_pos < s->data_len) { - retval = s->data[s->data_pos]; - smc_debug("READ_DATA[%d] = %#hhx\n", s->data_pos, - retval); - s->data_pos++; - if(s->data_pos == s->data_len) { - s->status = 0x00; - smc_debug("EOF\n"); - } else - s->status = 0x05; + switch (s->cmd) { + case APPLESMC_READ_CMD: + if (s->data_pos < s->data_len) { + retval = s->data[s->data_pos]; + smc_debug("READ_DATA[%d] = %#hhx\n", s->data_pos, + retval); + s->data_pos++; + if (s->data_pos == s->data_len) { + s->status = 0x00; + smc_debug("EOF\n"); + } else { + s->status = 0x05; } + } } - smc_debug("DATA Read b: %#x = %#x\n", addr1, retval); + smc_debug("DATA Read b: %#x = %#x\n", addr, retval); return retval; } -static uint64_t applesmc_io_cmd_read(void *opaque, hwaddr addr1, unsigned size) +static uint64_t applesmc_io_cmd_read(void *opaque, hwaddr addr, unsigned size) { AppleSMCState *s = opaque; - smc_debug("CMD Read B: %#x\n", addr1); + smc_debug("CMD Read B: %#x\n", addr); return s->status; }