Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 *              GRU KERNEL MCS INSTRUCTIONS
  3 *
  4 *  Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
  5 *
  6 *  This program is free software; you can redistribute it and/or modify
  7 *  it under the terms of the GNU General Public License as published by
  8 *  the Free Software Foundation; either version 2 of the License, or
  9 *  (at your option) any later version.
 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
 19 */
 20
 21#include <linux/kernel.h>
 22#include "gru.h"
 23#include "grulib.h"
 24#include "grutables.h"
 25
 26/* 10 sec */
 27#ifdef CONFIG_IA64
 28#include <asm/processor.h>
 29#define GRU_OPERATION_TIMEOUT	(((cycles_t) local_cpu_data->itc_freq)*10)
 30#define CLKS2NSEC(c)		((c) *1000000000 / local_cpu_data->itc_freq)
 31#else
 32#include <asm/tsc.h>
 33#define GRU_OPERATION_TIMEOUT	((cycles_t) tsc_khz*10*1000)
 34#define CLKS2NSEC(c)		((c) * 1000000 / tsc_khz)
 35#endif
 36
 37/* Extract the status field from a kernel handle */
 38#define GET_MSEG_HANDLE_STATUS(h)	(((*(unsigned long *)(h)) >> 16) & 3)
 39
 40struct mcs_op_statistic mcs_op_statistics[mcsop_last];
 41
 42static void update_mcs_stats(enum mcs_op op, unsigned long clks)
 43{
 44	unsigned long nsec;
 45
 46	nsec = CLKS2NSEC(clks);
 47	atomic_long_inc(&mcs_op_statistics[op].count);
 48	atomic_long_add(nsec, &mcs_op_statistics[op].total);
 49	if (mcs_op_statistics[op].max < nsec)
 50		mcs_op_statistics[op].max = nsec;
 51}
 52
 53static void start_instruction(void *h)
 54{
 55	unsigned long *w0 = h;
 56
 57	wmb();		/* setting CMD/STATUS bits must be last */
 58	*w0 = *w0 | 0x20001;
 59	gru_flush_cache(h);
 60}
 61
 62static void report_instruction_timeout(void *h)
 63{
 64	unsigned long goff = GSEGPOFF((unsigned long)h);
 65	char *id = "???";
 66
 67	if (TYPE_IS(CCH, goff))
 68		id = "CCH";
 69	else if (TYPE_IS(TGH, goff))
 70		id = "TGH";
 71	else if (TYPE_IS(TFH, goff))
 72		id = "TFH";
 73
 74	panic(KERN_ALERT "GRU %p (%s) is malfunctioning\n", h, id);
 75}
 76
 77static int wait_instruction_complete(void *h, enum mcs_op opc)
 78{
 79	int status;
 80	unsigned long start_time = get_cycles();
 81
 82	while (1) {
 83		cpu_relax();
 84		status = GET_MSEG_HANDLE_STATUS(h);
 85		if (status != CCHSTATUS_ACTIVE)
 86			break;
 87		if (GRU_OPERATION_TIMEOUT < (get_cycles() - start_time)) {
 88			report_instruction_timeout(h);
 89			start_time = get_cycles();
 90		}
 91	}
 92	if (gru_options & OPT_STATS)
 93		update_mcs_stats(opc, get_cycles() - start_time);
 94	return status;
 95}
 96
 97int cch_allocate(struct gru_context_configuration_handle *cch)
 98{
 99	int ret;
100
101	cch->opc = CCHOP_ALLOCATE;
102	start_instruction(cch);
103	ret = wait_instruction_complete(cch, cchop_allocate);
104
105	/*
106	 * Stop speculation into the GSEG being mapped by the previous ALLOCATE.
107	 * The GSEG memory does not exist until the ALLOCATE completes.
108	 */
109	sync_core();
110	return ret;
111}
112
113int cch_start(struct gru_context_configuration_handle *cch)
114{
115	cch->opc = CCHOP_START;
116	start_instruction(cch);
117	return wait_instruction_complete(cch, cchop_start);
118}
119
120int cch_interrupt(struct gru_context_configuration_handle *cch)
121{
122	cch->opc = CCHOP_INTERRUPT;
123	start_instruction(cch);
124	return wait_instruction_complete(cch, cchop_interrupt);
125}
126
127int cch_deallocate(struct gru_context_configuration_handle *cch)
128{
129	int ret;
130
131	cch->opc = CCHOP_DEALLOCATE;
132	start_instruction(cch);
133	ret = wait_instruction_complete(cch, cchop_deallocate);
134
135	/*
136	 * Stop speculation into the GSEG being unmapped by the previous
137	 * DEALLOCATE.
138	 */
139	sync_core();
140	return ret;
141}
142
143int cch_interrupt_sync(struct gru_context_configuration_handle
144				     *cch)
145{
146	cch->opc = CCHOP_INTERRUPT_SYNC;
147	start_instruction(cch);
148	return wait_instruction_complete(cch, cchop_interrupt_sync);
149}
150
151int tgh_invalidate(struct gru_tlb_global_handle *tgh,
152				 unsigned long vaddr, unsigned long vaddrmask,
153				 int asid, int pagesize, int global, int n,
154				 unsigned short ctxbitmap)
155{
156	tgh->vaddr = vaddr;
157	tgh->asid = asid;
158	tgh->pagesize = pagesize;
159	tgh->n = n;
160	tgh->global = global;
161	tgh->vaddrmask = vaddrmask;
162	tgh->ctxbitmap = ctxbitmap;
163	tgh->opc = TGHOP_TLBINV;
164	start_instruction(tgh);
165	return wait_instruction_complete(tgh, tghop_invalidate);
166}
167
168int tfh_write_only(struct gru_tlb_fault_handle *tfh,
169				  unsigned long paddr, int gaa,
170				  unsigned long vaddr, int asid, int dirty,
171				  int pagesize)
172{
173	tfh->fillasid = asid;
174	tfh->fillvaddr = vaddr;
175	tfh->pfn = paddr >> GRU_PADDR_SHIFT;
176	tfh->gaa = gaa;
177	tfh->dirty = dirty;
178	tfh->pagesize = pagesize;
179	tfh->opc = TFHOP_WRITE_ONLY;
180	start_instruction(tfh);
181	return wait_instruction_complete(tfh, tfhop_write_only);
182}
183
184void tfh_write_restart(struct gru_tlb_fault_handle *tfh,
185				     unsigned long paddr, int gaa,
186				     unsigned long vaddr, int asid, int dirty,
187				     int pagesize)
188{
189	tfh->fillasid = asid;
190	tfh->fillvaddr = vaddr;
191	tfh->pfn = paddr >> GRU_PADDR_SHIFT;
192	tfh->gaa = gaa;
193	tfh->dirty = dirty;
194	tfh->pagesize = pagesize;
195	tfh->opc = TFHOP_WRITE_RESTART;
196	start_instruction(tfh);
197}
198
199void tfh_restart(struct gru_tlb_fault_handle *tfh)
200{
201	tfh->opc = TFHOP_RESTART;
202	start_instruction(tfh);
203}
204
205void tfh_user_polling_mode(struct gru_tlb_fault_handle *tfh)
206{
207	tfh->opc = TFHOP_USER_POLLING_MODE;
208	start_instruction(tfh);
209}
210
211void tfh_exception(struct gru_tlb_fault_handle *tfh)
212{
213	tfh->opc = TFHOP_EXCEPTION;
214	start_instruction(tfh);
215}
216
v6.9.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *              GRU KERNEL MCS INSTRUCTIONS
  4 *
  5 *  Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include <linux/kernel.h>
  9#include "gru.h"
 10#include "grulib.h"
 11#include "grutables.h"
 12
 13/* 10 sec */
 14#include <linux/sync_core.h>
 
 
 
 
 15#include <asm/tsc.h>
 16#define GRU_OPERATION_TIMEOUT	((cycles_t) tsc_khz*10*1000)
 17#define CLKS2NSEC(c)		((c) * 1000000 / tsc_khz)
 
 18
 19/* Extract the status field from a kernel handle */
 20#define GET_MSEG_HANDLE_STATUS(h)	(((*(unsigned long *)(h)) >> 16) & 3)
 21
 22struct mcs_op_statistic mcs_op_statistics[mcsop_last];
 23
 24static void update_mcs_stats(enum mcs_op op, unsigned long clks)
 25{
 26	unsigned long nsec;
 27
 28	nsec = CLKS2NSEC(clks);
 29	atomic_long_inc(&mcs_op_statistics[op].count);
 30	atomic_long_add(nsec, &mcs_op_statistics[op].total);
 31	if (mcs_op_statistics[op].max < nsec)
 32		mcs_op_statistics[op].max = nsec;
 33}
 34
 35static void start_instruction(void *h)
 36{
 37	unsigned long *w0 = h;
 38
 39	wmb();		/* setting CMD/STATUS bits must be last */
 40	*w0 = *w0 | 0x20001;
 41	gru_flush_cache(h);
 42}
 43
 44static void report_instruction_timeout(void *h)
 45{
 46	unsigned long goff = GSEGPOFF((unsigned long)h);
 47	char *id = "???";
 48
 49	if (TYPE_IS(CCH, goff))
 50		id = "CCH";
 51	else if (TYPE_IS(TGH, goff))
 52		id = "TGH";
 53	else if (TYPE_IS(TFH, goff))
 54		id = "TFH";
 55
 56	panic(KERN_ALERT "GRU %p (%s) is malfunctioning\n", h, id);
 57}
 58
 59static int wait_instruction_complete(void *h, enum mcs_op opc)
 60{
 61	int status;
 62	unsigned long start_time = get_cycles();
 63
 64	while (1) {
 65		cpu_relax();
 66		status = GET_MSEG_HANDLE_STATUS(h);
 67		if (status != CCHSTATUS_ACTIVE)
 68			break;
 69		if (GRU_OPERATION_TIMEOUT < (get_cycles() - start_time)) {
 70			report_instruction_timeout(h);
 71			start_time = get_cycles();
 72		}
 73	}
 74	if (gru_options & OPT_STATS)
 75		update_mcs_stats(opc, get_cycles() - start_time);
 76	return status;
 77}
 78
 79int cch_allocate(struct gru_context_configuration_handle *cch)
 80{
 81	int ret;
 82
 83	cch->opc = CCHOP_ALLOCATE;
 84	start_instruction(cch);
 85	ret = wait_instruction_complete(cch, cchop_allocate);
 86
 87	/*
 88	 * Stop speculation into the GSEG being mapped by the previous ALLOCATE.
 89	 * The GSEG memory does not exist until the ALLOCATE completes.
 90	 */
 91	sync_core();
 92	return ret;
 93}
 94
 95int cch_start(struct gru_context_configuration_handle *cch)
 96{
 97	cch->opc = CCHOP_START;
 98	start_instruction(cch);
 99	return wait_instruction_complete(cch, cchop_start);
100}
101
102int cch_interrupt(struct gru_context_configuration_handle *cch)
103{
104	cch->opc = CCHOP_INTERRUPT;
105	start_instruction(cch);
106	return wait_instruction_complete(cch, cchop_interrupt);
107}
108
109int cch_deallocate(struct gru_context_configuration_handle *cch)
110{
111	int ret;
112
113	cch->opc = CCHOP_DEALLOCATE;
114	start_instruction(cch);
115	ret = wait_instruction_complete(cch, cchop_deallocate);
116
117	/*
118	 * Stop speculation into the GSEG being unmapped by the previous
119	 * DEALLOCATE.
120	 */
121	sync_core();
122	return ret;
123}
124
125int cch_interrupt_sync(struct gru_context_configuration_handle
126				     *cch)
127{
128	cch->opc = CCHOP_INTERRUPT_SYNC;
129	start_instruction(cch);
130	return wait_instruction_complete(cch, cchop_interrupt_sync);
131}
132
133int tgh_invalidate(struct gru_tlb_global_handle *tgh,
134				 unsigned long vaddr, unsigned long vaddrmask,
135				 int asid, int pagesize, int global, int n,
136				 unsigned short ctxbitmap)
137{
138	tgh->vaddr = vaddr;
139	tgh->asid = asid;
140	tgh->pagesize = pagesize;
141	tgh->n = n;
142	tgh->global = global;
143	tgh->vaddrmask = vaddrmask;
144	tgh->ctxbitmap = ctxbitmap;
145	tgh->opc = TGHOP_TLBINV;
146	start_instruction(tgh);
147	return wait_instruction_complete(tgh, tghop_invalidate);
148}
149
150int tfh_write_only(struct gru_tlb_fault_handle *tfh,
151				  unsigned long paddr, int gaa,
152				  unsigned long vaddr, int asid, int dirty,
153				  int pagesize)
154{
155	tfh->fillasid = asid;
156	tfh->fillvaddr = vaddr;
157	tfh->pfn = paddr >> GRU_PADDR_SHIFT;
158	tfh->gaa = gaa;
159	tfh->dirty = dirty;
160	tfh->pagesize = pagesize;
161	tfh->opc = TFHOP_WRITE_ONLY;
162	start_instruction(tfh);
163	return wait_instruction_complete(tfh, tfhop_write_only);
164}
165
166void tfh_write_restart(struct gru_tlb_fault_handle *tfh,
167				     unsigned long paddr, int gaa,
168				     unsigned long vaddr, int asid, int dirty,
169				     int pagesize)
170{
171	tfh->fillasid = asid;
172	tfh->fillvaddr = vaddr;
173	tfh->pfn = paddr >> GRU_PADDR_SHIFT;
174	tfh->gaa = gaa;
175	tfh->dirty = dirty;
176	tfh->pagesize = pagesize;
177	tfh->opc = TFHOP_WRITE_RESTART;
 
 
 
 
 
 
178	start_instruction(tfh);
179}
180
181void tfh_user_polling_mode(struct gru_tlb_fault_handle *tfh)
182{
183	tfh->opc = TFHOP_USER_POLLING_MODE;
184	start_instruction(tfh);
185}
186
187void tfh_exception(struct gru_tlb_fault_handle *tfh)
188{
189	tfh->opc = TFHOP_EXCEPTION;
190	start_instruction(tfh);
191}
192