^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * SN Platform Special Memory (mspec) Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This driver exports the SN special memory (mspec) facility to user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * processes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * There are two types of memory made available thru this driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * uncached and cached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Uncached are used for memory write combining feature of the ia64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * cpu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Cached are used for areas of memory that are used as cached addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * on our partition and used as uncached addresses from other partitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Due to a design constraint of the SN2 Shub, you can not have processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * on the same FSB perform both a cached and uncached reference to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * same cache line. These special memory cached regions prevent the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * kernel from ever dropping in a TLB entry and therefore prevent the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * processor from ever speculating a cache line from this page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/uncached.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define CACHED_ID "Cached,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define UNCACHED_ID "Uncached"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define REVISION "4.0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define MSPEC_BASENAME "mspec"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Page types allocated by the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) enum mspec_page_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) MSPEC_CACHED = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) MSPEC_UNCACHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * One of these structures is allocated when an mspec region is mmaped. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * structure is pointed to by the vma->vm_private_data field in the vma struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * This structure is used to record the addresses of the mspec pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * This structure is shared by all vma's that are split off from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * original vma when split_vma()'s are done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * The refcnt is incremented atomically because mm->mmap_lock does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * protect in fork case where multiple tasks share the vma_data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct vma_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) refcount_t refcnt; /* Number of vmas sharing the data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spinlock_t lock; /* Serialize access to this structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int count; /* Number of pages allocated. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) enum mspec_page_type type; /* Type of pages allocated. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned long vm_start; /* Original (unsplit) base. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) unsigned long vm_end; /* Original (unsplit) end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned long maddr[]; /* Array of MSPEC addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * mspec_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Called when a device mapping is created by a means other than mmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * (via fork, munmap, etc.). Increments the reference count on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * underlying mspec data so it is not freed prematurely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) mspec_open(struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct vma_data *vdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) vdata = vma->vm_private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) refcount_inc(&vdata->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * mspec_close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * Called when unmapping a device mapping. Frees all mspec pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * belonging to all the vma's sharing this vma_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) mspec_close(struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct vma_data *vdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int index, last_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned long my_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) vdata = vma->vm_private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (!refcount_dec_and_test(&vdata->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) for (index = 0; index < last_index; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (vdata->maddr[index] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Clear the page before sticking it back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * into the pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) my_page = vdata->maddr[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) vdata->maddr[index] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) memset((char *)my_page, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) uncached_free_page(my_page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) kvfree(vdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * mspec_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Creates a mspec page and maps it to user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static vm_fault_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) mspec_fault(struct vm_fault *vmf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned long paddr, maddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned long pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) pgoff_t index = vmf->pgoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct vma_data *vdata = vmf->vma->vm_private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) maddr = (volatile unsigned long) vdata->maddr[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (maddr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) maddr = uncached_alloc_page(numa_node_id(), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (maddr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return VM_FAULT_OOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) spin_lock(&vdata->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (vdata->maddr[index] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) vdata->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) vdata->maddr[index] = maddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) uncached_free_page(maddr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) maddr = vdata->maddr[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) spin_unlock(&vdata->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) paddr = maddr & ~__IA64_UNCACHED_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pfn = paddr >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static const struct vm_operations_struct mspec_vm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .open = mspec_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .close = mspec_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .fault = mspec_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * mspec_mmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * Called when mmapping the device. Initializes the vma with a fault handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * and private data structure necessary to allocate, track, and free the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * underlying pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) mspec_mmap(struct file *file, struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) enum mspec_page_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct vma_data *vdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int pages, vdata_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (vma->vm_pgoff != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if ((vma->vm_flags & VM_SHARED) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if ((vma->vm_flags & VM_WRITE) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pages = vma_pages(vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) vdata = kvzalloc(vdata_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!vdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) vdata->vm_start = vma->vm_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) vdata->vm_end = vma->vm_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) vdata->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) spin_lock_init(&vdata->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) refcount_set(&vdata->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) vma->vm_private_data = vdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (vdata->type == MSPEC_UNCACHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) vma->vm_ops = &mspec_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) cached_mmap(struct file *file, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return mspec_mmap(file, vma, MSPEC_CACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) uncached_mmap(struct file *file, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return mspec_mmap(file, vma, MSPEC_UNCACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static const struct file_operations cached_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .mmap = cached_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static struct miscdevice cached_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .minor = MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .name = "mspec_cached",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .fops = &cached_fops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct file_operations uncached_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .mmap = uncached_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static struct miscdevice uncached_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .minor = MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .name = "mspec_uncached",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .fops = &uncached_fops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * mspec_init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * Called at boot time to initialize the mspec facility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) mspec_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ret = misc_register(&cached_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) printk(KERN_ERR "%s: failed to register device %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) CACHED_ID, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = misc_register(&uncached_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) printk(KERN_ERR "%s: failed to register device %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) UNCACHED_ID, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) misc_deregister(&cached_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) printk(KERN_INFO "%s %s initialized devices: %s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) MSPEC_BASENAME, REVISION, CACHED_ID, UNCACHED_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) mspec_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) misc_deregister(&uncached_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) misc_deregister(&cached_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) module_init(mspec_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) module_exit(mspec_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) MODULE_AUTHOR("Silicon Graphics, Inc. <linux-altix@sgi.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) MODULE_DESCRIPTION("Driver for SGI SN special memory operations");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) MODULE_LICENSE("GPL");