From patchwork Sat Sep 24 16:42:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 9349215 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 87165607F0 for ; Sat, 24 Sep 2016 16:44:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67BA329124 for ; Sat, 24 Sep 2016 16:44:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49DFC29130; Sat, 24 Sep 2016 16:44:43 +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 BAE1E29124 for ; Sat, 24 Sep 2016 16:44:42 +0000 (UTC) Received: from localhost ([::1]:34726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnq49-0005VN-QP for patchwork-qemu-devel@patchwork.kernel.org; Sat, 24 Sep 2016 12:44:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnq21-0003x3-1h for qemu-devel@nongnu.org; Sat, 24 Sep 2016 12:42:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnq20-0000Ae-18 for qemu-devel@nongnu.org; Sat, 24 Sep 2016 12:42:29 -0400 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:36427) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnq1s-00009H-BO; Sat, 24 Sep 2016 12:42:20 -0400 Received: by mail-it0-x244.google.com with SMTP id n143so2713127ita.3; Sat, 24 Sep 2016 09:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:message-id:cc:content-transfer-encoding:from:subject :date:to; bh=xWH0yZO151jYfvv8najbCW2kBoafNwP8fPZjGjGB/3U=; b=uIB9s9bnqB52xJcbsoQPKjXhD22zp0Wr96QiQKjiptFXuUWCIeLK0wLZt6ZTWesxfk 5p2mqlgp0XHFclaTB4yX13Nu5coZDxgvFs4aEzw32T669Ml3N6Xpxk+gX5rJtMvwBt/a 4jjEKnBy5QpvUev2xEdFrMSARbqvK/A0qBV6n7+IamlYzcnK4AV7T5M4UJTfeZLYbf2c ZoqKNleu0teqd5Sx+k9ZFid4QhnO7HNDWHv5nkAdYHYg4Yyc9CWee61U2FnaAKUV5otl Ul5pbrFY9wJC/nA6hNqZ2fSlpVRrkFeUOajbkggifro3X+xxqiBiSF9BBst0tM22jtcw xsPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:cc :content-transfer-encoding:from:subject:date:to; bh=xWH0yZO151jYfvv8najbCW2kBoafNwP8fPZjGjGB/3U=; b=j6LCpJtUynA8Ynix1W5/hGrBwlO6Sop1bRqad3CqMRKuzbsJJ+J/qFkF5bESEKaYCe zM8QVmW349J1dAJSGMO9bw5vB9fpeiR74Hp9K9Hgvy9iexloef3P9tCBK+19k9jb49XE d/KyQHmUCVKpKrzafAsp595kgPW43cgDLYAEQAUStqPVKEKdMr/RpSr0FfIhpxWuM2dr ehTXGPkVy8q/rENItDgivUkgBvhyiW6lUACU5hr6jMgncnJD/na2frLk013gYV6fRFHo q082MFaY39jS7IWY9D0e+f8QVBlPEYflZVSj3FH0kjw0N5aX1cDRSYUjmHUoCerVMGan N4Gw== X-Gm-Message-State: AA6/9RnXaNdfDeTQ6VpmkrmE2WVUKyCDl9GoN6XjmkORvrFZhisuuq/moI648OPb1OKzLA== X-Received: by 10.36.238.134 with SMTP id b128mr9898269iti.72.1474735339135; Sat, 24 Sep 2016 09:42:19 -0700 (PDT) Received: from [192.168.0.9] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id f131sm564793itc.8.2016.09.24.09.42.17 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 24 Sep 2016 09:42:18 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v753.1) Message-Id: From: G 3 Date: Sat, 24 Sep 2016 12:42:09 -0400 To: Benjamin Herrenschmidt X-Mailer: Apple Mail (2.753.1) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c0b::244 Subject: [Qemu-devel] [PATCH v4] Add resolutions via the command-line 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: "list@suse.de:PowerPC list:PowerPC" , qemu-devel qemu-devel Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add the ability to add resolutions from the command-line. This patch works by looking for a property called 'resolutions' in the QEMU,VGA node of OpenBIOS. If it is found all the resolutions are parsed and loaded. Example command-line: -prom-env resolutions=512x342,640x480,800x600,1024x600,1200x700,1440x900 Signed-off-by: John Arbuckle --- v4 Removed all ASCII text processing code and replaced it with integer processing code. v3 Changed implementation of atoi(). Removed strlen() implementation. Removed pow() implementation. Changed entry_id from pointer to automatic variable. v2 Implemented my own malloc(), strlen(), pow(), and atoi() functions. Removed free() calls. Changed get_set_count() to get_resolution_set_count(). QemuVGADriver/src/QemuVga.c | 107 ++++++++++++++++++++++++++++++++++ +++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) OSStatus QemuVga_Init(void) { UInt16 id, i; UInt32 mem, width, height, depth; + add_user_resolutions(); + lprintf("First MMIO read...\n"); id = DispiReadW(VBE_DISPI_INDEX_ID); mem = DispiReadW(VBE_DISPI_INDEX_VIDEO_MEMORY_64K); @@ -183,7 +286,7 @@ OSStatus QemuVga_Init(void) i = 0; } GLOBAL.bootMode = i; - GLOBAL.numModes = sizeof(vModes) / sizeof(struct vMode) - 1; + GLOBAL.numModes = get_number_of_resolutions(); QemuVga_SetMode(GLOBAL.bootMode, depth, 0); diff --git a/QemuVGADriver/src/QemuVga.c b/QemuVGADriver/src/QemuVga.c index 4584242..9d2967e 100644 --- a/QemuVGADriver/src/QemuVga.c +++ b/QemuVGADriver/src/QemuVga.c @@ -18,9 +18,25 @@ static struct vMode vModes[] = { { 1600, 1200 }, { 1920, 1080 }, { 1920, 1200 }, - { 0,0 } + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, + { 0,0 }, }; +/* The number of width-height pairs in the above vModes structure */ +#define AVAILABLE_SLOTS 20 + + static void VgaWriteB(UInt16 port, UInt8 val) { UInt8 *ptr; @@ -148,11 +164,98 @@ static InterruptMemberNumber PCIInterruptHandler (InterruptSetMember ISTmember, #endif +/* Returns the number of resolutions in the vModes array */ +static int get_number_of_resolutions() +{ + int size_of_array, num_of_resolutions, index; + + num_of_resolutions = 0; + size_of_array = sizeof(vModes) / sizeof(struct vMode); + + for(index = 0; index < size_of_array; index++) + { + if (vModes[index].width != 0) { + num_of_resolutions++; + } + } + + return num_of_resolutions; +} + + +/* Looks in the /options node for the value of the resolutions property */ +static int add_user_resolutions(void) +{ + RegEntryID entry_id; + OSErr err; + OSStatus os_status = noErr; + Boolean is_done; + void *value; + RegPropertyValueSize property_size = -1; + int index, res_set_count, *res_values; + + #define PROPERTY_NAME "resolutions" + #define NODE_PATH "Devices:device-tree:pci:QEMU,VGA" + + /* init the entry variable */ + err = RegistryEntryIDInit(&entry_id); + if (err != noErr) { + lprintf("Error: Failed to init entry variable! (Error: %d)\n", err); + return err; + } + is_done = false; + + /* Get the entry ID value */ + err = RegistryCStrEntryLookup(NULL /* start root */, NODE_PATH, &entry_id); + if (err != noErr) { + lprintf("RegistryCStrEntryLookup() failure (Error: %d)\n", err); + return err; + } + + /* Get the size of the property */ + os_status = RegistryPropertyGetSize(&entry_id, PROPERTY_NAME, &property_size); + if (os_status != noErr) { + lprintf("Error: Failed to get property size! (Error: %d)\n", os_status); + return os_status; + } + + /* Allocate memory to the value variable */ + value = (void *) PoolAllocateResident(property_size, false); + if (value == NULL) { + lprintf("Error: Failed to allocate memory to value variable\n"); + return -1; + } + + /* Get the value of the property */ + err = RegistryPropertyGet(&entry_id, PROPERTY_NAME, value, &property_size); + if (err != noErr) { + lprintf("Error: Failed to find property value %s! (Error: %d)\n", PROPERTY_NAME, err); + return err; + } + + res_values = value; + res_set_count = property_size/4/2; /* divide by bytes per cell then by cells per set */ + + /* Limit the number of resolutions to number of available slots in vMode */ + res_set_count = (res_set_count > AVAILABLE_SLOTS ? AVAILABLE_SLOTS : res_set_count); + + /* Load each resolution set */ + for(index = 0; index < res_set_count; index++) + { + vModes[index].width = *(res_values++); + vModes[index].height = *(res_values++); + } + return 0; +} + +