From nobody Tue May 7 17:45:31 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 1487398972394465.6759234781965; Fri, 17 Feb 2017 22:22:52 -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 1ceyPi-0004TL-Mu; Sat, 18 Feb 2017 07:22:34 +0100 Received: from mail-oi0-f46.google.com ([209.85.218.46]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ceyPY-0004Rb-Sq for seabios@seabios.org; Sat, 18 Feb 2017 07:22:31 +0100 Received: by mail-oi0-f46.google.com with SMTP id y140so4304740oie.1 for ; Fri, 17 Feb 2017 22:22:24 -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 v31sm5479134ota.26.2017.02.17.22.22.21 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 17 Feb 2017 22:22:21 -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=rL+JAfoSApNX+2bRp/0qR/XeP9VIV6AGbVGz+AoOxWo=; b=r1RmtsSy7y3UmydKjBJOb2oxDxZsWYq1C4Nwg7/ZdSyFv+sQAldchZTnSFSaC6fCpI Z3ZOHrgV2QfocL9f76VADozzvjc98AEryiB/qyiJkk+Yt4v8Cw9lFLoTHx5fyGZhOf32 EHBbnn9XS0sGdMxpoAqcTUix/d2En8xK9TcTs= 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=rL+JAfoSApNX+2bRp/0qR/XeP9VIV6AGbVGz+AoOxWo=; b=eEczk0vc8CMGFmVZTxD4YD/C2hw+46VyOZTGPhKKhbuvWCDJvToVpJFjvmEU3foAik 61lfdL495JAN+PkxqaiILXave9c5sK/6a4jB4BW4JJt/lpk/WspyFHGJspvR/dVDgtip 3/d3KQUmIrCp1GBC7ds4CuH8u5iYgQJxeTrWwJuGbgQ7NVXjUA/uTCSBSqKlve0l4Czs /37URAWthsKZpP8Rfy/rwBZTk/6x3HM81TuTguSnzyePpdAOC1c+cXeHW1e4hbo4krfv jP15C/BbhCesRUUnmYj7NUjb0T3NWulny8mv82yYiL0SqVrB6f6LQEccMmxY//iHSvh5 65Nw== X-Gm-Message-State: AMke39kRWpPRmiOXg33dVUVQ0UhdTMn/5qZh+cbG/bHmUZj/+zPsUiaEhSfPxMGAoUN73MAL X-Received: by 10.202.64.132 with SMTP id n126mr5548031oia.89.1487398942489; Fri, 17 Feb 2017 22:22:22 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Fri, 17 Feb 2017 22:21:55 -0800 Message-Id: <3c9850957d51bb1bd1f49cdb0031ddae814e72ff.1487398714.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.8 (-) Subject: [SeaBIOS] [PATCH v5 1/5] 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 Reviewed-by: Igor Mammedov Reviewed-by: Laszlo Ersek --- 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..4618647 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 ((offset + len) > file->size) + 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 Tue May 7 17:45:31 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 1487398973275967.9801984145191; Fri, 17 Feb 2017 22:22:53 -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 1ceyPr-0004VJ-NN; Sat, 18 Feb 2017 07:22:43 +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 1ceyPZ-0004Ru-N8 for seabios@seabios.org; Sat, 18 Feb 2017 07:22:42 +0100 Received: by mail-oi0-f49.google.com with SMTP id u143so33451079oif.3 for ; Fri, 17 Feb 2017 22:22:25 -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 v31sm5479134ota.26.2017.02.17.22.22.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 17 Feb 2017 22:22:22 -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=4kkQHKERFe3iy3MTKId8LtkyTX9IChmULxyRVvsTxTk=; b=ccoShxqMH7xC9G0kuWMctyhxEMxAZEPOvS46qlF3YC+G0BSyvQQj/4Rljw2dzRfq9i 4DsPkL8PRDXG6fMcJWXQj5N6isg9dVx7cheRlV7u3KQl4cOurEKlSzmRG1/taAzkomep hY7KrhUtNFEI8zw0ZN+FT9BrKY+aB8H+c4CgQ= 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=4kkQHKERFe3iy3MTKId8LtkyTX9IChmULxyRVvsTxTk=; b=Fb+LXUN03a/x0TxQXrGvhORBlvxYwLjfeAM7xddktj4J1c3VhA0DrmpKAILKr4qNm2 rEJbrl7xo2tDWmKh09m7JVDU7pO2kj/tS8OgHa7ZQVkNMC4SRxLWzkMYcVFS99riLzZQ 6yUhi4pXvgDTfTtSYMFg+SwJMCtNos3phx4vB738lMf5Dwm/mRV2Ofgsoav0+YB93Fww DnFH50pU6kH/RPGCvZ+Ga0GcVwgHKATJvysm5suSprlnbTBWepE2BoFvLcxvtPMnHwM3 3UpS1BifiayiKYSqUwkc+O0WV2dfRnka69YRhb6n0J2RpME4hrOjBhBJdOtmJBLa0peN EOgg== X-Gm-Message-State: AMke39k0rTFXrsdoQGtakxwYVshetk4IIpNgblScqzW9h9fJPv6GckhTCJrtl4Kv/oeJKd97 X-Received: by 10.202.7.68 with SMTP id 65mr631511oih.34.1487398943452; Fri, 17 Feb 2017 22:22:23 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Fri, 17 Feb 2017 22:21:56 -0800 Message-Id: <0658070dcddab2f14c0278cdf23ad9836d44d062.1487398715.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: -3.7 (---) Subject: [SeaBIOS] [PATCH v5 2/5] 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 Reviewed-by: Igor Mammedov --- 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 Tue May 7 17:45:31 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 1487398970853263.2917690707826; Fri, 17 Feb 2017 22:22:50 -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 1ceyPn-0004UW-Ri; Sat, 18 Feb 2017 07:22:39 +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 1ceyPa-0004Rv-Lm for seabios@seabios.org; Sat, 18 Feb 2017 07:22:38 +0100 Received: by mail-oi0-f49.google.com with SMTP id 62so20237668oih.2 for ; Fri, 17 Feb 2017 22:22:26 -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 v31sm5479134ota.26.2017.02.17.22.22.23 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 17 Feb 2017 22:22:23 -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=LloHXHltrR8b1XQb6IwlxOUjNqUQ6Sa4MV2q1G9xbj0=; b=xM96IB2LwHq3r1DvF8qQmcX4798YpPHG00lYzI+kkt6qAiXWOUK/oIjLI7P0ToJEqs CC58TpXUlnsrqpFJUNY6L4xBuGecbeoO1wj50/lmQZvsOjJaYPDZ40PUI7/CG238rLxY PaRX/4dSgvUJP/ERPICyzXdpP8cfbYdRxcleg= 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=LloHXHltrR8b1XQb6IwlxOUjNqUQ6Sa4MV2q1G9xbj0=; b=qf53uwBM4XHxIt7YdqEFsDzqs1e5MJPsbbRXxv6iE/XHheTH3XjcQ0ERfav5l03SYK 7r7WTOWmYR6fUySmXLbchqtwSsJmNvdrwNHfr0SgZ/dqYy1i5VOGftrlF5bivdnxtJ/Y 3LA9ALltZ+8W8NNP/TpbOiUaP6K1HW6jpQjzXFR5Svef2Td0pCbbvvUXOAI03SSllGS/ fc2RBtiIj2YQpKgYtj7VKMumGE/s+24s5t5aQYjEmgBunueikmsRzx0rh9eTWEeh8RXv y59ZNqEL1QJACAqDFMUKdvk8T+mdNzwWG9hL2nnik3f2STzJW43URyulyRR+lIGkjI9B 0nQw== X-Gm-Message-State: AMke39nalvgWuuFNMxz6Kx+fWdyo+iVcPqVX+cKD/KAt7tgnsgdz0ROwWL/9cRda5M2ZJIv5 X-Received: by 10.202.244.19 with SMTP id s19mr6290243oih.24.1487398944418; Fri, 17 Feb 2017 22:22:24 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Fri, 17 Feb 2017 22:21:57 -0800 Message-Id: <9f65dc22ca53eb9927c80eaba293898f46861cbc.1487398715.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.8 (-) Subject: [SeaBIOS] [PATCH v5 3/5] 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 Reviewed-by: Igor Mammedov Reviewed-by: Laszlo Ersek --- src/fw/romfile_loader.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/fw/romfile_loader.h | 23 ++++++++++++++++++++--- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/fw/romfile_loader.c b/src/fw/romfile_loader.c index 7737453..30e7b58 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,46 @@ err: warn_internalerror(); } =20 +static void romfile_loader_write_pointer(struct romfile_loader_entry_s *en= try, + struct romfile_loader_files *file= s) +{ + 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 >=3D 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; + /* Make sure the pointer fits within wr_pointer.size */ + if ((entry->wr_pointer.size !=3D sizeof(u64)) && + ((pointer >> (entry->wr_pointer.size * 8)) > 0)) { + goto err; + } + 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 +202,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..4dc50ab 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 point= er + * 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 From nobody Tue May 7 17:45:31 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 1487398980240790.913403819764; Fri, 17 Feb 2017 22:23:00 -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 1ceyPs-0004Vh-GD; Sat, 18 Feb 2017 07:22:44 +0100 Received: from mail-oi0-f47.google.com ([209.85.218.47]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ceyPb-0004SF-Jr for seabios@seabios.org; Sat, 18 Feb 2017 07:22:42 +0100 Received: by mail-oi0-f47.google.com with SMTP id t68so13903425oie.0 for ; Fri, 17 Feb 2017 22:22:27 -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 v31sm5479134ota.26.2017.02.17.22.22.24 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 17 Feb 2017 22:22:25 -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=pR//kvuRWBd4eDHZ5l/73qlEG4ZV4zU8BnaNzLI8Dms=; b=vI0qLeM8b3j6ORyTUDlDc/HpbDRc+sSHHwVV+wBZOTu7SAhbJ4gm0+CJCo5L8BPqUv y2kbHVQuaSbORnE+Hg2Dgj4DZ7ZSdTjG+Ybk+auaWwKGBFocGc5VygSX7Gx5BK5M08En nzKcqOyMNsxurrvH8wGkyO4/vYPeGV8nm5mnA= 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=pR//kvuRWBd4eDHZ5l/73qlEG4ZV4zU8BnaNzLI8Dms=; b=VsFChg7D3wUEI2OX2ZDQib1yJP6uQbLtmcI1+h9qZcsWPcLWvTjnou7cKCLLyRECA1 2KSzfiznERjQRU97XaGT5M4GkSWyZ1mLEXeYJqCv4eyScEUffF7wn7IBj0IaMvBCSf/U Lnd2Jf7dgDV5h+LbNJj9Z3TDHPokMO8WpshFjeHjpzXBMJNtTQ1Zf2HSPabGnLvCT6+f r7/ELSEjixkLspiGa398pLefaIyNwH8VvvkZlzRxzYkoOhvwcjv8OxcgSfa/TVIZeFj+ R3ZN6bl0OMfleaPYCW/p5mQTxbrBI/eliA8n3rJjZ69UUgpOjc4QNfkmP1Q90xhkdoTi tfKQ== X-Gm-Message-State: AMke39mDHr0b4Cn2ozqhXV59Q/duqH1Yi8PukNhdEEiH9yWdseHnGyZYL/qNLFtF7ADAFc6q X-Received: by 10.202.212.70 with SMTP id l67mr6111644oig.153.1487398945379; Fri, 17 Feb 2017 22:22:25 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Fri, 17 Feb 2017 22:21:58 -0800 Message-Id: <4e9c3844d76bdf47c75629b0b6e954f2a03172b7.1487398715.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: -2.9 (--) Subject: [SeaBIOS] [PATCH v5 4/5] QEMU fw_cfg: Add functions for accessing files by key 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 When resuming from S3, only fw_cfg file keys are known. Signed-off-by: Ben Warren Reviewed-by: Igor Mammedov --- src/fw/paravirt.c | 23 +++++++++++++++++++++++ src/fw/paravirt.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 4618647..e513dd5 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -352,6 +352,17 @@ qemu_cfg_write_file(void *src, struct romfile_s *file,= u32 offset, u32 len) return len; } =20 +// Bare-bones function for writing a file knowing only its unique +// identifying key (select) +int +qemu_cfg_write_file_simple(void *src, u16 key, u32 offset, u32 len) +{ + qemu_cfg_select(key); + qemu_cfg_skip(offset); + qemu_cfg_write(src, len); + return len; +} + static void qemu_romfile_add(char *name, int select, int skip, int size) { @@ -370,6 +381,18 @@ qemu_romfile_add(char *name, int select, int skip, int= size) } =20 u16 +qemu_get_romfile_key(struct romfile_s *file) +{ + struct qemu_romfile_s *qfile; + qfile =3D container_of(file, struct qemu_romfile_s, file); + if (!qfile) { + warn_internalerror(); + return 0; + } + return qfile->select; +} + +u16 qemu_get_present_cpus_count(void) { u16 smp_count =3D 0; diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h index fb220d8..16f3d9a 100644 --- a/src/fw/paravirt.h +++ b/src/fw/paravirt.h @@ -56,5 +56,7 @@ 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); +int qemu_cfg_write_file_simple(void *src, u16 key, u32 offset, u32 len); +u16 qemu_get_romfile_key(struct romfile_s *file); =20 #endif --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://www.coreboot.org/mailman/listinfo/seabios From nobody Tue May 7 17:45:31 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 1487398975294215.32734814400237; Fri, 17 Feb 2017 22:22:55 -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 1ceyPv-0004WP-Sv; Sat, 18 Feb 2017 07:22:47 +0100 Received: from mail-oi0-f47.google.com ([209.85.218.47]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ceyPk-0004SN-Jo for seabios@seabios.org; Sat, 18 Feb 2017 07:22:44 +0100 Received: by mail-oi0-f47.google.com with SMTP id u143so33451275oif.3 for ; Fri, 17 Feb 2017 22:22:36 -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 v31sm5479134ota.26.2017.02.17.22.22.25 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 17 Feb 2017 22:22:25 -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=sIHKgMC7/3FQQpHGPbuaJ7TS6liqB7ASNHQKatc3Mtk=; b=qNMCt72bvJkvXgzRpRzhtufcgpGowMrVYHwYM1foVFTOuR/JLMA32SDXIP1NuSwAmO 9c8qDj7CK9Q60Z9nW9/jxLvWQYUGZLvoGgVpd8brxdbCLhJhhFWFDbTkBHyw7HvylM93 Mgn30wqOt/JlkCv+DqWPFdREIkX6u4FuZTVMU= 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=sIHKgMC7/3FQQpHGPbuaJ7TS6liqB7ASNHQKatc3Mtk=; b=Q/ZAgKWXTVO9gY7YNE2enoFYUec0J4aE2TPJb4z17+86FrbH+zoqg8is2txlz56+XZ B4V4H/uWcf1+VS+cNxjDr10n+5sIO2Or1erWXhxWSHf29niZx9D2D16kAzBY0QxRQj9Y Ba2qXIJnqS5vHmYjuJR1DM3f0xO2Sw5zB8Hdrf1krrTwNhNa2JdrafNlMK/JiC80TOXd NUspxAFdxatnfwL11b6o6YpQ/igSS0x0WIQ40gl4EdBpEEYZit1F3hZ5aga1tx61dV8C 9lD95wIVX69pfkpkvQmg6PEJl3SUD/VLdwxSa0DPaz+HhbguCV5OY4/XnJADGoxZwWgo uyAw== X-Gm-Message-State: AMke39kUMKHKYrJqDjGUpikRL4beNPfvlLgK1F/iCDH4a2hzspWzkYt9bkhuyMHy+4/wv2f4 X-Received: by 10.202.241.70 with SMTP id p67mr5463844oih.67.1487398946388; Fri, 17 Feb 2017 22:22:26 -0800 (PST) From: ben@skyportsystems.com To: seabios@seabios.org Date: Fri, 17 Feb 2017 22:21:59 -0800 Message-Id: <603c0dc95cae771416ed6bb7a8e66a3b6103381a.1487398715.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: -0.3 (/) Subject: [SeaBIOS] [PATCH v5 5/5] QEMU fw_cfg: Write fw_cfg back on S3 resume 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 Any pointers to BIOS-allocated memory that were written back to QEMU fw_cfg files are replayed when resuming from S3 sleep. Signed-off-by: Ben Warren --- src/fw/romfile_loader.c | 35 +++++++++++++++++++++++++++++++++++ src/fw/romfile_loader.h | 2 ++ src/resume.c | 4 ++++ 3 files changed, 41 insertions(+) diff --git a/src/fw/romfile_loader.c b/src/fw/romfile_loader.c index 30e7b58..33aaec4 100644 --- a/src/fw/romfile_loader.c +++ b/src/fw/romfile_loader.c @@ -4,6 +4,7 @@ #include "string.h" // strcmp #include "romfile.h" // struct romfile_s #include "malloc.h" // Zone*, _malloc +#include "list.h" // struct hlist_node #include "output.h" // warn_* #include "paravirt.h" // qemu_cfg_write_file =20 @@ -16,6 +17,16 @@ struct romfile_loader_files { struct romfile_loader_file files[]; }; =20 +// Data structures for storing "write pointer" entries for possible replay +struct romfile_wr_pointer_entry { + u64 pointer; + u32 offset; + u16 key; + u8 ptr_size; + struct hlist_node node; +}; +static struct hlist_head romfile_pointer_list; + static struct romfile_loader_file * romfile_loader_find(const char *name, struct romfile_loader_files *files) @@ -29,6 +40,16 @@ romfile_loader_find(const char *name, return NULL; } =20 +// Replay "write pointer" entries back to QEMU +void romfile_fw_cfg_resume(void) +{ + struct romfile_wr_pointer_entry *entry; + hlist_for_each_entry(entry, &romfile_pointer_list, node) { + qemu_cfg_write_file_simple(&entry->pointer, entry->key, + entry->offset, entry->ptr_size); + } +} + static void romfile_loader_allocate(struct romfile_loader_entry_s *entry, struct romfile_loader_files *files) { @@ -163,6 +184,20 @@ static void romfile_loader_write_pointer(struct romfil= e_loader_entry_s *entry, entry->wr_pointer.size) !=3D entry->wr_pointer= .size) { goto err; } + + /* Store the info so it can replayed later if necessary */ + struct romfile_wr_pointer_entry *store =3D _malloc(&ZoneHigh, + sizeof(*store), 4); + struct hlist_node **pprev =3D &romfile_pointer_list.first; + store->pointer =3D pointer; + store->key =3D qemu_get_romfile_key(dest_file); + if (store->key =3D=3D 0) { + goto err; + } + store->offset =3D dst_offset; + store->ptr_size =3D entry->wr_pointer.size; + hlist_add(&store->node, pprev); + return; err: warn_internalerror(); diff --git a/src/fw/romfile_loader.h b/src/fw/romfile_loader.h index 4dc50ab..fcd4ab2 100644 --- a/src/fw/romfile_loader.h +++ b/src/fw/romfile_loader.h @@ -86,4 +86,6 @@ enum { =20 int romfile_loader_execute(const char *name); =20 +void romfile_fw_cfg_resume(void); + #endif diff --git a/src/resume.c b/src/resume.c index e67cfce..99fa34f 100644 --- a/src/resume.c +++ b/src/resume.c @@ -17,6 +17,7 @@ #include "string.h" // memset #include "util.h" // dma_setup #include "tcgbios.h" // tpm_s3_resume +#include "fw/romfile_loader.h" // romfile_fw_cfg_resume =20 // Handler for post calls that look like a resume. void VISIBLE16 @@ -105,6 +106,9 @@ s3_resume(void) tpm_s3_resume(); s3_resume_vga(); =20 + /* Replay any fw_cfg entries that go back to the host */ + romfile_fw_cfg_resume(); + make_bios_readonly(); =20 // Invoke the resume vector. --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://www.coreboot.org/mailman/listinfo/seabios