Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[deliverable/linux.git] / drivers / misc / sgi-gru / grutables.h
CommitLineData
13d19498
JS
1/*
2 * SN Platform GRU Driver
3 *
4 * GRU DRIVER TABLES, MACROS, externs, etc
5 *
6 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __GRUTABLES_H__
24#define __GRUTABLES_H__
25
26/*
9ca8e40c
JS
27 * GRU Chiplet:
28 * The GRU is a user addressible memory accelerator. It provides
29 * several forms of load, store, memset, bcopy instructions. In addition, it
30 * contains special instructions for AMOs, sending messages to message
31 * queues, etc.
32 *
33 * The GRU is an integral part of the node controller. It connects
34 * directly to the cpu socket. In its current implementation, there are 2
35 * GRU chiplets in the node controller on each blade (~node).
36 *
37 * The entire GRU memory space is fully coherent and cacheable by the cpus.
38 *
39 * Each GRU chiplet has a physical memory map that looks like the following:
40 *
41 * +-----------------+
42 * |/////////////////|
43 * |/////////////////|
44 * |/////////////////|
45 * |/////////////////|
46 * |/////////////////|
47 * |/////////////////|
48 * |/////////////////|
49 * |/////////////////|
50 * +-----------------+
51 * | system control |
52 * +-----------------+ _______ +-------------+
53 * |/////////////////| / | |
54 * |/////////////////| / | |
55 * |/////////////////| / | instructions|
56 * |/////////////////| / | |
57 * |/////////////////| / | |
58 * |/////////////////| / |-------------|
59 * |/////////////////| / | |
60 * +-----------------+ | |
61 * | context 15 | | data |
62 * +-----------------+ | |
63 * | ...... | \ | |
64 * +-----------------+ \____________ +-------------+
65 * | context 1 |
66 * +-----------------+
67 * | context 0 |
68 * +-----------------+
69 *
70 * Each of the "contexts" is a chunk of memory that can be mmaped into user
71 * space. The context consists of 2 parts:
72 *
73 * - an instruction space that can be directly accessed by the user
74 * to issue GRU instructions and to check instruction status.
75 *
76 * - a data area that acts as normal RAM.
77 *
78 * User instructions contain virtual addresses of data to be accessed by the
79 * GRU. The GRU contains a TLB that is used to convert these user virtual
80 * addresses to physical addresses.
81 *
82 * The "system control" area of the GRU chiplet is used by the kernel driver
83 * to manage user contexts and to perform functions such as TLB dropin and
84 * purging.
85 *
86 * One context may be reserved for the kernel and used for cross-partition
87 * communication. The GRU will also be used to asynchronously zero out
88 * large blocks of memory (not currently implemented).
89 *
90 *
13d19498
JS
91 * Tables:
92 *
93 * VDATA-VMA Data - Holds a few parameters. Head of linked list of
94 * GTS tables for threads using the GSEG
95 * GTS - Gru Thread State - contains info for managing a GSEG context. A
96 * GTS is allocated for each thread accessing a
97 * GSEG.
98 * GTD - GRU Thread Data - contains shadow copy of GRU data when GSEG is
99 * not loaded into a GRU
100 * GMS - GRU Memory Struct - Used to manage TLB shootdowns. Tracks GRUs
101 * where a GSEG has been loaded. Similar to
102 * an mm_struct but for GRU.
103 *
104 * GS - GRU State - Used to manage the state of a GRU chiplet
105 * BS - Blade State - Used to manage state of all GRU chiplets
106 * on a blade
107 *
108 *
109 * Normal task tables for task using GRU.
110 * - 2 threads in process
111 * - 2 GSEGs open in process
112 * - GSEG1 is being used by both threads
113 * - GSEG2 is used only by thread 2
114 *
115 * task -->|
116 * task ---+---> mm ->------ (notifier) -------+-> gms
117 * | |
118 * |--> vma -> vdata ---> gts--->| GSEG1 (thread1)
119 * | | |
120 * | +-> gts--->| GSEG1 (thread2)
121 * | |
122 * |--> vma -> vdata ---> gts--->| GSEG2 (thread2)
123 * .
124 * .
125 *
126 * GSEGs are marked DONTCOPY on fork
127 *
128 * At open
129 * file.private_data -> NULL
130 *
131 * At mmap,
132 * vma -> vdata
133 *
134 * After gseg reference
135 * vma -> vdata ->gts
136 *
137 * After fork
138 * parent
139 * vma -> vdata -> gts
140 * child
141 * (vma is not copied)
142 *
143 */
144
145#include <linux/rmap.h>
146#include <linux/interrupt.h>
147#include <linux/mutex.h>
148#include <linux/wait.h>
149#include <linux/mmu_notifier.h>
150#include "gru.h"
7e796a72 151#include "grulib.h"
13d19498
JS
152#include "gruhandles.h"
153
154extern struct gru_stats_s gru_stats;
155extern struct gru_blade_state *gru_base[];
156extern unsigned long gru_start_paddr, gru_end_paddr;
1a2c09e3 157extern void *gru_start_vaddr;
e1c3219d 158extern unsigned int gru_max_gids;
13d19498
JS
159
160#define GRU_MAX_BLADES MAX_NUMNODES
161#define GRU_MAX_GRUS (GRU_MAX_BLADES * GRU_CHIPLETS_PER_BLADE)
162
163#define GRU_DRIVER_ID_STR "SGI GRU Device Driver"
e5ae6e82 164#define GRU_DRIVER_VERSION_STR "0.85"
13d19498
JS
165
166/*
167 * GRU statistics.
168 */
169struct gru_stats_s {
170 atomic_long_t vdata_alloc;
171 atomic_long_t vdata_free;
172 atomic_long_t gts_alloc;
173 atomic_long_t gts_free;
563447d7
JS
174 atomic_long_t gms_alloc;
175 atomic_long_t gms_free;
13d19498
JS
176 atomic_long_t gts_double_allocate;
177 atomic_long_t assign_context;
178 atomic_long_t assign_context_failed;
179 atomic_long_t free_context;
836ce679
JS
180 atomic_long_t load_user_context;
181 atomic_long_t load_kernel_context;
182 atomic_long_t lock_kernel_context;
183 atomic_long_t unlock_kernel_context;
184 atomic_long_t steal_user_context;
185 atomic_long_t steal_kernel_context;
13d19498
JS
186 atomic_long_t steal_context_failed;
187 atomic_long_t nopfn;
13d19498
JS
188 atomic_long_t asid_new;
189 atomic_long_t asid_next;
190 atomic_long_t asid_wrap;
191 atomic_long_t asid_reuse;
192 atomic_long_t intr;
563447d7
JS
193 atomic_long_t intr_cbr;
194 atomic_long_t intr_tfh;
2ce4d4c9 195 atomic_long_t intr_spurious;
43884604 196 atomic_long_t intr_mm_lock_failed;
13d19498 197 atomic_long_t call_os;
13d19498
JS
198 atomic_long_t call_os_wait_queue;
199 atomic_long_t user_flush_tlb;
200 atomic_long_t user_unload_context;
201 atomic_long_t user_exception;
92b39388 202 atomic_long_t set_context_option;
55484c45
JS
203 atomic_long_t check_context_retarget_intr;
204 atomic_long_t check_context_unload;
13d19498 205 atomic_long_t tlb_dropin;
c550222f 206 atomic_long_t tlb_preload_page;
13d19498
JS
207 atomic_long_t tlb_dropin_fail_no_asid;
208 atomic_long_t tlb_dropin_fail_upm;
209 atomic_long_t tlb_dropin_fail_invalid;
210 atomic_long_t tlb_dropin_fail_range_active;
211 atomic_long_t tlb_dropin_fail_idle;
212 atomic_long_t tlb_dropin_fail_fmm;
cd1334f0 213 atomic_long_t tlb_dropin_fail_no_exception;
270952a9 214 atomic_long_t tfh_stale_on_fault;
13d19498
JS
215 atomic_long_t mmu_invalidate_range;
216 atomic_long_t mmu_invalidate_page;
13d19498
JS
217 atomic_long_t flush_tlb;
218 atomic_long_t flush_tlb_gru;
219 atomic_long_t flush_tlb_gru_tgh;
220 atomic_long_t flush_tlb_gru_zero_asid;
221
222 atomic_long_t copy_gpa;
289750d1 223 atomic_long_t read_gpa;
13d19498
JS
224
225 atomic_long_t mesq_receive;
226 atomic_long_t mesq_receive_none;
227 atomic_long_t mesq_send;
228 atomic_long_t mesq_send_failed;
229 atomic_long_t mesq_noop;
230 atomic_long_t mesq_send_unexpected_error;
231 atomic_long_t mesq_send_lb_overflow;
232 atomic_long_t mesq_send_qlimit_reached;
233 atomic_long_t mesq_send_amo_nacked;
234 atomic_long_t mesq_send_put_nacked;
563447d7 235 atomic_long_t mesq_page_overflow;
13d19498
JS
236 atomic_long_t mesq_qf_locked;
237 atomic_long_t mesq_qf_noop_not_full;
238 atomic_long_t mesq_qf_switch_head_failed;
239 atomic_long_t mesq_qf_unexpected_error;
240 atomic_long_t mesq_noop_unexpected_error;
241 atomic_long_t mesq_noop_lb_overflow;
242 atomic_long_t mesq_noop_qlimit_reached;
243 atomic_long_t mesq_noop_amo_nacked;
244 atomic_long_t mesq_noop_put_nacked;
563447d7 245 atomic_long_t mesq_noop_page_overflow;
13d19498
JS
246
247};
248
a24e5e1c 249enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
c550222f
JS
250 cchop_deallocate, tfhop_write_only, tfhop_write_restart,
251 tghop_invalidate, mcsop_last};
a24e5e1c 252
e56484da
JS
253struct mcs_op_statistic {
254 atomic_long_t count;
255 atomic_long_t total;
256 unsigned long max;
257};
258
259extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
260
563447d7
JS
261#define OPT_DPRINT 1
262#define OPT_STATS 2
13d19498
JS
263
264
265#define IRQ_GRU 110 /* Starting IRQ number for interrupts */
266
267/* Delay in jiffies between attempts to assign a GRU context */
268#define GRU_ASSIGN_DELAY ((HZ * 20) / 1000)
269
270/*
271 * If a process has it's context stolen, min delay in jiffies before trying to
272 * steal a context from another process.
273 */
274#define GRU_STEAL_DELAY ((HZ * 200) / 1000)
275
276#define STAT(id) do { \
9ca8e40c 277 if (gru_options & OPT_STATS) \
13d19498
JS
278 atomic_long_inc(&gru_stats.id); \
279 } while (0)
280
281#ifdef CONFIG_SGI_GRU_DEBUG
282#define gru_dbg(dev, fmt, x...) \
283 do { \
9ca8e40c 284 if (gru_options & OPT_DPRINT) \
563447d7 285 printk(KERN_DEBUG "GRU:%d %s: " fmt, smp_processor_id(), __func__, x);\
13d19498
JS
286 } while (0)
287#else
288#define gru_dbg(x...)
289#endif
290
291/*-----------------------------------------------------------------------------
292 * ASID management
293 */
294#define MAX_ASID 0xfffff0
295#define MIN_ASID 8
296#define ASID_INC 8 /* number of regions */
297
298/* Generate a GRU asid value from a GRU base asid & a virtual address. */
13d19498 299#define VADDR_HI_BIT 64
fe5bb6b0 300#define GRUREGION(addr) ((addr) >> (VADDR_HI_BIT - 3) & 3)
13d19498
JS
301#define GRUASID(asid, addr) ((asid) + GRUREGION(addr))
302
303/*------------------------------------------------------------------------------
304 * File & VMS Tables
305 */
306
307struct gru_state;
308
309/*
310 * This structure is pointed to from the mmstruct via the notifier pointer.
311 * There is one of these per address space.
312 */
fe5bb6b0
JS
313struct gru_mm_tracker { /* pack to reduce size */
314 unsigned int mt_asid_gen:24; /* ASID wrap count */
315 unsigned int mt_asid:24; /* current base ASID for gru */
316 unsigned short mt_ctxbitmap:16;/* bitmap of contexts using
13d19498 317 asid */
fe5bb6b0 318} __attribute__ ((packed));
13d19498
JS
319
320struct gru_mm_struct {
321 struct mmu_notifier ms_notifier;
322 atomic_t ms_refcnt;
323 spinlock_t ms_asid_lock; /* protects ASID assignment */
324 atomic_t ms_range_active;/* num range_invals active */
325 char ms_released;
326 wait_queue_head_t ms_wait_queue;
327 DECLARE_BITMAP(ms_asidmap, GRU_MAX_GRUS);
328 struct gru_mm_tracker ms_asids[GRU_MAX_GRUS];
329};
330
331/*
332 * One of these structures is allocated when a GSEG is mmaped. The
333 * structure is pointed to by the vma->vm_private_data field in the vma struct.
334 */
335struct gru_vma_data {
336 spinlock_t vd_lock; /* Serialize access to vma */
337 struct list_head vd_head; /* head of linked list of gts */
338 long vd_user_options;/* misc user option flags */
339 int vd_cbr_au_count;
340 int vd_dsr_au_count;
c550222f 341 unsigned char vd_tlb_preload_count;
13d19498
JS
342};
343
344/*
345 * One of these is allocated for each thread accessing a mmaped GRU. A linked
346 * list of these structure is hung off the struct gru_vma_data in the mm_struct.
347 */
348struct gru_thread_state {
349 struct list_head ts_next; /* list - head at vma-private */
350 struct mutex ts_ctxlock; /* load/unload CTX lock */
351 struct mm_struct *ts_mm; /* mm currently mapped to
352 context */
353 struct vm_area_struct *ts_vma; /* vma of GRU context */
354 struct gru_state *ts_gru; /* GRU where the context is
355 loaded */
356 struct gru_mm_struct *ts_gms; /* asid & ioproc struct */
c550222f 357 unsigned char ts_tlb_preload_count; /* TLB preload pages */
13d19498
JS
358 unsigned long ts_cbr_map; /* map of allocated CBRs */
359 unsigned long ts_dsr_map; /* map of allocated DATA
360 resources */
361 unsigned long ts_steal_jiffies;/* jiffies when context last
362 stolen */
363 long ts_user_options;/* misc user option flags */
364 pid_t ts_tgid_owner; /* task that is using the
365 context - for migration */
518e5cd4
JS
366 short ts_user_blade_id;/* user selected blade */
367 char ts_user_chiplet_id;/* user selected chiplet */
7b8274e9 368 unsigned short ts_sizeavail; /* Pagesizes in use */
13d19498
JS
369 int ts_tsid; /* thread that owns the
370 structure */
371 int ts_tlb_int_select;/* target cpu if interrupts
372 enabled */
373 int ts_ctxnum; /* context number where the
374 context is loaded */
375 atomic_t ts_refcnt; /* reference count GTS */
376 unsigned char ts_dsr_au_count;/* Number of DSR resources
377 required for contest */
378 unsigned char ts_cbr_au_count;/* Number of CBR resources
379 required for contest */
b1b19fcf 380 char ts_cch_req_slice;/* CCH packet slice */
fe5bb6b0
JS
381 char ts_blade; /* If >= 0, migrate context if
382 ref from diferent blade */
7b8274e9 383 char ts_force_cch_reload;
13d19498
JS
384 char ts_cbr_idx[GRU_CBR_AU];/* CBR numbers of each
385 allocated CB */
940229b9
JS
386 int ts_data_valid; /* Indicates if ts_gdata has
387 valid data */
5958ab88 388 struct gru_gseg_statistics ustats; /* User statistics */
13d19498
JS
389 unsigned long ts_gdata[0]; /* save area for GRU data (CB,
390 DS, CBE) */
391};
392
393/*
394 * Threaded programs actually allocate an array of GSEGs when a context is
395 * created. Each thread uses a separate GSEG. TSID is the index into the GSEG
396 * array.
397 */
398#define TSID(a, v) (((a) - (v)->vm_start) / GRU_GSEG_PAGESIZE)
399#define UGRUADDR(gts) ((gts)->ts_vma->vm_start + \
400 (gts)->ts_tsid * GRU_GSEG_PAGESIZE)
401
402#define NULLCTX (-1) /* if context not loaded into GRU */
403
404/*-----------------------------------------------------------------------------
405 * GRU State Tables
406 */
407
408/*
409 * One of these exists for each GRU chiplet.
410 */
411struct gru_state {
412 struct gru_blade_state *gs_blade; /* GRU state for entire
413 blade */
414 unsigned long gs_gru_base_paddr; /* Physical address of
415 gru segments (64) */
416 void *gs_gru_base_vaddr; /* Virtual address of
417 gru segments (64) */
e1c3219d
JS
418 unsigned short gs_gid; /* unique GRU number */
419 unsigned short gs_blade_id; /* blade of GRU */
55484c45 420 unsigned char gs_chiplet_id; /* blade chiplet of GRU */
13d19498
JS
421 unsigned char gs_tgh_local_shift; /* used to pick TGH for
422 local flush */
423 unsigned char gs_tgh_first_remote; /* starting TGH# for
424 remote flush */
13d19498
JS
425 spinlock_t gs_asid_lock; /* lock used for
426 assigning asids */
427 spinlock_t gs_lock; /* lock used for
428 assigning contexts */
429
430 /* -- the following are protected by the gs_asid_lock spinlock ---- */
431 unsigned int gs_asid; /* Next availe ASID */
432 unsigned int gs_asid_limit; /* Limit of available
433 ASIDs */
434 unsigned int gs_asid_gen; /* asid generation.
435 Inc on wrap */
436
437 /* --- the following fields are protected by the gs_lock spinlock --- */
438 unsigned long gs_context_map; /* bitmap to manage
439 contexts in use */
440 unsigned long gs_cbr_map; /* bitmap to manage CB
441 resources */
442 unsigned long gs_dsr_map; /* bitmap used to manage
443 DATA resources */
444 unsigned int gs_reserved_cbrs; /* Number of kernel-
445 reserved cbrs */
446 unsigned int gs_reserved_dsr_bytes; /* Bytes of kernel-
447 reserved dsrs */
448 unsigned short gs_active_contexts; /* number of contexts
449 in use */
450 struct gru_thread_state *gs_gts[GRU_NUM_CCH]; /* GTS currently using
451 the context */
4107e1d3 452 int gs_irq[GRU_NUM_TFM]; /* Interrupt irqs */
13d19498
JS
453};
454
455/*
456 * This structure contains the GRU state for all the GRUs on a blade.
457 */
458struct gru_blade_state {
459 void *kernel_cb; /* First kernel
460 reserved cb */
461 void *kernel_dsr; /* First kernel
462 reserved DSR */
836ce679
JS
463 struct rw_semaphore bs_kgts_sema; /* lock for kgts */
464 struct gru_thread_state *bs_kgts; /* GTS for kernel use */
465
4a7a17c1
JS
466 /* ---- the following are used for managing kernel async GRU CBRs --- */
467 int bs_async_dsr_bytes; /* DSRs for async */
468 int bs_async_cbrs; /* CBRs AU for async */
469 struct completion *bs_async_wq;
470
13d19498
JS
471 /* ---- the following are protected by the bs_lock spinlock ---- */
472 spinlock_t bs_lock; /* lock used for
473 stealing contexts */
474 int bs_lru_ctxnum; /* STEAL - last context
475 stolen */
476 struct gru_state *bs_lru_gru; /* STEAL - last gru
477 stolen */
478
479 struct gru_state bs_grus[GRU_CHIPLETS_PER_BLADE];
480};
481
482/*-----------------------------------------------------------------------------
483 * Address Primitives
484 */
485#define get_tfm_for_cpu(g, c) \
486 ((struct gru_tlb_fault_map *)get_tfm((g)->gs_gru_base_vaddr, (c)))
487#define get_tfh_by_index(g, i) \
488 ((struct gru_tlb_fault_handle *)get_tfh((g)->gs_gru_base_vaddr, (i)))
489#define get_tgh_by_index(g, i) \
490 ((struct gru_tlb_global_handle *)get_tgh((g)->gs_gru_base_vaddr, (i)))
491#define get_cbe_by_index(g, i) \
492 ((struct gru_control_block_extended *)get_cbe((g)->gs_gru_base_vaddr,\
493 (i)))
494
495/*-----------------------------------------------------------------------------
496 * Useful Macros
497 */
498
499/* Given a blade# & chiplet#, get a pointer to the GRU */
500#define get_gru(b, c) (&gru_base[b]->bs_grus[c])
501
502/* Number of bytes to save/restore when unloading/loading GRU contexts */
503#define DSR_BYTES(dsr) ((dsr) * GRU_DSR_AU_BYTES)
504#define CBR_BYTES(cbr) ((cbr) * GRU_HANDLE_BYTES * GRU_CBR_AU_SIZE * 2)
505
506/* Convert a user CB number to the actual CBRNUM */
507#define thread_cbr_number(gts, n) ((gts)->ts_cbr_idx[(n) / GRU_CBR_AU_SIZE] \
508 * GRU_CBR_AU_SIZE + (n) % GRU_CBR_AU_SIZE)
509
510/* Convert a gid to a pointer to the GRU */
511#define GID_TO_GRU(gid) \
512 (gru_base[(gid) / GRU_CHIPLETS_PER_BLADE] ? \
513 (&gru_base[(gid) / GRU_CHIPLETS_PER_BLADE]-> \
514 bs_grus[(gid) % GRU_CHIPLETS_PER_BLADE]) : \
515 NULL)
516
517/* Scan all active GRUs in a GRU bitmap */
518#define for_each_gru_in_bitmap(gid, map) \
8c1840f1 519 for_each_set_bit((gid), (map), GRU_MAX_GRUS)
13d19498
JS
520
521/* Scan all active GRUs on a specific blade */
522#define for_each_gru_on_blade(gru, nid, i) \
523 for ((gru) = gru_base[nid]->bs_grus, (i) = 0; \
524 (i) < GRU_CHIPLETS_PER_BLADE; \
525 (i)++, (gru)++)
526
e1c3219d
JS
527/* Scan all GRUs */
528#define foreach_gid(gid) \
529 for ((gid) = 0; (gid) < gru_max_gids; (gid)++)
530
13d19498
JS
531/* Scan all active GTSs on a gru. Note: must hold ss_lock to use this macro. */
532#define for_each_gts_on_gru(gts, gru, ctxnum) \
533 for ((ctxnum) = 0; (ctxnum) < GRU_NUM_CCH; (ctxnum)++) \
534 if (((gts) = (gru)->gs_gts[ctxnum]))
535
536/* Scan each CBR whose bit is set in a TFM (or copy of) */
537#define for_each_cbr_in_tfm(i, map) \
8c1840f1 538 for_each_set_bit((i), (map), GRU_NUM_CBE)
13d19498
JS
539
540/* Scan each CBR in a CBR bitmap. Note: multiple CBRs in an allocation unit */
541#define for_each_cbr_in_allocation_map(i, map, k) \
8c1840f1 542 for_each_set_bit((k), (map), GRU_CBR_AU) \
13d19498
JS
543 for ((i) = (k)*GRU_CBR_AU_SIZE; \
544 (i) < ((k) + 1) * GRU_CBR_AU_SIZE; (i)++)
545
546/* Scan each DSR in a DSR bitmap. Note: multiple DSRs in an allocation unit */
547#define for_each_dsr_in_allocation_map(i, map, k) \
8c1840f1 548 for_each_set_bit((k), (const unsigned long *)(map), GRU_DSR_AU) \
13d19498
JS
549 for ((i) = (k) * GRU_DSR_AU_CL; \
550 (i) < ((k) + 1) * GRU_DSR_AU_CL; (i)++)
551
552#define gseg_physical_address(gru, ctxnum) \
553 ((gru)->gs_gru_base_paddr + ctxnum * GRU_GSEG_STRIDE)
554#define gseg_virtual_address(gru, ctxnum) \
555 ((gru)->gs_gru_base_vaddr + ctxnum * GRU_GSEG_STRIDE)
556
557/*-----------------------------------------------------------------------------
558 * Lock / Unlock GRU handles
559 * Use the "delresp" bit in the handle as a "lock" bit.
560 */
561
562/* Lock hierarchy checking enabled only in emulator */
563
9cc9b056
JS
564/* 0 = lock failed, 1 = locked */
565static inline int __trylock_handle(void *h)
566{
567 return !test_and_set_bit(1, h);
568}
569
13d19498
JS
570static inline void __lock_handle(void *h)
571{
572 while (test_and_set_bit(1, h))
573 cpu_relax();
574}
575
576static inline void __unlock_handle(void *h)
577{
578 clear_bit(1, h);
579}
580
9cc9b056
JS
581static inline int trylock_cch_handle(struct gru_context_configuration_handle *cch)
582{
583 return __trylock_handle(cch);
584}
585
13d19498
JS
586static inline void lock_cch_handle(struct gru_context_configuration_handle *cch)
587{
588 __lock_handle(cch);
589}
590
591static inline void unlock_cch_handle(struct gru_context_configuration_handle
592 *cch)
593{
594 __unlock_handle(cch);
595}
596
597static inline void lock_tgh_handle(struct gru_tlb_global_handle *tgh)
598{
599 __lock_handle(tgh);
600}
601
602static inline void unlock_tgh_handle(struct gru_tlb_global_handle *tgh)
603{
604 __unlock_handle(tgh);
605}
606
836ce679
JS
607static inline int is_kernel_context(struct gru_thread_state *gts)
608{
609 return !gts->ts_mm;
610}
611
4107e1d3
JS
612/*
613 * The following are for Nehelem-EX. A more general scheme is needed for
614 * future processors.
615 */
616#define UV_MAX_INT_CORES 8
617#define uv_cpu_socket_number(p) ((cpu_physical_id(p) >> 5) & 1)
618#define uv_cpu_ht_number(p) (cpu_physical_id(p) & 1)
619#define uv_cpu_core_number(p) (((cpu_physical_id(p) >> 2) & 4) | \
620 ((cpu_physical_id(p) >> 1) & 3))
13d19498
JS
621/*-----------------------------------------------------------------------------
622 * Function prototypes & externs
623 */
624struct gru_unload_context_req;
625
f0f37e2f 626extern const struct vm_operations_struct gru_vm_ops;
13d19498
JS
627extern struct device *grudev;
628
629extern struct gru_vma_data *gru_alloc_vma_data(struct vm_area_struct *vma,
630 int tsid);
631extern struct gru_thread_state *gru_find_thread_state(struct vm_area_struct
632 *vma, int tsid);
633extern struct gru_thread_state *gru_alloc_thread_state(struct vm_area_struct
634 *vma, int tsid);
55484c45 635extern struct gru_state *gru_assign_gru_context(struct gru_thread_state *gts);
d57c82b1 636extern void gru_load_context(struct gru_thread_state *gts);
55484c45 637extern void gru_steal_context(struct gru_thread_state *gts);
13d19498 638extern void gru_unload_context(struct gru_thread_state *gts, int savestate);
99f7c229 639extern int gru_update_cch(struct gru_thread_state *gts);
13d19498
JS
640extern void gts_drop(struct gru_thread_state *gts);
641extern void gru_tgh_flush_init(struct gru_state *gru);
d5826dd6
JS
642extern int gru_kservices_init(void);
643extern void gru_kservices_exit(void);
4107e1d3
JS
644extern irqreturn_t gru0_intr(int irq, void *dev_id);
645extern irqreturn_t gru1_intr(int irq, void *dev_id);
646extern irqreturn_t gru_intr_mblade(int irq, void *dev_id);
9cc9b056 647extern int gru_dump_chiplet_request(unsigned long arg);
7e796a72 648extern long gru_get_gseg_statistics(unsigned long arg);
13d19498
JS
649extern int gru_handle_user_call_os(unsigned long address);
650extern int gru_user_flush_tlb(unsigned long arg);
651extern int gru_user_unload_context(unsigned long arg);
652extern int gru_get_exception_detail(unsigned long arg);
92b39388 653extern int gru_set_context_option(unsigned long address);
55484c45 654extern void gru_check_context_placement(struct gru_thread_state *gts);
13d19498
JS
655extern int gru_cpu_fault_map_id(void);
656extern struct vm_area_struct *gru_find_vma(unsigned long vaddr);
657extern void gru_flush_all_tlb(struct gru_state *gru);
658extern int gru_proc_init(void);
659extern void gru_proc_exit(void);
660
364b76df 661extern struct gru_thread_state *gru_alloc_gts(struct vm_area_struct *vma,
c550222f
JS
662 int cbr_au_count, int dsr_au_count,
663 unsigned char tlb_preload_count, int options, int tsid);
9ca8e40c 664extern unsigned long gru_reserve_cb_resources(struct gru_state *gru,
13d19498 665 int cbr_au_count, char *cbmap);
9ca8e40c 666extern unsigned long gru_reserve_ds_resources(struct gru_state *gru,
13d19498
JS
667 int dsr_au_count, char *dsmap);
668extern int gru_fault(struct vm_area_struct *, struct vm_fault *vmf);
669extern struct gru_mm_struct *gru_register_mmu_notifier(void);
670extern void gru_drop_mmu_notifier(struct gru_mm_struct *gms);
671
eb5bd5e5 672extern int gru_ktest(unsigned long arg);
13d19498
JS
673extern void gru_flush_tlb_range(struct gru_mm_struct *gms, unsigned long start,
674 unsigned long len);
675
9ca8e40c 676extern unsigned long gru_options;
13d19498
JS
677
678#endif /* __GRUTABLES_H__ */
This page took 0.198809 seconds and 5 git commands to generate.