summaryrefslogtreecommitdiff
path: root/lkm/ap/aperture.c
blob: face345804173c59acd47c7edfd7c58764ad2e65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*	$OpenbSD$	*/

/*
 * Copyright 1994 the XFree86 Project Inc. 
 */

/* 
 * linear framebuffer aperture driver for OpenBSD
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/errno.h>

#define VGA_START 0xA0000
#ifdef PC98 
#define VGA_END   0xFFFFF
#define HOLE16M_START	0xF00000
#define HOLE16M_END	0xFFFFFF
#else 
#define VGA_END   0xBFFFF
#endif 

/* open counter */
static int ap_open_count = 0;

/*
 * Open the device
 */
int
apopen(dev_t dev, int oflags, int devtype, struct proc *p)
{

    if (suser(p->p_ucred, &p->p_acflag) != 0) {
	return(EPERM);
    }
    /* authorize only one simultaneous open() */
    if (ap_open_count > 0) {
	return(EPERM);
    }
    ap_open_count++;

    return(0);
}

/*
 * Close the device
 */
int
apclose(dev_t dev, int cflags, int devtype, struct proc *p)
{

    ap_open_count--;
    return(0);
}

/*
 *  mmap() physical memory sections
 * 
 * allow only section in the vga framebuffer and above main memory 
 * to be mapped
 */
int
apmmap(dev_t dev, int offset, int length)
{

#ifdef AP_DEBUG
    printf("apmmap: addr 0x%x\n", offset);
#endif
    if  ((minor(dev) == 0) 
	 && ((offset >= VGA_START && offset <= VGA_END )
	     || (unsigned)offset > (unsigned)ctob(physmem)
#ifdef PC98
	     || ((unsigned)offset >=HOLE16M_START
                   && (unsigned)offset <= HOLE16M_END)
#endif
	     )) {
	return i386_btop(offset);
    } else {
	return(-1);
    }
}