1873e65bcSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c01ea72aSGeoff Levand /*
3540270d8SGeoff Levand  * spu hypervisor abstraction for direct hardware access.
4540270d8SGeoff Levand  *
5540270d8SGeoff Levand  *  (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6540270d8SGeoff Levand  *  Copyright 2006 Sony Corp.
7c01ea72aSGeoff Levand  */
8540270d8SGeoff Levand 
9e28b0031SGeoff Levand #include <linux/interrupt.h>
10e28b0031SGeoff Levand #include <linux/list.h>
11e28b0031SGeoff Levand #include <linux/ptrace.h>
12e28b0031SGeoff Levand #include <linux/wait.h>
13e28b0031SGeoff Levand #include <linux/mm.h>
14e28b0031SGeoff Levand #include <linux/io.h>
15e28b0031SGeoff Levand #include <linux/mutex.h>
16e28b0031SGeoff Levand #include <linux/device.h>
177a214200SLuke Browning #include <linux/sched.h>
18c01ea72aSGeoff Levand 
19c01ea72aSGeoff Levand #include <asm/spu.h>
20540270d8SGeoff Levand #include <asm/spu_priv1.h>
21e28b0031SGeoff Levand #include <asm/firmware.h>
22c01ea72aSGeoff Levand 
23a91942aeSGeoff Levand #include "interrupt.h"
24e28b0031SGeoff Levand #include "spu_priv1_mmio.h"
25e28b0031SGeoff Levand 
int_mask_and(struct spu * spu,int class,u64 mask)26540270d8SGeoff Levand static void int_mask_and(struct spu *spu, int class, u64 mask)
27c01ea72aSGeoff Levand {
28c01ea72aSGeoff Levand 	u64 old_mask;
29c01ea72aSGeoff Levand 
30c9868fe0SIshizaki Kou 	old_mask = in_be64(&spu->priv1->int_mask_RW[class]);
31c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->int_mask_RW[class], old_mask & mask);
32c01ea72aSGeoff Levand }
33c01ea72aSGeoff Levand 
int_mask_or(struct spu * spu,int class,u64 mask)34540270d8SGeoff Levand static void int_mask_or(struct spu *spu, int class, u64 mask)
35c01ea72aSGeoff Levand {
36c01ea72aSGeoff Levand 	u64 old_mask;
37c01ea72aSGeoff Levand 
38c9868fe0SIshizaki Kou 	old_mask = in_be64(&spu->priv1->int_mask_RW[class]);
39c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->int_mask_RW[class], old_mask | mask);
40c01ea72aSGeoff Levand }
41c01ea72aSGeoff Levand 
int_mask_set(struct spu * spu,int class,u64 mask)42540270d8SGeoff Levand static void int_mask_set(struct spu *spu, int class, u64 mask)
43c01ea72aSGeoff Levand {
44c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->int_mask_RW[class], mask);
45c01ea72aSGeoff Levand }
46c01ea72aSGeoff Levand 
int_mask_get(struct spu * spu,int class)47540270d8SGeoff Levand static u64 int_mask_get(struct spu *spu, int class)
48c01ea72aSGeoff Levand {
49c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->int_mask_RW[class]);
50c01ea72aSGeoff Levand }
51c01ea72aSGeoff Levand 
int_stat_clear(struct spu * spu,int class,u64 stat)52540270d8SGeoff Levand static void int_stat_clear(struct spu *spu, int class, u64 stat)
53c01ea72aSGeoff Levand {
54c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->int_stat_RW[class], stat);
55c01ea72aSGeoff Levand }
56c01ea72aSGeoff Levand 
int_stat_get(struct spu * spu,int class)57540270d8SGeoff Levand static u64 int_stat_get(struct spu *spu, int class)
58c01ea72aSGeoff Levand {
59c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->int_stat_RW[class]);
60c01ea72aSGeoff Levand }
61c01ea72aSGeoff Levand 
cpu_affinity_set(struct spu * spu,int cpu)62a91942aeSGeoff Levand static void cpu_affinity_set(struct spu *spu, int cpu)
63c01ea72aSGeoff Levand {
647a214200SLuke Browning 	u64 target;
657a214200SLuke Browning 	u64 route;
667a214200SLuke Browning 
677a214200SLuke Browning 	if (nr_cpus_node(spu->node)) {
6886c6f274SRusty Russell 		const struct cpumask *spumask = cpumask_of_node(spu->node),
6986c6f274SRusty Russell 			*cpumask = cpumask_of_node(cpu_to_node(cpu));
707a214200SLuke Browning 
7186c6f274SRusty Russell 		if (!cpumask_intersects(spumask, cpumask))
727a214200SLuke Browning 			return;
737a214200SLuke Browning 	}
747a214200SLuke Browning 
757a214200SLuke Browning 	target = iic_get_target_id(cpu);
767a214200SLuke Browning 	route = target << 48 | target << 32 | target << 16;
77c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->int_route_RW, route);
78c01ea72aSGeoff Levand }
79c01ea72aSGeoff Levand 
mfc_dar_get(struct spu * spu)80540270d8SGeoff Levand static u64 mfc_dar_get(struct spu *spu)
81c01ea72aSGeoff Levand {
82c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->mfc_dar_RW);
83c01ea72aSGeoff Levand }
84c01ea72aSGeoff Levand 
mfc_dsisr_get(struct spu * spu)85540270d8SGeoff Levand static u64 mfc_dsisr_get(struct spu *spu)
86c01ea72aSGeoff Levand {
87c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->mfc_dsisr_RW);
88c01ea72aSGeoff Levand }
89c01ea72aSGeoff Levand 
mfc_dsisr_set(struct spu * spu,u64 dsisr)90540270d8SGeoff Levand static void mfc_dsisr_set(struct spu *spu, u64 dsisr)
91c01ea72aSGeoff Levand {
92c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->mfc_dsisr_RW, dsisr);
93c01ea72aSGeoff Levand }
94c01ea72aSGeoff Levand 
mfc_sdr_setup(struct spu * spu)9524f43b33SMasato Noguchi static void mfc_sdr_setup(struct spu *spu)
96c01ea72aSGeoff Levand {
97c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->mfc_sdr_RW, mfspr(SPRN_SDR1));
98c01ea72aSGeoff Levand }
99c01ea72aSGeoff Levand 
mfc_sr1_set(struct spu * spu,u64 sr1)100540270d8SGeoff Levand static void mfc_sr1_set(struct spu *spu, u64 sr1)
101c01ea72aSGeoff Levand {
102c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->mfc_sr1_RW, sr1);
103c01ea72aSGeoff Levand }
104c01ea72aSGeoff Levand 
mfc_sr1_get(struct spu * spu)105540270d8SGeoff Levand static u64 mfc_sr1_get(struct spu *spu)
106c01ea72aSGeoff Levand {
107c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->mfc_sr1_RW);
108c01ea72aSGeoff Levand }
109c01ea72aSGeoff Levand 
mfc_tclass_id_set(struct spu * spu,u64 tclass_id)110540270d8SGeoff Levand static void mfc_tclass_id_set(struct spu *spu, u64 tclass_id)
111c01ea72aSGeoff Levand {
112c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->mfc_tclass_id_RW, tclass_id);
113c01ea72aSGeoff Levand }
114c01ea72aSGeoff Levand 
mfc_tclass_id_get(struct spu * spu)115540270d8SGeoff Levand static u64 mfc_tclass_id_get(struct spu *spu)
116c01ea72aSGeoff Levand {
117c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->mfc_tclass_id_RW);
118c01ea72aSGeoff Levand }
119c01ea72aSGeoff Levand 
tlb_invalidate(struct spu * spu)120540270d8SGeoff Levand static void tlb_invalidate(struct spu *spu)
121c01ea72aSGeoff Levand {
122c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->tlb_invalidate_entry_W, 0ul);
123c01ea72aSGeoff Levand }
124c01ea72aSGeoff Levand 
resource_allocation_groupID_set(struct spu * spu,u64 id)125540270d8SGeoff Levand static void resource_allocation_groupID_set(struct spu *spu, u64 id)
126c01ea72aSGeoff Levand {
127c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->resource_allocation_groupID_RW, id);
128c01ea72aSGeoff Levand }
129c01ea72aSGeoff Levand 
resource_allocation_groupID_get(struct spu * spu)130540270d8SGeoff Levand static u64 resource_allocation_groupID_get(struct spu *spu)
131c01ea72aSGeoff Levand {
132c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->resource_allocation_groupID_RW);
133c01ea72aSGeoff Levand }
134c01ea72aSGeoff Levand 
resource_allocation_enable_set(struct spu * spu,u64 enable)135540270d8SGeoff Levand static void resource_allocation_enable_set(struct spu *spu, u64 enable)
136c01ea72aSGeoff Levand {
137c9868fe0SIshizaki Kou 	out_be64(&spu->priv1->resource_allocation_enable_RW, enable);
138c01ea72aSGeoff Levand }
139c01ea72aSGeoff Levand 
resource_allocation_enable_get(struct spu * spu)140540270d8SGeoff Levand static u64 resource_allocation_enable_get(struct spu *spu)
141c01ea72aSGeoff Levand {
142c9868fe0SIshizaki Kou 	return in_be64(&spu->priv1->resource_allocation_enable_RW);
143c01ea72aSGeoff Levand }
144540270d8SGeoff Levand 
145540270d8SGeoff Levand const struct spu_priv1_ops spu_priv1_mmio_ops =
146540270d8SGeoff Levand {
147540270d8SGeoff Levand 	.int_mask_and = int_mask_and,
148540270d8SGeoff Levand 	.int_mask_or = int_mask_or,
149540270d8SGeoff Levand 	.int_mask_set = int_mask_set,
150540270d8SGeoff Levand 	.int_mask_get = int_mask_get,
151540270d8SGeoff Levand 	.int_stat_clear = int_stat_clear,
152540270d8SGeoff Levand 	.int_stat_get = int_stat_get,
153a91942aeSGeoff Levand 	.cpu_affinity_set = cpu_affinity_set,
154540270d8SGeoff Levand 	.mfc_dar_get = mfc_dar_get,
155540270d8SGeoff Levand 	.mfc_dsisr_get = mfc_dsisr_get,
156540270d8SGeoff Levand 	.mfc_dsisr_set = mfc_dsisr_set,
15724f43b33SMasato Noguchi 	.mfc_sdr_setup = mfc_sdr_setup,
158540270d8SGeoff Levand 	.mfc_sr1_set = mfc_sr1_set,
159540270d8SGeoff Levand 	.mfc_sr1_get = mfc_sr1_get,
160540270d8SGeoff Levand 	.mfc_tclass_id_set = mfc_tclass_id_set,
161540270d8SGeoff Levand 	.mfc_tclass_id_get = mfc_tclass_id_get,
162540270d8SGeoff Levand 	.tlb_invalidate = tlb_invalidate,
163540270d8SGeoff Levand 	.resource_allocation_groupID_set = resource_allocation_groupID_set,
164540270d8SGeoff Levand 	.resource_allocation_groupID_get = resource_allocation_groupID_get,
165540270d8SGeoff Levand 	.resource_allocation_enable_set = resource_allocation_enable_set,
166540270d8SGeoff Levand 	.resource_allocation_enable_get = resource_allocation_enable_get,
167540270d8SGeoff Levand };
168