1 /* sbuslib.c: Helper library for SBUS framebuffer drivers.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
6 #include <linux/compat.h>
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/string.h>
13 #include <asm/oplib.h>
18 void sbusfb_fill_var(struct fb_var_screeninfo *var, int prom_node, int bpp)
20 memset(var, 0, sizeof(*var));
22 var->xres = prom_getintdefault(prom_node, "width", 1152);
23 var->yres = prom_getintdefault(prom_node, "height", 900);
24 var->xres_virtual = var->xres;
25 var->yres_virtual = var->yres;
26 var->bits_per_pixel = bpp;
29 EXPORT_SYMBOL(sbusfb_fill_var);
31 static unsigned long sbusfb_mmapsize(long size, unsigned long fbsize)
33 if (size == SBUS_MMAP_EMPTY) return 0;
34 if (size >= 0) return size;
35 return fbsize * (-size);
38 int sbusfb_mmap_helper(struct sbus_mmap_map *map,
39 unsigned long physbase,
41 unsigned long iospace,
42 struct vm_area_struct *vma)
44 unsigned int size, page, r, map_size;
45 unsigned long map_offset = 0;
49 if (!(vma->vm_flags & (VM_SHARED | VM_MAYSHARE)))
52 size = vma->vm_end - vma->vm_start;
53 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
56 off = vma->vm_pgoff << PAGE_SHIFT;
58 /* To stop the swapper from even considering these pages */
59 vma->vm_flags |= (VM_IO | VM_RESERVED);
61 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
63 /* Each page, see which map applies */
64 for (page = 0; page < size; ){
66 for (i = 0; map[i].size; i++)
67 if (map[i].voff == off+page) {
68 map_size = sbusfb_mmapsize(map[i].size, fbsize);
70 #define POFF_MASK (PAGE_MASK|0x1UL)
72 #define POFF_MASK (PAGE_MASK)
74 map_offset = (physbase + map[i].poff) & POFF_MASK;
81 if (page + map_size > size)
82 map_size = size - page;
83 r = io_remap_pfn_range(vma,
85 MK_IOSPACE_PFN(iospace,
86 map_offset >> PAGE_SHIFT),
96 EXPORT_SYMBOL(sbusfb_mmap_helper);
98 int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
100 int type, int fb_depth, unsigned long fb_size)
104 struct fbtype __user *f = (struct fbtype __user *) arg;
106 if (put_user(type, &f->fb_type) ||
107 __put_user(info->var.yres, &f->fb_height) ||
108 __put_user(info->var.xres, &f->fb_width) ||
109 __put_user(fb_depth, &f->fb_depth) ||
110 __put_user(0, &f->fb_cmsize) ||
111 __put_user(fb_size, &f->fb_cmsize))
115 case FBIOPUTCMAP_SPARC: {
116 struct fbcmap __user *c = (struct fbcmap __user *) arg;
118 u16 red, green, blue;
119 u8 red8, green8, blue8;
120 unsigned char __user *ured;
121 unsigned char __user *ugreen;
122 unsigned char __user *ublue;
125 if (get_user(index, &c->index) ||
126 __get_user(count, &c->count) ||
127 __get_user(ured, &c->red) ||
128 __get_user(ugreen, &c->green) ||
129 __get_user(ublue, &c->blue))
137 for (i = 0; i < count; i++) {
140 if (get_user(red8, &ured[i]) ||
141 get_user(green8, &ugreen[i]) ||
142 get_user(blue8, &ublue[i]))
149 cmap.start = index + i;
150 err = fb_set_cmap(&cmap, info);
156 case FBIOGETCMAP_SPARC: {
157 struct fbcmap __user *c = (struct fbcmap __user *) arg;
158 unsigned char __user *ured;
159 unsigned char __user *ugreen;
160 unsigned char __user *ublue;
161 struct fb_cmap *cmap = &info->cmap;
165 if (get_user(index, &c->index) ||
166 __get_user(count, &c->count) ||
167 __get_user(ured, &c->red) ||
168 __get_user(ugreen, &c->green) ||
169 __get_user(ublue, &c->blue))
172 if (index + count > cmap->len)
175 for (i = 0; i < count; i++) {
176 red = cmap->red[index + i] >> 8;
177 green = cmap->green[index + i] >> 8;
178 blue = cmap->blue[index + i] >> 8;
179 if (put_user(red, &ured[i]) ||
180 put_user(green, &ugreen[i]) ||
181 put_user(blue, &ublue[i]))
190 EXPORT_SYMBOL(sbusfb_ioctl_helper);
193 static int fbiogetputcmap(struct fb_info *info, unsigned int cmd, unsigned long arg)
195 struct fbcmap32 __user *argp = (void __user *)arg;
196 struct fbcmap __user *p = compat_alloc_user_space(sizeof(*p));
200 ret = copy_in_user(p, argp, 2 * sizeof(int));
201 ret |= get_user(addr, &argp->red);
202 ret |= put_user(compat_ptr(addr), &p->red);
203 ret |= get_user(addr, &argp->green);
204 ret |= put_user(compat_ptr(addr), &p->green);
205 ret |= get_user(addr, &argp->blue);
206 ret |= put_user(compat_ptr(addr), &p->blue);
209 return info->fbops->fb_ioctl(info,
210 (cmd == FBIOPUTCMAP32) ?
211 FBIOPUTCMAP_SPARC : FBIOGETCMAP_SPARC,
215 static int fbiogscursor(struct fb_info *info, unsigned long arg)
217 struct fbcursor __user *p = compat_alloc_user_space(sizeof(*p));
218 struct fbcursor32 __user *argp = (void __user *)arg;
222 ret = copy_in_user(p, argp,
223 2 * sizeof (short) + 2 * sizeof(struct fbcurpos));
224 ret |= copy_in_user(&p->size, &argp->size, sizeof(struct fbcurpos));
225 ret |= copy_in_user(&p->cmap, &argp->cmap, 2 * sizeof(int));
226 ret |= get_user(addr, &argp->cmap.red);
227 ret |= put_user(compat_ptr(addr), &p->cmap.red);
228 ret |= get_user(addr, &argp->cmap.green);
229 ret |= put_user(compat_ptr(addr), &p->cmap.green);
230 ret |= get_user(addr, &argp->cmap.blue);
231 ret |= put_user(compat_ptr(addr), &p->cmap.blue);
232 ret |= get_user(addr, &argp->mask);
233 ret |= put_user(compat_ptr(addr), &p->mask);
234 ret |= get_user(addr, &argp->image);
235 ret |= put_user(compat_ptr(addr), &p->image);
238 return info->fbops->fb_ioctl(info, FBIOSCURSOR, (unsigned long)p);
241 int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
249 case FBIOGCURSOR32: /* This is not implemented yet.
250 Later it should be converted... */
254 return info->fbops->fb_ioctl(info, cmd, arg);
256 return fbiogetputcmap(info, cmd, arg);
258 return fbiogetputcmap(info, cmd, arg);
260 return fbiogscursor(info, arg);
265 EXPORT_SYMBOL(sbusfb_compat_ioctl);