Permalink
Browse files

NV50: Rework the modesetting code into a different model.

- There is now interface independent code for most things.
- This structure, although not exclusive, is only used for NV50 atm.
- The change in approach is that the concept of a connector is added to the model (randr12 sucks in this aspect).
- I'm hacking around randr trying to create a single output for each connector, the indices are the bus numbers.
- Limitations: Hot swapping vga and dvi of same monitor will not make randr12 think it changed, so for the moment force a change.
- Concept is largely inspired by the radeonhd driver.
  • Loading branch information...
1 parent 5e1b570 commit a7af057ff67cf5d7baf78d852dee5ac69b24e706 @madman2003 madman2003 committed May 4, 2008
Showing with 1,774 additions and 914 deletions.
  1. +1 −1 autogen.sh
  2. +7 −0 src/Makefile.am
  3. +65 −0 src/nouveau_connector.h
  4. +80 −0 src/nouveau_crtc.h
  5. +31 −0 src/nouveau_modeset.h
  6. +66 −0 src/nouveau_output.h
  7. +116 −0 src/nv50_connector.c
  8. +276 −231 src/nv50_crtc.c
  9. +8 −73 src/nv50_cursor.c
  10. +93 −136 src/nv50_dac.c
  11. +7 −9 src/nv50_display.c
  12. +153 −152 src/nv50_output.c
  13. +661 −0 src/nv50_randr.c
  14. +40 −0 src/nv50_randr.h
  15. +87 −175 src/nv50_sor.c
  16. +1 −7 src/nv_crtc.c
  17. +32 −18 src/nv_driver.c
  18. +13 −72 src/nv_output.c
  19. +17 −30 src/nv_proto.h
  20. +20 −10 src/nv_type.h
View
@@ -9,4 +9,4 @@ cd $srcdir
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
-$srcdir/configure --enable-maintainer-mode "$@"
+$srcdir/configure "$@"
View
@@ -78,6 +78,13 @@ nouveau_drv_la_SOURCES = \
nv50_exa.c \
nv50_output.c \
nv50_sor.c \
+ nv50_randr.c \
+ nv50_randr.h \
+ nv50_connector.c \
nv50reg.h \
+ nouveau_crtc.h \
+ nouveau_output.h \
+ nouveau_connector.h \
+ nouveau_modeset.h \
nv_pcicompat.h
View
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2008 Maarten Maathuis
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __NOUVEAU_CONNECTOR_H_
+#define __NOUVEAU_CONNECTOR_H_
+
+#include "nv_include.h"
+#include "nouveau_modeset.h"
+#include "nouveau_crtc.h"
+#include "nouveau_output.h"
+
+/* I have yet to find specific information on connectors, so it's all derived from outputs. */
+typedef enum {
+ CONNECTOR_NONE = 4,
+ CONNECTOR_VGA = 0,
+ CONNECTOR_DVI = 1,
+ CONNECTOR_TV = 2,
+ CONNECTOR_PANEL = 3
+} NVConnectorType;
+
+#define MAX_OUTPUTS_PER_CONNECTOR 2
+
+typedef struct nouveauConnector {
+ ScrnInfoPtr scrn;
+ int index;
+
+ char *name;
+ Bool active;
+
+ NVConnectorType type;
+
+ I2CBusPtr pDDCBus;
+ int i2c_index;
+
+ /* For load detect amongst other things. */
+ nouveauOutputPtr outputs[MAX_OUTPUTS_PER_CONNECTOR];
+ int connected_output;
+
+ Bool hotplug_detected; /* better name? */
+ /* Function pointers. */
+ Bool (*HotplugDetect) (nouveauConnectorPtr connector);
+ xf86MonPtr (*DDCDetect) (nouveauConnectorPtr connector);
+ DisplayModePtr (*GetDDCModes) (nouveauConnectorPtr connector);
+} nouveauConnectorRec;
+
+#endif /* __NOUVEAU_CONNECTOR_H_ */
View
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2008 Maarten Maathuis
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __NOUVEAU_CRTC_H_
+#define __NOUVEAU_CRTC_H_
+
+#include "nv_include.h"
+#include "nouveau_modeset.h"
+
+typedef struct nouveauCrtc {
+ ScrnInfoPtr scrn;
+
+ char *name;
+ uint8_t index;
+ Bool active;
+
+ /* Scanout area. */
+ struct nouveau_bo * front_buffer;
+ uint32_t fb_pitch;
+ uint32_t x; /* relative to the frontbuffer */
+ uint32_t y;
+
+ /* Options and some state. */
+ Bool modeset_lock;
+ Bool dithering;
+ Bool cursor_visible;
+ Bool use_native_mode;
+ int scale_mode;
+ int pixel_clock;
+
+ /* Mode info. */
+ DisplayModePtr cur_mode;
+ DisplayModePtr native_mode;
+ DisplayModePtr mode_list;
+
+ /* Function pointers. */
+ Bool (*ModeValid) (nouveauCrtcPtr crtc, DisplayModePtr mode);
+ void (*ModeSet) (nouveauCrtcPtr crtc, DisplayModePtr mode);
+ void (*SetPixelClock) (nouveauCrtcPtr crtc, int clock);
+ void (*SetClockMode) (nouveauCrtcPtr crtc, int clock); /* maybe another name? */
+
+ void (*SetFB) (nouveauCrtcPtr crtc, struct nouveau_bo * buffer);
+ void (*SetFBOffset) (nouveauCrtcPtr crtc, uint32_t x, uint32_t y);
+
+ void (*Blank) (nouveauCrtcPtr crtc, Bool blanked);
+ void (*SetDither) (nouveauCrtcPtr crtc);
+
+ void (*SetScaleMode) (nouveauCrtcPtr crtc, int scale);
+
+ void (*ShowCursor) (nouveauCrtcPtr crtc, Bool forced_lock);
+ void (*HideCursor) (nouveauCrtcPtr crtc, Bool forced_lock);
+ void (*SetCursorPosition) (nouveauCrtcPtr crtc, int x, int y);
+ void (*LoadCursor) (nouveauCrtcPtr crtc, Bool argb, uint32_t *src);
+
+ void (*GammaSet) (nouveauCrtcPtr crtc, uint16_t *red, uint16_t *green, uint16_t *blue, int size);
+
+ void (*Save) (nouveauCrtcPtr crtc);
+ void (*Load) (nouveauCrtcPtr crtc);
+} nouveauCrtcRec;
+
+#endif /* __NOUVEAU_CRTC_H_ */
View
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2008 Maarten Maathuis
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __NOUVEAU_MODESET_H_
+#define __NOUVEAU_MODESET_H_
+
+/* Forward declarations. */
+typedef struct nouveauCrtc *nouveauCrtcPtr;
+typedef struct nouveauConnector *nouveauConnectorPtr;
+typedef struct nouveauOutput *nouveauOutputPtr;
+
+#endif /* __NOUVEAU_MODESET_H_ */
View
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2008 Maarten Maathuis
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __NOUVEAU_OUTPUT_H_
+#define __NOUVEAU_OUTPUT_H_
+
+#include "nv_include.h"
+#include "nouveau_modeset.h"
+#include "nouveau_crtc.h"
+#include "nouveau_connector.h"
+
+typedef struct nouveauOutput {
+ ScrnInfoPtr scrn;
+
+ char *name;
+ Bool active;
+ nouveauOutputPtr next;
+
+ nouveauCrtcPtr crtc;
+ nouveauConnectorPtr connector; /* the one that is currently in use, not all possibilities. */
+
+ /* This can change in rare circumstances, when an output resource is shared. */
+ struct dcb_entry *dcb;
+ int type;
+ uint8_t allowed_crtc; /* bit0: crtc0, bit1: crtc1 */
+ int scale_mode;
+ Bool dithering;
+
+ /* Mode stuff. */
+ DisplayModePtr native_mode;
+
+ /* Function pointers. */
+ int (*ModeValid) (nouveauOutputPtr output, DisplayModePtr mode);
+ void (*ModeSet) (nouveauOutputPtr output, DisplayModePtr mode);
+ void (*SetClockMode) (nouveauOutputPtr output, int clock); /* maybe another name? */
+
+ /* This will handle the case where output resources are shared. */
+ int (*Sense) (nouveauOutputPtr output); /* this is not for ddc or load detect, and will often just return a fixed type. */
+ Bool (*Detect) (nouveauOutputPtr output); /* usually only load detect, everything else is at the connector level. */
+
+ void (*SetPowerMode) (nouveauOutputPtr output, int mode);
+
+ void (*Save) (nouveauOutputPtr output);
+ void (*Load) (nouveauOutputPtr output);
+} nouveauOutputRec;
+
+#endif /* __NOUVEAU_OUTPUT_H_ */
View
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2008 Maarten Maathuis
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "nouveau_modeset.h"
+#include "nouveau_crtc.h"
+#include "nouveau_output.h"
+#include "nouveau_connector.h"
+
+static xf86MonPtr
+NV50ConnectorGetEDID(nouveauConnectorPtr connector)
+{
+ ScrnInfoPtr pScrn = connector->scrn;
+ NVPtr pNv = NVPTR(pScrn);
+ xf86MonPtr rval = NULL;
+
+ NVWrite(pNv, NV50_I2C_PORT(connector->pDDCBus->DriverPrivate.val), NV50_I2C_START);
+
+ rval = xf86DoEDID_DDC2(pScrn->scrnIndex, connector->pDDCBus);
+
+ NVWrite(pNv, NV50_I2C_PORT(connector->pDDCBus->DriverPrivate.val), NV50_I2C_STOP);
+
+ return rval;
+}
+
+static xf86MonPtr
+NV50ConnectorDDCDetect(nouveauConnectorPtr connector)
+{
+ ScrnInfoPtr pScrn = connector->scrn;
+ xf86MonPtr ddc_mon;
+
+ xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NV50ConnectorDDCDetect is called.\n");
+
+ if (!connector->pDDCBus)
+ return FALSE;
+
+ ddc_mon = NV50ConnectorGetEDID(connector);
+
+ return ddc_mon;
+}
+
+static DisplayModePtr
+NV50ConnectorGetDDCModes(nouveauConnectorPtr connector)
+{
+ ScrnInfoPtr pScrn = connector->scrn;
+ xf86MonPtr ddc_mon;
+
+ xf86DrvMsg(pScrn->scrnIndex, X_INFO, "NV50ConnectorGetDDCModes is called.\n");
+
+ ddc_mon = NV50ConnectorGetEDID(connector);
+
+ if (!ddc_mon)
+ return NULL;
+
+ return xf86DDCGetModes(pScrn->scrnIndex, ddc_mon);
+}
+
+void
+NV50ConnectorInit(ScrnInfoPtr pScrn)
+{
+ int i;
+ NVPtr pNv = NVPTR(pScrn);
+
+ /* Maybe a bit overdone, because often only 3 or 4 connectors are present. */
+ for (i = 0; i < MAX_NUM_DCB_ENTRIES; i++) {
+ nouveauConnectorPtr connector = xnfcalloc(sizeof(nouveauConnectorRec), 1);
+ connector->scrn = pScrn;
+ connector->index = i;
+
+ char connector_name[20];
+ sprintf(connector_name, "Connector-%d", i);
+ connector->name = xstrdup(connector_name);
+
+ /* Function pointers. */
+ connector->DDCDetect = NV50ConnectorDDCDetect;
+ connector->GetDDCModes = NV50ConnectorGetDDCModes;
+ connector->HotplugDetect = NULL;
+
+ pNv->connector[i] = connector;
+ }
+}
+
+void
+NV50ConnectorDestroy(ScrnInfoPtr pScrn)
+{
+ int i;
+ NVPtr pNv = NVPTR(pScrn);
+
+ /* Maybe a bit overdone, because often only 3 or 4 connectors are present. */
+ for (i = 0; i < MAX_NUM_DCB_ENTRIES; i++) {
+ nouveauConnectorPtr connector = pNv->connector[i];
+
+ xfree(connector->name);
+ xfree(connector);
+ pNv->connector[i] = NULL;
+ }
+}
+
Oops, something went wrong.

0 comments on commit a7af057

Please sign in to comment.