18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Defines an spu hypervisor abstraction layer.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright 2006 Sony Corp.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#if !defined(_SPU_PRIV1_H)
98c2ecf20Sopenharmony_ci#define _SPU_PRIV1_H
108c2ecf20Sopenharmony_ci#if defined(__KERNEL__)
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/types.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct spu;
158c2ecf20Sopenharmony_cistruct spu_context;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* access to priv1 registers */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct spu_priv1_ops {
208c2ecf20Sopenharmony_ci	void (*int_mask_and) (struct spu *spu, int class, u64 mask);
218c2ecf20Sopenharmony_ci	void (*int_mask_or) (struct spu *spu, int class, u64 mask);
228c2ecf20Sopenharmony_ci	void (*int_mask_set) (struct spu *spu, int class, u64 mask);
238c2ecf20Sopenharmony_ci	u64 (*int_mask_get) (struct spu *spu, int class);
248c2ecf20Sopenharmony_ci	void (*int_stat_clear) (struct spu *spu, int class, u64 stat);
258c2ecf20Sopenharmony_ci	u64 (*int_stat_get) (struct spu *spu, int class);
268c2ecf20Sopenharmony_ci	void (*cpu_affinity_set) (struct spu *spu, int cpu);
278c2ecf20Sopenharmony_ci	u64 (*mfc_dar_get) (struct spu *spu);
288c2ecf20Sopenharmony_ci	u64 (*mfc_dsisr_get) (struct spu *spu);
298c2ecf20Sopenharmony_ci	void (*mfc_dsisr_set) (struct spu *spu, u64 dsisr);
308c2ecf20Sopenharmony_ci	void (*mfc_sdr_setup) (struct spu *spu);
318c2ecf20Sopenharmony_ci	void (*mfc_sr1_set) (struct spu *spu, u64 sr1);
328c2ecf20Sopenharmony_ci	u64 (*mfc_sr1_get) (struct spu *spu);
338c2ecf20Sopenharmony_ci	void (*mfc_tclass_id_set) (struct spu *spu, u64 tclass_id);
348c2ecf20Sopenharmony_ci	u64 (*mfc_tclass_id_get) (struct spu *spu);
358c2ecf20Sopenharmony_ci	void (*tlb_invalidate) (struct spu *spu);
368c2ecf20Sopenharmony_ci	void (*resource_allocation_groupID_set) (struct spu *spu, u64 id);
378c2ecf20Sopenharmony_ci	u64 (*resource_allocation_groupID_get) (struct spu *spu);
388c2ecf20Sopenharmony_ci	void (*resource_allocation_enable_set) (struct spu *spu, u64 enable);
398c2ecf20Sopenharmony_ci	u64 (*resource_allocation_enable_get) (struct spu *spu);
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciextern const struct spu_priv1_ops* spu_priv1_ops;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline void
458c2ecf20Sopenharmony_cispu_int_mask_and (struct spu *spu, int class, u64 mask)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	spu_priv1_ops->int_mask_and(spu, class, mask);
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic inline void
518c2ecf20Sopenharmony_cispu_int_mask_or (struct spu *spu, int class, u64 mask)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	spu_priv1_ops->int_mask_or(spu, class, mask);
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic inline void
578c2ecf20Sopenharmony_cispu_int_mask_set (struct spu *spu, int class, u64 mask)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	spu_priv1_ops->int_mask_set(spu, class, mask);
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic inline u64
638c2ecf20Sopenharmony_cispu_int_mask_get (struct spu *spu, int class)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	return spu_priv1_ops->int_mask_get(spu, class);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic inline void
698c2ecf20Sopenharmony_cispu_int_stat_clear (struct spu *spu, int class, u64 stat)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	spu_priv1_ops->int_stat_clear(spu, class, stat);
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic inline u64
758c2ecf20Sopenharmony_cispu_int_stat_get (struct spu *spu, int class)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	return spu_priv1_ops->int_stat_get (spu, class);
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline void
818c2ecf20Sopenharmony_cispu_cpu_affinity_set (struct spu *spu, int cpu)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	spu_priv1_ops->cpu_affinity_set(spu, cpu);
848c2ecf20Sopenharmony_ci}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic inline u64
878c2ecf20Sopenharmony_cispu_mfc_dar_get (struct spu *spu)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	return spu_priv1_ops->mfc_dar_get(spu);
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic inline u64
938c2ecf20Sopenharmony_cispu_mfc_dsisr_get (struct spu *spu)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	return spu_priv1_ops->mfc_dsisr_get(spu);
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline void
998c2ecf20Sopenharmony_cispu_mfc_dsisr_set (struct spu *spu, u64 dsisr)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	spu_priv1_ops->mfc_dsisr_set(spu, dsisr);
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline void
1058c2ecf20Sopenharmony_cispu_mfc_sdr_setup (struct spu *spu)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	spu_priv1_ops->mfc_sdr_setup(spu);
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic inline void
1118c2ecf20Sopenharmony_cispu_mfc_sr1_set (struct spu *spu, u64 sr1)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	spu_priv1_ops->mfc_sr1_set(spu, sr1);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline u64
1178c2ecf20Sopenharmony_cispu_mfc_sr1_get (struct spu *spu)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	return spu_priv1_ops->mfc_sr1_get(spu);
1208c2ecf20Sopenharmony_ci}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic inline void
1238c2ecf20Sopenharmony_cispu_mfc_tclass_id_set (struct spu *spu, u64 tclass_id)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	spu_priv1_ops->mfc_tclass_id_set(spu, tclass_id);
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistatic inline u64
1298c2ecf20Sopenharmony_cispu_mfc_tclass_id_get (struct spu *spu)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	return spu_priv1_ops->mfc_tclass_id_get(spu);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic inline void
1358c2ecf20Sopenharmony_cispu_tlb_invalidate (struct spu *spu)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	spu_priv1_ops->tlb_invalidate(spu);
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline void
1418c2ecf20Sopenharmony_cispu_resource_allocation_groupID_set (struct spu *spu, u64 id)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	spu_priv1_ops->resource_allocation_groupID_set(spu, id);
1448c2ecf20Sopenharmony_ci}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic inline u64
1478c2ecf20Sopenharmony_cispu_resource_allocation_groupID_get (struct spu *spu)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	return spu_priv1_ops->resource_allocation_groupID_get(spu);
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic inline void
1538c2ecf20Sopenharmony_cispu_resource_allocation_enable_set (struct spu *spu, u64 enable)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	spu_priv1_ops->resource_allocation_enable_set(spu, enable);
1568c2ecf20Sopenharmony_ci}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic inline u64
1598c2ecf20Sopenharmony_cispu_resource_allocation_enable_get (struct spu *spu)
1608c2ecf20Sopenharmony_ci{
1618c2ecf20Sopenharmony_ci	return spu_priv1_ops->resource_allocation_enable_get(spu);
1628c2ecf20Sopenharmony_ci}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* spu management abstraction */
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cistruct spu_management_ops {
1678c2ecf20Sopenharmony_ci	int (*enumerate_spus)(int (*fn)(void *data));
1688c2ecf20Sopenharmony_ci	int (*create_spu)(struct spu *spu, void *data);
1698c2ecf20Sopenharmony_ci	int (*destroy_spu)(struct spu *spu);
1708c2ecf20Sopenharmony_ci	void (*enable_spu)(struct spu_context *ctx);
1718c2ecf20Sopenharmony_ci	void (*disable_spu)(struct spu_context *ctx);
1728c2ecf20Sopenharmony_ci	int (*init_affinity)(void);
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ciextern const struct spu_management_ops* spu_management_ops;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_cistatic inline int
1788c2ecf20Sopenharmony_cispu_enumerate_spus (int (*fn)(void *data))
1798c2ecf20Sopenharmony_ci{
1808c2ecf20Sopenharmony_ci	return spu_management_ops->enumerate_spus(fn);
1818c2ecf20Sopenharmony_ci}
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic inline int
1848c2ecf20Sopenharmony_cispu_create_spu (struct spu *spu, void *data)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	return spu_management_ops->create_spu(spu, data);
1878c2ecf20Sopenharmony_ci}
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic inline int
1908c2ecf20Sopenharmony_cispu_destroy_spu (struct spu *spu)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	return spu_management_ops->destroy_spu(spu);
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistatic inline int
1968c2ecf20Sopenharmony_cispu_init_affinity (void)
1978c2ecf20Sopenharmony_ci{
1988c2ecf20Sopenharmony_ci	return spu_management_ops->init_affinity();
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistatic inline void
2028c2ecf20Sopenharmony_cispu_enable_spu (struct spu_context *ctx)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	spu_management_ops->enable_spu(ctx);
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic inline void
2088c2ecf20Sopenharmony_cispu_disable_spu (struct spu_context *ctx)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	spu_management_ops->disable_spu(ctx);
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci/*
2148c2ecf20Sopenharmony_ci * The declarations following are put here for convenience
2158c2ecf20Sopenharmony_ci * and only intended to be used by the platform setup code.
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ciextern const struct spu_priv1_ops spu_priv1_mmio_ops;
2198c2ecf20Sopenharmony_ciextern const struct spu_priv1_ops spu_priv1_beat_ops;
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ciextern const struct spu_management_ops spu_management_of_ops;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
2248c2ecf20Sopenharmony_ci#endif
225