1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Defines an spu hypervisor abstraction layer.
4  *
5  *  Copyright 2006 Sony Corp.
6  */
7 
8 #if !defined(_SPU_PRIV1_H)
9 #define _SPU_PRIV1_H
10 #if defined(__KERNEL__)
11 
12 #include <linux/types.h>
13 
14 struct spu;
15 struct spu_context;
16 
17 /* access to priv1 registers */
18 
19 struct spu_priv1_ops {
20 	void (*int_mask_and) (struct spu *spu, int class, u64 mask);
21 	void (*int_mask_or) (struct spu *spu, int class, u64 mask);
22 	void (*int_mask_set) (struct spu *spu, int class, u64 mask);
23 	u64 (*int_mask_get) (struct spu *spu, int class);
24 	void (*int_stat_clear) (struct spu *spu, int class, u64 stat);
25 	u64 (*int_stat_get) (struct spu *spu, int class);
26 	void (*cpu_affinity_set) (struct spu *spu, int cpu);
27 	u64 (*mfc_dar_get) (struct spu *spu);
28 	u64 (*mfc_dsisr_get) (struct spu *spu);
29 	void (*mfc_dsisr_set) (struct spu *spu, u64 dsisr);
30 	void (*mfc_sdr_setup) (struct spu *spu);
31 	void (*mfc_sr1_set) (struct spu *spu, u64 sr1);
32 	u64 (*mfc_sr1_get) (struct spu *spu);
33 	void (*mfc_tclass_id_set) (struct spu *spu, u64 tclass_id);
34 	u64 (*mfc_tclass_id_get) (struct spu *spu);
35 	void (*tlb_invalidate) (struct spu *spu);
36 	void (*resource_allocation_groupID_set) (struct spu *spu, u64 id);
37 	u64 (*resource_allocation_groupID_get) (struct spu *spu);
38 	void (*resource_allocation_enable_set) (struct spu *spu, u64 enable);
39 	u64 (*resource_allocation_enable_get) (struct spu *spu);
40 };
41 
42 extern const struct spu_priv1_ops* spu_priv1_ops;
43 
44 static inline void
spu_int_mask_and(struct spu * spu,int class,u64 mask)45 spu_int_mask_and (struct spu *spu, int class, u64 mask)
46 {
47 	spu_priv1_ops->int_mask_and(spu, class, mask);
48 }
49 
50 static inline void
spu_int_mask_or(struct spu * spu,int class,u64 mask)51 spu_int_mask_or (struct spu *spu, int class, u64 mask)
52 {
53 	spu_priv1_ops->int_mask_or(spu, class, mask);
54 }
55 
56 static inline void
spu_int_mask_set(struct spu * spu,int class,u64 mask)57 spu_int_mask_set (struct spu *spu, int class, u64 mask)
58 {
59 	spu_priv1_ops->int_mask_set(spu, class, mask);
60 }
61 
62 static inline u64
spu_int_mask_get(struct spu * spu,int class)63 spu_int_mask_get (struct spu *spu, int class)
64 {
65 	return spu_priv1_ops->int_mask_get(spu, class);
66 }
67 
68 static inline void
spu_int_stat_clear(struct spu * spu,int class,u64 stat)69 spu_int_stat_clear (struct spu *spu, int class, u64 stat)
70 {
71 	spu_priv1_ops->int_stat_clear(spu, class, stat);
72 }
73 
74 static inline u64
spu_int_stat_get(struct spu * spu,int class)75 spu_int_stat_get (struct spu *spu, int class)
76 {
77 	return spu_priv1_ops->int_stat_get (spu, class);
78 }
79 
80 static inline void
spu_cpu_affinity_set(struct spu * spu,int cpu)81 spu_cpu_affinity_set (struct spu *spu, int cpu)
82 {
83 	spu_priv1_ops->cpu_affinity_set(spu, cpu);
84 }
85 
86 static inline u64
spu_mfc_dar_get(struct spu * spu)87 spu_mfc_dar_get (struct spu *spu)
88 {
89 	return spu_priv1_ops->mfc_dar_get(spu);
90 }
91 
92 static inline u64
spu_mfc_dsisr_get(struct spu * spu)93 spu_mfc_dsisr_get (struct spu *spu)
94 {
95 	return spu_priv1_ops->mfc_dsisr_get(spu);
96 }
97 
98 static inline void
spu_mfc_dsisr_set(struct spu * spu,u64 dsisr)99 spu_mfc_dsisr_set (struct spu *spu, u64 dsisr)
100 {
101 	spu_priv1_ops->mfc_dsisr_set(spu, dsisr);
102 }
103 
104 static inline void
spu_mfc_sdr_setup(struct spu * spu)105 spu_mfc_sdr_setup (struct spu *spu)
106 {
107 	spu_priv1_ops->mfc_sdr_setup(spu);
108 }
109 
110 static inline void
spu_mfc_sr1_set(struct spu * spu,u64 sr1)111 spu_mfc_sr1_set (struct spu *spu, u64 sr1)
112 {
113 	spu_priv1_ops->mfc_sr1_set(spu, sr1);
114 }
115 
116 static inline u64
spu_mfc_sr1_get(struct spu * spu)117 spu_mfc_sr1_get (struct spu *spu)
118 {
119 	return spu_priv1_ops->mfc_sr1_get(spu);
120 }
121 
122 static inline void
spu_mfc_tclass_id_set(struct spu * spu,u64 tclass_id)123 spu_mfc_tclass_id_set (struct spu *spu, u64 tclass_id)
124 {
125 	spu_priv1_ops->mfc_tclass_id_set(spu, tclass_id);
126 }
127 
128 static inline u64
spu_mfc_tclass_id_get(struct spu * spu)129 spu_mfc_tclass_id_get (struct spu *spu)
130 {
131 	return spu_priv1_ops->mfc_tclass_id_get(spu);
132 }
133 
134 static inline void
spu_tlb_invalidate(struct spu * spu)135 spu_tlb_invalidate (struct spu *spu)
136 {
137 	spu_priv1_ops->tlb_invalidate(spu);
138 }
139 
140 static inline void
spu_resource_allocation_groupID_set(struct spu * spu,u64 id)141 spu_resource_allocation_groupID_set (struct spu *spu, u64 id)
142 {
143 	spu_priv1_ops->resource_allocation_groupID_set(spu, id);
144 }
145 
146 static inline u64
spu_resource_allocation_groupID_get(struct spu * spu)147 spu_resource_allocation_groupID_get (struct spu *spu)
148 {
149 	return spu_priv1_ops->resource_allocation_groupID_get(spu);
150 }
151 
152 static inline void
spu_resource_allocation_enable_set(struct spu * spu,u64 enable)153 spu_resource_allocation_enable_set (struct spu *spu, u64 enable)
154 {
155 	spu_priv1_ops->resource_allocation_enable_set(spu, enable);
156 }
157 
158 static inline u64
spu_resource_allocation_enable_get(struct spu * spu)159 spu_resource_allocation_enable_get (struct spu *spu)
160 {
161 	return spu_priv1_ops->resource_allocation_enable_get(spu);
162 }
163 
164 /* spu management abstraction */
165 
166 struct spu_management_ops {
167 	int (*enumerate_spus)(int (*fn)(void *data));
168 	int (*create_spu)(struct spu *spu, void *data);
169 	int (*destroy_spu)(struct spu *spu);
170 	void (*enable_spu)(struct spu_context *ctx);
171 	void (*disable_spu)(struct spu_context *ctx);
172 	int (*init_affinity)(void);
173 };
174 
175 extern const struct spu_management_ops* spu_management_ops;
176 
177 static inline int
spu_enumerate_spus(int (* fn)(void * data))178 spu_enumerate_spus (int (*fn)(void *data))
179 {
180 	return spu_management_ops->enumerate_spus(fn);
181 }
182 
183 static inline int
spu_create_spu(struct spu * spu,void * data)184 spu_create_spu (struct spu *spu, void *data)
185 {
186 	return spu_management_ops->create_spu(spu, data);
187 }
188 
189 static inline int
spu_destroy_spu(struct spu * spu)190 spu_destroy_spu (struct spu *spu)
191 {
192 	return spu_management_ops->destroy_spu(spu);
193 }
194 
195 static inline int
spu_init_affinity(void)196 spu_init_affinity (void)
197 {
198 	return spu_management_ops->init_affinity();
199 }
200 
201 static inline void
spu_enable_spu(struct spu_context * ctx)202 spu_enable_spu (struct spu_context *ctx)
203 {
204 	spu_management_ops->enable_spu(ctx);
205 }
206 
207 static inline void
spu_disable_spu(struct spu_context * ctx)208 spu_disable_spu (struct spu_context *ctx)
209 {
210 	spu_management_ops->disable_spu(ctx);
211 }
212 
213 /*
214  * The declarations following are put here for convenience
215  * and only intended to be used by the platform setup code.
216  */
217 
218 extern const struct spu_priv1_ops spu_priv1_mmio_ops;
219 extern const struct spu_priv1_ops spu_priv1_beat_ops;
220 
221 extern const struct spu_management_ops spu_management_of_ops;
222 
223 #endif /* __KERNEL__ */
224 #endif
225