From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web12.2685.1646977401676776093 for ; Thu, 10 Mar 2022 21:43:22 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AbYLchJz; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646977400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TItPc0fE2UsGjli7PlF8G8APbKyoYXWEYFHCO8i6A4s=; b=AbYLchJz6FylWO4vx7YJt0vK+KQrHjacnYUJ8UZ9KlBs4WddR82uC6O5MBwI0BNS35QIGp DM3JHoUkEkRgcUQJVz0bfbqMZis/EDdG06lMfzU8CpdIWBwwKL1L2ujwpe5VQgVH7DOZVA VPzFDWb80S4s1+w/DKHG1MY1zlLpWyw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-17-W4uvEYg4Opm5nwpNpgYQng-1; Fri, 11 Mar 2022 00:43:19 -0500 X-MC-Unique: W4uvEYg4Opm5nwpNpgYQng-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66F921006AA8 for ; Fri, 11 Mar 2022 05:43:18 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.196.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF73E1006915; Fri, 11 Mar 2022 05:43:17 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A4D9A18000B4; Fri, 11 Mar 2022 06:43:15 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Pawel Polawski , Gerd Hoffmann Subject: [PATCH v2 1/6] OvmfPkg/VirtioGpuDxe: add VirtioGpuSendCommandWithReply Date: Fri, 11 Mar 2022 06:43:10 +0100 Message-Id: <20220311054315.876774-2-kraxel@redhat.com> In-Reply-To: <20220311054315.876774-1-kraxel@redhat.com> References: <20220311054315.876774-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Extend VirtioGpuSendCommand() to support commands which return data, rename the function to VirtioGpuSendCommandWithReply() to indicate that. Add a new VirtioGpuSendCommand() function which is just a thin wrapper around VirtioGpuSendCommandWithReply() so existing code continues to work without changes. Signed-off-by: Gerd Hoffmann --- OvmfPkg/VirtioGpuDxe/Commands.c | 75 +++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/OvmfPkg/VirtioGpuDxe/Commands.c b/OvmfPkg/VirtioGpuDxe/Commands.c index 873a71656700..b9a3ea923021 100644 --- a/OvmfPkg/VirtioGpuDxe/Commands.c +++ b/OvmfPkg/VirtioGpuDxe/Commands.c @@ -393,6 +393,14 @@ VirtioGpuExitBoot ( @param[in] RequestSize Size of the entire caller-allocated request object, including the leading VIRTIO_GPU_CONTROL_HEADER. + @param[in] ResponseType The type of the response (VirtioGpuResp*). + + @param[in,out] Response Pointer to the caller-allocated response object. The + request must start with VIRTIO_GPU_CONTROL_HEADER. + + @param[in] ResponseSize Size of the entire caller-allocated response object, + including the leading VIRTIO_GPU_CONTROL_HEADER. + @retval EFI_SUCCESS Operation successful. @retval EFI_DEVICE_ERROR The host rejected the request. The host error @@ -404,22 +412,24 @@ VirtioGpuExitBoot ( **/ STATIC EFI_STATUS -VirtioGpuSendCommand ( +VirtioGpuSendCommandWithReply ( IN OUT VGPU_DEV *VgpuDev, IN VIRTIO_GPU_CONTROL_TYPE RequestType, IN BOOLEAN Fence, IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Header, - IN UINTN RequestSize + IN UINTN RequestSize, + IN VIRTIO_GPU_CONTROL_TYPE ResponseType, + IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Response, + IN UINTN ResponseSize ) { - DESC_INDICES Indices; - volatile VIRTIO_GPU_CONTROL_HEADER Response; - EFI_STATUS Status; - UINT32 ResponseSize; - EFI_PHYSICAL_ADDRESS RequestDeviceAddress; - VOID *RequestMap; - EFI_PHYSICAL_ADDRESS ResponseDeviceAddress; - VOID *ResponseMap; + DESC_INDICES Indices; + EFI_STATUS Status; + UINT32 ResponseSizeRet; + EFI_PHYSICAL_ADDRESS RequestDeviceAddress; + VOID *RequestMap; + EFI_PHYSICAL_ADDRESS ResponseDeviceAddress; + VOID *ResponseMap; // // Initialize Header. @@ -457,8 +467,8 @@ VirtioGpuSendCommand ( Status = VirtioMapAllBytesInSharedBuffer ( VgpuDev->VirtIo, VirtioOperationBusMasterWrite, - (VOID *)&Response, - sizeof Response, + (VOID *)Response, + ResponseSize, &ResponseDeviceAddress, &ResponseMap ); @@ -480,7 +490,7 @@ VirtioGpuSendCommand ( VirtioAppendDesc ( &VgpuDev->Ring, ResponseDeviceAddress, - (UINT32)sizeof Response, + (UINT32)ResponseSize, VRING_DESC_F_WRITE, &Indices ); @@ -493,7 +503,7 @@ VirtioGpuSendCommand ( VIRTIO_GPU_CONTROL_QUEUE, &VgpuDev->Ring, &Indices, - &ResponseSize + &ResponseSizeRet ); if (EFI_ERROR (Status)) { goto UnmapResponse; @@ -502,7 +512,7 @@ VirtioGpuSendCommand ( // // Verify response size. // - if (ResponseSize != sizeof Response) { + if (ResponseSize != ResponseSizeRet) { DEBUG (( DEBUG_ERROR, "%a: malformed response to Request=0x%x\n", @@ -531,16 +541,17 @@ VirtioGpuSendCommand ( // // Parse the response. // - if (Response.Type == VirtioGpuRespOkNodata) { + if (Response->Type == (UINT32)ResponseType) { return EFI_SUCCESS; } DEBUG (( DEBUG_ERROR, - "%a: Request=0x%x Response=0x%x\n", + "%a: Request=0x%x Response=0x%x (expected 0x%x)\n", __FUNCTION__, (UINT32)RequestType, - Response.Type + Response->Type, + ResponseType )); return EFI_DEVICE_ERROR; @@ -553,6 +564,34 @@ VirtioGpuSendCommand ( return Status; } +/** + Simplified version of VirtioGpuSendCommandWithReply() for commands + which do not send back any data. +**/ +STATIC +EFI_STATUS +VirtioGpuSendCommand ( + IN OUT VGPU_DEV *VgpuDev, + IN VIRTIO_GPU_CONTROL_TYPE RequestType, + IN BOOLEAN Fence, + IN OUT volatile VIRTIO_GPU_CONTROL_HEADER *Header, + IN UINTN RequestSize + ) +{ + volatile VIRTIO_GPU_CONTROL_HEADER Response; + + return VirtioGpuSendCommandWithReply ( + VgpuDev, + RequestType, + Fence, + Header, + RequestSize, + VirtioGpuRespOkNodata, + &Response, + sizeof (Response) + ); +} + /** The following functions send requests to the VirtIo GPU device model, await the answer from the host, and return a status. They share the following -- 2.35.1