xref: /openbmc/qemu/include/hw/xen/interface/io/fbif.h (revision 2e1cacfb)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * fbif.h -- Xen virtual frame buffer device
4  *
5  * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
6  * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
7  */
8 
9 #ifndef __XEN_PUBLIC_IO_FBIF_H__
10 #define __XEN_PUBLIC_IO_FBIF_H__
11 
12 /* Out events (frontend -> backend) */
13 
14 /*
15  * Out events may be sent only when requested by backend, and receipt
16  * of an unknown out event is an error.
17  */
18 
19 /* Event type 1 currently not used */
20 /*
21  * Framebuffer update notification event
22  * Capable frontend sets feature-update in xenstore.
23  * Backend requests it by setting request-update in xenstore.
24  */
25 #define XENFB_TYPE_UPDATE 2
26 
27 struct xenfb_update
28 {
29     uint8_t type;    /* XENFB_TYPE_UPDATE */
30     int32_t x;      /* source x */
31     int32_t y;      /* source y */
32     int32_t width;  /* rect width */
33     int32_t height; /* rect height */
34 };
35 
36 /*
37  * Framebuffer resize notification event
38  * Capable backend sets feature-resize in xenstore.
39  */
40 #define XENFB_TYPE_RESIZE 3
41 
42 struct xenfb_resize
43 {
44     uint8_t type;    /* XENFB_TYPE_RESIZE */
45     int32_t width;   /* width in pixels */
46     int32_t height;  /* height in pixels */
47     int32_t stride;  /* stride in bytes */
48     int32_t depth;   /* depth in bits */
49     int32_t offset;  /* offset of the framebuffer in bytes */
50 };
51 
52 #define XENFB_OUT_EVENT_SIZE 40
53 
54 union xenfb_out_event
55 {
56     uint8_t type;
57     struct xenfb_update update;
58     struct xenfb_resize resize;
59     char pad[XENFB_OUT_EVENT_SIZE];
60 };
61 
62 /* In events (backend -> frontend) */
63 
64 /*
65  * Frontends should ignore unknown in events.
66  */
67 
68 /*
69  * Framebuffer refresh period advice
70  * Backend sends it to advise the frontend their preferred period of
71  * refresh.  Frontends that keep the framebuffer constantly up-to-date
72  * just ignore it.  Frontends that use the advice should immediately
73  * refresh the framebuffer (and send an update notification event if
74  * those have been requested), then use the update frequency to guide
75  * their periodical refreshs.
76  */
77 #define XENFB_TYPE_REFRESH_PERIOD 1
78 #define XENFB_NO_REFRESH 0
79 
80 struct xenfb_refresh_period
81 {
82     uint8_t type;    /* XENFB_TYPE_UPDATE_PERIOD */
83     uint32_t period; /* period of refresh, in ms,
84                       * XENFB_NO_REFRESH if no refresh is needed */
85 };
86 
87 #define XENFB_IN_EVENT_SIZE 40
88 
89 union xenfb_in_event
90 {
91     uint8_t type;
92     struct xenfb_refresh_period refresh_period;
93     char pad[XENFB_IN_EVENT_SIZE];
94 };
95 
96 /* shared page */
97 
98 #define XENFB_IN_RING_SIZE 1024
99 #define XENFB_IN_RING_LEN (XENFB_IN_RING_SIZE / XENFB_IN_EVENT_SIZE)
100 #define XENFB_IN_RING_OFFS 1024
101 #define XENFB_IN_RING(page) \
102     ((union xenfb_in_event *)((char *)(page) + XENFB_IN_RING_OFFS))
103 #define XENFB_IN_RING_REF(page, idx) \
104     (XENFB_IN_RING((page))[(idx) % XENFB_IN_RING_LEN])
105 
106 #define XENFB_OUT_RING_SIZE 2048
107 #define XENFB_OUT_RING_LEN (XENFB_OUT_RING_SIZE / XENFB_OUT_EVENT_SIZE)
108 #define XENFB_OUT_RING_OFFS (XENFB_IN_RING_OFFS + XENFB_IN_RING_SIZE)
109 #define XENFB_OUT_RING(page) \
110     ((union xenfb_out_event *)((char *)(page) + XENFB_OUT_RING_OFFS))
111 #define XENFB_OUT_RING_REF(page, idx) \
112     (XENFB_OUT_RING((page))[(idx) % XENFB_OUT_RING_LEN])
113 
114 struct xenfb_page
115 {
116     uint32_t in_cons, in_prod;
117     uint32_t out_cons, out_prod;
118 
119     int32_t width;          /* the width of the framebuffer (in pixels) */
120     int32_t height;         /* the height of the framebuffer (in pixels) */
121     uint32_t line_length;   /* the length of a row of pixels (in bytes) */
122     uint32_t mem_length;    /* the length of the framebuffer (in bytes) */
123     uint8_t depth;          /* the depth of a pixel (in bits) */
124 
125     /*
126      * Framebuffer page directory
127      *
128      * Each directory page holds PAGE_SIZE / sizeof(*pd)
129      * framebuffer pages, and can thus map up to PAGE_SIZE *
130      * PAGE_SIZE / sizeof(*pd) bytes.  With PAGE_SIZE == 4096 and
131      * sizeof(unsigned long) == 4/8, that's 4 Megs 32 bit and 2 Megs
132      * 64 bit.  256 directories give enough room for a 512 Meg
133      * framebuffer with a max resolution of 12,800x10,240.  Should
134      * be enough for a while with room leftover for expansion.
135      */
136     unsigned long pd[256];
137 };
138 
139 /*
140  * Wart: xenkbd needs to know default resolution.  Put it here until a
141  * better solution is found, but don't leak it to the backend.
142  */
143 #ifdef __KERNEL__
144 #define XENFB_WIDTH 800
145 #define XENFB_HEIGHT 600
146 #define XENFB_DEPTH 32
147 #endif
148 
149 #endif
150 
151 /*
152  * Local variables:
153  * mode: C
154  * c-file-style: "BSD"
155  * c-basic-offset: 4
156  * tab-width: 4
157  * indent-tabs-mode: nil
158  * End:
159  */
160