Home | History | Annotate | Line # | Download | only in amdgpu
amdgpu_gfx.c revision 1.1
      1 /*	$NetBSD: amdgpu_gfx.c,v 1.1 2018/08/27 01:34:44 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2014 Advanced Micro Devices, Inc.
      5  * Copyright 2008 Red Hat Inc.
      6  * Copyright 2009 Jerome Glisse.
      7  *
      8  * Permission is hereby granted, free of charge, to any person obtaining a
      9  * copy of this software and associated documentation files (the "Software"),
     10  * to deal in the Software without restriction, including without limitation
     11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     12  * and/or sell copies of the Software, and to permit persons to whom the
     13  * Software is furnished to do so, subject to the following conditions:
     14  *
     15  * The above copyright notice and this permission notice shall be included in
     16  * all copies or substantial portions of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     21  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     24  * OTHER DEALINGS IN THE SOFTWARE.
     25  *
     26  */
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: amdgpu_gfx.c,v 1.1 2018/08/27 01:34:44 riastradh Exp $");
     29 
     30 #include <drm/drmP.h>
     31 #include "amdgpu.h"
     32 
     33 /*
     34  * GPU scratch registers helpers function.
     35  */
     36 /**
     37  * amdgpu_gfx_scratch_get - Allocate a scratch register
     38  *
     39  * @adev: amdgpu_device pointer
     40  * @reg: scratch register mmio offset
     41  *
     42  * Allocate a CP scratch register for use by the driver (all asics).
     43  * Returns 0 on success or -EINVAL on failure.
     44  */
     45 int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
     46 {
     47 	int i;
     48 
     49 	for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
     50 		if (adev->gfx.scratch.free[i]) {
     51 			adev->gfx.scratch.free[i] = false;
     52 			*reg = adev->gfx.scratch.reg[i];
     53 			return 0;
     54 		}
     55 	}
     56 	return -EINVAL;
     57 }
     58 
     59 /**
     60  * amdgpu_gfx_scratch_free - Free a scratch register
     61  *
     62  * @adev: amdgpu_device pointer
     63  * @reg: scratch register mmio offset
     64  *
     65  * Free a CP scratch register allocated for use by the driver (all asics)
     66  */
     67 void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
     68 {
     69 	int i;
     70 
     71 	for (i = 0; i < adev->gfx.scratch.num_reg; i++) {
     72 		if (adev->gfx.scratch.reg[i] == reg) {
     73 			adev->gfx.scratch.free[i] = true;
     74 			return;
     75 		}
     76 	}
     77 }
     78