Home | History | Annotate | Line # | Download | only in core
      1 /*	$NetBSD: amdgpu_dc_vm_helper.c,v 1.2 2021/12/18 23:45:02 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2018 Advanced Micro Devices, Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors: AMD
     25  *
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: amdgpu_dc_vm_helper.c,v 1.2 2021/12/18 23:45:02 riastradh Exp $");
     30 
     31 #include "vm_helper.h"
     32 #include "dc.h"
     33 
     34 void vm_helper_mark_vmid_used(struct vm_helper *vm_helper, unsigned int pos, uint8_t hubp_idx)
     35 {
     36 	struct vmid_usage vmids = vm_helper->hubp_vmid_usage[hubp_idx];
     37 
     38 	vmids.vmid_usage[0] = vmids.vmid_usage[1];
     39 	vmids.vmid_usage[1] = 1 << pos;
     40 }
     41 
     42 int dc_setup_system_context(struct dc *dc, struct dc_phy_addr_space_config *pa_config)
     43 {
     44 	int num_vmids = 0;
     45 
     46 	/* Call HWSS to setup HUBBUB for address config */
     47 	if (dc->hwss.init_sys_ctx) {
     48 		num_vmids = dc->hwss.init_sys_ctx(dc->hwseq, dc, pa_config);
     49 
     50 		/* Pre-init system aperture start/end for all HUBP instances (if not gating?)
     51 		 * or cache system aperture if using power gating
     52 		 */
     53 		memcpy(&dc->vm_pa_config, pa_config, sizeof(struct dc_phy_addr_space_config));
     54 		dc->vm_pa_config.valid = true;
     55 	}
     56 
     57 	return num_vmids;
     58 }
     59 
     60 void dc_setup_vm_context(struct dc *dc, struct dc_virtual_addr_space_config *va_config, int vmid)
     61 {
     62 	dc->hwss.init_vm_ctx(dc->hwseq, dc, va_config, vmid);
     63 }
     64 
     65 int dc_get_vmid_use_vector(struct dc *dc)
     66 {
     67 	int i;
     68 	int in_use = 0;
     69 
     70 	for (i = 0; i < dc->vm_helper->num_vmid; i++)
     71 		in_use |= dc->vm_helper->hubp_vmid_usage[i].vmid_usage[0]
     72 			| dc->vm_helper->hubp_vmid_usage[i].vmid_usage[1];
     73 	return in_use;
     74 }
     75 
     76 void vm_helper_init(struct vm_helper *vm_helper, unsigned int num_vmid)
     77 {
     78 	vm_helper->num_vmid = num_vmid;
     79 
     80 	memset(vm_helper->hubp_vmid_usage, 0, sizeof(vm_helper->hubp_vmid_usage[0]) * MAX_HUBP);
     81 }
     82