Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2800536pxb; Sat, 6 Feb 2021 08:09:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyi6B/RkGdzJh+Cit9+6sDqvh6quxNzgwxLU+L19YszqwZwSsIKorKZfipkHuNAjIGW8+0U X-Received: by 2002:a17:906:b2c6:: with SMTP id cf6mr8824388ejb.99.1612627767931; Sat, 06 Feb 2021 08:09:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612627767; cv=none; d=google.com; s=arc-20160816; b=EMU17xY6Cxh4hUkKLDs+MdRiS+U1nfu9iOcQ0MRtneVe2aTky+69B7cad8uMYrJWwE ZDL+9+3BvKFbVaTTOU60WyrQPBUba2ZdIvK5zIEIHIrxktIJZB7Y0wcVITKdrIZxNFl9 jD8V43mN5uMy4Cask0i8clN6u47Bxui1vucmFe8yP5hhoqkcByQcU1F3lHWdrO1mKwN0 Sob9DLO58tdJ5HlnBDxVrKkNpiZp+O6sVD+oxQ3Tz/NpNv97PU7BocZoJ0gljQGFWeSd wrcJm6Xr7mjWTdVi3m51BRRGWDccPb6yRbCdzLepVJWFAHHh8bGpFsyMTNBeY9dzf4dn lxxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=1VOhrH7MnJ7e31hKFlNKdNH+sWOCB/1tw9I93lQDyhs=; b=fD9k1gD8RAJutWFYP1dKVpx1URSH9g4z7NNWoUfWWxSxXva+YkGh6ANwFORItaczKZ 8f3uDJy0/GNKrF6efBD3iZzk4CteIuQxJxEk0Ze8svpB4JPl9GsNbGPVbOkTCIfvOP5u tUC3nJUpSsidMYlzde2tHLT/ezRXwcucwwe7acvcQ5HTrZmV7Gk53fHIQYmEqP0WKGFm oNLC8J5K0bY1CH0ITBCjjqWgsG5nvt6/GOAMQQFjGNrXuxKlsxDQW1+W+ALAcXhdAJdm iaG/UCX8FlxVWz3GY13AQipZ1G+Gv5Vb90hcDRPFCwjMG3FyfD7pTj7D/yTYkdta9inG 6bcA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si9688038edc.514.2021.02.06.08.09.03; Sat, 06 Feb 2021 08:09:27 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbhBFOpZ (ORCPT + 99 others); Sat, 6 Feb 2021 09:45:25 -0500 Received: from mga01.intel.com ([192.55.52.88]:38620 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230247AbhBFOot (ORCPT ); Sat, 6 Feb 2021 09:44:49 -0500 IronPort-SDR: qx7oWrw87hjsGDlUqbAtsR389kewQtkwqObvyDeg4LhzlIGymv5ACPIioVAnH0HpqmD/2W/xUr tIDzOIKi4qRA== X-IronPort-AV: E=McAfee;i="6000,8403,9886"; a="200566044" X-IronPort-AV: E=Sophos;i="5.81,158,1610438400"; d="scan'208";a="200566044" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2021 06:43:47 -0800 IronPort-SDR: gA45uT67lxOzE4s5fSMLrQzbrFN0ln6BpLAvCjxo24mlsuHHWUzTvgOB9SPBceQ7lR6b6+W3yU ZZAlPK9QS4Vg== X-IronPort-AV: E=Sophos;i="5.81,158,1610438400"; d="scan'208";a="394360228" Received: from twinkler-lnx.jer.intel.com ([10.12.91.138]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2021 06:43:45 -0800 From: Tomas Winkler To: Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, Tomas Winkler Subject: [char-misc-next 6/6] mei: bus: add client dma interface Date: Sat, 6 Feb 2021 16:43:25 +0200 Message-Id: <20210206144325.25682-6-tomas.winkler@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210206144325.25682-1-tomas.winkler@intel.com> References: <20210206144325.25682-1-tomas.winkler@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Usyskin Expose the client dma mapping via mei client bus interface. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler --- drivers/misc/mei/bus.c | 46 ++++++++++++++++++++++++++++++++++++++ drivers/misc/mei/hw.h | 5 +++++ include/linux/mei_cl_bus.h | 3 +++ 3 files changed, 54 insertions(+) diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 34fb5e541fe5..d430710a5fe5 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -636,6 +636,52 @@ static void mei_cl_bus_vtag_free(struct mei_cl_device *cldev) kfree(cl_vtag); } +void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size) +{ + struct mei_device *bus; + struct mei_cl *cl; + int ret; + + if (!cldev || !buffer_id || !size) + return ERR_PTR(-EINVAL); + + if (!IS_ALIGNED(size, MEI_FW_PAGE_SIZE)) { + dev_err(&cldev->dev, "Map size should be aligned to %lu\n", + MEI_FW_PAGE_SIZE); + return ERR_PTR(-EINVAL); + } + + cl = cldev->cl; + bus = cldev->bus; + + mutex_lock(&bus->device_lock); + ret = mei_cl_dma_alloc_and_map(cl, NULL, buffer_id, size); + mutex_unlock(&bus->device_lock); + if (ret) + return ERR_PTR(ret); + return cl->dma.vaddr; +} +EXPORT_SYMBOL_GPL(mei_cldev_dma_map); + +int mei_cldev_dma_unmap(struct mei_cl_device *cldev) +{ + struct mei_device *bus; + struct mei_cl *cl; + int ret; + + if (!cldev) + return -EINVAL; + + cl = cldev->cl; + bus = cldev->bus; + + mutex_lock(&bus->device_lock); + ret = mei_cl_dma_unmap(cl, NULL); + mutex_unlock(&bus->device_lock); + return ret; +} +EXPORT_SYMBOL_GPL(mei_cldev_dma_unmap); + /** * mei_cldev_enable - enable me client device * create connection with me client diff --git a/drivers/misc/mei/hw.h b/drivers/misc/mei/hw.h index b10606550613..bc240b88abf1 100644 --- a/drivers/misc/mei/hw.h +++ b/drivers/misc/mei/hw.h @@ -22,6 +22,11 @@ #define MEI_D0I3_TIMEOUT 5 /* D0i3 set/unset max response time */ #define MEI_HBM_TIMEOUT 1 /* 1 second */ +/* + * FW page size for DMA allocations + */ +#define MEI_FW_PAGE_SIZE 4096UL + /* * MEI Version */ diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h index 959ad7d850b4..53801eacfaef 100644 --- a/include/linux/mei_cl_bus.h +++ b/include/linux/mei_cl_bus.h @@ -116,4 +116,7 @@ int mei_cldev_enable(struct mei_cl_device *cldev); int mei_cldev_disable(struct mei_cl_device *cldev); bool mei_cldev_enabled(struct mei_cl_device *cldev); +void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size); +int mei_cldev_dma_unmap(struct mei_cl_device *cldev); + #endif /* _LINUX_MEI_CL_BUS_H */ -- 2.26.2