summaryrefslogtreecommitdiff
path: root/src/qxl_io.c
blob: c59263104ffe416026c7347f1776b9d2e78c353d (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * Copyright 2008 Red Hat, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/* all the IO routines for QXL userspace code */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <unistd.h>
#include <errno.h>
#include <time.h>
#include "qxl.h"
#ifndef XSPICE
static void
qxl_wait_for_io_command (qxl_screen_t *qxl)
{
    struct QXLRam *ram_header;
    
    ram_header = (void *)((unsigned long)qxl->ram + qxl->rom->ram_header_offset);
    
    while (!(ram_header->int_pending & QXL_INTERRUPT_IO_CMD))
	usleep (1);
    
    ram_header->int_pending &= ~QXL_INTERRUPT_IO_CMD;
}

#if 0
static void
qxl_wait_for_display_interrupt (qxl_screen_t *qxl)
{
    struct QXLRam *ram_header;
    
    ram_header = (void *)((unsigned long)qxl->ram + qxl->rom->ram_header_offset);
    
    while (!(ram_header->int_pending & QXL_INTERRUPT_DISPLAY))
	usleep (1);
    
    ram_header->int_pending &= ~QXL_INTERRUPT_DISPLAY;
}

#endif
#endif

void
qxl_update_area (qxl_screen_t *qxl)
{
#ifndef XSPICE
    if (qxl->pci->revision >= 3)
    {
	ioport_write (qxl, QXL_IO_UPDATE_AREA_ASYNC, 0);
	qxl_wait_for_io_command (qxl);
    }
    else
    {
	ioport_write (qxl, QXL_IO_UPDATE_AREA, 0);
    }
#else
    ioport_write (qxl, QXL_IO_UPDATE_AREA, 0);
#endif
}

void
qxl_io_memslot_add (qxl_screen_t *qxl, uint8_t id)
{
#ifndef XSPICE
    if (qxl->pci->revision >= 3)
    {
	ioport_write (qxl, QXL_IO_MEMSLOT_ADD_ASYNC, id);
	qxl_wait_for_io_command (qxl);
    }
    else
    {
	ioport_write (qxl, QXL_IO_MEMSLOT_ADD, id);
    }
#else
    ioport_write (qxl, QXL_IO_MEMSLOT_ADD, id);
#endif
}

void
qxl_io_create_primary (qxl_screen_t *qxl)
{
#ifndef XSPICE
    if (qxl->pci->revision >= 3)
    {
	ioport_write (qxl, QXL_IO_CREATE_PRIMARY_ASYNC, 0);
	qxl_wait_for_io_command (qxl);
    }
    else
    {
	ioport_write (qxl, QXL_IO_CREATE_PRIMARY, 0);
    }
#else
    ioport_write (qxl, QXL_IO_CREATE_PRIMARY, 0);
#endif
    qxl->device_primary = QXL_DEVICE_PRIMARY_CREATED;
}

void
qxl_io_destroy_primary (qxl_screen_t *qxl)
{
#ifndef XSPICE
    if (qxl->pci->revision >= 3)
    {
	ioport_write (qxl, QXL_IO_DESTROY_PRIMARY_ASYNC, 0);
	qxl_wait_for_io_command (qxl);
    }
    else
    {
	ioport_write (qxl, QXL_IO_DESTROY_PRIMARY, 0);
    }
#else
    ioport_write (qxl, QXL_IO_DESTROY_PRIMARY, 0);
#endif
    qxl->device_primary = QXL_DEVICE_PRIMARY_NONE;
}

void
qxl_io_notify_oom (qxl_screen_t *qxl)
{
    ioport_write (qxl, QXL_IO_NOTIFY_OOM, 0);
}

void
qxl_io_flush_surfaces (qxl_screen_t *qxl)
{
    // FIXME: write individual update_area for revision < V10
#ifndef XSPICE
    ioport_write (qxl, QXL_IO_FLUSH_SURFACES_ASYNC, 0);
    qxl_wait_for_io_command (qxl);
#else
    ioport_write (qxl, QXL_IO_FLUSH_SURFACES_ASYNC, 0);
#endif
}

#ifdef QXLDRV_RESIZABLE_SURFACE0
void
qxl_io_flush_release (qxl_screen_t *qxl)
{
#ifndef XSPICE
    int sum = 0;
    
    sum += qxl_garbage_collect (qxl);
    ioport_write (qxl, QXL_IO_FLUSH_RELEASE, 0);
    sum +=  qxl_garbage_collect (qxl);
    ErrorF ("%s: collected %d\n", __func__, sum);
#else
#endif
}

#endif

void
qxl_io_monitors_config_async (qxl_screen_t *qxl)
{
#ifndef XSPICE
    if (qxl->pci->revision < 4)
	return;
    
    ioport_write (qxl, QXL_IO_MONITORS_CONFIG_ASYNC, 0);
    qxl_wait_for_io_command (qxl);
#else
    fprintf (stderr, "UNIMPLEMENTED!\n");
#endif
}


void
qxl_io_destroy_all_surfaces (qxl_screen_t *qxl)
{
#ifndef XSPICE
    if (qxl->pci->revision >= 3)
    {
	ioport_write (qxl, QXL_IO_DESTROY_ALL_SURFACES_ASYNC, 0);
	qxl_wait_for_io_command (qxl);
    }
    else
    {
	ioport_write (qxl, QXL_IO_DESTROY_ALL_SURFACES, 0);
    }
#else
    ErrorF ("Xspice: error: UNIMPLEMENTED qxl_io_destroy_all_surfaces\n");
#endif
    qxl->device_primary = QXL_DEVICE_PRIMARY_NONE;
}