tests: add uncached memory test
[pandora-misc.git] / ofbset.c
1 /*
2  * ofbset - fbset for OMAP displays
3  *
4  * Copyright (c) 2010, GraÅžvydas Ignotas
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in the
12  *       documentation and/or other materials provided with the distribution.
13  *     * Neither the name of the organization nor the
14  *       names of its contributors may be used to endorse or promote products
15  *       derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <sys/ioctl.h>
35 #include <unistd.h>
36
37 #define __user
38 #include "omapfb.h"
39
40 #define RET_CHECK(r, msg) \
41         if (ret < 0) { \
42                 perror(msg); \
43                 return 1; \
44         }
45
46 static void usage(void)
47 {
48         fprintf(stderr, "usage:\n"
49                 "    -h, --help   : this help\n"
50                 "    -s, --show   : show current settings\n"
51                 "    -fb <device> : framebuffer device (default /dev/fb0)\n"
52                 "    -mem <bytes> : memory to reserve for this FB\n"
53                 "    -pos <x y>   : overlay position on display\n"
54                 "    -size <w h>  : overlay size\n"
55                 "    -en <{1,0}>  : enable/disable the overlay\n");
56
57         exit(1);
58 }
59
60 int main(int argc, char *argv[])
61 {
62         struct omapfb_plane_info pi;
63         struct omapfb_mem_info mi;
64         const char *fbname = "/dev/fb0";
65         const char *newmem = NULL;
66         const char *newx = NULL, *newy = NULL;
67         const char *neww = NULL, *newh = NULL;
68         const char *enable = NULL;
69         int old_enable, show = 0, change = 0;
70         int i, ret, fd;
71
72         if (argc < 2)
73                 usage();
74
75         for (i = 1; i < argc; i++) {
76                 if      (!strcmp(argv[i], "-s"))
77                         show = 1;
78                 else if (!strcmp(argv[i], "-fb") && i + 1 < argc)
79                         fbname = argv[++i];
80                 else if (!strcmp(argv[i], "-mem") && i + 1 < argc) {
81                         newmem = argv[++i];
82                         change = 1;
83                 }
84                 else if (!strcmp(argv[i], "-pos") && i + 2 < argc) {
85                         newx = argv[++i];
86                         newy = argv[++i];
87                         change = 1;
88                 }
89                 else if (!strcmp(argv[i], "-size") && i + 2 < argc) {
90                         neww = argv[++i];
91                         newh = argv[++i];
92                         change = 1;
93                 }
94                 else if (!strcmp(argv[i], "-en") && i + 1 < argc) {
95                         enable = argv[++i];
96                         change = 1;
97                 }
98                 else
99                         usage();
100         }
101
102         fd = open(fbname, O_RDWR);
103         if (fd < 0) {
104                 fprintf(stderr, "open %s", fbname);
105                 perror("");
106                 return 1;
107         }
108
109         ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
110         RET_CHECK(ret, "ioctl QUERY_PLANE");
111
112         ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
113         RET_CHECK(ret, "ioctl QUERY_MEM");
114
115         if (show) {
116                 printf("pos:     %d %d\n", pi.pos_x, pi.pos_y);
117                 printf("size:    %d %d\n", pi.out_width, pi.out_height);
118                 printf("mem:     %d\n", mi.size);
119                 printf("enabled: %s\n", pi.enabled ? "yes" : "no");
120         }
121         if (!change)
122                 return 0;
123
124         /* must disable when changing stuff */
125         old_enable = pi.enabled;
126         if (pi.enabled) {
127                 pi.enabled = 0;
128                 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
129                 RET_CHECK(ret, "ioctl SETUP_PLANE");
130         }
131
132         if (newmem) {
133                 mi.size = strtoul(newmem, NULL, 0);
134                 ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
135                 RET_CHECK(ret, "ioctl SETUP_MEM");
136         }
137
138         if (newx && newy) {
139                 pi.pos_x = atoi(newx);
140                 pi.pos_y = atoi(newy);
141         }
142         if (neww && newh) {
143                 pi.out_width = atoi(neww);
144                 pi.out_height = atoi(newh);
145         }
146         if (enable)
147                 pi.enabled = atoi(enable);
148         else
149                 pi.enabled = old_enable;
150
151         ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
152         if (ret < 0) {
153                 perror("ioctl SETUP_PLANE");
154                 return 1;
155         }
156
157         close(fd);
158         return 0;
159 }
160