grutables.h 22 KB

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