xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/common/mali_hw_core.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2011-2017 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10 
11 #ifndef __MALI_HW_CORE_H__
12 #define __MALI_HW_CORE_H__
13 
14 #include "mali_osk.h"
15 #include "mali_kernel_common.h"
16 
17 /**
18  * The common parts for all Mali HW cores (GP, PP, MMU, L2 and PMU)
19  * This struct is embedded inside all core specific structs.
20  */
21 struct mali_hw_core {
22 	uintptr_t phys_addr;              /**< Physical address of the registers */
23 	u32 phys_offset;                  /**< Offset from start of Mali to registers */
24 	u32 size;                         /**< Size of registers */
25 	mali_io_address mapped_registers; /**< Virtual mapping of the registers */
26 	const char *description;          /**< Name of unit (as specified in device configuration) */
27 };
28 
29 #define MALI_REG_POLL_COUNT_FAST 1000000
30 #define MALI_REG_POLL_COUNT_SLOW 1000000
31 
32 /*
33  * GP and PP core translate their int_stat/rawstat into one of these
34  */
35 enum mali_interrupt_result {
36 	MALI_INTERRUPT_RESULT_NONE,
37 	MALI_INTERRUPT_RESULT_SUCCESS,
38 	MALI_INTERRUPT_RESULT_SUCCESS_VS,
39 	MALI_INTERRUPT_RESULT_SUCCESS_PLBU,
40 	MALI_INTERRUPT_RESULT_OOM,
41 	MALI_INTERRUPT_RESULT_ERROR
42 };
43 
44 _mali_osk_errcode_t mali_hw_core_create(struct mali_hw_core *core, const _mali_osk_resource_t *resource, u32 reg_size);
45 void mali_hw_core_delete(struct mali_hw_core *core);
46 
mali_hw_core_register_read(struct mali_hw_core * core,u32 relative_address)47 MALI_STATIC_INLINE u32 mali_hw_core_register_read(struct mali_hw_core *core, u32 relative_address)
48 {
49 	u32 read_val;
50 	read_val = _mali_osk_mem_ioread32(core->mapped_registers, relative_address);
51 	MALI_DEBUG_PRINT(6, ("register_read for core %s, relative addr=0x%04X, val=0x%08X\n",
52 			     core->description, relative_address, read_val));
53 	return read_val;
54 }
55 
mali_hw_core_register_write_relaxed(struct mali_hw_core * core,u32 relative_address,u32 new_val)56 MALI_STATIC_INLINE void mali_hw_core_register_write_relaxed(struct mali_hw_core *core, u32 relative_address, u32 new_val)
57 {
58 	MALI_DEBUG_PRINT(6, ("register_write_relaxed for core %s, relative addr=0x%04X, val=0x%08X\n",
59 			     core->description, relative_address, new_val));
60 	_mali_osk_mem_iowrite32_relaxed(core->mapped_registers, relative_address, new_val);
61 }
62 
63 /* Conditionally write a register.
64  * The register will only be written if the new value is different from the old_value.
65  * If the new value is different, the old value will also be updated */
mali_hw_core_register_write_relaxed_conditional(struct mali_hw_core * core,u32 relative_address,u32 new_val,const u32 old_val)66 MALI_STATIC_INLINE void mali_hw_core_register_write_relaxed_conditional(struct mali_hw_core *core, u32 relative_address, u32 new_val, const u32 old_val)
67 {
68 	MALI_DEBUG_PRINT(6, ("register_write_relaxed for core %s, relative addr=0x%04X, val=0x%08X\n",
69 			     core->description, relative_address, new_val));
70 	if (old_val != new_val) {
71 		_mali_osk_mem_iowrite32_relaxed(core->mapped_registers, relative_address, new_val);
72 	}
73 }
74 
mali_hw_core_register_write(struct mali_hw_core * core,u32 relative_address,u32 new_val)75 MALI_STATIC_INLINE void mali_hw_core_register_write(struct mali_hw_core *core, u32 relative_address, u32 new_val)
76 {
77 	MALI_DEBUG_PRINT(6, ("register_write for core %s, relative addr=0x%04X, val=0x%08X\n",
78 			     core->description, relative_address, new_val));
79 	_mali_osk_mem_iowrite32(core->mapped_registers, relative_address, new_val);
80 }
81 
mali_hw_core_register_write_array_relaxed(struct mali_hw_core * core,u32 relative_address,u32 * write_array,u32 nr_of_regs)82 MALI_STATIC_INLINE void mali_hw_core_register_write_array_relaxed(struct mali_hw_core *core, u32 relative_address, u32 *write_array, u32 nr_of_regs)
83 {
84 	u32 i;
85 	MALI_DEBUG_PRINT(6, ("register_write_array: for core %s, relative addr=0x%04X, nr of regs=%u\n",
86 			     core->description, relative_address, nr_of_regs));
87 
88 	/* Do not use burst writes against the registers */
89 	for (i = 0; i < nr_of_regs; i++) {
90 		mali_hw_core_register_write_relaxed(core, relative_address + i * 4, write_array[i]);
91 	}
92 }
93 
94 /* Conditionally write a set of registers.
95  * The register will only be written if the new value is different from the old_value.
96  * If the new value is different, the old value will also be updated */
mali_hw_core_register_write_array_relaxed_conditional(struct mali_hw_core * core,u32 relative_address,u32 * write_array,u32 nr_of_regs,const u32 * old_array)97 MALI_STATIC_INLINE void mali_hw_core_register_write_array_relaxed_conditional(struct mali_hw_core *core, u32 relative_address, u32 *write_array, u32 nr_of_regs, const u32 *old_array)
98 {
99 	u32 i;
100 	MALI_DEBUG_PRINT(6, ("register_write_array: for core %s, relative addr=0x%04X, nr of regs=%u\n",
101 			     core->description, relative_address, nr_of_regs));
102 
103 	/* Do not use burst writes against the registers */
104 	for (i = 0; i < nr_of_regs; i++) {
105 		if (old_array[i] != write_array[i]) {
106 			mali_hw_core_register_write_relaxed(core, relative_address + i * 4, write_array[i]);
107 		}
108 	}
109 }
110 
111 #endif /* __MALI_HW_CORE_H__ */
112