Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp778066pxa; Wed, 5 Aug 2020 12:31:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkbjofT2MRwhBY61Awgj+B+y2an1va0H7fJYgGq7l2bFnR4HdCCuwSKv+ErQK6LQdpwyz9 X-Received: by 2002:a17:906:27db:: with SMTP id k27mr612422ejc.433.1596655866693; Wed, 05 Aug 2020 12:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596655866; cv=none; d=google.com; s=arc-20160816; b=KJ8FOK3DVb5IhK+9rsECLkZTx+CZcWxQKOEwCgklXlUcFbqswx3A8wsZ5luU/iS6c6 7pZiYVMtUXuRbMC4IwxE0arK5qCL0Jvu23R3TO+8d7B3IutkYBfoLdmhBNjfoipS+54g O7lGdgu/5k7zdfgo3L5C/bTsExXCpuP2+FYDiD4Cf8wmwRzHM0+GzXz8u1Kcp1SxlGZE y38XJOQXndkyXMlTob0zXv8UUpCpo5bmaiY5KXdnHiMFd1w6DaRBdyvq+oi3DzaTm1YK XiBKaM9BUlfiVUSIh1YZo0SGUf8JcgQI17PbjU0AQW56mZ446STtyK4iOrNTdsU/1Oj7 Y5bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Oi4CR23bemPbIyBSn03I/oQ2VbOHBaULBpoKArW5b+0=; b=P/Yr8rWlwLDWHLCVqGFVu8Zeu5hNexa+a2qilP8SksEDWoKZXV9H8mBLqBF/LOXEG5 nW7hVg/uVlb6hWe7wkik7KYSwg1qrdwqMJXgyJzIpgXJ1CJrSRv2dy7OgtxTokbxZvOD 8r6lUOMEhZWFkxz4H8zBdMg+El1JzSGx2Sy0PlcCYJIgyKh3OFeKHqq9nQ7DvejSYspR ExCKyKAw3S9J0N8Jfffohy/TCilFBkzYTtmElNV0gm8weUa0f69PRzNopZKtsJPndgIR dbg4i0exgjIAGQfgYw85GkhCjJ/Xm6CcHlrdG70gtsB+rK4vDb8RYOKaM002oGy5isYl AesQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ViAD3CNc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si1744396edy.176.2020.08.05.12.30.42; Wed, 05 Aug 2020 12:31:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ViAD3CNc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728607AbgHET2b (ORCPT + 99 others); Wed, 5 Aug 2020 15:28:31 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:57257 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728412AbgHERLb (ORCPT ); Wed, 5 Aug 2020 13:11:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596647489; 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: in-reply-to:in-reply-to:references:references; bh=Oi4CR23bemPbIyBSn03I/oQ2VbOHBaULBpoKArW5b+0=; b=ViAD3CNcWmAN+e7peJFWHsT+zKS3N43OEGellPj+jSCrWT8OSkzZADjHqSV4xTCdt4bZUK OIOka4YdA5UWwhRly6sHuSA6X4LOcWy4DELszkiUSXVCp0DibrQNkICDwHR2aOUetYgBaI z3iai655ST8C9C4pbkMrOHpU8fh07DM= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-263-llVJfvwOO2eWaNG9W5d4-w-1; Wed, 05 Aug 2020 09:44:30 -0400 X-MC-Unique: llVJfvwOO2eWaNG9W5d4-w-1 Received: by mail-wm1-f71.google.com with SMTP id f74so2745943wmf.1 for ; Wed, 05 Aug 2020 06:44:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Oi4CR23bemPbIyBSn03I/oQ2VbOHBaULBpoKArW5b+0=; b=Y2eARn+6kbtDlXRvhaOkKyEVGLnu46NN16BFCFOXw6M4LBWP9vXLKxcDmwl15FOkHQ AWLeziy1fyugjsgStUFYRmd3Yyx7oEvRo4cwUYPjHqs2TVrBdcQa/r3nebBcSV96ic1P hy8LwbO/gijGSDKLz7zZHD8JG4ovDRB1Mezltwew4ZfLbO6pP/Pat4+XFHXF0eYr+ICt KITFF5fp2SaVrzMcQFSTSAYHOtvTbgLd0soYxM/SgxOLU7SOesx+Cy+n37p1ffAtDYkx Ka0FYinR5ufcWuJ1rnFpGAL+edqIBA4cMx5gXyZ//ABP8wohT7B61jmu0ptLbZdEfjSA UT5A== X-Gm-Message-State: AOAM532/pqmIcRO37b6fd9mzhFfCy/3ah4pIXa0yxWgQia2qvIIokvR9 vVxq+mkU+tWhmNhM+iK8KI2miCiwCqmYJNjM2rh2LjVhjWnnKCbV2H6u67l9oLEeVRlRHCvvDEB mtwnojATlPhXvIm8xuKFiJcep X-Received: by 2002:a7b:cc90:: with SMTP id p16mr3095000wma.79.1596635068411; Wed, 05 Aug 2020 06:44:28 -0700 (PDT) X-Received: by 2002:a7b:cc90:: with SMTP id p16mr3094984wma.79.1596635068196; Wed, 05 Aug 2020 06:44:28 -0700 (PDT) Received: from redhat.com (bzq-79-178-123-8.red.bezeqint.net. [79.178.123.8]) by smtp.gmail.com with ESMTPSA id y203sm2960492wmc.29.2020.08.05.06.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 06:44:27 -0700 (PDT) Date: Wed, 5 Aug 2020 09:44:26 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Jason Wang , virtualization@lists.linux-foundation.org Subject: [PATCH v3 26/38] virtio_config: LE config space accessors Message-ID: <20200805134226.1106164-27-mst@redhat.com> References: <20200805134226.1106164-1-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200805134226.1106164-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To be used by modern code, as well as to handle LE only fields such as balloon. Signed-off-by: Michael S. Tsirkin --- include/linux/virtio_config.h | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 441fd6dd42ab..5b5196fec899 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -375,6 +375,71 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) sizeof(virtio_cwrite_v)); \ } while(0) +/* + * Nothing virtio-specific about these, but let's worry about generalizing + * these later. + */ +#define virtio_le_to_cpu(x) \ + _Generic((x), \ + __u8: (x), \ + __le16: le16_to_cpu(x), \ + __le32: le32_to_cpu(x), \ + __le64: le64_to_cpu(x) \ + ) + +#define virtio_cpu_to_le(x, m) \ + _Generic((m), \ + __u8: (x), \ + __le16: cpu_to_le16(x), \ + __le32: cpu_to_le32(x), \ + __le64: cpu_to_le64(x) \ + ) + +/* LE (e.g. modern) Config space accessors. */ +#define virtio_cread_le(vdev, structname, member, ptr) \ + do { \ + typeof(((structname*)0)->member) virtio_cread_v; \ + \ + might_sleep(); \ + /* Sanity check: must match the member's type */ \ + typecheck(typeof(virtio_le_to_cpu(virtio_cread_v)), *(ptr)); \ + \ + switch (sizeof(virtio_cread_v)) { \ + case 1: \ + case 2: \ + case 4: \ + vdev->config->get((vdev), \ + offsetof(structname, member), \ + &virtio_cread_v, \ + sizeof(virtio_cread_v)); \ + break; \ + default: \ + __virtio_cread_many((vdev), \ + offsetof(structname, member), \ + &virtio_cread_v, \ + 1, \ + sizeof(virtio_cread_v)); \ + break; \ + } \ + *(ptr) = virtio_le_to_cpu(virtio_cread_v); \ + } while(0) + +/* Config space accessors. */ +#define virtio_cwrite_le(vdev, structname, member, ptr) \ + do { \ + typeof(((structname*)0)->member) virtio_cwrite_v = \ + virtio_cpu_to_le(*(ptr), ((structname*)0)->member); \ + \ + might_sleep(); \ + /* Sanity check: must match the member's type */ \ + typecheck(typeof(virtio_le_to_cpu(virtio_cwrite_v)), *(ptr)); \ + \ + vdev->config->set((vdev), offsetof(structname, member), \ + &virtio_cwrite_v, \ + sizeof(virtio_cwrite_v)); \ + } while(0) + + /* Read @count fields, @bytes each. */ static inline void __virtio_cread_many(struct virtio_device *vdev, unsigned int offset, -- MST