From nobody Thu May 2 10:50:23 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 148731284156189.87143212408535; Thu, 16 Feb 2017 22:27:21 -0800 (PST) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1cec0V-0004K5-DW; Fri, 17 Feb 2017 07:27:03 +0100 Received: from mail-oi0-f53.google.com ([209.85.218.53]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1cec0L-0004IX-O0 for seabios@seabios.org; Fri, 17 Feb 2017 07:27:01 +0100 Received: by mail-oi0-f53.google.com with SMTP id u143so20023812oif.3 for ; Thu, 16 Feb 2017 22:26:53 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id 76sm4096050otf.21.2017.02.16.22.26.50 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 Feb 2017 22:26:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=9rAsWfryfiRutXxYuyuMn4dQH7nkYZ5S1Rehhi8cUZw=; b=5T65lN9ey1zfd8M+6NExB+nCnHLGgNTPE/jMJ73KBiOpZ69gEaUKm2eIkjbQsa93bV Gr5CfjyUHnYVDedQkZT47gw36DIhbusHcMFevB6rXZ339Ca5ZM6kTGhS+KK3ILmifzh2 K4+MqIiZiKf/24v0R0a86B0EUo8PZmjDr4qUk= 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:in-reply-to:references; bh=9rAsWfryfiRutXxYuyuMn4dQH7nkYZ5S1Rehhi8cUZw=; b=dEdvFMAwWO1YE5g4PbCsBWd947REdcuNc6GDgKYaUTzDn8yjauEb30zJ1p4o79mbFK X0vt/lFFn+SdHfDbjwCy/8Lm2ytFPKPQCqEy6MOxi5QldHAZ45xa8hYxWhOA7YDvZU3B an5yrD/5L/vBFcCljNiSqLwEc5VAb9E8yV2TjrZRk/dRUUOYOIyua+Oc3jeKgKgy4MUU ei+u9EC7CBwnFdAvV+0egQRuyQCNPdfI9yN1frP0/fMyR3scpJ7pMl4Bn2BSSXjcy8Oi /oWIGWYdtiFhiChcPUJfGfKKEKxTK/mxvBadnp0bYNkacDa7kceXmSrx1EukP/qSS3cM VwWg== X-Gm-Message-State: AMke39msbQx+9E8WH8PwTiQBftLQlyPkJ1NVa81jsQlWEx9IrzSeq0xJHRYau895v+z+IyWd X-Received: by 10.202.173.18 with SMTP id w18mr3585238oie.146.1487312811263; Thu, 16 Feb 2017 22:26:51 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Thu, 16 Feb 2017 22:26:38 -0800 Message-Id: X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-Spam-Score: -1.8 (-) Subject: [SeaBIOS] [PATCH v4 1/3] QEMU DMA: Add DMA write capability X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com, mst@redhat.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This allows BIOS to write data back to QEMU using the DMA interface and provides a higher-level abstraction to write to a fw_cfg file Signed-off-by: Ben Warren --- src/fw/paravirt.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/fw/paravirt.h | 3 +++ 2 files changed, 52 insertions(+) diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 6de70f6..75cb992 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -253,6 +253,20 @@ qemu_cfg_read(void *buf, int len) } =20 static void +qemu_cfg_write(void *buf, int len) +{ + if (len =3D=3D 0) { + return; + } + + if (qemu_cfg_dma_enabled()) { + qemu_cfg_dma_transfer(buf, len, QEMU_CFG_DMA_CTL_WRITE); + } else { + warn_internalerror(); + } +} + +static void qemu_cfg_skip(int len) { if (len =3D=3D 0) { @@ -280,6 +294,18 @@ qemu_cfg_read_entry(void *buf, int e, int len) } } =20 +static void +qemu_cfg_write_entry(void *buf, int e, int len) +{ + if (qemu_cfg_dma_enabled()) { + u32 control =3D (e << 16) | QEMU_CFG_DMA_CTL_SELECT + | QEMU_CFG_DMA_CTL_WRITE; + qemu_cfg_dma_transfer(buf, len, control); + } else { + warn_internalerror(); + } +} + struct qemu_romfile_s { struct romfile_s file; int select, skip; @@ -303,6 +329,29 @@ qemu_cfg_read_file(struct romfile_s *file, void *dst, = u32 maxlen) return file->size; } =20 +int +qemu_cfg_write_file(void *src, struct romfile_s *file, u32 offset, u32 len) +{ + if ((file->size + offset) < len) + return -1; + + if (!qemu_cfg_dma_enabled() || (file->copy !=3D qemu_cfg_read_file)) { + warn_internalerror(); + return -1; + } + struct qemu_romfile_s *qfile; + qfile =3D container_of(file, struct qemu_romfile_s, file); + if (offset =3D=3D 0) { + /* Do it in one transfer */ + qemu_cfg_write_entry(src, qfile->select, len); + } else { + qemu_cfg_select(qfile->select); + qemu_cfg_skip(offset); + qemu_cfg_write(src, len); + } + return len; +} + static void qemu_romfile_add(char *name, int select, int skip, int size) { diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h index d8eb7c4..fb220d8 100644 --- a/src/fw/paravirt.h +++ b/src/fw/paravirt.h @@ -3,6 +3,7 @@ =20 #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL +#include "romfile.h" // struct romfile_s =20 // Types of paravirtualized platforms. #define PF_QEMU (1<<0) @@ -43,6 +44,7 @@ static inline int runningOnKVM(void) { #define QEMU_CFG_DMA_CTL_READ 0x02 #define QEMU_CFG_DMA_CTL_SKIP 0x04 #define QEMU_CFG_DMA_CTL_SELECT 0x08 +#define QEMU_CFG_DMA_CTL_WRITE 0x10 =20 // QEMU_CFG_DMA ID bit #define QEMU_CFG_VERSION_DMA 2 @@ -53,5 +55,6 @@ void qemu_platform_setup(void); void qemu_cfg_init(void); =20 u16 qemu_get_present_cpus_count(void); +int qemu_cfg_write_file(void *src, struct romfile_s *file, u32 offset, u32= len); =20 #endif --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://www.coreboot.org/mailman/listinfo/seabios From nobody Thu May 2 10:50:23 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 148731285589347.47196403597991; Thu, 16 Feb 2017 22:27:35 -0800 (PST) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1cec0d-0004MF-6S; Fri, 17 Feb 2017 07:27:11 +0100 Received: from mail-oi0-f49.google.com ([209.85.218.49]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1cec0M-0004IY-JN for seabios@seabios.org; Fri, 17 Feb 2017 07:27:09 +0100 Received: by mail-oi0-f49.google.com with SMTP id u143so20023917oif.3 for ; Thu, 16 Feb 2017 22:26:54 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id 76sm4096050otf.21.2017.02.16.22.26.51 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 Feb 2017 22:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=uzJytUXggJWZcuR8bPGL1iUBAOEcphCSAtLdZjZhJks=; b=GGcKdMjLunvrs/eBHzVMK/Ga2C6WqHWXSe3vyfw6yS8HS7qNFI6rvHUw3EkgK26gz2 NfXO88RakkZyqhPQsx4O6y33fhnRCRNsvoNxfmLZa7UZQshoJlKJvNibR+33qM2P80qg iU0JaWIyham7/gkDCdUU1fwRokhUpR6/kXswI= 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:in-reply-to:references; bh=uzJytUXggJWZcuR8bPGL1iUBAOEcphCSAtLdZjZhJks=; b=pwVm8zLB+t9bKdiKq43sdI3KCzLwg77BwD9bXgUZTnsZ2y/3qMMGxl9ZNZOk8yJcZS eZ0bjN8kFm4TMTpNxe9FbskPoilrMsUywq5vLlJufcOGN9pDm6s/a6gG/4ViOFXMneVq 8iHJvxMd+0QMg9AvlYt9Z8cXKnBG1m/rPjuezYeGijC/BJLZVRkmL9l4WZj3MjNb6XXF N4lRO7UlX6q1kK2CmENI9Fhmnd5bz27vyFpepGdtAdQ+J+ZOVE9R4NJINwoFIr7gW+Ph Y6po3cTyUpGGq+kFWCtSsdEVs+o8auY2WVHr9RC6/oRdr1qJsh6MU2UZDyMVcaRX/lOT 359w== X-Gm-Message-State: AMke39lL8Nr3rXrD0PzOsU46Dh6osc3kZqHYlJei6Z2+0uCvUAyqKmKmVHhP3p2a4RPM5X4d X-Received: by 10.202.240.70 with SMTP id o67mr3495812oih.195.1487312812309; Thu, 16 Feb 2017 22:26:52 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Thu, 16 Feb 2017 22:26:39 -0800 Message-Id: <4453385f599275aa464426e2a292f833dcb013e0.1487312143.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-Spam-Score: -1.2 (-) Subject: [SeaBIOS] [PATCH v4 2/3] romfile-loader: Switch to using named structs X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com, mst@redhat.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This is a little cleaner and matches how the command structures are defined in QEMU. Signed-off-by: Ben Warren Reviewed-by: Laszlo Ersek --- src/fw/romfile_loader.c | 34 +++++++++++++++++----------------- src/fw/romfile_loader.h | 40 ++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/fw/romfile_loader.c b/src/fw/romfile_loader.c index f4b17ff..7737453 100644 --- a/src/fw/romfile_loader.c +++ b/src/fw/romfile_loader.c @@ -35,12 +35,12 @@ static void romfile_loader_allocate(struct romfile_load= er_entry_s *entry, struct romfile_loader_file *file =3D &files->files[files->nfiles]; void *data; int ret; - unsigned alloc_align =3D le32_to_cpu(entry->alloc_align); + unsigned alloc_align =3D le32_to_cpu(entry->alloc.align); =20 if (alloc_align & (alloc_align - 1)) goto err; =20 - switch (entry->alloc_zone) { + switch (entry->alloc.zone) { case ROMFILE_LOADER_ALLOC_ZONE_HIGH: zone =3D &ZoneHigh; break; @@ -52,9 +52,9 @@ static void romfile_loader_allocate(struct romfile_loader= _entry_s *entry, } if (alloc_align < MALLOC_MIN_ALIGN) alloc_align =3D MALLOC_MIN_ALIGN; - if (entry->alloc_file[ROMFILE_LOADER_FILESZ - 1]) + if (entry->alloc.file[ROMFILE_LOADER_FILESZ - 1]) goto err; - file->file =3D romfile_find(entry->alloc_file); + file->file =3D romfile_find(entry->alloc.file); if (!file->file || !file->file->size) return; data =3D _malloc(zone, file->file->size, alloc_align); @@ -80,24 +80,24 @@ static void romfile_loader_add_pointer(struct romfile_l= oader_entry_s *entry, { struct romfile_loader_file *dest_file; struct romfile_loader_file *src_file; - unsigned offset =3D le32_to_cpu(entry->pointer_offset); + unsigned offset =3D le32_to_cpu(entry->pointer.offset); u64 pointer =3D 0; =20 - dest_file =3D romfile_loader_find(entry->pointer_dest_file, files); - src_file =3D romfile_loader_find(entry->pointer_src_file, files); + dest_file =3D romfile_loader_find(entry->pointer.dest_file, files); + src_file =3D romfile_loader_find(entry->pointer.src_file, files); =20 if (!dest_file || !src_file || !dest_file->data || !src_file->data || - offset + entry->pointer_size < offset || - offset + entry->pointer_size > dest_file->file->size || - entry->pointer_size < 1 || entry->pointer_size > 8 || - entry->pointer_size & (entry->pointer_size - 1)) + offset + entry->pointer.size < offset || + offset + entry->pointer.size > dest_file->file->size || + entry->pointer.size < 1 || entry->pointer.size > 8 || + entry->pointer.size & (entry->pointer.size - 1)) goto err; =20 - memcpy(&pointer, dest_file->data + offset, entry->pointer_size); + memcpy(&pointer, dest_file->data + offset, entry->pointer.size); pointer =3D le64_to_cpu(pointer); pointer +=3D (unsigned long)src_file->data; pointer =3D cpu_to_le64(pointer); - memcpy(dest_file->data + offset, &pointer, entry->pointer_size); + memcpy(dest_file->data + offset, &pointer, entry->pointer.size); =20 return; err: @@ -108,12 +108,12 @@ static void romfile_loader_add_checksum(struct romfil= e_loader_entry_s *entry, struct romfile_loader_files *files) { struct romfile_loader_file *file; - unsigned offset =3D le32_to_cpu(entry->cksum_offset); - unsigned start =3D le32_to_cpu(entry->cksum_start); - unsigned len =3D le32_to_cpu(entry->cksum_length); + unsigned offset =3D le32_to_cpu(entry->cksum.offset); + unsigned start =3D le32_to_cpu(entry->cksum.start); + unsigned len =3D le32_to_cpu(entry->cksum.length); u8 *data; =20 - file =3D romfile_loader_find(entry->cksum_file, files); + file =3D romfile_loader_find(entry->cksum.file, files); =20 if (!file || !file->data || offset >=3D file->file->size || start + len < start || start + len > file->file->size) diff --git a/src/fw/romfile_loader.h b/src/fw/romfile_loader.h index 15eab2a..bce3719 100644 --- a/src/fw/romfile_loader.h +++ b/src/fw/romfile_loader.h @@ -11,45 +11,45 @@ struct romfile_loader_entry_s { u32 command; union { /* - * COMMAND_ALLOCATE - allocate a table from @alloc_file - * subject to @alloc_align alignment (must be power of 2) - * and @alloc_zone (can be HIGH or FSEG) requirements. + * COMMAND_ALLOCATE - allocate a table from @alloc.file + * subject to @alloc.align alignment (must be power of 2) + * and @alloc.zone (can be HIGH or FSEG) requirements. * * Must appear exactly once for each file, and before * this file is referenced by any other command. */ struct { - char alloc_file[ROMFILE_LOADER_FILESZ]; - u32 alloc_align; - u8 alloc_zone; - }; + char file[ROMFILE_LOADER_FILESZ]; + u32 align; + u8 zone; + } alloc; =20 /* * COMMAND_ADD_POINTER - patch the table (originating from - * @dest_file) at @pointer_offset, by adding a pointer to the table + * @dest_file) at @pointer.offset, by adding a pointer to the table * originating from @src_file. 1,2,4 or 8 byte unsigned - * addition is used depending on @pointer_size. + * addition is used depending on @pointer.size. */ struct { - char pointer_dest_file[ROMFILE_LOADER_FILESZ]; - char pointer_src_file[ROMFILE_LOADER_FILESZ]; - u32 pointer_offset; - u8 pointer_size; - }; + char dest_file[ROMFILE_LOADER_FILESZ]; + char src_file[ROMFILE_LOADER_FILESZ]; + u32 offset; + u8 size; + } pointer; =20 /* * COMMAND_ADD_CHECKSUM - calculate checksum of the range specifie= d by - * @cksum_start and @cksum_length fields, + * @cksum.start and @cksum.length fields, * and then add the value at @cksum_offset. * Checksum simply sums -X for each byte X in the range * using 8-bit math. */ struct { - char cksum_file[ROMFILE_LOADER_FILESZ]; - u32 cksum_offset; - u32 cksum_start; - u32 cksum_length; - }; + char file[ROMFILE_LOADER_FILESZ]; + u32 offset; + u32 start; + u32 length; + } cksum; =20 /* padding */ char pad[124]; --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://www.coreboot.org/mailman/listinfo/seabios From nobody Thu May 2 10:50:23 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1487312850149947.3247625784538; Thu, 16 Feb 2017 22:27:30 -0800 (PST) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1cec0l-0004Nj-Ou; Fri, 17 Feb 2017 07:27:19 +0100 Received: from mail-oi0-f53.google.com ([209.85.218.53]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1cec0N-0004Io-PH for seabios@seabios.org; Fri, 17 Feb 2017 07:27:17 +0100 Received: by mail-oi0-f53.google.com with SMTP id u143so20024049oif.3 for ; Thu, 16 Feb 2017 22:26:55 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (76-236-31-201.lightspeed.sntcca.sbcglobal.net. [76.236.31.201]) by smtp.gmail.com with ESMTPSA id 76sm4096050otf.21.2017.02.16.22.26.52 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 Feb 2017 22:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=i4vL5Dhxz/2Q1vLEGzl+zRIck3Ydv1tv6KDObugI9wk=; b=EL6lr2JDUvMKSavJn29t9VWKvJqvtYVX11lNZj0oXVw47Mm8P7cUCVTXMMIVZIt97n d8I3ShBMte+uelHO8uFl9d2l9yByKsEflGc84OmBNcyiWw/odFS86YQ7jJLIVvm3kP3Z 50XOD1xcR9bHxuevzQkGRzjge8IuzTZEKysSo= 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:in-reply-to:references; bh=i4vL5Dhxz/2Q1vLEGzl+zRIck3Ydv1tv6KDObugI9wk=; b=XWLFDaCrOS/F/lsHrnJfd5/aVFXO5kgWuRTVd5wnzswYXQeM20RvIEQquUBWqliUJQ 18pjCYN9PduIH2lRCCw+3GMCddmRByxfh3l5neP9RiZiM1ytshj7QhGVVAGjZ2HsQz82 oqVylhKOkx3Do47ZCR64uhu6IKc88g7Whu8jHeO2suD+KVs1ixzjRsrBrhpOLRwj7ZEG UBiVynAGWh86AVJZMqFKFYbQUdXHhylMFJPepzDVrGHDMBQ0j/XYl/klnDYlqfPhQ2mw PNIOrxYBuFLZbqFDhjspk+e+s+d/xi5eBgAZb5aLK9U9fPTCX4b7xaVP2Yf83uO6TyHG 0bVg== X-Gm-Message-State: AMke39mhu/+03+V6Q05xxmJzKYsYhUym+X49XQpsJPn7+o8S/IRj7PslGJ28Fkm15kESa5iw X-Received: by 10.202.79.208 with SMTP id d199mr3188734oib.199.1487312813467; Thu, 16 Feb 2017 22:26:53 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Thu, 16 Feb 2017 22:26:40 -0800 Message-Id: <7ee05fe2eb106ac368a2382e6b89251270280bd1.1487312143.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-Spam-Score: 4.2 (++++) Subject: [SeaBIOS] [PATCH v4 3/3] QEMU fw_cfg: Add command to write back address of file X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com, mst@redhat.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Ben Warren This command is similar to ADD_POINTER, but instead of patching memory, it writes the pointer back to QEMU over the DMA interface. Signed-off-by: Ben Warren --- src/fw/romfile_loader.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/fw/romfile_loader.h | 23 ++++++++++++++++++++--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/fw/romfile_loader.c b/src/fw/romfile_loader.c index 7737453..1ddcb2a 100644 --- a/src/fw/romfile_loader.c +++ b/src/fw/romfile_loader.c @@ -5,6 +5,7 @@ #include "romfile.h" // struct romfile_s #include "malloc.h" // Zone*, _malloc #include "output.h" // warn_* +#include "paravirt.h" // qemu_cfg_write_file =20 struct romfile_loader_file { struct romfile_s *file; @@ -127,6 +128,41 @@ err: warn_internalerror(); } =20 +static void romfile_loader_write_pointer(struct romfile_loader_entry_s *en= try, + struct romfile_loader_files *files) +{ + struct romfile_s *dest_file; + struct romfile_loader_file *src_file; + unsigned dst_offset =3D le32_to_cpu(entry->wr_pointer.dst_offset); + unsigned src_offset =3D le32_to_cpu(entry->wr_pointer.src_offset); + u64 pointer =3D 0; + + /* Writing back to a file that may not be loaded in RAM */ + dest_file =3D romfile_find(entry->wr_pointer.dest_file); + src_file =3D romfile_loader_find(entry->wr_pointer.src_file, files); + + if (!dest_file || !src_file || !src_file->data || + dst_offset + entry->wr_pointer.size < dst_offset || + dst_offset + entry->wr_pointer.size > dest_file->size || + src_offset > src_file->file->size || + entry->wr_pointer.size < 1 || entry->wr_pointer.size > 8 || + entry->wr_pointer.size & (entry->wr_pointer.size - 1)) { + goto err; + } + + pointer =3D (unsigned long)src_file->data + src_offset; + pointer =3D cpu_to_le64(pointer); + + /* Only supported on QEMU */ + if (qemu_cfg_write_file(&pointer, dest_file, dst_offset, + entry->wr_pointer.size) !=3D entry->wr_pointer= .size) { + goto err; + } + return; + err: + warn_internalerror(); +} + int romfile_loader_execute(const char *name) { struct romfile_loader_entry_s *entry; @@ -161,6 +197,10 @@ int romfile_loader_execute(const char *name) break; case ROMFILE_LOADER_COMMAND_ADD_CHECKSUM: romfile_loader_add_checksum(entry, files); + break; + case ROMFILE_LOADER_COMMAND_WRITE_POINTER: + romfile_loader_write_pointer(entry, files); + break; default: /* Skip commands that we don't recognize. */ break; diff --git a/src/fw/romfile_loader.h b/src/fw/romfile_loader.h index bce3719..8b557a3 100644 --- a/src/fw/romfile_loader.h +++ b/src/fw/romfile_loader.h @@ -51,15 +51,32 @@ struct romfile_loader_entry_s { u32 length; } cksum; =20 + /* + * COMMAND_WRITE_POINTER - Write back to a host file via DMA, + * wr_pointer@dest_file at offset @wr_pointer.dst_offset, a pointer + * to the table originating from @wr_pointer.src_file at offset + * @wr_pointer.src_offset. + * 1,2,4 or 8 byte unsigned addition is used depending on + * @wr_pointer.size. + */ + struct { + char dest_file[ROMFILE_LOADER_FILESZ]; + char src_file[ROMFILE_LOADER_FILESZ]; + u32 dst_offset; + u32 src_offset; + u8 size; + } wr_pointer; + /* padding */ char pad[124]; }; }; =20 enum { - ROMFILE_LOADER_COMMAND_ALLOCATE =3D 0x1, - ROMFILE_LOADER_COMMAND_ADD_POINTER =3D 0x2, - ROMFILE_LOADER_COMMAND_ADD_CHECKSUM =3D 0x3, + ROMFILE_LOADER_COMMAND_ALLOCATE =3D 0x1, + ROMFILE_LOADER_COMMAND_ADD_POINTER =3D 0x2, + ROMFILE_LOADER_COMMAND_ADD_CHECKSUM =3D 0x3, + ROMFILE_LOADER_COMMAND_WRITE_POINTER =3D 0x4, }; =20 enum { --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://www.coreboot.org/mailman/listinfo/seabios