hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/char/mspec.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights
34 * reserved.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of version 2 of the GNU General Public License
7
- * as published by the Free Software Foundation.
85 */
96
107 /*
....@@ -12,11 +9,8 @@
129 *
1310 * This driver exports the SN special memory (mspec) facility to user
1411 * processes.
15
- * There are three types of memory made available thru this driver:
16
- * fetchops, uncached and cached.
17
- *
18
- * Fetchops are atomic memory operations that are implemented in the
19
- * memory controller on SGI SN hardware.
12
+ * There are two types of memory made available thru this driver:
13
+ * uncached and cached.
2014 *
2115 * Uncached are used for memory write combining feature of the ia64
2216 * cpu.
....@@ -45,20 +39,11 @@
4539 #include <linux/numa.h>
4640 #include <linux/refcount.h>
4741 #include <asm/page.h>
48
-#include <asm/pgtable.h>
4942 #include <linux/atomic.h>
5043 #include <asm/tlbflush.h>
5144 #include <asm/uncached.h>
52
-#include <asm/sn/addrs.h>
53
-#include <asm/sn/arch.h>
54
-#include <asm/sn/mspec.h>
55
-#include <asm/sn/sn_cpuid.h>
56
-#include <asm/sn/io.h>
57
-#include <asm/sn/bte.h>
58
-#include <asm/sn/shubio.h>
5945
6046
61
-#define FETCHOP_ID "SGI Fetchop,"
6247 #define CACHED_ID "Cached,"
6348 #define UNCACHED_ID "Uncached"
6449 #define REVISION "4.0"
....@@ -68,16 +53,9 @@
6853 * Page types allocated by the device.
6954 */
7055 enum mspec_page_type {
71
- MSPEC_FETCHOP = 1,
72
- MSPEC_CACHED,
56
+ MSPEC_CACHED = 2,
7357 MSPEC_UNCACHED
7458 };
75
-
76
-#ifdef CONFIG_SGI_SN
77
-static int is_sn2;
78
-#else
79
-#define is_sn2 0
80
-#endif
8159
8260 /*
8361 * One of these structures is allocated when an mspec region is mmaped. The
....@@ -86,7 +64,7 @@
8664 * This structure is shared by all vma's that are split off from the
8765 * original vma when split_vma()'s are done.
8866 *
89
- * The refcnt is incremented atomically because mm->mmap_sem does not
67
+ * The refcnt is incremented atomically because mm->mmap_lock does not
9068 * protect in fork case where multiple tasks share the vma_data.
9169 */
9270 struct vma_data {
....@@ -96,41 +74,8 @@
9674 enum mspec_page_type type; /* Type of pages allocated. */
9775 unsigned long vm_start; /* Original (unsplit) base. */
9876 unsigned long vm_end; /* Original (unsplit) end. */
99
- unsigned long maddr[0]; /* Array of MSPEC addresses. */
77
+ unsigned long maddr[]; /* Array of MSPEC addresses. */
10078 };
101
-
102
-/* used on shub2 to clear FOP cache in the HUB */
103
-static unsigned long scratch_page[MAX_NUMNODES];
104
-#define SH2_AMO_CACHE_ENTRIES 4
105
-
106
-static inline int
107
-mspec_zero_block(unsigned long addr, int len)
108
-{
109
- int status;
110
-
111
- if (is_sn2) {
112
- if (is_shub2()) {
113
- int nid;
114
- void *p;
115
- int i;
116
-
117
- nid = nasid_to_cnodeid(get_node_number(__pa(addr)));
118
- p = (void *)TO_AMO(scratch_page[nid]);
119
-
120
- for (i=0; i < SH2_AMO_CACHE_ENTRIES; i++) {
121
- FETCHOP_LOAD_OP(p, FETCHOP_LOAD);
122
- p += FETCHOP_VAR_SIZE;
123
- }
124
- }
125
-
126
- status = bte_copy(0, addr & ~__IA64_UNCACHED_OFFSET, len,
127
- BTE_WACQUIRE | BTE_ZERO_FILL, NULL);
128
- } else {
129
- memset((char *) addr, 0, len);
130
- status = 0;
131
- }
132
- return status;
133
-}
13479
13580 /*
13681 * mspec_open
....@@ -176,11 +121,8 @@
176121 */
177122 my_page = vdata->maddr[index];
178123 vdata->maddr[index] = 0;
179
- if (!mspec_zero_block(my_page, PAGE_SIZE))
180
- uncached_free_page(my_page, 1);
181
- else
182
- printk(KERN_WARNING "mspec_close(): "
183
- "failed to zero page %ld\n", my_page);
124
+ memset((char *)my_page, 0, PAGE_SIZE);
125
+ uncached_free_page(my_page, 1);
184126 }
185127
186128 kvfree(vdata);
....@@ -216,11 +158,7 @@
216158 spin_unlock(&vdata->lock);
217159 }
218160
219
- if (vdata->type == MSPEC_FETCHOP)
220
- paddr = TO_AMO(maddr);
221
- else
222
- paddr = maddr & ~__IA64_UNCACHED_OFFSET;
223
-
161
+ paddr = maddr & ~__IA64_UNCACHED_OFFSET;
224162 pfn = paddr >> PAGE_SHIFT;
225163
226164 return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
....@@ -257,10 +195,7 @@
257195
258196 pages = vma_pages(vma);
259197 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
260
- if (vdata_size <= PAGE_SIZE)
261
- vdata = kzalloc(vdata_size, GFP_KERNEL);
262
- else
263
- vdata = vzalloc(vdata_size);
198
+ vdata = kvzalloc(vdata_size, GFP_KERNEL);
264199 if (!vdata)
265200 return -ENOMEM;
266201
....@@ -272,17 +207,11 @@
272207 vma->vm_private_data = vdata;
273208
274209 vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
275
- if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED)
210
+ if (vdata->type == MSPEC_UNCACHED)
276211 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
277212 vma->vm_ops = &mspec_vm_ops;
278213
279214 return 0;
280
-}
281
-
282
-static int
283
-fetchop_mmap(struct file *file, struct vm_area_struct *vma)
284
-{
285
- return mspec_mmap(file, vma, MSPEC_FETCHOP);
286215 }
287216
288217 static int
....@@ -296,18 +225,6 @@
296225 {
297226 return mspec_mmap(file, vma, MSPEC_UNCACHED);
298227 }
299
-
300
-static const struct file_operations fetchop_fops = {
301
- .owner = THIS_MODULE,
302
- .mmap = fetchop_mmap,
303
- .llseek = noop_llseek,
304
-};
305
-
306
-static struct miscdevice fetchop_miscdev = {
307
- .minor = MISC_DYNAMIC_MINOR,
308
- .name = "sgi_fetchop",
309
- .fops = &fetchop_fops
310
-};
311228
312229 static const struct file_operations cached_fops = {
313230 .owner = THIS_MODULE,
....@@ -342,89 +259,32 @@
342259 mspec_init(void)
343260 {
344261 int ret;
345
- int nid;
346262
347
- /*
348
- * The fetchop device only works on SN2 hardware, uncached and cached
349
- * memory drivers should both be valid on all ia64 hardware
350
- */
351
-#ifdef CONFIG_SGI_SN
352
- if (ia64_platform_is("sn2")) {
353
- is_sn2 = 1;
354
- if (is_shub2()) {
355
- ret = -ENOMEM;
356
- for_each_node_state(nid, N_ONLINE) {
357
- int actual_nid;
358
- int nasid;
359
- unsigned long phys;
360
-
361
- scratch_page[nid] = uncached_alloc_page(nid, 1);
362
- if (scratch_page[nid] == 0)
363
- goto free_scratch_pages;
364
- phys = __pa(scratch_page[nid]);
365
- nasid = get_node_number(phys);
366
- actual_nid = nasid_to_cnodeid(nasid);
367
- if (actual_nid != nid)
368
- goto free_scratch_pages;
369
- }
370
- }
371
-
372
- ret = misc_register(&fetchop_miscdev);
373
- if (ret) {
374
- printk(KERN_ERR
375
- "%s: failed to register device %i\n",
376
- FETCHOP_ID, ret);
377
- goto free_scratch_pages;
378
- }
379
- }
380
-#endif
381263 ret = misc_register(&cached_miscdev);
382264 if (ret) {
383265 printk(KERN_ERR "%s: failed to register device %i\n",
384266 CACHED_ID, ret);
385
- if (is_sn2)
386
- misc_deregister(&fetchop_miscdev);
387
- goto free_scratch_pages;
267
+ return ret;
388268 }
389269 ret = misc_register(&uncached_miscdev);
390270 if (ret) {
391271 printk(KERN_ERR "%s: failed to register device %i\n",
392272 UNCACHED_ID, ret);
393273 misc_deregister(&cached_miscdev);
394
- if (is_sn2)
395
- misc_deregister(&fetchop_miscdev);
396
- goto free_scratch_pages;
274
+ return ret;
397275 }
398276
399
- printk(KERN_INFO "%s %s initialized devices: %s %s %s\n",
400
- MSPEC_BASENAME, REVISION, is_sn2 ? FETCHOP_ID : "",
401
- CACHED_ID, UNCACHED_ID);
277
+ printk(KERN_INFO "%s %s initialized devices: %s %s\n",
278
+ MSPEC_BASENAME, REVISION, CACHED_ID, UNCACHED_ID);
402279
403280 return 0;
404
-
405
- free_scratch_pages:
406
- for_each_node(nid) {
407
- if (scratch_page[nid] != 0)
408
- uncached_free_page(scratch_page[nid], 1);
409
- }
410
- return ret;
411281 }
412282
413283 static void __exit
414284 mspec_exit(void)
415285 {
416
- int nid;
417
-
418286 misc_deregister(&uncached_miscdev);
419287 misc_deregister(&cached_miscdev);
420
- if (is_sn2) {
421
- misc_deregister(&fetchop_miscdev);
422
-
423
- for_each_node(nid) {
424
- if (scratch_page[nid] != 0)
425
- uncached_free_page(scratch_page[nid], 1);
426
- }
427
- }
428288 }
429289
430290 module_init(mspec_init);