Module Name:    xsrc
Committed By:   mrg
Date:           Sun Mar  3 09:44:37 UTC 2019

Modified Files:
        xsrc/external/mit/xf86-video-nouveau/dist/src: drmmode_display.c
            nouveau_xv.c nv30_xv_tex.c nv40_xv_tex.c nv50_xv.c nv_driver.c
            nv_proto.h nvc0_xv.c

Log Message:
merge xf86-video-nouveau 1.0.16.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 \
    xsrc/external/mit/xf86-video-nouveau/dist/src/drmmode_display.c
cvs rdiff -u -r1.3 -r1.4 \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nouveau_xv.c \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nvc0_xv.c
cvs rdiff -u -r1.2 -r1.3 \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nv30_xv_tex.c \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nv40_xv_tex.c \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nv50_xv.c \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nv_driver.c
cvs rdiff -u -r1.6 -r1.7 \
    xsrc/external/mit/xf86-video-nouveau/dist/src/nv_proto.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xf86-video-nouveau/dist/src/drmmode_display.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/drmmode_display.c:1.9 xsrc/external/mit/xf86-video-nouveau/dist/src/drmmode_display.c:1.10
--- xsrc/external/mit/xf86-video-nouveau/dist/src/drmmode_display.c:1.9	Tue Jan  1 00:34:53 2019
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/drmmode_display.c	Sun Mar  3 09:44:37 2019
@@ -49,7 +49,6 @@ static Bool drmmode_xf86crtc_resize(Scrn
 typedef struct {
     int fd;
     uint32_t fb_id;
-    drmModeResPtr mode_res;
     int cpp;
     drmEventContext event_context;
 #ifdef HAVE_LIBUDEV
@@ -86,6 +85,7 @@ typedef struct {
     drmModeConnectorPtr mode_output;
     drmModeEncoderPtr mode_encoder;
     drmModePropertyBlobPtr edid_blob;
+    drmModePropertyBlobPtr tile_blob;
     int num_props;
     drmmode_prop_ptr props;
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
@@ -480,6 +480,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc,
 			continue;
 
 		drmmode_output = output->driver_private;
+		if (drmmode_output->output_id == -1)
+			continue;
 		output_ids[output_count] =
 			drmmode_output->mode_output->connector_id;
 		output_count++;
@@ -525,7 +527,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc,
 
 #ifdef HAVE_XF86_CURSOR_RESET_CURSOR
 	xf86CursorResetCursor(crtc->scrn->pScreen);
-#else   
+#else
 	xf86_reload_cursors(crtc->scrn->pScreen);
 #endif
 
@@ -685,7 +687,8 @@ drmmode_gamma_set(xf86CrtcPtr crtc, CARD
 				  size, red, green, blue);
 	if (ret != 0) {
 		xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
-			   "failed to set gamma: %s\n", strerror(-ret));
+			   "failed to set gamma with %d entries: %s\n",
+			   size, strerror(-ret));
 	}
 }
 
@@ -701,7 +704,11 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr c
 	int c, total_width = 0, max_height = 0, this_x = 0;
 	if (!ppix) {
 		if (crtc->randr_crtc->scanout_pixmap) {
-			PixmapStopDirtyTracking((DrawablePtr)crtc->randr_crtc->scanout_pixmap, screenpix);
+#ifdef HAS_DIRTYTRACKING_DRAWABLE_SRC
+			PixmapStopDirtyTracking(&crtc->randr_crtc->scanout_pixmap->drawable, screenpix);
+#else
+			PixmapStopDirtyTracking(crtc->randr_crtc->scanout_pixmap, screenpix);
+#endif
 			if (drmmode && drmmode->fb_id) {
 				drmModeRmFB(drmmode->fd, drmmode->fb_id);
 				drmmode->fb_id = 0;
@@ -747,8 +754,11 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr c
 		screen->height = screenpix->drawable.height = max_height;
 	}
 	drmmode_crtc->scanout_pixmap_x = this_x;
-#ifdef HAS_DIRTYTRACKING_ROTATION
-	PixmapStartDirtyTracking((DrawablePtr)ppix, screenpix, 0, 0, this_x, 0, RR_Rotate_0);
+
+#ifdef HAS_DIRTYTRACKING_DRAWABLE_SRC
+	PixmapStartDirtyTracking(&ppix->drawable, screenpix, 0, 0, this_x, 0, RR_Rotate_0);
+#elif defined(HAS_DIRTYTRACKING_ROTATION)
+	PixmapStartDirtyTracking(ppix, screenpix, 0, 0, this_x, 0, RR_Rotate_0);
 #elif defined(HAS_DIRTYTRACKING2)
 	PixmapStartDirtyTracking2(ppix, screenpix, 0, 0, this_x, 0);
 #else
@@ -777,7 +787,7 @@ static const xf86CrtcFuncsRec drmmode_cr
 
 
 static unsigned int
-drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num)
+drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num)
 {
 	NVPtr pNv = NVPTR(pScrn);
 	NVEntPtr pNVEnt = NVEntPriv(pScrn);
@@ -791,7 +801,7 @@ drmmode_crtc_init(ScrnInfoPtr pScrn, drm
 
 	drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
 	drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd,
-						 drmmode->mode_res->crtcs[num]);
+						 mode_res->crtcs[num]);
 	drmmode_crtc->drmmode = drmmode;
 	drmmode_crtc->hw_crtc_index = num;
 
@@ -816,13 +826,19 @@ drmmode_output_detect(xf86OutputPtr outp
 	drmmode_output_private_ptr drmmode_output = output->driver_private;
 	drmmode_ptr drmmode = drmmode_output->drmmode;
 	xf86OutputStatus status;
+
+	if (drmmode_output->output_id == -1)
+		return XF86OutputStatusDisconnected;
+
 	drmModeFreeConnector(drmmode_output->mode_output);
 
 	drmmode_output->mode_output =
 		drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
 
-	if (!drmmode_output->mode_output)
+	if (!drmmode_output->mode_output) {
+		drmmode_output->output_id = -1;
 		return XF86OutputStatusDisconnected;
+	}
 
 	switch (drmmode_output->mode_output->connection) {
 	case DRM_MODE_CONNECTED:
@@ -849,6 +865,69 @@ drmmode_output_mode_valid(xf86OutputPtr 
 	return MODE_OK;
 }
 
+static int
+koutput_get_prop_idx(int fd, drmModeConnectorPtr koutput,
+		     int type, const char *name)
+{
+	int idx = -1;
+
+	for (int i = 0; i < koutput->count_props; i++) {
+		drmModePropertyPtr prop = drmModeGetProperty(fd, koutput->props[i]);
+
+		if (!prop)
+			continue;
+
+		if (drm_property_type_is(prop, type) && !strcmp(prop->name, name))
+			idx = i;
+
+		drmModeFreeProperty(prop);
+
+		if (idx > -1)
+			break;
+	}
+
+	return idx;
+}
+
+static drmModePropertyBlobPtr
+koutput_get_prop_blob(int fd, drmModeConnectorPtr koutput, const char *name)
+{
+	drmModePropertyBlobPtr blob = NULL;
+	int idx = koutput_get_prop_idx(fd, koutput, DRM_MODE_PROP_BLOB, name);
+
+	if (idx > -1)
+		blob = drmModeGetPropertyBlob(fd, koutput->prop_values[idx]);
+
+	return blob;
+}
+
+static void
+drmmode_output_attach_tile(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	struct xf86CrtcTileInfo tile_info, *set = NULL;
+
+	if (!koutput) {
+		xf86OutputSetTile(output, NULL);
+		return;
+	}
+
+	drmModeFreePropertyBlob(drmmode_output->tile_blob);
+
+	/* look for a TILE property */
+	drmmode_output->tile_blob =
+		koutput_get_prop_blob(drmmode->fd, koutput, "TILE");
+
+	if (drmmode_output->tile_blob) {
+		if (xf86OutputParseKMSTile(drmmode_output->tile_blob->data, drmmode_output->tile_blob->length, &tile_info) == TRUE)
+			set = &tile_info;
+	}
+	xf86OutputSetTile(output, set);
+}
+
+
 static DisplayModePtr
 drmmode_output_get_modes(xf86OutputPtr output)
 {
@@ -857,27 +936,14 @@ drmmode_output_get_modes(xf86OutputPtr o
 	drmmode_ptr drmmode = drmmode_output->drmmode;
 	int i;
 	DisplayModePtr Modes = NULL, Mode;
-	drmModePropertyPtr props;
 	xf86MonPtr ddc_mon = NULL;
 
 	if (!koutput)
 		return NULL;
 
 	/* look for an EDID property */
-	for (i = 0; i < koutput->count_props; i++) {
-		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
-		if (!props || !(props->flags & DRM_MODE_PROP_BLOB))
-			continue;
-
-		if (!strcmp(props->name, "EDID")) {
-			if (drmmode_output->edid_blob)
-				drmModeFreePropertyBlob(drmmode_output->edid_blob);
-			drmmode_output->edid_blob =
-				drmModeGetPropertyBlob(drmmode->fd,
-						       koutput->prop_values[i]);
-		}
-		drmModeFreeProperty(props);
-	}
+	drmmode_output->edid_blob =
+		koutput_get_prop_blob(drmmode->fd, koutput, "EDID");
 
 	if (drmmode_output->edid_blob) {
 		ddc_mon = xf86InterpretEDID(output->scrn->scrnIndex,
@@ -887,6 +953,8 @@ drmmode_output_get_modes(xf86OutputPtr o
 	}
 	xf86OutputSetEDID(output, ddc_mon);
 
+	drmmode_output_attach_tile(output);
+
 	/* modes should already be available */
 	for (i = 0; i < koutput->count_modes; i++) {
 		Mode = xnfalloc(sizeof(DisplayModeRec));
@@ -907,6 +975,8 @@ drmmode_output_destroy(xf86OutputPtr out
 
 	if (drmmode_output->edid_blob)
 		drmModeFreePropertyBlob(drmmode_output->edid_blob);
+	if (drmmode_output->tile_blob)
+		drmModeFreePropertyBlob(drmmode_output->tile_blob);
 	for (i = 0; i < drmmode_output->num_props; i++) {
 		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
 		free(drmmode_output->props[i].atoms);
@@ -925,6 +995,9 @@ drmmode_output_dpms(xf86OutputPtr output
 	drmmode_ptr drmmode = drmmode_output->drmmode;
 	int mode_id = -1, i;
 
+	if (!koutput)
+		return;
+
 	for (i = 0; i < koutput->count_props; i++) {
 		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
 		if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
@@ -1088,7 +1161,8 @@ drmmode_output_set_property(xf86OutputPt
 			if (value->type != XA_ATOM || value->format != 32 || value->size != 1)
 				return FALSE;
 			memcpy(&atom, value->data, 4);
-			name = NameForAtom(atom);
+			if (!(name = NameForAtom(atom)))
+				return FALSE;
 
 			/* search for matching name string, then set its value down */
 			for (j = 0; j < p->mode_prop->count_enums; j++) {
@@ -1233,42 +1307,130 @@ drmmode_zaphod_match(ScrnInfoPtr pScrn, 
     return FALSE;
 }
 
+static xf86OutputPtr find_output(ScrnInfoPtr pScrn, int id)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int i;
+	for (i = 0; i < xf86_config->num_output; i++) {
+		xf86OutputPtr output = xf86_config->output[i];
+		drmmode_output_private_ptr drmmode_output;
+
+		drmmode_output = output->driver_private;
+		if (drmmode_output->output_id == id)
+			return output;
+	}
+	return NULL;
+}
+
+static int parse_path_blob(drmModePropertyBlobPtr path_blob, int *conn_base_id, char **path)
+{
+	char *conn;
+	char conn_id[5];
+	int id, len;
+	char *blob_data;
+
+	if (!path_blob)
+		return -1;
+
+	blob_data = path_blob->data;
+	/* we only handle MST paths for now */
+	if (strncmp(blob_data, "mst:", 4))
+		return -1;
+
+	conn = strchr(blob_data + 4, '-');
+	if (!conn)
+		return -1;
+	len = conn - (blob_data + 4);
+	if (len + 1 > 5)
+		return -1;
+	memcpy(conn_id, blob_data + 4, len);
+	conn_id[len] = '\0';
+	id = strtoul(conn_id, NULL, 10);
+
+	*conn_base_id = id;
+
+	*path = conn + 1;
+	return 0;
+}
+
+static void
+drmmode_create_name(ScrnInfoPtr pScrn, drmModeConnectorPtr koutput, char *name,
+                    drmModePropertyBlobPtr path_blob)
+{
+	int ret;
+	char *extra_path;
+	int conn_id;
+	xf86OutputPtr output;
+
+	ret = parse_path_blob(path_blob, &conn_id, &extra_path);
+	if (ret == -1)
+		goto fallback;
+
+	output = find_output(pScrn, conn_id);
+	if (!output)
+		goto fallback;
+
+	snprintf(name, 32, "%s-%s", output->name, extra_path);
+	return;
+
+fallback:
+	if (koutput->connector_type >= ARRAY_SIZE(output_names))
+		snprintf(name, 32, "Unknown%d-%d", koutput->connector_type, koutput->connector_type_id);
+	else if (pScrn->is_gpu)
+		snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id);
+	else
+		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id);
+}
+
 static unsigned int
-drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int crtcshift)
+drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num, Bool dynamic, int crtcshift)
 {
 	NVPtr pNv = NVPTR(pScrn);
 	xf86OutputPtr output;
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	drmModeConnectorPtr koutput;
 	drmModeEncoderPtr kencoder;
 	drmmode_output_private_ptr drmmode_output;
 	const char *s;
 	char name[32];
+	drmModePropertyBlobPtr path_blob = NULL;
+	int i;
 
 	koutput = drmModeGetConnector(drmmode->fd,
-				      drmmode->mode_res->connectors[num]);
+				      mode_res->connectors[num]);
 	if (!koutput)
 		return 0;
 
+	path_blob = koutput_get_prop_blob(drmmode->fd, koutput, "PATH");
+
+	drmmode_create_name(pScrn, koutput, name, path_blob);
+
+	if (path_blob)
+		drmModeFreePropertyBlob(path_blob);
+
+	if (path_blob && dynamic) {
+		/* see if we have an output with this name already
+		   and hook stuff up */
+		for (i = 0; i < xf86_config->num_output; i++) {
+			output = xf86_config->output[i];
+
+			if (strncmp(output->name, name, 32))
+				continue;
+
+			drmmode_output = output->driver_private;
+			drmmode_output->output_id = mode_res->connectors[num];
+			drmmode_output->mode_output = koutput;
+			return 1;
+		}
+	}
+
+
 	kencoder = drmModeGetEncoder(drmmode->fd, koutput->encoders[0]);
 	if (!kencoder) {
 		drmModeFreeConnector(koutput);
 		return 0;
 	}
 
-	if (koutput->connector_type >= NUM_OUTPUT_NAMES)
-		snprintf(name, 32, "Unknown%d-%d", koutput->connector_type,
-			 koutput->connector_type_id);
-#ifdef NOUVEAU_PIXMAP_SHARING
-	else if (pScrn->is_gpu)
-		snprintf(name, 32, "%s-%d-%d",
-			 output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1,
-			 koutput->connector_type_id);
-#endif
-	else
-		snprintf(name, 32, "%s-%d",
-			 output_names[koutput->connector_type],
-			 koutput->connector_type_id);
-
 	if (xf86IsEntityShared(pScrn->entityList[0])) {
 		s = xf86GetOptValString(pNv->Options, OPTION_ZAPHOD_HEADS);
 		if (s) {
@@ -1306,7 +1468,7 @@ drmmode_output_init(ScrnInfoPtr pScrn, d
 		return 0;
 	}
 
-	drmmode_output->output_id = drmmode->mode_res->connectors[num];
+	drmmode_output->output_id = mode_res->connectors[num];
 	drmmode_output->mode_output = koutput;
 	drmmode_output->mode_encoder = kencoder;
 	drmmode_output->drmmode = drmmode;
@@ -1322,6 +1484,9 @@ drmmode_output_init(ScrnInfoPtr pScrn, d
 	output->interlaceAllowed = true;
 	output->doubleScanAllowed = true;
 
+	if (dynamic)
+		output->randr_output = RROutputCreate(xf86ScrnToScreen(pScrn), output->name, strlen(output->name), output);
+
 	return 1;
 }
 
@@ -1435,6 +1600,7 @@ static const xf86CrtcConfigFuncsRec drmm
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp)
 {
 	drmmode_ptr drmmode;
+	drmModeResPtr mode_res;
 	NVEntPtr pNVEnt = NVEntPriv(pScrn);
 	int i;
 	unsigned int crtcs_needed = 0;
@@ -1447,32 +1613,31 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn,
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
 
 	drmmode->cpp = cpp;
-	drmmode->mode_res = drmModeGetResources(drmmode->fd);
-	if (!drmmode->mode_res)
+	mode_res = drmModeGetResources(drmmode->fd);
+	if (!mode_res)
 		return FALSE;
 
-	xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width,
-			     drmmode->mode_res->max_height);
+	xf86CrtcSetSizeRange(pScrn, 320, 200, mode_res->max_width,
+			     mode_res->max_height);
 
-	if (!drmmode->mode_res->count_connectors ||
-	    !drmmode->mode_res->count_crtcs) {
-		drmModeFreeResources(drmmode->mode_res);
+	if (!mode_res->count_connectors ||
+	    !mode_res->count_crtcs) {
 		free(drmmode);
 		goto done;
 	}
 
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing outputs ...\n");
 	crtcshift = ffs(pNVEnt->assigned_crtcs ^ 0xffffffff) - 1;
-	for (i = 0; i < drmmode->mode_res->count_connectors; i++)
-		crtcs_needed += drmmode_output_init(pScrn, drmmode, i, crtcshift);
+	for (i = 0; i < mode_res->count_connectors; i++)
+		crtcs_needed += drmmode_output_init(pScrn, drmmode, mode_res, i, FALSE, crtcshift);
 
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		   "%d crtcs needed for screen.\n", crtcs_needed);
 
-	for (i = 0; i < drmmode->mode_res->count_crtcs; i++) {
+	for (i = 0; i < mode_res->count_crtcs; i++) {
 		if (!xf86IsEntityShared(pScrn->entityList[0]) ||
 		    (crtcs_needed && !(pNVEnt->assigned_crtcs & (1 << i))))
-			crtcs_needed -= drmmode_crtc_init(pScrn, drmmode, i);
+			crtcs_needed -= drmmode_crtc_init(pScrn, drmmode, mode_res, i);
 	}
 
 	/* All ZaphodHeads outputs provided with matching crtcs? */
@@ -1482,6 +1647,8 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn,
 			   crtcs_needed);
 
 done:
+	drmModeFreeResources(mode_res);
+
 #ifdef NOUVEAU_PIXMAP_SHARING
 	xf86ProviderSetup(pScrn, NULL, "nouveau");
 #endif
@@ -1539,19 +1706,142 @@ drmmode_cursor_init(ScreenPtr pScreen)
 }
 
 #ifdef HAVE_LIBUDEV
+
+#define DRM_MODE_LINK_STATUS_GOOD       0
+#define DRM_MODE_LINK_STATUS_BAD        1
+
 static void
 drmmode_handle_uevents(ScrnInfoPtr scrn)
 {
-	drmmode_ptr drmmode = drmmode_from_scrn(scrn);
-	struct udev_device *dev;
+    struct udev_device *dev;
+    drmmode_ptr drmmode = drmmode_from_scrn(scrn);
+    drmModeResPtr mode_res;
+    xf86CrtcConfigPtr  config = XF86_CRTC_CONFIG_PTR(scrn);
+    int i, j;
+    Bool found = FALSE;
+    Bool changed = FALSE;
+
+    while ((dev = udev_monitor_receive_device(drmmode->uevent_monitor))) {
+        udev_device_unref(dev);
+        found = TRUE;
+    }
+    if (!found)
+        return;
+
+    /* Try to re-set the mode on all the connectors with a BAD link-state:
+     * This may happen if a link degrades and a new modeset is necessary, using
+     * different link-training parameters. If the kernel found that the current
+     * mode is not achievable anymore, it should have pruned the mode before
+     * sending the hotplug event. Try to re-set the currently-set mode to keep
+     * the display alive, this will fail if the mode has been pruned.
+     * In any case, we will send randr events for the Desktop Environment to
+     * deal with it, if it wants to.
+     */
+    for (i = 0; i < config->num_output; i++) {
+        xf86OutputPtr output = config->output[i];
+        xf86CrtcPtr crtc = output->crtc;
+        drmmode_output_private_ptr drmmode_output = output->driver_private;
+        uint32_t con_id, idx;
+        drmModeConnectorPtr koutput;
+
+        if (crtc == NULL || drmmode_output->mode_output == NULL)
+            continue;
+
+        con_id = drmmode_output->mode_output->connector_id;
+        /* Get an updated view of the properties for the current connector and
+         * look for the link-status property
+         */
+        koutput = drmModeGetConnectorCurrent(drmmode->fd, con_id);
+        if (!koutput)
+            continue;
+
+        idx = koutput_get_prop_idx(drmmode->fd, koutput,
+                DRM_MODE_PROP_ENUM, "link-status");
+
+        if ((idx > -1) &&
+                (koutput->prop_values[idx] == DRM_MODE_LINK_STATUS_BAD)) {
+            /* the connector got a link failure, re-set the current mode */
+            drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
+                                   crtc->x, crtc->y);
+
+            xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                       "hotplug event: connector %u's link-state is BAD, "
+                       "tried resetting the current mode. You may be left"
+                       "with a black screen if this fails...\n", con_id);
+        }
+
+        drmModeFreeConnector(koutput);
+    }
+
+    mode_res = drmModeGetResources(drmmode->fd);
+    if (!mode_res)
+        goto out;
+
+    if (mode_res->count_crtcs != config->num_crtc) {
+        ErrorF("number of CRTCs changed - failed to handle, %d vs %d\n", mode_res->count_crtcs, config->num_crtc);
+        goto out_free_res;
+    }
+
+    /* figure out if we have gotten rid of any connectors
+       traverse old output list looking for outputs */
+    for (i = 0; i < config->num_output; i++) {
+        xf86OutputPtr output = config->output[i];
+        drmmode_output_private_ptr drmmode_output;
+
+        drmmode_output = output->driver_private;
+        found = FALSE;
+        for (j = 0; j < mode_res->count_connectors; j++) {
+            if (mode_res->connectors[j] == drmmode_output->output_id) {
+                found = TRUE;
+                break;
+            }
+        }
+        if (found)
+            continue;
+
+        drmModeFreeConnector(drmmode_output->mode_output);
+        drmmode_output->mode_output = NULL;
+        drmmode_output->output_id = -1;
+
+        changed = TRUE;
+    }
+
+    /* find new output ids we don't have outputs for */
+    for (i = 0; i < mode_res->count_connectors; i++) {
+        found = FALSE;
+
+        for (j = 0; j < config->num_output; j++) {
+            xf86OutputPtr output = config->output[j];
+            drmmode_output_private_ptr drmmode_output;
+
+            drmmode_output = output->driver_private;
+            if (mode_res->connectors[i] == drmmode_output->output_id) {
+                found = TRUE;
+                break;
+            }
+        }
+        if (found)
+            continue;
+
+        changed = TRUE;
+        drmmode_output_init(scrn, drmmode, mode_res, i, TRUE, 0);
+    }
+
+    if (changed) {
+        RRSetChanged(xf86ScrnToScreen(scrn));
+        RRTellChanged(xf86ScrnToScreen(scrn));
+    }
+
+out_free_res:
+    drmModeFreeResources(mode_res);
+out:
+    RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
+}
 
-	dev = udev_monitor_receive_device(drmmode->uevent_monitor);
-	if (!dev)
-		return;
+#undef DRM_MODE_LINK_STATUS_BAD
+#undef DRM_MODE_LINK_STATUS_GOOD
 
-	RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
-	udev_device_unref(dev);
-}
+#endif
 
 #if HAVE_NOTIFY_FD
 static void
@@ -1561,7 +1851,6 @@ drmmode_udev_notify(int fd, int notify, 
 	drmmode_handle_uevents(scrn);
 }
 #endif
-#endif
 
 static bool has_randr(void)
 {

Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nouveau_xv.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nouveau_xv.c:1.3 xsrc/external/mit/xf86-video-nouveau/dist/src/nouveau_xv.c:1.4
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nouveau_xv.c:1.3	Tue Aug 29 04:43:42 2017
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nouveau_xv.c	Sun Mar  3 09:44:37 2019
@@ -113,6 +113,13 @@ XF86VideoFormatRec NVFormats[NUM_FORMATS
 	{15, DirectColor}, {16, DirectColor}, {24, DirectColor}
 };
 
+#define NUM_FORMATS_NV50 8
+XF86VideoFormatRec NV50Formats[NUM_FORMATS_NV50] =
+{
+	{15, TrueColor}, {16, TrueColor}, {24, TrueColor}, {30, TrueColor},
+	{15, DirectColor}, {16, DirectColor}, {24, DirectColor}, {30, DirectColor}
+};
+
 #define NUM_NV04_OVERLAY_ATTRIBUTES 4
 XF86AttributeRec NV04OverlayAttributes[NUM_NV04_OVERLAY_ATTRIBUTES] =
 {
@@ -1186,7 +1193,6 @@ NVPutImage(ScrnInfoPtr pScrn, short src_
 
 	if (newTTSize <= destination_buffer->size) {
 		unsigned char *dst;
-		int i = 0;
 
 		/* Upload to GART */
 		nouveau_bo_map(destination_buffer, NOUVEAU_BO_WR, pNv->client);
@@ -1361,7 +1367,7 @@ CPU_copy:
 		pPriv->currentBuffer ^= 1;
 	} else 
 	if (action_flags & USE_TEXTURE) {
-		int ret = BadImplementation;
+		ret = BadImplementation;
 
 		if (pNv->Architecture == NV_ARCH_30) {
 			ret = NV30PutTextureImage(pScrn, pPriv->video_mem,
@@ -2088,8 +2094,8 @@ NV50SetupTexturedVideo (ScreenPtr pScree
 	adapt->name		= "Nouveau GeForce 8/9 Textured Video";
 	adapt->nEncodings	= 1;
 	adapt->pEncodings	= &DummyEncodingNV50;
-	adapt->nFormats		= NUM_FORMATS_ALL;
-	adapt->pFormats		= NVFormats;
+	adapt->nFormats		= NUM_FORMATS_NV50;
+	adapt->pFormats		= NV50Formats;
 	adapt->nPorts		= NUM_TEXTURE_PORTS;
 	adapt->pPortPrivates	= (DevUnion*)(&adapt[1]);
 
@@ -2126,7 +2132,7 @@ NV50SetupTexturedVideo (ScreenPtr pScree
 	return adapt;
 }
 
-void
+static void
 NVSetupTexturedVideo (ScreenPtr pScreen, XF86VideoAdaptorPtr *textureAdaptor)
 {
 	ScrnInfoPtr          pScrn = xf86ScreenToScrn(pScreen);
@@ -2238,7 +2244,7 @@ NVInitVideo(ScreenPtr pScreen)
 		XF86MCAdaptorPtr *adaptorsXvMC = malloc(sizeof(XF86MCAdaptorPtr));
 		
 		if (adaptorsXvMC) {
-			adaptorsXvMC[0] = vlCreateAdaptorXvMC(pScreen, textureAdaptor[0]->name);
+			adaptorsXvMC[0] = vlCreateAdaptorXvMC(pScreen, (char *)textureAdaptor[0]->name);
 			
 			if (adaptorsXvMC[0]) {
 				vlInitXvMC(pScreen, 1, adaptorsXvMC);
Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nvc0_xv.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nvc0_xv.c:1.3 xsrc/external/mit/xf86-video-nouveau/dist/src/nvc0_xv.c:1.4
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nvc0_xv.c:1.3	Tue Aug 29 04:43:42 2017
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nvc0_xv.c	Sun Mar  3 09:44:37 2019
@@ -90,8 +90,9 @@ nvc0_xv_image_put(ScrnInfoPtr pScrn,
 	PUSH_DATA (push, dst->offset);
 	PUSH_DATA (push, ppix->drawable.width);
 	PUSH_DATA (push, ppix->drawable.height);
-	switch (ppix->drawable.bitsPerPixel) {
+	switch (ppix->drawable.depth) {
 	case 32: PUSH_DATA (push, NV50_SURFACE_FORMAT_BGRA8_UNORM); break;
+	case 30: PUSH_DATA (push, NV50_SURFACE_FORMAT_RGB10_A2_UNORM); break;
 	case 24: PUSH_DATA (push, NV50_SURFACE_FORMAT_BGRX8_UNORM); break;
 	case 16: PUSH_DATA (push, NV50_SURFACE_FORMAT_B5G6R5_UNORM); break;
 	case 15: PUSH_DATA (push, NV50_SURFACE_FORMAT_BGR5_X1_UNORM); break;

Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nv30_xv_tex.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nv30_xv_tex.c:1.2 xsrc/external/mit/xf86-video-nouveau/dist/src/nv30_xv_tex.c:1.3
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nv30_xv_tex.c:1.2	Tue Aug 16 07:43:03 2016
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nv30_xv_tex.c	Sun Mar  3 09:44:37 2019
@@ -135,7 +135,7 @@ NV30VideoTexture(ScrnInfoPtr pScrn, stru
 	return TRUE;
 }
 
-Bool
+static Bool
 NV30GetSurfaceFormat(PixmapPtr ppix, int *fmt_ret)
 {
 	switch (ppix->drawable.bitsPerPixel) {
Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nv40_xv_tex.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nv40_xv_tex.c:1.2 xsrc/external/mit/xf86-video-nouveau/dist/src/nv40_xv_tex.c:1.3
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nv40_xv_tex.c:1.2	Tue Aug 16 07:43:03 2016
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nv40_xv_tex.c	Sun Mar  3 09:44:37 2019
@@ -135,7 +135,7 @@ NV40VideoTexture(ScrnInfoPtr pScrn, stru
 	return TRUE;
 }
 
-Bool
+static Bool
 NV40GetSurfaceFormat(PixmapPtr ppix, int *fmt_ret)
 {
 	switch (ppix->drawable.bitsPerPixel) {
Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nv50_xv.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nv50_xv.c:1.2 xsrc/external/mit/xf86-video-nouveau/dist/src/nv50_xv.c:1.3
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nv50_xv.c:1.2	Tue Aug 16 07:43:03 2016
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nv50_xv.c	Sun Mar  3 09:44:37 2019
@@ -92,8 +92,9 @@ nv50_xv_image_put(ScrnInfoPtr pScrn,
 	BEGIN_NV04(push, NV50_3D(RT_ADDRESS_HIGH(0)), 5);
 	PUSH_DATA (push, dst->offset >> 32);
 	PUSH_DATA (push, dst->offset);
-	switch (ppix->drawable.bitsPerPixel) {
+	switch (ppix->drawable.depth) {
 	case 32: PUSH_DATA (push, NV50_SURFACE_FORMAT_BGRA8_UNORM); break;
+	case 30: PUSH_DATA (push, NV50_SURFACE_FORMAT_RGB10_A2_UNORM); break;
 	case 24: PUSH_DATA (push, NV50_SURFACE_FORMAT_BGRX8_UNORM); break;
 	case 16: PUSH_DATA (push, NV50_SURFACE_FORMAT_B5G6R5_UNORM); break;
 	case 15: PUSH_DATA (push, NV50_SURFACE_FORMAT_BGR5_X1_UNORM); break;
Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nv_driver.c
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nv_driver.c:1.2 xsrc/external/mit/xf86-video-nouveau/dist/src/nv_driver.c:1.3
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nv_driver.c:1.2	Mon Dec 31 22:17:20 2018
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nv_driver.c	Sun Mar  3 09:44:37 2019
@@ -140,8 +140,12 @@ static struct NvFamily NVKnownFamilies[]
   { "GeForce 6",   "NV4x" },
   { "GeForce 7",   "G7x" },
   { "GeForce 8",   "G8x" },
-  { "GeForce GTX 200", "NVA0" },
-  { "GeForce GTX 400", "NVC0" },
+  { "GeForce 9",   "G9x" },
+  { "GeForce GTX 2xx/3xx", "GT2xx" },
+  { "GeForce GTX 4xx/5xx", "GFxxx" },
+  { "GeForce GTX 6xx/7xx", "GKxxx" },
+  { "GeForce GTX 9xx", "GMxxx" },
+  { "GeForce GTX 10xx", "GPxxx" },
   { NULL, NULL}
 };
 
@@ -154,7 +158,7 @@ static XF86ModuleVersionInfo nouveauVers
     MODINFOSTRING1,
     MODINFOSTRING2,
     XORG_VERSION_CURRENT,
-    NV_MAJOR_VERSION, NV_MINOR_VERSION, NV_PATCHLEVEL,
+    PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
     ABI_CLASS_VIDEODRV,                     /* This is a video driver */
     ABI_VIDEODRV_VERSION,
     MOD_CLASS_VIDEODRV,
@@ -1577,11 +1581,14 @@ NVScreenInit(SCREEN_INIT_ARGS_DECL)
 
 	/*
 	 * Initialize colormap layer.
-	 * Must follow initialization of the default colormap 
+	 * Must follow initialization of the default colormap.
+	 * X-Server < 1.20 mishandles > 256 slots / > 8 bpc color maps, so skip
+	 * color map setup on old servers at > 8 bpc. Gamma luts still work.
 	 */
-	if (xf86_config->num_crtc &&
-	    !xf86HandleColormaps(pScreen, 256, 8, NVLoadPalette,
-				 NULL, CMAP_PALETTED_TRUECOLOR))
+	if (xf86_config->num_crtc && (pScrn->rgbBits <= 8 ||
+	    XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,20,0,0,0)) &&
+	    !xf86HandleColormaps(pScreen, 1 << pScrn->rgbBits, pScrn->rgbBits,
+				 NVLoadPalette, NULL, CMAP_PALETTED_TRUECOLOR))
 		return FALSE;
 
 	/* Report any unused options (only for the first generation) */

Index: xsrc/external/mit/xf86-video-nouveau/dist/src/nv_proto.h
diff -u xsrc/external/mit/xf86-video-nouveau/dist/src/nv_proto.h:1.6 xsrc/external/mit/xf86-video-nouveau/dist/src/nv_proto.h:1.7
--- xsrc/external/mit/xf86-video-nouveau/dist/src/nv_proto.h:1.6	Thu Jan 31 19:52:31 2019
+++ xsrc/external/mit/xf86-video-nouveau/dist/src/nv_proto.h	Sun Mar  3 09:44:37 2019
@@ -61,7 +61,6 @@ Bool NVAccelM2MF(NVPtr pNv, int w, int h
 void nouveau_wfb_setup_wrap(ReadMemoryProcPtr *, WriteMemoryProcPtr *,
 			    DrawablePtr);
 void nouveau_wfb_finish_wrap(DrawablePtr);
-void nouveau_wfb_init();
 
 /* in nv_shadow.c */
 void NVRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);

Reply via email to