blob: 66d33724f16e2cd759c07088f4900e9690a40fe8 [file] [log] [blame]
Arnd Bergmannf0831ac2006-01-04 20:31:30 +01001/*
Geoff Levand540270d2006-06-19 20:33:29 +02002 * spu hypervisor abstraction for direct hardware access.
3 *
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
5 * Copyright 2006 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010019 */
Geoff Levand540270d2006-06-19 20:33:29 +020020
Geoff Levande28b0032006-11-23 00:46:49 +010021#include <linux/interrupt.h>
22#include <linux/list.h>
Geoff Levande28b0032006-11-23 00:46:49 +010023#include <linux/ptrace.h>
Geoff Levande28b0032006-11-23 00:46:49 +010024#include <linux/wait.h>
25#include <linux/mm.h>
26#include <linux/io.h>
27#include <linux/mutex.h>
28#include <linux/device.h>
Luke Browning7a214202008-04-28 14:32:34 +100029#include <linux/sched.h>
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010030
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010031#include <asm/spu.h>
Geoff Levand540270d2006-06-19 20:33:29 +020032#include <asm/spu_priv1.h>
Geoff Levande28b0032006-11-23 00:46:49 +010033#include <asm/firmware.h>
34#include <asm/prom.h>
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010035
Geoff Levanda91942a2006-06-19 20:33:30 +020036#include "interrupt.h"
Geoff Levande28b0032006-11-23 00:46:49 +010037#include "spu_priv1_mmio.h"
38
Geoff Levand540270d2006-06-19 20:33:29 +020039static void int_mask_and(struct spu *spu, int class, u64 mask)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010040{
41 u64 old_mask;
42
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090043 old_mask = in_be64(&spu->priv1->int_mask_RW[class]);
44 out_be64(&spu->priv1->int_mask_RW[class], old_mask & mask);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010045}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010046
Geoff Levand540270d2006-06-19 20:33:29 +020047static void int_mask_or(struct spu *spu, int class, u64 mask)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010048{
49 u64 old_mask;
50
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090051 old_mask = in_be64(&spu->priv1->int_mask_RW[class]);
52 out_be64(&spu->priv1->int_mask_RW[class], old_mask | mask);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010053}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010054
Geoff Levand540270d2006-06-19 20:33:29 +020055static void int_mask_set(struct spu *spu, int class, u64 mask)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010056{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090057 out_be64(&spu->priv1->int_mask_RW[class], mask);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010058}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010059
Geoff Levand540270d2006-06-19 20:33:29 +020060static u64 int_mask_get(struct spu *spu, int class)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010061{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090062 return in_be64(&spu->priv1->int_mask_RW[class]);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010063}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010064
Geoff Levand540270d2006-06-19 20:33:29 +020065static void int_stat_clear(struct spu *spu, int class, u64 stat)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010066{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090067 out_be64(&spu->priv1->int_stat_RW[class], stat);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010068}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010069
Geoff Levand540270d2006-06-19 20:33:29 +020070static u64 int_stat_get(struct spu *spu, int class)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010071{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090072 return in_be64(&spu->priv1->int_stat_RW[class]);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010073}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010074
Geoff Levanda91942a2006-06-19 20:33:30 +020075static void cpu_affinity_set(struct spu *spu, int cpu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010076{
Luke Browning7a214202008-04-28 14:32:34 +100077 u64 target;
78 u64 route;
79
80 if (nr_cpus_node(spu->node)) {
Rusty Russell86c6f272008-12-26 22:23:39 +103081 const struct cpumask *spumask = cpumask_of_node(spu->node),
82 *cpumask = cpumask_of_node(cpu_to_node(cpu));
Luke Browning7a214202008-04-28 14:32:34 +100083
Rusty Russell86c6f272008-12-26 22:23:39 +103084 if (!cpumask_intersects(spumask, cpumask))
Luke Browning7a214202008-04-28 14:32:34 +100085 return;
86 }
87
88 target = iic_get_target_id(cpu);
89 route = target << 48 | target << 32 | target << 16;
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090090 out_be64(&spu->priv1->int_route_RW, route);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010091}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010092
Geoff Levand540270d2006-06-19 20:33:29 +020093static u64 mfc_dar_get(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010094{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +090095 return in_be64(&spu->priv1->mfc_dar_RW);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010096}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010097
Geoff Levand540270d2006-06-19 20:33:29 +020098static u64 mfc_dsisr_get(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +010099{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900100 return in_be64(&spu->priv1->mfc_dsisr_RW);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100101}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100102
Geoff Levand540270d2006-06-19 20:33:29 +0200103static void mfc_dsisr_set(struct spu *spu, u64 dsisr)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100104{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900105 out_be64(&spu->priv1->mfc_dsisr_RW, dsisr);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100106}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100107
Masato Noguchi24f43b32006-10-24 18:31:14 +0200108static void mfc_sdr_setup(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100109{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900110 out_be64(&spu->priv1->mfc_sdr_RW, mfspr(SPRN_SDR1));
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100111}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100112
Geoff Levand540270d2006-06-19 20:33:29 +0200113static void mfc_sr1_set(struct spu *spu, u64 sr1)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100114{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900115 out_be64(&spu->priv1->mfc_sr1_RW, sr1);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100116}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100117
Geoff Levand540270d2006-06-19 20:33:29 +0200118static u64 mfc_sr1_get(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100119{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900120 return in_be64(&spu->priv1->mfc_sr1_RW);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100121}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100122
Geoff Levand540270d2006-06-19 20:33:29 +0200123static void mfc_tclass_id_set(struct spu *spu, u64 tclass_id)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100124{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900125 out_be64(&spu->priv1->mfc_tclass_id_RW, tclass_id);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100126}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100127
Geoff Levand540270d2006-06-19 20:33:29 +0200128static u64 mfc_tclass_id_get(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100129{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900130 return in_be64(&spu->priv1->mfc_tclass_id_RW);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100131}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100132
Geoff Levand540270d2006-06-19 20:33:29 +0200133static void tlb_invalidate(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100134{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900135 out_be64(&spu->priv1->tlb_invalidate_entry_W, 0ul);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100136}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100137
Geoff Levand540270d2006-06-19 20:33:29 +0200138static void resource_allocation_groupID_set(struct spu *spu, u64 id)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100139{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900140 out_be64(&spu->priv1->resource_allocation_groupID_RW, id);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100141}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100142
Geoff Levand540270d2006-06-19 20:33:29 +0200143static u64 resource_allocation_groupID_get(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100144{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900145 return in_be64(&spu->priv1->resource_allocation_groupID_RW);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100146}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100147
Geoff Levand540270d2006-06-19 20:33:29 +0200148static void resource_allocation_enable_set(struct spu *spu, u64 enable)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100149{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900150 out_be64(&spu->priv1->resource_allocation_enable_RW, enable);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100151}
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100152
Geoff Levand540270d2006-06-19 20:33:29 +0200153static u64 resource_allocation_enable_get(struct spu *spu)
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100154{
Ishizaki Kouc9868fe2007-02-02 16:45:33 +0900155 return in_be64(&spu->priv1->resource_allocation_enable_RW);
Arnd Bergmannf0831ac2006-01-04 20:31:30 +0100156}
Geoff Levand540270d2006-06-19 20:33:29 +0200157
158const struct spu_priv1_ops spu_priv1_mmio_ops =
159{
160 .int_mask_and = int_mask_and,
161 .int_mask_or = int_mask_or,
162 .int_mask_set = int_mask_set,
163 .int_mask_get = int_mask_get,
164 .int_stat_clear = int_stat_clear,
165 .int_stat_get = int_stat_get,
Geoff Levanda91942a2006-06-19 20:33:30 +0200166 .cpu_affinity_set = cpu_affinity_set,
Geoff Levand540270d2006-06-19 20:33:29 +0200167 .mfc_dar_get = mfc_dar_get,
168 .mfc_dsisr_get = mfc_dsisr_get,
169 .mfc_dsisr_set = mfc_dsisr_set,
Masato Noguchi24f43b32006-10-24 18:31:14 +0200170 .mfc_sdr_setup = mfc_sdr_setup,
Geoff Levand540270d2006-06-19 20:33:29 +0200171 .mfc_sr1_set = mfc_sr1_set,
172 .mfc_sr1_get = mfc_sr1_get,
173 .mfc_tclass_id_set = mfc_tclass_id_set,
174 .mfc_tclass_id_get = mfc_tclass_id_get,
175 .tlb_invalidate = tlb_invalidate,
176 .resource_allocation_groupID_set = resource_allocation_groupID_set,
177 .resource_allocation_groupID_get = resource_allocation_groupID_get,
178 .resource_allocation_enable_set = resource_allocation_enable_set,
179 .resource_allocation_enable_get = resource_allocation_enable_get,
180};