xref: /openbmc/qemu/include/hw/xen/interface/io/fbif.h (revision ebe15582)
1 /*
2  * fbif.h -- Xen virtual frame buffer device
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  *
22  * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
23  * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
24  */
25 
26 #ifndef __XEN_PUBLIC_IO_FBIF_H__
27 #define __XEN_PUBLIC_IO_FBIF_H__
28 
29 /* Out events (frontend -> backend) */
30 
31 /*
32  * Out events may be sent only when requested by backend, and receipt
33  * of an unknown out event is an error.
34  */
35 
36 /* Event type 1 currently not used */
37 /*
38  * Framebuffer update notification event
39  * Capable frontend sets feature-update in xenstore.
40  * Backend requests it by setting request-update in xenstore.
41  */
42 #define XENFB_TYPE_UPDATE 2
43 
44 struct xenfb_update
45 {
46     uint8_t type;    /* XENFB_TYPE_UPDATE */
47     int32_t x;      /* source x */
48     int32_t y;      /* source y */
49     int32_t width;  /* rect width */
50     int32_t height; /* rect height */
51 };
52 
53 /*
54  * Framebuffer resize notification event
55  * Capable backend sets feature-resize in xenstore.
56  */
57 #define XENFB_TYPE_RESIZE 3
58 
59 struct xenfb_resize
60 {
61     uint8_t type;    /* XENFB_TYPE_RESIZE */
62     int32_t width;   /* width in pixels */
63     int32_t height;  /* height in pixels */
64     int32_t stride;  /* stride in bytes */
65     int32_t depth;   /* depth in bits */
66     int32_t offset;  /* offset of the framebuffer in bytes */
67 };
68 
69 #define XENFB_OUT_EVENT_SIZE 40
70 
71 union xenfb_out_event
72 {
73     uint8_t type;
74     struct xenfb_update update;
75     struct xenfb_resize resize;
76     char pad[XENFB_OUT_EVENT_SIZE];
77 };
78 
79 /* In events (backend -> frontend) */
80 
81 /*
82  * Frontends should ignore unknown in events.
83  */
84 
85 /*
86  * Framebuffer refresh period advice
87  * Backend sends it to advise the frontend their preferred period of
88  * refresh.  Frontends that keep the framebuffer constantly up-to-date
89  * just ignore it.  Frontends that use the advice should immediately
90  * refresh the framebuffer (and send an update notification event if
91  * those have been requested), then use the update frequency to guide
92  * their periodical refreshs.
93  */
94 #define XENFB_TYPE_REFRESH_PERIOD 1
95 #define XENFB_NO_REFRESH 0
96 
97 struct xenfb_refresh_period
98 {
99     uint8_t type;    /* XENFB_TYPE_UPDATE_PERIOD */
100     uint32_t period; /* period of refresh, in ms,
101                       * XENFB_NO_REFRESH if no refresh is needed */
102 };
103 
104 #define XENFB_IN_EVENT_SIZE 40
105 
106 union xenfb_in_event
107 {
108     uint8_t type;
109     struct xenfb_refresh_period refresh_period;
110     char pad[XENFB_IN_EVENT_SIZE];
111 };
112 
113 /* shared page */
114 
115 #define XENFB_IN_RING_SIZE 1024
116 #define XENFB_IN_RING_LEN (XENFB_IN_RING_SIZE / XENFB_IN_EVENT_SIZE)
117 #define XENFB_IN_RING_OFFS 1024
118 #define XENFB_IN_RING(page) \
119     ((union xenfb_in_event *)((char *)(page) + XENFB_IN_RING_OFFS))
120 #define XENFB_IN_RING_REF(page, idx) \
121     (XENFB_IN_RING((page))[(idx) % XENFB_IN_RING_LEN])
122 
123 #define XENFB_OUT_RING_SIZE 2048
124 #define XENFB_OUT_RING_LEN (XENFB_OUT_RING_SIZE / XENFB_OUT_EVENT_SIZE)
125 #define XENFB_OUT_RING_OFFS (XENFB_IN_RING_OFFS + XENFB_IN_RING_SIZE)
126 #define XENFB_OUT_RING(page) \
127     ((union xenfb_out_event *)((char *)(page) + XENFB_OUT_RING_OFFS))
128 #define XENFB_OUT_RING_REF(page, idx) \
129     (XENFB_OUT_RING((page))[(idx) % XENFB_OUT_RING_LEN])
130 
131 struct xenfb_page
132 {
133     uint32_t in_cons, in_prod;
134     uint32_t out_cons, out_prod;
135 
136     int32_t width;          /* the width of the framebuffer (in pixels) */
137     int32_t height;         /* the height of the framebuffer (in pixels) */
138     uint32_t line_length;   /* the length of a row of pixels (in bytes) */
139     uint32_t mem_length;    /* the length of the framebuffer (in bytes) */
140     uint8_t depth;          /* the depth of a pixel (in bits) */
141 
142     /*
143      * Framebuffer page directory
144      *
145      * Each directory page holds PAGE_SIZE / sizeof(*pd)
146      * framebuffer pages, and can thus map up to PAGE_SIZE *
147      * PAGE_SIZE / sizeof(*pd) bytes.  With PAGE_SIZE == 4096 and
148      * sizeof(unsigned long) == 4/8, that's 4 Megs 32 bit and 2 Megs
149      * 64 bit.  256 directories give enough room for a 512 Meg
150      * framebuffer with a max resolution of 12,800x10,240.  Should
151      * be enough for a while with room leftover for expansion.
152      */
153     unsigned long pd[256];
154 };
155 
156 #endif
157