MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / video / sbuslib.c
blob3820d7e628657664a0e791571c44b68bc64eeda5
1 /* sbuslib.c: Helper library for SBUS framebuffer drivers.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
4 */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/string.h>
9 #include <linux/fb.h>
10 #include <linux/mm.h>
12 #include <asm/oplib.h>
13 #include <asm/fbio.h>
15 #include "sbuslib.h"
17 void sbusfb_fill_var(struct fb_var_screeninfo *var, int prom_node, int bpp)
19 memset(var, 0, sizeof(*var));
21 var->xres = prom_getintdefault(prom_node, "width", 1152);
22 var->yres = prom_getintdefault(prom_node, "height", 900);
23 var->xres_virtual = var->xres;
24 var->yres_virtual = var->yres;
25 var->bits_per_pixel = bpp;
28 EXPORT_SYMBOL(sbusfb_fill_var);
30 static unsigned long sbusfb_mmapsize(long size, unsigned long fbsize)
32 if (size == SBUS_MMAP_EMPTY) return 0;
33 if (size >= 0) return size;
34 return fbsize * (-size);
37 int sbusfb_mmap_helper(struct sbus_mmap_map *map,
38 unsigned long physbase,
39 unsigned long fbsize,
40 unsigned long iospace,
41 struct vm_area_struct *vma)
43 unsigned int size, page, r, map_size;
44 unsigned long map_offset = 0;
45 unsigned long off;
46 int i;
48 size = vma->vm_end - vma->vm_start;
49 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
50 return -EINVAL;
52 off = vma->vm_pgoff << PAGE_SHIFT;
54 /* To stop the swapper from even considering these pages */
55 vma->vm_flags |= (VM_SHM | VM_IO | VM_LOCKED);
57 /* Each page, see which map applies */
58 for (page = 0; page < size; ){
59 map_size = 0;
60 for (i = 0; map[i].size; i++)
61 if (map[i].voff == off+page) {
62 map_size = sbusfb_mmapsize(map[i].size, fbsize);
63 #ifdef __sparc_v9__
64 #define POFF_MASK (PAGE_MASK|0x1UL)
65 #else
66 #define POFF_MASK (PAGE_MASK)
67 #endif
68 map_offset = (physbase + map[i].poff) & POFF_MASK;
69 break;
71 if (!map_size){
72 page += PAGE_SIZE;
73 continue;
75 if (page + map_size > size)
76 map_size = size - page;
77 r = io_remap_page_range(vma,
78 vma->vm_start + page,
79 map_offset, map_size,
80 vma->vm_page_prot, iospace);
81 if (r)
82 return -EAGAIN;
83 page += map_size;
86 return 0;
88 EXPORT_SYMBOL(sbusfb_mmap_helper);
90 int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
91 struct fb_info *info,
92 int type, int fb_depth, unsigned long fb_size)
94 switch(cmd) {
95 case FBIOGTYPE: {
96 struct fbtype __user *f = (struct fbtype __user *) arg;
98 if (put_user(type, &f->fb_type) ||
99 __put_user(info->var.yres, &f->fb_height) ||
100 __put_user(info->var.xres, &f->fb_width) ||
101 __put_user(fb_depth, &f->fb_depth) ||
102 __put_user(0, &f->fb_cmsize) ||
103 __put_user(fb_size, &f->fb_cmsize))
104 return -EFAULT;
105 return 0;
107 case FBIOPUTCMAP_SPARC: {
108 struct fbcmap __user *c = (struct fbcmap __user *) arg;
109 struct fb_cmap cmap;
110 u16 red, green, blue;
111 unsigned char __user *ured;
112 unsigned char __user *ugreen;
113 unsigned char __user *ublue;
114 int index, count, i;
116 if (get_user(index, &c->index) ||
117 __get_user(count, &c->count) ||
118 __get_user(ured, &c->red) ||
119 __get_user(ugreen, &c->green) ||
120 __get_user(ublue, &c->blue))
121 return -EFAULT;
123 cmap.len = 1;
124 cmap.red = &red;
125 cmap.green = &green;
126 cmap.blue = &blue;
127 cmap.transp = NULL;
128 for (i = 0; i < count; i++) {
129 int err;
131 if (get_user(red, &ured[i]) ||
132 get_user(green, &ugreen[i]) ||
133 get_user(blue, &ublue[i]))
134 return -EFAULT;
136 cmap.start = index + i;
137 err = fb_set_cmap(&cmap, info);
138 if (err)
139 return err;
141 return 0;
143 case FBIOGETCMAP_SPARC: {
144 struct fbcmap __user *c = (struct fbcmap __user *) arg;
145 unsigned char __user *ured;
146 unsigned char __user *ugreen;
147 unsigned char __user *ublue;
148 struct fb_cmap *cmap = &info->cmap;
149 int index, count, i;
151 if (get_user(index, &c->index) ||
152 __get_user(count, &c->count) ||
153 __get_user(ured, &c->red) ||
154 __get_user(ugreen, &c->green) ||
155 __get_user(ublue, &c->blue))
156 return -EFAULT;
158 if (index + count > cmap->len)
159 return -EINVAL;
161 for (i = 0; i < count; i++) {
162 if (put_user(cmap->red[index + i], &ured[i]) ||
163 put_user(cmap->green[index + i], &ugreen[i]) ||
164 put_user(cmap->blue[index + i], &ublue[i]))
165 return -EFAULT;
167 return 0;
169 default:
170 return -EINVAL;
173 EXPORT_SYMBOL(sbusfb_ioctl_helper);