1 /* sbuslib.c: Helper library for SBUS framebuffer drivers.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/string.h>
12 #include <asm/oplib.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,
40 unsigned long iospace,
41 struct vm_area_struct *vma)
43 unsigned int size, page, r, map_size;
44 unsigned long map_offset = 0;
48 size = vma->vm_end - vma->vm_start;
49 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
52 off = vma->vm_pgoff << PAGE_SHIFT;
54 /* To stop the swapper from even considering these pages */
55 vma->vm_flags |= (VM_IO | VM_RESERVED);
57 /* Each page, see which map applies */
58 for (page = 0; page < size; ){
60 for (i = 0; map[i].size; i++)
61 if (map[i].voff == off+page) {
62 map_size = sbusfb_mmapsize(map[i].size, fbsize);
64 #define POFF_MASK (PAGE_MASK|0x1UL)
66 #define POFF_MASK (PAGE_MASK)
68 map_offset = (physbase + map[i].poff) & POFF_MASK;
75 if (page + map_size > size)
76 map_size = size - page;
77 r = io_remap_pfn_range(vma,
79 MK_IOSPACE_PFN(iospace,
80 map_offset >> PAGE_SHIFT),
90 EXPORT_SYMBOL(sbusfb_mmap_helper);
92 int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
94 int type, int fb_depth, unsigned long fb_size)
98 struct fbtype __user *f = (struct fbtype __user *) arg;
100 if (put_user(type, &f->fb_type) ||
101 __put_user(info->var.yres, &f->fb_height) ||
102 __put_user(info->var.xres, &f->fb_width) ||
103 __put_user(fb_depth, &f->fb_depth) ||
104 __put_user(0, &f->fb_cmsize) ||
105 __put_user(fb_size, &f->fb_cmsize))
109 case FBIOPUTCMAP_SPARC: {
110 struct fbcmap __user *c = (struct fbcmap __user *) arg;
112 u16 red, green, blue;
113 u8 red8, green8, blue8;
114 unsigned char __user *ured;
115 unsigned char __user *ugreen;
116 unsigned char __user *ublue;
119 if (get_user(index, &c->index) ||
120 __get_user(count, &c->count) ||
121 __get_user(ured, &c->red) ||
122 __get_user(ugreen, &c->green) ||
123 __get_user(ublue, &c->blue))
131 for (i = 0; i < count; i++) {
134 if (get_user(red8, &ured[i]) ||
135 get_user(green8, &ugreen[i]) ||
136 get_user(blue8, &ublue[i]))
143 cmap.start = index + i;
144 err = fb_set_cmap(&cmap, info);
150 case FBIOGETCMAP_SPARC: {
151 struct fbcmap __user *c = (struct fbcmap __user *) arg;
152 unsigned char __user *ured;
153 unsigned char __user *ugreen;
154 unsigned char __user *ublue;
155 struct fb_cmap *cmap = &info->cmap;
159 if (get_user(index, &c->index) ||
160 __get_user(count, &c->count) ||
161 __get_user(ured, &c->red) ||
162 __get_user(ugreen, &c->green) ||
163 __get_user(ublue, &c->blue))
166 if (index + count > cmap->len)
169 for (i = 0; i < count; i++) {
170 red = cmap->red[index + i] >> 8;
171 green = cmap->green[index + i] >> 8;
172 blue = cmap->blue[index + i] >> 8;
173 if (put_user(red, &ured[i]) ||
174 put_user(green, &ugreen[i]) ||
175 put_user(blue, &ublue[i]))
184 EXPORT_SYMBOL(sbusfb_ioctl_helper);