Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1 | /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright © 2011 Texas Instruments, Inc |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | * |
| 25 | * Authors: |
| 26 | * Ian Elliott <ianelliottus@yahoo.com> |
| 27 | * Rob Clark <rob@ti.com> |
| 28 | */ |
| 29 | |
Raymond Smith | 41ecf3e | 2012-05-01 14:51:34 +0100 | [diff] [blame] | 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | #include <fcntl.h> |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 33 | #include <unistd.h> |
David Garbett | dccb73f | 2013-09-02 11:48:21 +0100 | [diff] [blame] | 34 | #include <linux/fb.h> |
| 35 | #include <sys/ioctl.h> |
| 36 | #include <sys/mman.h> |
| 37 | |
| 38 | #include <pixman.h> |
Raymond Smith | 41ecf3e | 2012-05-01 14:51:34 +0100 | [diff] [blame] | 39 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 40 | #ifdef HAVE_CONFIG_H |
| 41 | #include "config.h" |
| 42 | #endif |
| 43 | |
Paul Geary | f8b9969 | 2013-04-15 10:55:17 +0100 | [diff] [blame] | 44 | #include "armsoc_driver.h" |
Dave Barnish | 257c6f1 | 2013-06-05 17:00:29 +0100 | [diff] [blame] | 45 | |
| 46 | #include "micmap.h" |
| 47 | |
| 48 | #include "xf86cmap.h" |
| 49 | #include "xf86RandR12.h" |
| 50 | |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 51 | #include "compat-api.h" |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 52 | |
Ray Smith | 3c33c3d | 2013-03-26 16:06:37 +0000 | [diff] [blame] | 53 | #include "drmmode_driver.h" |
| 54 | |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 55 | #define DRM_DEVICE "/dev/dri/card%d" |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 56 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 57 | Bool armsocDebug; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Forward declarations: |
| 61 | */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 62 | static const OptionInfoRec *ARMSOCAvailableOptions(int chipid, int busid); |
| 63 | static void ARMSOCIdentify(int flags); |
| 64 | static Bool ARMSOCProbe(DriverPtr drv, int flags); |
| 65 | static Bool ARMSOCPreInit(ScrnInfoPtr pScrn, int flags); |
| 66 | static Bool ARMSOCScreenInit(SCREEN_INIT_ARGS_DECL); |
| 67 | static void ARMSOCLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 68 | LOCO *colors, VisualPtr pVisual); |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 69 | static Bool ARMSOCCloseScreen(CLOSE_SCREEN_ARGS_DECL); |
| 70 | static Bool ARMSOCCreateScreenResources(ScreenPtr pScreen); |
| 71 | static void ARMSOCBlockHandler(BLOCKHANDLER_ARGS_DECL); |
| 72 | static Bool ARMSOCSwitchMode(SWITCH_MODE_ARGS_DECL); |
| 73 | static void ARMSOCAdjustFrame(ADJUST_FRAME_ARGS_DECL); |
| 74 | static Bool ARMSOCEnterVT(VT_FUNC_ARGS_DECL); |
| 75 | static void ARMSOCLeaveVT(VT_FUNC_ARGS_DECL); |
| 76 | static void ARMSOCFreeScreen(FREE_SCREEN_ARGS_DECL); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 77 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 78 | /** |
| 79 | * A structure used by the XFree86 code when loading this driver, so that it |
| 80 | * can access the Probe() function, and other functions/info that it uses |
| 81 | * before it calls the Probe() function. The name of this structure must be |
| 82 | * the all-upper-case version of the driver name. |
| 83 | */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 84 | _X_EXPORT DriverRec ARMSOC = { |
| 85 | ARMSOC_VERSION, |
| 86 | (char *)ARMSOC_DRIVER_NAME, |
| 87 | ARMSOCIdentify, |
| 88 | ARMSOCProbe, |
| 89 | ARMSOCAvailableOptions, |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 90 | NULL, |
| 91 | 0, |
| 92 | NULL, |
| 93 | #ifdef XSERVER_LIBPCIACCESS |
| 94 | NULL, |
| 95 | NULL |
| 96 | #endif |
| 97 | }; |
| 98 | |
Dave Barnish | 01b5c17 | 2013-04-10 11:01:17 +0100 | [diff] [blame] | 99 | #define MALI_4XX_CHIPSET_ID (0x0400) |
| 100 | #define MALI_T6XX_CHIPSET_ID (0x0600) |
| 101 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 102 | /** Supported "chipsets." */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 103 | static SymTabRec ARMSOCChipsets[] = { |
Dave Barnish | 01b5c17 | 2013-04-10 11:01:17 +0100 | [diff] [blame] | 104 | { MALI_4XX_CHIPSET_ID, "Mali-4XX" }, |
| 105 | { MALI_T6XX_CHIPSET_ID, "Mali-T6XX" }, |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 106 | {-1, NULL } |
| 107 | }; |
| 108 | |
| 109 | /** Supported options, as enum values. */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 110 | enum { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 111 | OPTION_DEBUG, |
Dave Barnish | c50baf5 | 2012-11-29 14:39:36 +0000 | [diff] [blame] | 112 | OPTION_NO_FLIP, |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 113 | OPTION_CARD_NUM, |
| 114 | OPTION_BUSID, |
| 115 | OPTION_DRIVERNAME, |
David Garbett | 4d37be3 | 2013-04-04 09:04:29 +0100 | [diff] [blame] | 116 | OPTION_DRI_NUM_BUF, |
David Garbett | dccb73f | 2013-09-02 11:48:21 +0100 | [diff] [blame] | 117 | OPTION_INIT_FROM_FBDEV, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 118 | }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 119 | |
| 120 | /** Supported options. */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 121 | static const OptionInfoRec ARMSOCOptions[] = { |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 122 | { OPTION_DEBUG, "Debug", OPTV_BOOLEAN, {0}, FALSE }, |
| 123 | { OPTION_NO_FLIP, "NoFlip", OPTV_BOOLEAN, {0}, FALSE }, |
| 124 | { OPTION_CARD_NUM, "DRICard", OPTV_INTEGER, {0}, FALSE }, |
| 125 | { OPTION_BUSID, "BusID", OPTV_STRING, {0}, FALSE }, |
| 126 | { OPTION_DRIVERNAME, "DriverName", OPTV_STRING, {0}, FALSE }, |
David Garbett | 4d37be3 | 2013-04-04 09:04:29 +0100 | [diff] [blame] | 127 | { OPTION_DRI_NUM_BUF, "DRI2MaxBuffers", OPTV_INTEGER, {-1}, FALSE }, |
David Garbett | dccb73f | 2013-09-02 11:48:21 +0100 | [diff] [blame] | 128 | { OPTION_INIT_FROM_FBDEV, "InitFromFBDev", OPTV_STRING, {0}, FALSE }, |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 129 | { -1, NULL, OPTV_NONE, {0}, FALSE } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /** |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 133 | * Helper functions for sharing a DRM connection across screens. |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 134 | */ |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 135 | static struct ARMSOCConnection { |
Ray Smith | b31657f | 2013-06-25 11:47:36 +0100 | [diff] [blame] | 136 | const char *driver_name; |
| 137 | const char *bus_id; |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 138 | unsigned int card_num; |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 139 | int fd; |
| 140 | int open_count; |
| 141 | int master_count; |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 142 | } connection = {NULL, NULL, 0, -1, 0, 0}; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 143 | |
| 144 | static int |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 145 | ARMSOCSetDRMMaster(void) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 146 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 147 | int ret = 0; |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 148 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 149 | assert(connection.fd >= 0); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 150 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 151 | if (!connection.master_count) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 152 | ret = drmSetMaster(connection.fd); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 153 | |
| 154 | if (!ret) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 155 | connection.master_count++; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 156 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | static int |
| 161 | ARMSOCDropDRMMaster(void) |
| 162 | { |
| 163 | int ret = 0; |
| 164 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 165 | assert(connection.fd >= 0); |
| 166 | assert(connection.master_count > 0); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 167 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 168 | if (1 == connection.master_count) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 169 | ret = drmDropMaster(connection.fd); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 170 | |
| 171 | if (!ret) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 172 | connection.master_count--; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 173 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 174 | return ret; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 175 | } |
| 176 | |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 177 | static void |
| 178 | ARMSOCShowDriverInfo(int fd) |
| 179 | { |
| 180 | char *bus_id; |
| 181 | drmVersionPtr version; |
| 182 | char *deviceName; |
| 183 | |
| 184 | EARLY_INFO_MSG("Opened DRM"); |
| 185 | deviceName = drmGetDeviceNameFromFd(fd); |
| 186 | EARLY_INFO_MSG(" DeviceName is [%s]", |
| 187 | deviceName ? deviceName : "NULL"); |
| 188 | drmFree(deviceName); |
| 189 | bus_id = drmGetBusid(fd); |
| 190 | EARLY_INFO_MSG(" bus_id is [%s]", |
| 191 | bus_id ? bus_id : "NULL"); |
| 192 | drmFreeBusid(bus_id); |
| 193 | version = drmGetVersion(fd); |
| 194 | if (version) { |
| 195 | EARLY_INFO_MSG(" DriverName is [%s]", |
| 196 | version->name); |
| 197 | EARLY_INFO_MSG(" version is [%d.%d.%d]", |
| 198 | version->version_major, |
| 199 | version->version_minor, |
| 200 | version->version_patchlevel); |
| 201 | drmFreeVersion(version); |
| 202 | } else { |
| 203 | EARLY_INFO_MSG(" version is [NULL]"); |
| 204 | } |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | static int |
| 209 | ARMSOCOpenDRMCard(void) |
| 210 | { |
| 211 | int fd; |
| 212 | |
| 213 | if ((connection.bus_id) || (connection.driver_name)) { |
| 214 | /* user specified bus ID or driver name - pass to drmOpen */ |
| 215 | EARLY_INFO_MSG("Opening driver [%s], bus_id [%s]", |
| 216 | connection.driver_name ? |
| 217 | connection.driver_name : "NULL", |
| 218 | connection.bus_id ? |
| 219 | connection.bus_id : "NULL"); |
| 220 | fd = drmOpen(connection.driver_name, connection.bus_id); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 221 | if (fd < 0) |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 222 | goto fail2; |
| 223 | } else { |
| 224 | char filename[32]; |
| 225 | int err; |
| 226 | drmSetVersion sv; |
| 227 | char *bus_id, *bus_id_copy; |
| 228 | |
| 229 | /* open with card_num */ |
| 230 | snprintf(filename, sizeof(filename), |
| 231 | DRM_DEVICE, connection.card_num); |
| 232 | EARLY_INFO_MSG( |
| 233 | "No BusID or DriverName specified - opening %s", |
| 234 | filename); |
| 235 | fd = open(filename, O_RDWR, 0); |
| 236 | if (-1 == fd) |
| 237 | goto fail2; |
| 238 | /* Set interface version to initialise bus id */ |
| 239 | sv.drm_di_major = 1; |
| 240 | sv.drm_di_minor = 1; |
| 241 | sv.drm_dd_major = -1; |
| 242 | sv.drm_dd_minor = -1; |
| 243 | err = drmSetInterfaceVersion(fd, &sv); |
| 244 | if (err) { |
| 245 | EARLY_ERROR_MSG( |
| 246 | "Cannot set the DRM interface version."); |
| 247 | goto fail1; |
| 248 | } |
| 249 | /* get the bus id */ |
| 250 | bus_id = drmGetBusid(fd); |
| 251 | if (!bus_id) { |
| 252 | EARLY_ERROR_MSG("Couldn't get BusID from %s", |
| 253 | filename); |
| 254 | goto fail1; |
| 255 | } |
| 256 | EARLY_INFO_MSG("Got BusID %s", bus_id); |
| 257 | bus_id_copy = malloc(strlen(bus_id)+1); |
| 258 | if (!bus_id_copy) { |
| 259 | EARLY_ERROR_MSG("Memory alloc failed"); |
| 260 | goto fail1; |
| 261 | } |
| 262 | strcpy(bus_id_copy, bus_id); |
| 263 | drmFreeBusid(bus_id); |
| 264 | err = close(fd); |
| 265 | if (err) { |
| 266 | free(bus_id_copy); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 267 | EARLY_ERROR_MSG("Couldn't close %s", filename); |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 268 | goto fail2; |
| 269 | } |
| 270 | /* use bus_id to open driver */ |
| 271 | fd = drmOpen(NULL, bus_id_copy); |
| 272 | free(bus_id_copy); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 273 | if (fd < 0) |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 274 | goto fail2; |
| 275 | } |
| 276 | ARMSOCShowDriverInfo(fd); |
| 277 | return fd; |
| 278 | |
| 279 | fail1: |
| 280 | close(fd); |
| 281 | fail2: |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 282 | EARLY_ERROR_MSG( |
| 283 | "Cannot open a connection with the DRM - %s", |
| 284 | strerror(errno)); |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 285 | return -1; |
| 286 | } |
| 287 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 288 | static Bool |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 289 | ARMSOCOpenDRM(ScrnInfoPtr pScrn) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 290 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 291 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 292 | drmSetVersion sv; |
| 293 | int err; |
| 294 | |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 295 | if (connection.fd < 0) { |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 296 | assert(!connection.open_count); |
| 297 | assert(!connection.master_count); |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 298 | pARMSOC->drmFD = ARMSOCOpenDRMCard(); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 299 | if (pARMSOC->drmFD < 0) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 300 | return FALSE; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 301 | /* Check that what we are or can become drm master by |
| 302 | * attempting a drmSetInterfaceVersion(). If successful |
| 303 | * this leaves us as master. |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 304 | * (see DRIOpenDRMMaster() in DRI1) |
| 305 | */ |
| 306 | sv.drm_di_major = 1; |
| 307 | sv.drm_di_minor = 1; |
| 308 | sv.drm_dd_major = -1; |
| 309 | sv.drm_dd_minor = -1; |
| 310 | err = drmSetInterfaceVersion(pARMSOC->drmFD, &sv); |
| 311 | if (err != 0) { |
| 312 | ERROR_MSG("Cannot set the DRM interface version."); |
| 313 | drmClose(pARMSOC->drmFD); |
| 314 | pARMSOC->drmFD = -1; |
| 315 | return FALSE; |
| 316 | } |
| 317 | connection.fd = pARMSOC->drmFD; |
| 318 | connection.open_count = 1; |
| 319 | connection.master_count = 1; |
Ray Smith | 04af999 | 2013-06-26 13:44:54 +0100 | [diff] [blame] | 320 | drmmode_init_wakeup_handler(connection.fd); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 321 | } else { |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 322 | assert(connection.open_count); |
| 323 | connection.open_count++; |
| 324 | connection.master_count++; |
| 325 | pARMSOC->drmFD = connection.fd; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 326 | } |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 327 | pARMSOC->deviceName = drmGetDeviceNameFromFd(pARMSOC->drmFD); |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 328 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 329 | return TRUE; |
| 330 | } |
| 331 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 332 | /** |
| 333 | * Helper function for closing a connection to the DRM. |
| 334 | */ |
| 335 | static void |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 336 | ARMSOCCloseDRM(ScrnInfoPtr pScrn) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 337 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 338 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 339 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 340 | if (pARMSOC && (pARMSOC->drmFD >= 0)) { |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 341 | drmFree(pARMSOC->deviceName); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 342 | connection.open_count--; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 343 | if (!connection.open_count) { |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 344 | assert(!connection.master_count); |
Ray Smith | 04af999 | 2013-06-26 13:44:54 +0100 | [diff] [blame] | 345 | drmmode_fini_wakeup_handler(connection.fd); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 346 | drmClose(pARMSOC->drmFD); |
| 347 | connection.fd = -1; |
| 348 | } |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 349 | pARMSOC->drmFD = -1; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
David Garbett | dccb73f | 2013-09-02 11:48:21 +0100 | [diff] [blame] | 353 | static Bool ARMSOCCopyFB(ScrnInfoPtr pScrn, const char *fb_dev) |
| 354 | { |
| 355 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
| 356 | int src_cpp; |
| 357 | uint32_t src_pitch; |
| 358 | int src_pixman_stride; |
| 359 | int dst_pixman_stride; |
| 360 | int dst_width, dst_height, dst_bpp, dst_pitch; |
| 361 | unsigned int src_size = 0; |
| 362 | unsigned char *src = NULL, *dst = NULL; |
| 363 | struct fb_var_screeninfo vinfo; |
| 364 | int fd = -1; |
| 365 | int width, height; |
| 366 | pixman_bool_t pixman_ret; |
| 367 | Bool ret = FALSE; |
| 368 | |
| 369 | dst = armsoc_bo_map(pARMSOC->scanout); |
| 370 | if (!dst) { |
| 371 | ERROR_MSG("Couldn't map scanout bo"); |
| 372 | goto exit; |
| 373 | } |
| 374 | |
| 375 | fd = open(fb_dev, O_RDONLY | O_SYNC); |
| 376 | if (fd == -1) { |
| 377 | ERROR_MSG("Couldn't open %s", fb_dev); |
| 378 | goto exit; |
| 379 | } |
| 380 | |
| 381 | if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { |
| 382 | ERROR_MSG("Vscreeninfo ioctl failed"); |
| 383 | goto exit; |
| 384 | } |
| 385 | |
| 386 | src_cpp = (vinfo.bits_per_pixel + 7) / 8; |
| 387 | src_pitch = vinfo.xres_virtual * src_cpp; |
| 388 | src_size = vinfo.yres_virtual * src_pitch; |
| 389 | |
| 390 | src = mmap(NULL, src_size, PROT_READ, MAP_SHARED, fd, 0); |
| 391 | if (src == MAP_FAILED) { |
| 392 | ERROR_MSG("Couldn't mmap %s", fb_dev); |
| 393 | goto exit; |
| 394 | } |
| 395 | |
| 396 | dst_width = armsoc_bo_width(pARMSOC->scanout); |
| 397 | dst_height = armsoc_bo_height(pARMSOC->scanout); |
| 398 | dst_bpp = armsoc_bo_bpp(pARMSOC->scanout); |
| 399 | dst_pitch = armsoc_bo_pitch(pARMSOC->scanout); |
| 400 | |
| 401 | width = min(vinfo.xres, dst_width); |
| 402 | height = min(vinfo.yres, dst_height); |
| 403 | |
| 404 | /* The stride parameters pixman takes are in multiples of uint32_t, |
| 405 | * which is the data type of the pointer passed */ |
| 406 | src_pixman_stride = src_pitch/sizeof(uint32_t); |
| 407 | dst_pixman_stride = dst_pitch/sizeof(uint32_t); |
| 408 | |
| 409 | /* We could handle the cases where stride is not a multiple of uint32_t, |
| 410 | * but they will be rare so not currently worth the added complexity */ |
| 411 | if (src_pitch%sizeof(uint32_t) || dst_pitch%sizeof(uint32_t)) { |
| 412 | ERROR_MSG( |
| 413 | "Buffer strides need to be a multiple of 4 bytes to initialize from fbdev device"); |
| 414 | goto exit; |
| 415 | } |
| 416 | |
| 417 | /* similarly using pixman_blt doesn't allow for format conversion, so |
| 418 | * check if they don't match and print a message */ |
| 419 | if (vinfo.bits_per_pixel != dst_bpp || vinfo.grayscale != 0 || |
| 420 | vinfo.nonstd != 0 || |
| 421 | vinfo.red.offset != pScrn->offset.red || |
| 422 | vinfo.red.length != pScrn->weight.red || |
| 423 | vinfo.red.msb_right != 0 || |
| 424 | vinfo.green.offset != pScrn->offset.green || |
| 425 | vinfo.green.length != pScrn->weight.green || |
| 426 | vinfo.green.msb_right != 0 || |
| 427 | vinfo.blue.offset != pScrn->offset.blue || |
| 428 | vinfo.blue.length != pScrn->weight.blue || |
| 429 | vinfo.blue.msb_right != 0) { |
| 430 | ERROR_MSG("Format of %s does not match scanout buffer", fb_dev); |
| 431 | goto exit; |
| 432 | } |
| 433 | |
| 434 | armsoc_bo_cpu_prep(pARMSOC->scanout, ARMSOC_GEM_WRITE); |
| 435 | |
| 436 | /* NB: We have to call pixman direct instead of wrapping the buffers as |
| 437 | * Pixmaps as this function is called from ScreenInit. Pixmaps cannot be |
| 438 | * created until X calls CreateScratchPixmapsForScreen(), and the screen |
| 439 | * pixmap is not initialized until X calls CreateScreenResources */ |
| 440 | pixman_ret = pixman_blt((uint32_t *)src, (uint32_t *)dst, |
| 441 | src_pixman_stride, dst_pixman_stride, |
| 442 | vinfo.bits_per_pixel, dst_bpp, vinfo.xoffset, |
| 443 | vinfo.yoffset, 0, 0, width, height); |
| 444 | if (!pixman_ret) { |
| 445 | armsoc_bo_cpu_fini(pARMSOC->scanout, 0); |
| 446 | ERROR_MSG("Pixman failed to blit from %s to scanout buffer", |
| 447 | fb_dev); |
| 448 | goto exit; |
| 449 | } |
| 450 | |
| 451 | /* fill any area not covered by the blit */ |
| 452 | if (width < dst_width) { |
| 453 | pixman_ret = pixman_fill((uint32_t *)dst, dst_pixman_stride, |
| 454 | dst_bpp, width, 0, dst_width-width, dst_height, |
| 455 | 0); |
| 456 | if (!pixman_ret) { |
| 457 | armsoc_bo_cpu_fini(pARMSOC->scanout, 0); |
| 458 | ERROR_MSG( |
| 459 | "Pixman failed to fill margin of scanout buffer"); |
| 460 | goto exit; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if (height < dst_height) { |
| 465 | pixman_ret = pixman_fill((uint32_t *)dst, dst_pixman_stride, |
| 466 | dst_bpp, 0, height, width, dst_height-height, |
| 467 | 0); |
| 468 | if (!pixman_ret) { |
| 469 | armsoc_bo_cpu_fini(pARMSOC->scanout, 0); |
| 470 | ERROR_MSG( |
| 471 | "Pixman failed to fill margin of scanout buffer"); |
| 472 | goto exit; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | armsoc_bo_cpu_fini(pARMSOC->scanout, 0); |
| 477 | |
| 478 | ret = TRUE; |
| 479 | |
| 480 | exit: |
| 481 | if (src) |
| 482 | munmap(src, src_size); |
| 483 | |
| 484 | if (fd >= 0) |
| 485 | close(fd); |
| 486 | |
| 487 | return ret; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 492 | /** Let the XFree86 code know the Setup() function. */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 493 | static MODULESETUPPROTO(ARMSOCSetup); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 494 | |
| 495 | /** Provide basic version information to the XFree86 code. */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 496 | static XF86ModuleVersionInfo ARMSOCVersRec = { |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 497 | ARMSOC_DRIVER_NAME, |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 498 | MODULEVENDORSTRING, |
| 499 | MODINFOSTRING1, |
| 500 | MODINFOSTRING2, |
| 501 | XORG_VERSION_CURRENT, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 502 | PACKAGE_VERSION_MAJOR, |
| 503 | PACKAGE_VERSION_MINOR, |
| 504 | PACKAGE_VERSION_PATCHLEVEL, |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 505 | ABI_CLASS_VIDEODRV, |
| 506 | ABI_VIDEODRV_VERSION, |
| 507 | MOD_CLASS_VIDEODRV, |
| 508 | {0, 0, 0, 0} |
| 509 | }; |
| 510 | |
| 511 | /** Let the XFree86 code know about the VersRec and Setup() function. */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 512 | _X_EXPORT XF86ModuleData armsocModuleData = { &ARMSOCVersRec, ARMSOCSetup, NULL }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 513 | |
| 514 | |
| 515 | /** |
| 516 | * The first function that the XFree86 code calls, after loading this module. |
| 517 | */ |
| 518 | static pointer |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 519 | ARMSOCSetup(pointer module, pointer opts, int *errmaj, int *errmin) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 520 | { |
| 521 | static Bool setupDone = FALSE; |
| 522 | |
| 523 | /* This module should be loaded only once, but check to be sure: */ |
| 524 | if (!setupDone) { |
| 525 | setupDone = TRUE; |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 526 | xf86AddDriver(&ARMSOC, module, 0); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 527 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 528 | /* The return value must be non-NULL on success even |
| 529 | * though there is no TearDownProc. |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 530 | */ |
| 531 | return (pointer) 1; |
| 532 | } else { |
| 533 | if (errmaj) |
| 534 | *errmaj = LDR_ONCEONLY; |
| 535 | return NULL; |
| 536 | } |
| 537 | } |
| 538 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 539 | /** |
| 540 | * The mandatory AvailableOptions() function. It returns the available driver |
| 541 | * options to the "-configure" option, so that an xorg.conf file can be built |
| 542 | * and the user can see which options are available for them to use. |
| 543 | */ |
| 544 | static const OptionInfoRec * |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 545 | ARMSOCAvailableOptions(int chipid, int busid) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 546 | { |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 547 | return ARMSOCOptions; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
| 551 | |
| 552 | /** |
| 553 | * The mandatory Identify() function. It is run before Probe(), and prints out |
| 554 | * an identifying message, which includes the chipset(s) the driver supports. |
| 555 | */ |
| 556 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 557 | ARMSOCIdentify(int flags) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 558 | { |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 559 | xf86PrintChipsets(ARMSOC_NAME, "Driver for ARM compatible chipsets", |
| 560 | ARMSOCChipsets); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
| 564 | |
| 565 | /** |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 566 | * The driver's Probe() function. This function finds all instances of |
| 567 | * ARM hardware that the driver supports (from within the "xorg.conf" |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 568 | * device sections), and for instances not already claimed by another driver, |
| 569 | * claim the instances, and allocate a ScrnInfoRec. Only minimal hardware |
| 570 | * probing is allowed here. |
| 571 | */ |
| 572 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 573 | ARMSOCProbe(DriverPtr drv, int flags) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 574 | { |
| 575 | int i; |
| 576 | ScrnInfoPtr pScrn; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 577 | GDevPtr *devSections = NULL; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 578 | int numDevSections; |
| 579 | Bool foundScreen = FALSE; |
| 580 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 581 | /* Get the "xorg.conf" file device sections that match this driver, and |
| 582 | * return (error out) if there are none: |
| 583 | */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 584 | numDevSections = xf86MatchDevice(ARMSOC_DRIVER_NAME, &devSections); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 585 | if (numDevSections <= 0) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 586 | EARLY_ERROR_MSG( |
| 587 | "Did not find any matching device section in configuration file"); |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 588 | if (flags & PROBE_DETECT) { |
| 589 | /* if we are probing, assume one and lets see if we can |
| 590 | * open the device to confirm it is there: |
| 591 | */ |
| 592 | numDevSections = 1; |
| 593 | } else { |
| 594 | return FALSE; |
| 595 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | for (i = 0; i < numDevSections; i++) { |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 599 | int fd; |
| 600 | |
| 601 | if (devSections) { |
Ray Smith | b31657f | 2013-06-25 11:47:36 +0100 | [diff] [blame] | 602 | const char *busIdStr; |
| 603 | const char *driverNameStr; |
| 604 | const char *cardNumStr; |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 605 | |
| 606 | /* get the Bus ID */ |
| 607 | busIdStr = xf86FindOptionValue( |
| 608 | devSections[i]->options, |
| 609 | "BusID"); |
| 610 | |
| 611 | /* get the DriverName */ |
| 612 | driverNameStr = xf86FindOptionValue( |
| 613 | devSections[i]->options, |
| 614 | "DriverName"); |
| 615 | |
| 616 | /* get the card_num from xorg.conf if present */ |
| 617 | cardNumStr = xf86FindOptionValue( |
| 618 | devSections[i]->options, |
| 619 | "DRICard"); |
| 620 | |
| 621 | if (busIdStr && driverNameStr) { |
| 622 | EARLY_WARNING_MSG( |
| 623 | "Option DriverName ignored (BusID is specified)"); |
| 624 | } |
| 625 | if (busIdStr || driverNameStr) { |
| 626 | if (cardNumStr) { |
| 627 | EARLY_WARNING_MSG( |
| 628 | "Option DRICard ignored (BusID or DriverName are specified)"); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | if (busIdStr) { |
| 633 | if (0 == strlen(busIdStr)) { |
| 634 | EARLY_ERROR_MSG( |
| 635 | "Missing value for Option BusID"); |
| 636 | return FALSE; |
| 637 | } |
| 638 | connection.bus_id = busIdStr; |
| 639 | } else if (driverNameStr) { |
| 640 | if (0 == strlen(driverNameStr)) { |
| 641 | EARLY_ERROR_MSG( |
| 642 | "Missing value for Option DriverName"); |
| 643 | return FALSE; |
| 644 | } |
Ray Smith | b31657f | 2013-06-25 11:47:36 +0100 | [diff] [blame] | 645 | connection.driver_name = driverNameStr; |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 646 | } else if (cardNumStr) { |
| 647 | char *endptr; |
| 648 | errno = 0; |
| 649 | connection.card_num = strtol(cardNumStr, |
| 650 | &endptr, 10); |
| 651 | if (('\0' == *cardNumStr) || |
| 652 | ('\0' != *endptr) || |
| 653 | (errno != 0)) { |
| 654 | EARLY_ERROR_MSG( |
| 655 | "Bad Option DRICard value : %s", |
| 656 | cardNumStr); |
| 657 | return FALSE; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | fd = ARMSOCOpenDRMCard(); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 662 | if (fd >= 0) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 663 | struct ARMSOCRec *pARMSOC; |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 664 | |
| 665 | /* Allocate the ScrnInfoRec */ |
| 666 | pScrn = xf86AllocateScreen(drv, 0); |
| 667 | if (!pScrn) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 668 | EARLY_ERROR_MSG( |
| 669 | "Cannot allocate a ScrnInfoPtr"); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 670 | return FALSE; |
| 671 | } |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 672 | /* Allocate the driver's Screen-specific, "private" |
| 673 | * data structure and hook it into the ScrnInfoRec's |
| 674 | * driverPrivate field. |
| 675 | */ |
| 676 | pScrn->driverPrivate = |
| 677 | calloc(1, sizeof(struct ARMSOCRec)); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 678 | if (!pScrn->driverPrivate) |
| 679 | return FALSE; |
| 680 | |
| 681 | pARMSOC = ARMSOCPTR(pScrn); |
Dave Barnish | 1a3dac3 | 2013-06-20 19:01:38 +0100 | [diff] [blame] | 682 | /* initially mark to use all DRM crtcs */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 683 | pARMSOC->crtcNum = -1; |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 684 | |
| 685 | if (flags & PROBE_DETECT) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 686 | /* just add the device.. we aren't a PCI device, |
| 687 | * so call xf86AddBusDeviceToConfigure() |
| 688 | * directly |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 689 | */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 690 | xf86AddBusDeviceToConfigure(ARMSOC_DRIVER_NAME, |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 691 | BUS_NONE, NULL, i); |
| 692 | foundScreen = TRUE; |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 693 | drmClose(fd); |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 694 | continue; |
| 695 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 696 | |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 697 | if (devSections) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 698 | int entity = xf86ClaimNoSlot(drv, 0, |
| 699 | devSections[i], TRUE); |
Rob Clark | 83f49e0 | 2012-01-08 17:31:59 -0600 | [diff] [blame] | 700 | xf86AddEntityToScreen(pScrn, entity); |
| 701 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 702 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 703 | /* if there are multiple screens, use a separate |
| 704 | * crtc for each one |
| 705 | */ |
| 706 | if (numDevSections > 1) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 707 | pARMSOC->crtcNum = i; |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 708 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 709 | xf86Msg(X_INFO, "Screen:%d, CRTC:%d\n", |
| 710 | pScrn->scrnIndex, |
| 711 | pARMSOC->crtcNum); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 712 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 713 | foundScreen = TRUE; |
| 714 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 715 | pScrn->driverVersion = ARMSOC_VERSION; |
| 716 | pScrn->driverName = (char *)ARMSOC_DRIVER_NAME; |
| 717 | pScrn->name = (char *)ARMSOC_NAME; |
| 718 | pScrn->Probe = ARMSOCProbe; |
| 719 | pScrn->PreInit = ARMSOCPreInit; |
| 720 | pScrn->ScreenInit = ARMSOCScreenInit; |
| 721 | pScrn->SwitchMode = ARMSOCSwitchMode; |
| 722 | pScrn->AdjustFrame = ARMSOCAdjustFrame; |
| 723 | pScrn->EnterVT = ARMSOCEnterVT; |
| 724 | pScrn->LeaveVT = ARMSOCLeaveVT; |
| 725 | pScrn->FreeScreen = ARMSOCFreeScreen; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 726 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 727 | /* would be nice to keep the connection open */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 728 | drmClose(fd); |
| 729 | } |
| 730 | } |
| 731 | free(devSections); |
| 732 | return foundScreen; |
| 733 | } |
| 734 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 735 | /** |
| 736 | * The driver's PreInit() function. Additional hardware probing is allowed |
| 737 | * now, including display configuration. |
| 738 | */ |
| 739 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 740 | ARMSOCPreInit(ScrnInfoPtr pScrn, int flags) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 741 | { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 742 | struct ARMSOCRec *pARMSOC; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 743 | int default_depth, fbbpp; |
| 744 | rgb defaultWeight = { 0, 0, 0 }; |
| 745 | rgb defaultMask = { 0, 0, 0 }; |
| 746 | Gamma defaultGamma = { 0.0, 0.0, 0.0 }; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 747 | int i; |
David Garbett | 4d37be3 | 2013-04-04 09:04:29 +0100 | [diff] [blame] | 748 | int driNumBufs; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 749 | |
| 750 | TRACE_ENTER(); |
| 751 | |
| 752 | if (flags & PROBE_DETECT) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 753 | ERROR_MSG( |
| 754 | "The %s driver does not support the \"-configure\" or \"-probe\" command line arguments.", |
| 755 | ARMSOC_NAME); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 756 | return FALSE; |
| 757 | } |
| 758 | |
| 759 | /* Check the number of entities, and fail if it isn't one. */ |
| 760 | if (pScrn->numEntities != 1) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 761 | ERROR_MSG( |
| 762 | "Driver expected 1 entity, but found %d for screen %d", |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 763 | pScrn->numEntities, pScrn->scrnIndex); |
| 764 | return FALSE; |
| 765 | } |
| 766 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 767 | pARMSOC = ARMSOCPTR(pScrn); |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 768 | pARMSOC->pEntityInfo = xf86GetEntityInfo(pScrn->entityList[0]); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 769 | |
| 770 | pScrn->monitor = pScrn->confScreen->monitor; |
| 771 | |
| 772 | /* Get the current depth, and set it for XFree86: */ |
Dave Barnish | 2742d15 | 2013-03-13 13:36:58 +0000 | [diff] [blame] | 773 | default_depth = 24; /* TODO: MIDEGL-1445: get from kernel */ |
| 774 | fbbpp = 32; /* TODO: MIDEGL-1445: get from kernel */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 775 | |
| 776 | if (!xf86SetDepthBpp(pScrn, default_depth, 0, fbbpp, Support32bppFb)) { |
| 777 | /* The above function prints an error message. */ |
| 778 | goto fail; |
| 779 | } |
| 780 | xf86PrintDepthBpp(pScrn); |
| 781 | |
| 782 | /* Set the color weight: */ |
| 783 | if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) { |
| 784 | /* The above function prints an error message. */ |
| 785 | goto fail; |
| 786 | } |
| 787 | |
| 788 | /* Set the gamma: */ |
| 789 | if (!xf86SetGamma(pScrn, defaultGamma)) { |
| 790 | /* The above function prints an error message. */ |
| 791 | goto fail; |
| 792 | } |
| 793 | |
| 794 | /* Visual init: */ |
| 795 | if (!xf86SetDefaultVisual(pScrn, -1)) { |
| 796 | /* The above function prints an error message. */ |
| 797 | goto fail; |
| 798 | } |
| 799 | |
| 800 | /* We don't support 8-bit depths: */ |
| 801 | if (pScrn->depth < 16) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 802 | ERROR_MSG( |
| 803 | "The requested default visual (%s) has an unsupported depth (%d).", |
| 804 | xf86GetVisualName(pScrn->defaultVisual), |
| 805 | pScrn->depth); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 806 | goto fail; |
| 807 | } |
| 808 | |
| 809 | /* Using a programmable clock: */ |
| 810 | pScrn->progClock = TRUE; |
| 811 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 812 | /* Open a connection to the DRM, so we can communicate |
| 813 | * with the KMS code: |
| 814 | */ |
| 815 | if (!ARMSOCOpenDRM(pScrn)) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 816 | goto fail; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 817 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 818 | pARMSOC->drmmode_interface = |
| 819 | drmmode_interface_get_implementation(pARMSOC->drmFD); |
Dave Barnish | de45ed4 | 2013-06-05 13:47:56 +0100 | [diff] [blame] | 820 | if (!pARMSOC->drmmode_interface) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 821 | goto fail2; |
Ray Smith | 3c33c3d | 2013-03-26 16:06:37 +0000 | [diff] [blame] | 822 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 823 | /* create DRM device instance: */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 824 | pARMSOC->dev = armsoc_device_new(pARMSOC->drmFD, |
Javier Martin | 981264d | 2013-08-21 16:48:07 +0100 | [diff] [blame] | 825 | pARMSOC->drmmode_interface->create_custom_gem); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 826 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 827 | /* find matching chipset name: */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 828 | for (i = 0; ARMSOCChipsets[i].name; i++) { |
| 829 | if (ARMSOCChipsets[i].token == MALI_T6XX_CHIPSET_ID) { |
| 830 | pScrn->chipset = (char *)ARMSOCChipsets[i].name; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 831 | break; |
| 832 | } |
| 833 | } |
| 834 | |
Dave Barnish | 01b5c17 | 2013-04-10 11:01:17 +0100 | [diff] [blame] | 835 | INFO_MSG("Chipset: %s", pScrn->chipset); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 836 | |
| 837 | /* |
| 838 | * Process the "xorg.conf" file options: |
| 839 | */ |
| 840 | xf86CollectOptions(pScrn, NULL); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 841 | pARMSOC->pOptionInfo = calloc(1, sizeof(ARMSOCOptions)); |
| 842 | if (!pARMSOC->pOptionInfo) |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 843 | goto fail2; |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 844 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 845 | memcpy(pARMSOC->pOptionInfo, ARMSOCOptions, sizeof(ARMSOCOptions)); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 846 | xf86ProcessOptions(pScrn->scrnIndex, |
| 847 | pARMSOC->pEntityInfo->device->options, |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 848 | pARMSOC->pOptionInfo); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 849 | |
| 850 | /* Determine if the user wants debug messages turned on: */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 851 | armsocDebug = xf86ReturnOptValBool(pARMSOC->pOptionInfo, |
| 852 | OPTION_DEBUG, FALSE); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 853 | |
David Garbett | 4d37be3 | 2013-04-04 09:04:29 +0100 | [diff] [blame] | 854 | if (!xf86GetOptValInteger(pARMSOC->pOptionInfo, OPTION_DRI_NUM_BUF, |
| 855 | &driNumBufs)) { |
| 856 | /* Default to double buffering */ |
| 857 | driNumBufs = 2; |
| 858 | } |
| 859 | |
| 860 | if (driNumBufs < 2) { |
| 861 | ERROR_MSG( |
| 862 | "Invalid option for %s: %d. Must be greater than or equal to 2", |
| 863 | xf86TokenToOptName(pARMSOC->pOptionInfo, |
| 864 | OPTION_DRI_NUM_BUF), |
| 865 | driNumBufs); |
| 866 | return FALSE; |
| 867 | } |
| 868 | pARMSOC->driNumBufs = driNumBufs; |
Dave Barnish | c50baf5 | 2012-11-29 14:39:36 +0000 | [diff] [blame] | 869 | /* Determine if user wants to disable buffer flipping: */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 870 | pARMSOC->NoFlip = xf86ReturnOptValBool(pARMSOC->pOptionInfo, |
Dave Barnish | c50baf5 | 2012-11-29 14:39:36 +0000 | [diff] [blame] | 871 | OPTION_NO_FLIP, FALSE); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 872 | INFO_MSG("Buffer Flipping is %s", |
| 873 | pARMSOC->NoFlip ? "Disabled" : "Enabled"); |
Dave Barnish | c50baf5 | 2012-11-29 14:39:36 +0000 | [diff] [blame] | 874 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 875 | /* |
| 876 | * Select the video modes: |
| 877 | */ |
| 878 | INFO_MSG("Setting the video modes ..."); |
| 879 | |
| 880 | /* Don't call drmCheckModesettingSupported() as its written only for |
| 881 | * PCI devices. |
| 882 | */ |
| 883 | |
| 884 | /* Do initial KMS setup: */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 885 | if (!drmmode_pre_init(pScrn, pARMSOC->drmFD, |
| 886 | (pScrn->bitsPerPixel >> 3))) { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 887 | ERROR_MSG("Cannot get KMS resources"); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 888 | goto fail2; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 889 | } else { |
| 890 | INFO_MSG("Got KMS resources"); |
| 891 | } |
| 892 | |
| 893 | xf86RandR12PreInit(pScrn); |
| 894 | |
| 895 | /* Let XFree86 calculate or get (from command line) the display DPI: */ |
| 896 | xf86SetDpi(pScrn, 0, 0); |
| 897 | |
| 898 | /* Ensure we have a supported depth: */ |
| 899 | switch (pScrn->bitsPerPixel) { |
| 900 | case 16: |
| 901 | case 24: |
| 902 | case 32: |
| 903 | break; |
| 904 | default: |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 905 | ERROR_MSG( |
| 906 | "The requested number of bits per pixel (%d) is unsupported.", |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 907 | pScrn->bitsPerPixel); |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 908 | goto fail2; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | |
| 912 | /* Load external sub-modules now: */ |
| 913 | |
| 914 | if (!(xf86LoadSubModule(pScrn, "dri2") && |
| 915 | xf86LoadSubModule(pScrn, "exa") && |
| 916 | xf86LoadSubModule(pScrn, "fb"))) { |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 917 | goto fail2; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 918 | } |
| 919 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 920 | TRACE_EXIT(); |
| 921 | return TRUE; |
| 922 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 923 | fail2: |
| 924 | /* Cleanup here where we know whether we took a connection |
| 925 | * instead of in FreeScreen where we don't */ |
| 926 | ARMSOCDropDRMMaster(); |
| 927 | ARMSOCCloseDRM(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 928 | fail: |
| 929 | TRACE_EXIT(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 930 | return FALSE; |
| 931 | } |
| 932 | |
| 933 | |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 934 | /** |
| 935 | * Initialize EXA and DRI2 |
| 936 | */ |
| 937 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 938 | ARMSOCAccelInit(ScreenPtr pScreen) |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 939 | { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 940 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 941 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 942 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 943 | if (!pARMSOC->pARMSOCEXA) |
| 944 | pARMSOC->pARMSOCEXA = InitNullEXA(pScreen, pScrn, |
| 945 | pARMSOC->drmFD); |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 946 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 947 | if (pARMSOC->pARMSOCEXA) |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 948 | pARMSOC->dri = ARMSOCDRI2ScreenInit(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 949 | else |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 950 | pARMSOC->dri = FALSE; |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 951 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 952 | |
| 953 | /** |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 954 | * The driver's ScreenInit() function, called at the start of each server |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 955 | * generation. Fill in pScreen, map the frame buffer, save state, |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 956 | * initialize the mode, etc. |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 957 | */ |
| 958 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 959 | ARMSOCScreenInit(SCREEN_INIT_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 960 | { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 961 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 962 | #ifndef XF86_SCRN_INTERFACE |
| 963 | int scrnIndex = pScrn->scrnIndex; |
| 964 | #endif |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 965 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 966 | VisualPtr visual; |
| 967 | xf86CrtcConfigPtr xf86_config; |
David Garbett | 82b5183 | 2012-07-04 08:29:38 +0100 | [diff] [blame] | 968 | int j; |
David Garbett | dccb73f | 2013-09-02 11:48:21 +0100 | [diff] [blame] | 969 | char *fbdev; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 970 | |
| 971 | TRACE_ENTER(); |
| 972 | |
Dave Barnish | 982518c | 2013-04-22 16:09:22 +0100 | [diff] [blame] | 973 | /* set drm master before allocating scanout buffer */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 974 | if (ARMSOCSetDRMMaster()) { |
Dave Barnish | 982518c | 2013-04-22 16:09:22 +0100 | [diff] [blame] | 975 | ERROR_MSG("Cannot get DRM master: %s", strerror(errno)); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 976 | goto fail; |
Dave Barnish | 982518c | 2013-04-22 16:09:22 +0100 | [diff] [blame] | 977 | } |
Dave Barnish | 52faee0 | 2013-04-22 13:28:42 +0100 | [diff] [blame] | 978 | /* Allocate initial scanout buffer */ |
| 979 | DEBUG_MSG("allocating new scanout buffer: %dx%d", |
| 980 | pScrn->virtualX, pScrn->virtualY); |
Dave Barnish | 52faee0 | 2013-04-22 13:28:42 +0100 | [diff] [blame] | 981 | assert(!pARMSOC->scanout); |
| 982 | pARMSOC->scanout = armsoc_bo_new_with_dim(pARMSOC->dev, pScrn->virtualX, |
| 983 | pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 984 | ARMSOC_BO_SCANOUT); |
Dave Barnish | 52faee0 | 2013-04-22 13:28:42 +0100 | [diff] [blame] | 985 | if (!pARMSOC->scanout) { |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 986 | ERROR_MSG("Cannot allocate scanout buffer\n"); |
| 987 | goto fail1; |
Dave Barnish | 52faee0 | 2013-04-22 13:28:42 +0100 | [diff] [blame] | 988 | } |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 989 | pScrn->displayWidth = armsoc_bo_pitch(pARMSOC->scanout) / |
| 990 | ((pScrn->bitsPerPixel+7) / 8); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 991 | xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); |
| 992 | |
| 993 | /* need to point to new screen on server regeneration */ |
David Garbett | 82b5183 | 2012-07-04 08:29:38 +0100 | [diff] [blame] | 994 | for (j = 0; j < xf86_config->num_crtc; j++) |
| 995 | xf86_config->crtc[j]->scrn = pScrn; |
| 996 | for (j = 0; j < xf86_config->num_output; j++) |
| 997 | xf86_config->output[j]->scrn = pScrn; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 998 | |
| 999 | /* |
| 1000 | * The next step is to setup the screen's visuals, and initialize the |
| 1001 | * framebuffer code. In cases where the framebuffer's default |
| 1002 | * choices for things like visual layouts and bits per RGB are OK, |
| 1003 | * this may be as simple as calling the framebuffer's ScreenInit() |
| 1004 | * function. If not, the visuals will need to be setup before calling |
| 1005 | * a fb ScreenInit() function and fixed up after. |
| 1006 | * |
| 1007 | * For most PC hardware at depths >= 8, the defaults that fb uses |
| 1008 | * are not appropriate. In this driver, we fixup the visuals after. |
| 1009 | */ |
| 1010 | |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1011 | /* Reset the visual list. */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1012 | miClearVisualTypes(); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1013 | if (!miSetVisualTypes(pScrn->bitsPerPixel, |
| 1014 | miGetDefaultVisualMask(pScrn->depth), |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1015 | pScrn->rgbBits, pScrn->defaultVisual)) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1016 | ERROR_MSG( |
| 1017 | "Cannot initialize the visual type for %d bits per pixel!", |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1018 | pScrn->bitsPerPixel); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1019 | goto fail2; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1020 | } |
| 1021 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1022 | if (pScrn->bitsPerPixel == 32 && pScrn->depth == 24) { |
David Garbett | ef4b748 | 2012-09-26 14:09:01 +0100 | [diff] [blame] | 1023 | /* Also add a 24 bit depth visual */ |
| 1024 | if (!miSetVisualTypes(24, miGetDefaultVisualMask(pScrn->depth), |
| 1025 | pScrn->rgbBits, pScrn->defaultVisual)) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1026 | WARNING_MSG( |
| 1027 | "Cannot initialize a 24 depth visual for 32bpp"); |
| 1028 | } else { |
David Garbett | ef4b748 | 2012-09-26 14:09:01 +0100 | [diff] [blame] | 1029 | INFO_MSG("Initialized a 24 depth visual for 32bpp"); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1033 | if (!miSetPixmapDepths()) { |
| 1034 | ERROR_MSG("Cannot initialize the pixmap depth!"); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1035 | goto fail3; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /* Initialize some generic 2D drawing functions: */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1039 | if (!fbScreenInit(pScreen, armsoc_bo_map(pARMSOC->scanout), |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1040 | pScrn->virtualX, pScrn->virtualY, |
| 1041 | pScrn->xDpi, pScrn->yDpi, pScrn->displayWidth, |
| 1042 | pScrn->bitsPerPixel)) { |
| 1043 | ERROR_MSG("fbScreenInit() failed!"); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1044 | goto fail3; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | /* Fixup RGB ordering: */ |
| 1048 | visual = pScreen->visuals + pScreen->numVisuals; |
| 1049 | while (--visual >= pScreen->visuals) { |
| 1050 | if ((visual->class | DynamicClass) == DirectColor) { |
| 1051 | visual->offsetRed = pScrn->offset.red; |
| 1052 | visual->offsetGreen = pScrn->offset.green; |
| 1053 | visual->offsetBlue = pScrn->offset.blue; |
| 1054 | visual->redMask = pScrn->mask.red; |
| 1055 | visual->greenMask = pScrn->mask.green; |
| 1056 | visual->blueMask = pScrn->mask.blue; |
David Garbett | 100928b | 2012-10-03 14:20:54 +0100 | [diff] [blame] | 1057 | visual->bitsPerRGBValue = pScrn->rgbBits; |
| 1058 | visual->ColormapEntries = 1 << pScrn->rgbBits; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1062 | /* Continue initializing the generic 2D drawing functions after |
| 1063 | * fixing the RGB ordering: |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1064 | */ |
| 1065 | if (!fbPictureInit(pScreen, NULL, 0)) { |
| 1066 | ERROR_MSG("fbPictureInit() failed!"); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1067 | goto fail4; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /* Set the initial black & white colormap indices: */ |
| 1071 | xf86SetBlackWhitePixels(pScreen); |
| 1072 | |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 1073 | /* Initialize external sub-modules for EXA now, this has to be before |
| 1074 | * miDCInitialize() otherwise stacking order for wrapped ScreenPtr fxns |
| 1075 | * ends up in the wrong order. |
| 1076 | */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1077 | ARMSOCAccelInit(pScreen); |
Rob Clark | dc9dfae | 2012-01-11 18:20:18 -0600 | [diff] [blame] | 1078 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1079 | /* Initialize backing store: */ |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1080 | xf86SetBackingStore(pScreen); |
| 1081 | |
David Garbett | dccb73f | 2013-09-02 11:48:21 +0100 | [diff] [blame] | 1082 | fbdev = xf86GetOptValString(pARMSOC->pOptionInfo, |
| 1083 | OPTION_INIT_FROM_FBDEV); |
| 1084 | if (fbdev && *fbdev != '\0') { |
| 1085 | if (ARMSOCCopyFB(pScrn, fbdev)) { |
| 1086 | /* Only allow None BG root if we initialized the scanout |
| 1087 | * buffer */ |
| 1088 | pScreen->canDoBGNoneRoot = TRUE; |
| 1089 | } |
| 1090 | } |
| 1091 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1092 | /* Enable cursor position updates by mouse signal handler: */ |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 1093 | xf86SetSilkenMouse(pScreen); |
| 1094 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1095 | /* Initialize the cursor: */ |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1096 | if (!miDCInitialize(pScreen, xf86GetPointerScreenFuncs())) { |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1097 | ERROR_MSG("miDCInitialize() failed!"); |
| 1098 | goto fail5; |
Rob Clark | 687c608 | 2012-01-08 19:33:18 -0600 | [diff] [blame] | 1099 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1100 | |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1101 | /* ignore failures here as we will fall back to software cursor */ |
| 1102 | (void)drmmode_cursor_init(pScreen); |
| 1103 | |
| 1104 | /* TODO: MIDEGL-1458: Is this the right place for this? |
| 1105 | * The Intel i830 driver says: |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1106 | * "Must force it before EnterVT, so we are in control of VT..." |
| 1107 | */ |
| 1108 | pScrn->vtSema = TRUE; |
| 1109 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1110 | /* Take over the virtual terminal from the console, set the |
| 1111 | * desired mode, etc.: |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1112 | */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1113 | if (!ARMSOCEnterVT(VT_FUNC_ARGS(0))) { |
| 1114 | ERROR_MSG("ARMSOCEnterVT() failed!"); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1115 | goto fail6; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1116 | } |
| 1117 | |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1118 | /* Do some XRandR initialization. Return value is not useful */ |
| 1119 | (void)xf86CrtcScreenInit(pScreen); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1120 | |
| 1121 | if (!miCreateDefColormap(pScreen)) { |
| 1122 | ERROR_MSG("Cannot create colormap!"); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1123 | goto fail7; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1124 | } |
| 1125 | |
David Garbett | 100928b | 2012-10-03 14:20:54 +0100 | [diff] [blame] | 1126 | if (!xf86HandleColormaps(pScreen, 1 << pScrn->rgbBits, pScrn->rgbBits, |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1127 | ARMSOCLoadPalette, NULL, CMAP_PALETTED_TRUECOLOR)) { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1128 | ERROR_MSG("xf86HandleColormaps() failed!"); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1129 | goto fail8; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /* Setup power management: */ |
| 1133 | xf86DPMSInit(pScreen, xf86DPMSSet, 0); |
| 1134 | |
| 1135 | pScreen->SaveScreen = xf86SaveScreen; |
| 1136 | |
| 1137 | /* Wrap some screen functions: */ |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1138 | wrap(pARMSOC, pScreen, CloseScreen, ARMSOCCloseScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1139 | wrap(pARMSOC, pScreen, CreateScreenResources, |
| 1140 | ARMSOCCreateScreenResources); |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1141 | wrap(pARMSOC, pScreen, BlockHandler, ARMSOCBlockHandler); |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1142 | drmmode_screen_init(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1143 | |
| 1144 | TRACE_EXIT(); |
| 1145 | return TRUE; |
| 1146 | |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1147 | /* cleanup on failures */ |
| 1148 | fail8: |
| 1149 | /* uninstall the default colormap */ |
| 1150 | miUninstallColormap(GetInstalledmiColormap(pScreen)); |
| 1151 | |
| 1152 | fail7: |
| 1153 | ARMSOCLeaveVT(VT_FUNC_ARGS(0)); |
| 1154 | pScrn->vtSema = FALSE; |
| 1155 | |
| 1156 | fail6: |
| 1157 | drmmode_cursor_fini(pScreen); |
| 1158 | |
| 1159 | fail5: |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1160 | if (pARMSOC->dri) |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1161 | ARMSOCDRI2CloseScreen(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1162 | |
| 1163 | if (pARMSOC->pARMSOCEXA) |
| 1164 | if (pARMSOC->pARMSOCEXA->CloseScreen) |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 1165 | pARMSOC->pARMSOCEXA->CloseScreen(CLOSE_SCREEN_ARGS); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1166 | fail4: |
| 1167 | /* Call the CloseScreen functions for fbInitScreen, miDCInitialize, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1168 | * exaDriverInit & xf86CrtcScreenInit as appropriate via their |
| 1169 | * wrapped pointers. |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1170 | * exaDDXCloseScreen uses the XF86SCRNINFO macro so we must |
| 1171 | * set up the key for this before it gets called. |
| 1172 | */ |
| 1173 | dixSetPrivate(&pScreen->devPrivates, xf86ScreenKey, pScrn); |
Dave Barnish | dd94805 | 2013-06-25 16:52:37 +0100 | [diff] [blame] | 1174 | (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS); |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1175 | |
| 1176 | fail3: |
| 1177 | /* reset the visual list */ |
| 1178 | miClearVisualTypes(); |
| 1179 | |
| 1180 | fail2: |
| 1181 | /* release the scanout buffer */ |
| 1182 | armsoc_bo_unreference(pARMSOC->scanout); |
| 1183 | pARMSOC->scanout = NULL; |
| 1184 | pScrn->displayWidth = 0; |
| 1185 | |
| 1186 | fail1: |
| 1187 | /* drop drm master */ |
| 1188 | (void)drmDropMaster(pARMSOC->drmFD); |
| 1189 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1190 | fail: |
| 1191 | TRACE_EXIT(); |
| 1192 | return FALSE; |
| 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1197 | ARMSOCLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1198 | LOCO *colors, VisualPtr pVisual) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1199 | { |
| 1200 | TRACE_ENTER(); |
| 1201 | TRACE_EXIT(); |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | /** |
| 1206 | * The driver's CloseScreen() function. This is called at the end of each |
| 1207 | * server generation. Restore state, unmap the frame buffer (and any other |
| 1208 | * mapped memory regions), and free per-Screen data structures (except those |
| 1209 | * held by pScrn). |
| 1210 | */ |
| 1211 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1212 | ARMSOCCloseScreen(CLOSE_SCREEN_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1213 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1214 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1215 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Daniel Kurtz | 22437e9 | 2013-07-30 13:28:46 +0800 | [diff] [blame] | 1216 | Bool ret; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1217 | |
| 1218 | TRACE_ENTER(); |
| 1219 | |
Rob Clark | 4b8f30a | 2011-08-28 12:51:26 -0500 | [diff] [blame] | 1220 | drmmode_screen_fini(pScrn); |
Dave Barnish | caed3a1 | 2013-11-14 08:52:10 +0000 | [diff] [blame^] | 1221 | drmmode_cursor_fini(pScreen); |
| 1222 | |
| 1223 | /* pScreen->devPrivate holds the root pixmap created around our bo by miCreateResources which is installed |
| 1224 | * by fbScreenInit() when called from ARMSOCScreenInit(). |
| 1225 | * This pixmap should be destroyed in miScreenClose() but this isn't wrapped by fbScreenInit() so to prevent a leak |
| 1226 | * we do it here, before calling the CloseScreen chain which would just free pScreen->devPrivate in fbCloseScreen() |
| 1227 | */ |
| 1228 | if (pScreen->devPrivate) { |
| 1229 | (void) (*pScreen->DestroyPixmap)(pScreen->devPrivate); |
| 1230 | pScreen->devPrivate = NULL; |
| 1231 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1232 | |
Daniel Kurtz | 22437e9 | 2013-07-30 13:28:46 +0800 | [diff] [blame] | 1233 | unwrap(pARMSOC, pScreen, CloseScreen); |
| 1234 | unwrap(pARMSOC, pScreen, BlockHandler); |
| 1235 | unwrap(pARMSOC, pScreen, CreateScreenResources); |
| 1236 | |
Dave Barnish | c0bf230 | 2013-09-02 14:55:58 +0100 | [diff] [blame] | 1237 | ret = (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS); |
Daniel Kurtz | 22437e9 | 2013-07-30 13:28:46 +0800 | [diff] [blame] | 1238 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1239 | if (pARMSOC->dri) |
Dave Barnish | fd50b13 | 2013-05-16 15:00:02 +0100 | [diff] [blame] | 1240 | ARMSOCDRI2CloseScreen(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1241 | |
| 1242 | if (pARMSOC->pARMSOCEXA) |
| 1243 | if (pARMSOC->pARMSOCEXA->CloseScreen) |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1244 | pARMSOC->pARMSOCEXA->CloseScreen(CLOSE_SCREEN_ARGS); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1245 | |
Dave Barnish | caed3a1 | 2013-11-14 08:52:10 +0000 | [diff] [blame^] | 1246 | /* scanout buffer is released when root pixmap is destroyed */ |
Dave Barnish | 52faee0 | 2013-04-22 13:28:42 +0100 | [diff] [blame] | 1247 | pARMSOC->scanout = NULL; |
Dave Barnish | caed3a1 | 2013-11-14 08:52:10 +0000 | [diff] [blame^] | 1248 | |
Dave Barnish | 52faee0 | 2013-04-22 13:28:42 +0100 | [diff] [blame] | 1249 | pScrn->displayWidth = 0; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1250 | |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1251 | if (pScrn->vtSema == TRUE) |
Dave Barnish | 982518c | 2013-04-22 16:09:22 +0100 | [diff] [blame] | 1252 | ARMSOCLeaveVT(VT_FUNC_ARGS(0)); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1253 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1254 | pScrn->vtSema = FALSE; |
| 1255 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1256 | TRACE_EXIT(); |
| 1257 | |
Daniel Kurtz | 22437e9 | 2013-07-30 13:28:46 +0800 | [diff] [blame] | 1258 | return ret; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | /** |
| 1264 | * Adjust the screen pixmap for the current location of the front buffer. |
| 1265 | * This is done at EnterVT when buffers are bound as long as the resources |
| 1266 | * have already been created, but the first EnterVT happens before |
| 1267 | * CreateScreenResources. |
| 1268 | */ |
| 1269 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1270 | ARMSOCCreateScreenResources(ScreenPtr pScreen) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1271 | { |
Daniel Kurtz | 0361e00 | 2013-08-14 21:07:01 +0800 | [diff] [blame] | 1272 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1273 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1274 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1275 | swap(pARMSOC, pScreen, CreateScreenResources); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1276 | if (!(*pScreen->CreateScreenResources) (pScreen)) |
| 1277 | return FALSE; |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1278 | swap(pARMSOC, pScreen, CreateScreenResources); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1279 | |
| 1280 | return TRUE; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1285 | ARMSOCBlockHandler(BLOCKHANDLER_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1286 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1287 | SCREEN_PTR(arg); |
| 1288 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1289 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1290 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1291 | swap(pARMSOC, pScreen, BlockHandler); |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1292 | (*pScreen->BlockHandler) (BLOCKHANDLER_ARGS); |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1293 | swap(pARMSOC, pScreen, BlockHandler); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | |
| 1297 | |
| 1298 | /** |
| 1299 | * The driver's SwitchMode() function. Initialize the new mode for the |
| 1300 | * Screen. |
| 1301 | */ |
| 1302 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1303 | ARMSOCSwitchMode(SWITCH_MODE_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1304 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1305 | SCRN_INFO_PTR(arg); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1306 | return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); |
| 1307 | } |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | /** |
| 1312 | * The driver's AdjustFrame() function. For cases where the frame buffer is |
| 1313 | * larger than the monitor resolution, this function can pan around the frame |
| 1314 | * buffer within the "viewport" of the monitor. |
| 1315 | */ |
| 1316 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1317 | ARMSOCAdjustFrame(ADJUST_FRAME_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1318 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1319 | SCRN_INFO_PTR(arg); |
| 1320 | drmmode_adjust_frame(pScrn, x, y); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | /** |
| 1326 | * The driver's EnterVT() function. This is called at server startup time, and |
| 1327 | * when the X server takes over the virtual terminal from the console. As |
| 1328 | * such, it may need to save the current (i.e. console) HW state, and set the |
| 1329 | * HW state as needed by the X server. |
| 1330 | */ |
| 1331 | static Bool |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1332 | ARMSOCEnterVT(VT_FUNC_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1333 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1334 | SCRN_INFO_PTR(arg); |
Ray Smith | 6ae735f | 2013-03-21 15:57:18 +0000 | [diff] [blame] | 1335 | int i, ret; |
abhinav.k | d4bab32 | 2012-07-31 11:29:19 -0700 | [diff] [blame] | 1336 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1337 | TRACE_ENTER(); |
| 1338 | |
Ray Smith | 6ae735f | 2013-03-21 15:57:18 +0000 | [diff] [blame] | 1339 | for (i = 1; i < currentMaxClients; i++) { |
| 1340 | if (clients[i]) |
| 1341 | AttendClient(clients[i]); |
| 1342 | } |
| 1343 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1344 | ret = ARMSOCSetDRMMaster(); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1345 | if (ret) { |
Daniel Kurtz | 9220596 | 2013-02-05 13:50:12 +0800 | [diff] [blame] | 1346 | ERROR_MSG("Cannot get DRM master: %s", strerror(errno)); |
Daniel Kurtz | 01a91f6 | 2013-02-05 10:19:51 +0800 | [diff] [blame] | 1347 | return FALSE; |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | if (!xf86SetDesiredModes(pScrn)) { |
| 1351 | ERROR_MSG("xf86SetDesiredModes() failed!"); |
| 1352 | return FALSE; |
| 1353 | } |
| 1354 | |
| 1355 | TRACE_EXIT(); |
| 1356 | return TRUE; |
| 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | /** |
| 1362 | * The driver's LeaveVT() function. This is called when the X server |
| 1363 | * temporarily gives up the virtual terminal to the console. As such, it may |
| 1364 | * need to restore the console's HW state. |
| 1365 | */ |
| 1366 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1367 | ARMSOCLeaveVT(VT_FUNC_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1368 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1369 | SCRN_INFO_PTR(arg); |
Ray Smith | 6ae735f | 2013-03-21 15:57:18 +0000 | [diff] [blame] | 1370 | int i, ret; |
abhinav.k | d4bab32 | 2012-07-31 11:29:19 -0700 | [diff] [blame] | 1371 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1372 | TRACE_ENTER(); |
| 1373 | |
Ray Smith | 6ae735f | 2013-03-21 15:57:18 +0000 | [diff] [blame] | 1374 | for (i = 1; i < currentMaxClients; i++) { |
| 1375 | if (clients[i]) |
| 1376 | IgnoreClient(clients[i]); |
| 1377 | } |
| 1378 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1379 | ret = ARMSOCDropDRMMaster(); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1380 | if (ret) |
Daniel Kurtz | 9220596 | 2013-02-05 13:50:12 +0800 | [diff] [blame] | 1381 | WARNING_MSG("drmDropMaster failed: %s", strerror(errno)); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1382 | |
| 1383 | TRACE_EXIT(); |
| 1384 | } |
| 1385 | |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1386 | /** |
Dave Barnish | 982518c | 2013-04-22 16:09:22 +0100 | [diff] [blame] | 1387 | * The driver's FreeScreen() function. |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1388 | * Frees the ScrnInfoRec driverPrivate field when a screen is |
| 1389 | * deleted by the common layer. |
Dave Barnish | 982518c | 2013-04-22 16:09:22 +0100 | [diff] [blame] | 1390 | * This function is not used in normal (error free) operation. |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1391 | */ |
| 1392 | static void |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1393 | ARMSOCFreeScreen(FREE_SCREEN_ARGS_DECL) |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1394 | { |
Cooper Yuan | a83caa6 | 2012-06-28 17:19:06 +0200 | [diff] [blame] | 1395 | SCRN_INFO_PTR(arg); |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1396 | struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1397 | |
| 1398 | TRACE_ENTER(); |
| 1399 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1400 | if (!pARMSOC) { |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1401 | /* This can happen if a Screen is deleted after Probe(): */ |
| 1402 | return; |
| 1403 | } |
| 1404 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1405 | if (pARMSOC->pARMSOCEXA) { |
Dave Barnish | 2e99895 | 2013-06-11 16:31:10 +0100 | [diff] [blame] | 1406 | if (pARMSOC->pARMSOCEXA->FreeScreen) |
| 1407 | pARMSOC->pARMSOCEXA->FreeScreen( |
| 1408 | FREE_SCREEN_ARGS(pScrn)); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1409 | } |
| 1410 | |
Paul Geary | 8ffd91c | 2013-04-11 16:03:15 +0100 | [diff] [blame] | 1411 | armsoc_device_del(pARMSOC->dev); |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1412 | |
Dave Barnish | f0952c1 | 2013-05-10 15:52:23 +0100 | [diff] [blame] | 1413 | /* Free the driver's Screen-specific, "private" data structure and |
| 1414 | * NULL-out the ScrnInfoRec's driverPrivate field. |
| 1415 | */ |
| 1416 | if (pScrn->driverPrivate) { |
| 1417 | free(pScrn->driverPrivate); |
| 1418 | pScrn->driverPrivate = NULL; |
| 1419 | } |
Rob Clark | 487687e | 2011-07-17 17:29:02 -0500 | [diff] [blame] | 1420 | |
| 1421 | TRACE_EXIT(); |
| 1422 | } |
| 1423 | |