From patchwork Fri Dec 4 06:25:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chunming Zhou X-Patchwork-Id: 7765781 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D7D35BEEE1 for ; Fri, 4 Dec 2015 06:46:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BE9A5205E4 for ; Fri, 4 Dec 2015 06:46:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C6F4920552 for ; Fri, 4 Dec 2015 06:46:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27F3B6EDB3; Thu, 3 Dec 2015 22:46:32 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 901 seconds by postgrey-1.34 at gabe; Thu, 03 Dec 2015 22:46:30 PST Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0061.outbound.protection.outlook.com [207.46.100.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E0AC6EDB3 for ; Thu, 3 Dec 2015 22:46:30 -0800 (PST) Received: from SN1PR12CA0012.namprd12.prod.outlook.com (10.162.96.150) by CY1PR12MB0716.namprd12.prod.outlook.com (10.163.238.22) with Microsoft SMTP Server (TLS) id 15.1.337.19; Fri, 4 Dec 2015 06:31:30 +0000 Received: from BY2NAM03FT015.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::201) by SN1PR12CA0012.outlook.office365.com (2a01:111:e400:5174::22) with Microsoft SMTP Server (TLS) id 15.1.337.19 via Frontend Transport; Fri, 4 Dec 2015 06:31:30 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp01.amd.com (165.204.84.221) by BY2NAM03FT015.mail.protection.outlook.com (10.152.84.212) with Microsoft SMTP Server id 15.1.346.13 via Frontend Transport; Fri, 4 Dec 2015 06:31:30 +0000 X-WSS-ID: 0NYTM4H-07-O5L-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by atltwp01.amd.com (Axway MailGate 5.3.1) with ESMTPS id 257D7CAF041 for ; Fri, 4 Dec 2015 01:31:28 -0500 (EST) Received: from SATLEXDAG02.amd.com (10.181.40.5) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 4 Dec 2015 00:31:44 -0600 Received: from SCYBEXDAG02.amd.com (10.34.11.12) by SATLEXDAG02.amd.com (10.181.40.5) with Microsoft SMTP Server (TLS) id 14.3.266.1; Fri, 4 Dec 2015 01:31:28 -0500 Received: from zhoucm1.amd.com (10.237.74.94) by SCYBEXDAG02.amd.com (10.34.11.12) with Microsoft SMTP Server id 14.3.266.1; Fri, 4 Dec 2015 14:31:24 +0800 From: Chunming Zhou To: Subject: [PATCH 2/2] amdgpu: add amdgpu_find_bo_by_cpu_mapping interface Date: Fri, 4 Dec 2015 14:25:53 +0800 Message-ID: <1449210353-24082-3-git-send-email-David1.Zhou@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449210353-24082-1-git-send-email-David1.Zhou@amd.com> References: <1449210353-24082-1-git-send-email-David1.Zhou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.221; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(189002)(199003)(106466001)(36756003)(2351001)(229853001)(105586002)(97736004)(92566002)(76176999)(87936001)(189998001)(50986999)(47776003)(2950100001)(110136002)(77096005)(586003)(86362001)(23676002)(1096002)(5008740100001)(5003600100002)(1220700001)(450100001)(19580405001)(50226001)(19580395003)(5820100001)(575784001)(53416004)(11100500001)(50466002)(101416001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0716; H:atltwp01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0716; 2:wABdUCRLB93CoZB/C2/FeAVoPMXPLXT5IPXAcCr4YHOFyBR+5uBqQbuIKVpyDUvscrP751kgNtoYi5BvRKTwnQchmtCyTlEGtLmrt8872HLu/cWKU5Ky+1T3nANsCkBSdiUWmxvHTUVo5CkQPDLkuw==; 3:JFd6Ok+M+cGq7XJTdsfHrize2AUnwjGqcUeZ9/3JAT6uqBv5Wm/nBQjUm6aiw1a8w4Jz/0cnQh7DGX6+KVC4U3UKKACi0n6RP7GDozSSVnPEY0ZiC38WYRmyLtSmRxclLWxgxf/f9ADivmdPEV3ccduTDxk8pGSGYaRMpipediqDJqRUSP8bzF6PvHCpbXmoa7xv+5yad7XJ8QGEZE2ow6tWUo70IWY2uQFOQmmPXEg=; 25:PtcDjHCrCeKZ6phNauru3tyIe09WWmfQfUUerU/TfKmbtzs/WgH/m/6C3KgS0C+jVdvViM64D3c5s5qvuygpuE0lLGOUnB0ETs5oLQf7BLusOO1YVH59T7NnbwNZNaehBdmbDTYbpwrod9L98S08fpMDFJ/l/iPLV9athQv41iQGBuewXSSeweRufgNP4/2YC542B0QJh+J99c/p+V9MEqFj/SEPDj9rFCo2orr42yMGg+FQhrtTF2tVV0knpnnX X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0716; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0716; 20:h/5n6whZueM3tIeMTZwZTb3O4NREMqizFN2xkalll/WebN0RnJ27TU5im29tYMMQ0h5rcCJD8MUIlHxGWKNz3B2+FgrxRd5nRISHXpcuOhVIu7DvwJTpZnCaD1E050gEKvUn1pN+zxmtFAJx5gWQk8ij/LzU2i6QdclvNaonAXvHZBxrPRwkVwzeTkUmezMfGNavdRp0KtMf8Q94QabABrUJVrGjnYFwlJaVMcBVQ0eFWj93WFbyrn0dikLw4hAIHjDJ2JQm8nz0hJnG2vwm2KnbDB+Re96DSXYXn3kCKJWNi7+g40Thv/rq3DcmTnzCgJ2q+UaejfVFtNDA7nmBv8NyDrP6k+NGuEyWkFdox41uypqZkydxcIxZXoJo3b0Rc7cOU1ZDtFBKR3ylLTdluxjlMfPc6rpwYfU5bHI4+ZMkM9TiLeU95hqRwfS6OSoRBIOiYx/buwbOH2TOxaW0r1/+M4jr9LdmaWsuQfHk6Qi/V+3VExceOjWJInyRcQ24; 4:/m2qDcmQBDlpRqY4wXVop0KHrTcNPzXtbOp/fx+0fhsR4l0yv3TwKRlAK4OYTUWHZ/+Q48OENsO/02SorVGJhL1X2JHK7njbbReh/gKy9pCQ2VJhQhTj9hKO2YIWUMcIcT4AY4oCSzu4IeXx/YtN+m3m+D4fMeiwaP6Gk/wwSzgK30FbjKH+plTotRsDK5sx99CBEYtaClgADfo9DWBIDcwjECbwsxm50MXoj3AMEZ+s6jzA0v3TC3SkQ2fV6hh8Nxm83Vv9ghFfoTxrVXxyQICJViz8vk6ylRAD2aKNdu7lPcvZn7g/W+dgLTcpdKFY1swpz3D00qilJNbMa3Z49Ay2kwJsS9LTGWe8/MPNe0y3qmbFLYjDGqw8t0fDgVnn/qE5/M4b33IhZSQNqrth3FSuYH642AQDpMX4bQcJT/8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(10201501046)(3002001); SRVR:CY1PR12MB0716; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0716; X-Forefront-PRVS: 07807C55DC X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjEyTUIwNzE2OzIzOmw5cVJBNGpMTDl5SmtwazJRZ3dTdmFsRVBE?= =?utf-8?B?VTR5YzN1WHY0cGQxR0FONVM5ejA3ZnIxeDBjeSt2SUg3Y1pheHQ2ckl0VGVH?= =?utf-8?B?SW5iMmYzWW1zcWVwaVo0RmdVc3hjYkxUVmpEKzdOelRaeXg4dWZaMEt4djB1?= =?utf-8?B?UkdDaExmckxzTUNvaFpHVkNyV3R2eUQxNG5yWGhYam50SW8yZnVOZHltUU5F?= =?utf-8?B?c1JkejlIZnFFWktTVnl0aGRkOUtvZ1h5YTk5bDAzaXBlWHh2YzJ2ZS9HSEpQ?= =?utf-8?B?M1NJRDh0dEw1dkR2dVdoVHdoQXdvaDZNeHRONFlpdjZ1K0VBWkxTWjBzNkxY?= =?utf-8?B?Y0owSm03NjJ4U0Q5ckdHRlVQR2YyQ0lUZW0xTzRqUllPMk5RemhWYTRKd0dZ?= =?utf-8?B?aEJpMEc0enE4ajNPRnVZT29Gc0VLcGRBeUxxUkswcWdKQ01pL3hzM3ZsUFBB?= =?utf-8?B?QUhnOERHa0g3cU5PWi9uOWxDd3d5OHJ4QVZFNFBXZGJGMElaL0gyMG5UaDFN?= =?utf-8?B?eG1FUXVHS2xGcElEbjNYMXpkRy9pazlpTFJQSmdsSnJNUDQvT1NFSWRHSkNs?= =?utf-8?B?K3F1bHRFMXhac1JQK2xJT0crZEZUNzJ2NHRKL3VWb2hhclJCekVRS04xQ1FH?= =?utf-8?B?dnJyOFh0aXVRREFNR0RDalJId28wS3NCU2hucWNpRm0zaG5sVVExZjFZUHF6?= =?utf-8?B?cSt5aDUyVjFlV2xGdk5zQ24ybDB3SHhLSnhrUjRKUGRZZ0NH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T5TUuBJIqUhOCC+HOy68QvnTDAaI7xWqCL5DlMTg+ds+Oi6jhfUgq6WxwRiINUgDEvpL67sl6JwfCVZ2tdqvCPW13xYwdVXeHut68M/SOq2Y3ckw3pGSe4FfTswFMT8jbVM0r1LSlB0yTKZNNkx/cB47HQTFRf/zXH9hKpSDUk5BvCSFA3cIO6wazOCxPI SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2015 06:31:30.0449 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.221]; Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0716 Cc: christian.koenig@amd.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP userspace needs to know if the user memory is from BO or malloc. Change-Id: Ie2dbc13f1c02bc0a996f64f9db83a21da63c1d70 Signed-off-by: Chunming Zhou Reviewed-by: Jammy Zhou Reviewed-by: Christian König --- amdgpu/amdgpu.h | 24 ++++++++++++++++++++++++ amdgpu/amdgpu_bo.c | 37 +++++++++++++++++++++++++++++++++++++ include/drm/amdgpu_drm.h | 12 ++++++++++++ 3 files changed, 73 insertions(+) diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h index baae113..4925056 100644 --- a/amdgpu/amdgpu.h +++ b/amdgpu/amdgpu.h @@ -672,6 +672,30 @@ int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, amdgpu_bo_handle *buf_handle); /** + * Validate if the user memory comes from BO + * + * \param dev - [in] Device handle. See #amdgpu_device_initialize() + * \param cpu - [in] CPU address of user allocated memory which we + * want to map to GPU address space (make GPU accessible) + * (This address must be correctly aligned). + * \param size - [in] Size of allocation (must be correctly aligned) + * \param buf_handle - [out] Buffer handle for the userptr memory + * if the user memory is not from BO, the buf_handle will be NULL. + * \param offset_in_bo - [out] offset in this BO for this user memory + * + * + * \return 0 on success\n + * <0 - Negative POSIX Error code + * +*/ +int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, + void *cpu, + uint64_t size, + amdgpu_bo_handle *buf_handle, + uint64_t *offset_in_bo); + + +/** * Free previosuly allocated memory * * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 5a0f4ac..82659a4 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -528,6 +528,43 @@ int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo, } } +int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, + void *cpu, + uint64_t size, + amdgpu_bo_handle *buf_handle, + uint64_t *offset_in_bo) +{ + int r; + struct amdgpu_bo *bo; + struct drm_amdgpu_gem_find_bo args; + + args.addr = (uintptr_t)cpu; + args.size = size; + r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_GEM_FIND_BO, + &args, sizeof(args)); + if (r) + return r; + if (args.handle == 0) + return -EINVAL; + bo = util_hash_table_get(dev->bo_handles, + (void*)(uintptr_t)args.handle); + if (!bo) { + bo = calloc(1, sizeof(struct amdgpu_bo)); + if (!bo) + return -ENOMEM; + atomic_set(&bo->refcount, 1); + bo->dev = dev; + bo->alloc_size = size; + bo->handle = args.handle; + } else + atomic_inc(&bo->refcount); + + *buf_handle = bo; + *offset_in_bo = args.offset; + return r; +} + + int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, void *cpu, uint64_t size, diff --git a/include/drm/amdgpu_drm.h b/include/drm/amdgpu_drm.h index 050e7fe..e07904c 100644 --- a/include/drm/amdgpu_drm.h +++ b/include/drm/amdgpu_drm.h @@ -47,6 +47,7 @@ #define DRM_AMDGPU_GEM_OP 0x10 #define DRM_AMDGPU_GEM_USERPTR 0x11 #define DRM_AMDGPU_WAIT_FENCES 0x12 +#define DRM_AMDGPU_GEM_FIND_BO 0x13 #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create) #define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap) @@ -61,6 +62,7 @@ #define DRM_IOCTL_AMDGPU_GEM_OP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op) #define DRM_IOCTL_AMDGPU_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr) #define DRM_IOCTL_AMDGPU_WAIT_FENCES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_FENCES, union drm_amdgpu_wait_fences) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, struct drm_amdgpu_gem_find_bo) #define AMDGPU_GEM_DOMAIN_CPU 0x1 #define AMDGPU_GEM_DOMAIN_GTT 0x2 @@ -201,6 +203,16 @@ struct drm_amdgpu_gem_userptr { uint32_t handle; }; +struct drm_amdgpu_gem_find_bo { + uint64_t addr; + uint64_t size; + uint32_t flags; + /* Resulting GEM handle */ + uint32_t handle; + /* offset in bo */ + uint64_t offset; +}; + /* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */ #define AMDGPU_TILING_ARRAY_MODE_SHIFT 0 #define AMDGPU_TILING_ARRAY_MODE_MASK 0xf