Message ID | 1422029304-1926-6-git-send-email-thierry.reding@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Thierry, Thank you for the patch. On Friday 23 January 2015 17:08:18 Thierry Reding wrote: > From: Thierry Reding <treding@nvidia.com> > > These tables are duplicated in several places, so move them into libutil > so that they can be shared. > > Signed-off-by: Thierry Reding <treding@nvidia.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > tests/modetest/modetest.c | 50 ++----------------- > tests/proptest/Makefile.am | 4 +- > tests/proptest/proptest.c | 40 +-------------- > tests/util/Makefile.am | 2 + > tests/util/kms.c | 122 ++++++++++++++++++++++++++++++++++++++++++ > tests/util/kms.h | 33 ++++++++++++ > 6 files changed, 165 insertions(+), 86 deletions(-) > create mode 100644 tests/util/kms.c > create mode 100644 tests/util/kms.h > > diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c > index b610956adfcb..d5fd99ebe1fd 100644 > --- a/tests/modetest/modetest.c > +++ b/tests/modetest/modetest.c > @@ -61,6 +61,7 @@ > > #include "util/common.h" > #include "util/format.h" > +#include "util/kms.h" > #include "util/pattern.h" > > #include "buffers.h" > @@ -123,11 +124,6 @@ static inline int64_t U642I64(uint64_t val) > return (int64_t)*((int64_t *)&val); > } > > -struct type_name { > - int type; > - const char *name; > -}; > - > #define type_name_fn(res) \ > const char * res##_str(int type) { \ > unsigned int i; \ > @@ -138,44 +134,6 @@ const char * res##_str(int type) { \ > return "(invalid)"; \ > } > > -struct type_name encoder_type_names[] = { > - { DRM_MODE_ENCODER_NONE, "none" }, > - { DRM_MODE_ENCODER_DAC, "DAC" }, > - { DRM_MODE_ENCODER_TMDS, "TMDS" }, > - { DRM_MODE_ENCODER_LVDS, "LVDS" }, > - { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, > -}; > - > -static type_name_fn(encoder_type) > - > -struct type_name connector_status_names[] = { > - { DRM_MODE_CONNECTED, "connected" }, > - { DRM_MODE_DISCONNECTED, "disconnected" }, > - { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, > -}; > - > -static type_name_fn(connector_status) > - > -struct type_name connector_type_names[] = { > - { DRM_MODE_CONNECTOR_Unknown, "unknown" }, > - { DRM_MODE_CONNECTOR_VGA, "VGA" }, > - { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, > - { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, > - { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, > - { DRM_MODE_CONNECTOR_Composite, "composite" }, > - { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, > - { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, > - { DRM_MODE_CONNECTOR_Component, "component" }, > - { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, > - { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, > - { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, > - { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, > - { DRM_MODE_CONNECTOR_TV, "TV" }, > - { DRM_MODE_CONNECTOR_eDP, "eDP" }, > -}; > - > -static type_name_fn(connector_type) > - > #define bit_name_fn(res) \ > const char * res##_str(int type) { \ > unsigned int i; \ > @@ -235,7 +193,7 @@ static void dump_encoders(struct device *dev) > printf("%d\t%d\t%s\t0x%08x\t0x%08x\n", > encoder->encoder_id, > encoder->crtc_id, > - encoder_type_str(encoder->encoder_type), > + util_lookup_encoder_type_name(encoder->encoder_type), > encoder->possible_crtcs, > encoder->possible_clones); > } > @@ -379,8 +337,8 @@ static void dump_connectors(struct device *dev) > printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t", > connector->connector_id, > connector->encoder_id, > - connector_status_str(connector->connection), > - connector_type_str(connector->connector_type), > + util_lookup_connector_status_name(connector->connection), > + util_lookup_connector_type_name(connector->connector_type), > connector->mmWidth, connector->mmHeight, > connector->count_modes); > > diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am > index f81a3c00846b..c615489b9a92 100644 > --- a/tests/proptest/Makefile.am > +++ b/tests/proptest/Makefile.am > @@ -1,5 +1,6 @@ > AM_CFLAGS = \ > -I$(top_srcdir)/include/drm \ > + -I$(top_srcdir)/tests \ > -I$(top_srcdir) > > noinst_PROGRAMS = \ > @@ -8,4 +9,5 @@ noinst_PROGRAMS = \ > proptest_SOURCES = \ > proptest.c > proptest_LDADD = \ > - $(top_builddir)/libdrm.la > + $(top_builddir)/libdrm.la \ > + $(top_builddir)/tests/util/libutil.la > diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c > index ee3fa408a310..b442d583d528 100644 > --- a/tests/proptest/proptest.c > +++ b/tests/proptest/proptest.c > @@ -45,44 +45,6 @@ static inline int64_t U642I64(uint64_t val) > int fd; > drmModeResPtr res = NULL; > > -const char *connector_type_str(uint32_t type) > -{ > - switch (type) { > - case DRM_MODE_CONNECTOR_Unknown: > - return "Unknown"; > - case DRM_MODE_CONNECTOR_VGA: > - return "VGA"; > - case DRM_MODE_CONNECTOR_DVII: > - return "DVI-I"; > - case DRM_MODE_CONNECTOR_DVID: > - return "DVI-D"; > - case DRM_MODE_CONNECTOR_DVIA: > - return "DVI-A"; > - case DRM_MODE_CONNECTOR_Composite: > - return "Composite"; > - case DRM_MODE_CONNECTOR_SVIDEO: > - return "SVIDEO"; > - case DRM_MODE_CONNECTOR_LVDS: > - return "LVDS"; > - case DRM_MODE_CONNECTOR_Component: > - return "Component"; > - case DRM_MODE_CONNECTOR_9PinDIN: > - return "9PinDin"; > - case DRM_MODE_CONNECTOR_DisplayPort: > - return "DisplayPort"; > - case DRM_MODE_CONNECTOR_HDMIA: > - return "HDMI-A"; > - case DRM_MODE_CONNECTOR_HDMIB: > - return "HDMI-B"; > - case DRM_MODE_CONNECTOR_TV: > - return "TV"; > - case DRM_MODE_CONNECTOR_eDP: > - return "eDP"; > - default: > - return "Invalid"; > - } > -} > - > /* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c > */ static void > dump_blob(uint32_t blob_id) > @@ -226,7 +188,7 @@ static void listConnectorProperties(void) > } > > printf("Connector %u (%s-%u)\n", c->connector_id, > - connector_type_str(c->connector_type), > + util_lookup_connector_type_name(c->connector_type), > c->connector_type_id); > > listObjectProperties(c->connector_id, > diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am > index 1a2519fbea89..c00574484867 100644 > --- a/tests/util/Makefile.am > +++ b/tests/util/Makefile.am > @@ -12,6 +12,8 @@ libutil_la_SOURCES = \ > common.h \ > format.c \ > format.h \ > + kms.c \ > + kms.h \ > pattern.c \ > pattern.h > > diff --git a/tests/util/kms.c b/tests/util/kms.c > new file mode 100644 > index 000000000000..a271ca047c4e > --- /dev/null > +++ b/tests/util/kms.c > @@ -0,0 +1,122 @@ > +/* > + * Copyright 2008 Tungsten Graphics > + * Jakob Bornecrantz <jakob@tungstengraphics.com> > + * Copyright 2008 Intel Corporation > + * Jesse Barnes <jesse.barnes@intel.com> > + * > + * 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 OR COPYRIGHT HOLDERS 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. > + */ > + > +/* > + * This fairly simple test program dumps output in a similar format to the > + * "xrandr" tool everyone knows & loves. It's necessarily slightly > different + * since the kernel separates outputs into encoder and connector > structures, + * each with their own unique ID. The program also allows > test testing of the + * memory management and mode setting APIs by allowing > the user to specify a + * connector and mode to use for mode setting. If > all works as expected, a + * blue background should be painted on the > monitor attached to the specified + * connector after the selected mode is > set. > + * > + * TODO: use cairo to write the mode info on the selected output once > + * the mode has been programmed, along with possible test patterns. > + */ > + > +#ifdef HAVE_CONFIG_H > +#include "config.h" > +#endif > + > +#include <stdint.h> > +#include <stdlib.h> > + > +#include "xf86drmMode.h" > + > +#include "common.h" > + > +struct type_name { > + unsigned int type; > + const char *name; > +}; > + > +static const char *util_lookup_type_name(unsigned int type, > + const struct type_name *table, > + unsigned int count) > +{ > + unsigned int i; > + > + for (i = 0; i < count; i++) > + if (table[i].type == type) > + return table[i].name; > + > + return NULL; > +} > + > +static const struct type_name encoder_type_names[] = { > + { DRM_MODE_ENCODER_NONE, "none" }, > + { DRM_MODE_ENCODER_DAC, "DAC" }, > + { DRM_MODE_ENCODER_TMDS, "TMDS" }, > + { DRM_MODE_ENCODER_LVDS, "LVDS" }, > + { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, > + { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, > + { DRM_MODE_ENCODER_DSI, "DSI" }, > + { DRM_MODE_ENCODER_DPMST, "DisplayPort MST" }, > +}; > + > +const char *util_lookup_encoder_type_name(unsigned int type) > +{ > + return util_lookup_type_name(type, encoder_type_names, > + ARRAY_SIZE(encoder_type_names)); > +} > + > +static const struct type_name connector_status_names[] = { > + { DRM_MODE_CONNECTED, "connected" }, > + { DRM_MODE_DISCONNECTED, "disconnected" }, > + { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, > +}; > + > +const char *util_lookup_connector_status_name(unsigned int status) > +{ > + return util_lookup_type_name(status, connector_status_names, > + ARRAY_SIZE(connector_status_names)); > +} > + > +static const struct type_name connector_type_names[] = { > + { DRM_MODE_CONNECTOR_Unknown, "unknown" }, > + { DRM_MODE_CONNECTOR_VGA, "VGA" }, > + { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, > + { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, > + { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, > + { DRM_MODE_CONNECTOR_Composite, "composite" }, > + { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, > + { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, > + { DRM_MODE_CONNECTOR_Component, "component" }, > + { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, > + { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, > + { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, > + { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, > + { DRM_MODE_CONNECTOR_TV, "TV" }, > + { DRM_MODE_CONNECTOR_eDP, "eDP" }, > + { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, > + { DRM_MODE_CONNECTOR_DSI, "DSI" }, > +}; > + > +const char *util_lookup_connector_type_name(unsigned int type) > +{ > + return util_lookup_type_name(type, connector_type_names, > + ARRAY_SIZE(connector_type_names)); > +} > diff --git a/tests/util/kms.h b/tests/util/kms.h > new file mode 100644 > index 000000000000..fa9ab69983ac > --- /dev/null > +++ b/tests/util/kms.h > @@ -0,0 +1,33 @@ > +/* > + * Copyright 2008 Tungsten Graphics > + * Jakob Bornecrantz <jakob@tungstengraphics.com> > + * Copyright 2008 Intel Corporation > + * Jesse Barnes <jesse.barnes@intel.com> > + * > + * 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 OR COPYRIGHT HOLDERS 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 UTIL_KMS_H > +#define UTIL_KMS_H > + > +const char *util_lookup_encoder_type_name(unsigned int type); > +const char *util_lookup_connector_status_name(unsigned int type); > +const char *util_lookup_connector_type_name(unsigned int type); > + > +#endif /* UTIL_KMS_H */
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index b610956adfcb..d5fd99ebe1fd 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -61,6 +61,7 @@ #include "util/common.h" #include "util/format.h" +#include "util/kms.h" #include "util/pattern.h" #include "buffers.h" @@ -123,11 +124,6 @@ static inline int64_t U642I64(uint64_t val) return (int64_t)*((int64_t *)&val); } -struct type_name { - int type; - const char *name; -}; - #define type_name_fn(res) \ const char * res##_str(int type) { \ unsigned int i; \ @@ -138,44 +134,6 @@ const char * res##_str(int type) { \ return "(invalid)"; \ } -struct type_name encoder_type_names[] = { - { DRM_MODE_ENCODER_NONE, "none" }, - { DRM_MODE_ENCODER_DAC, "DAC" }, - { DRM_MODE_ENCODER_TMDS, "TMDS" }, - { DRM_MODE_ENCODER_LVDS, "LVDS" }, - { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, -}; - -static type_name_fn(encoder_type) - -struct type_name connector_status_names[] = { - { DRM_MODE_CONNECTED, "connected" }, - { DRM_MODE_DISCONNECTED, "disconnected" }, - { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, -}; - -static type_name_fn(connector_status) - -struct type_name connector_type_names[] = { - { DRM_MODE_CONNECTOR_Unknown, "unknown" }, - { DRM_MODE_CONNECTOR_VGA, "VGA" }, - { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, - { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, - { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, - { DRM_MODE_CONNECTOR_Composite, "composite" }, - { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, - { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, - { DRM_MODE_CONNECTOR_Component, "component" }, - { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, - { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, - { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, - { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, - { DRM_MODE_CONNECTOR_TV, "TV" }, - { DRM_MODE_CONNECTOR_eDP, "eDP" }, -}; - -static type_name_fn(connector_type) - #define bit_name_fn(res) \ const char * res##_str(int type) { \ unsigned int i; \ @@ -235,7 +193,7 @@ static void dump_encoders(struct device *dev) printf("%d\t%d\t%s\t0x%08x\t0x%08x\n", encoder->encoder_id, encoder->crtc_id, - encoder_type_str(encoder->encoder_type), + util_lookup_encoder_type_name(encoder->encoder_type), encoder->possible_crtcs, encoder->possible_clones); } @@ -379,8 +337,8 @@ static void dump_connectors(struct device *dev) printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t", connector->connector_id, connector->encoder_id, - connector_status_str(connector->connection), - connector_type_str(connector->connector_type), + util_lookup_connector_status_name(connector->connection), + util_lookup_connector_type_name(connector->connector_type), connector->mmWidth, connector->mmHeight, connector->count_modes); diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am index f81a3c00846b..c615489b9a92 100644 --- a/tests/proptest/Makefile.am +++ b/tests/proptest/Makefile.am @@ -1,5 +1,6 @@ AM_CFLAGS = \ -I$(top_srcdir)/include/drm \ + -I$(top_srcdir)/tests \ -I$(top_srcdir) noinst_PROGRAMS = \ @@ -8,4 +9,5 @@ noinst_PROGRAMS = \ proptest_SOURCES = \ proptest.c proptest_LDADD = \ - $(top_builddir)/libdrm.la + $(top_builddir)/libdrm.la \ + $(top_builddir)/tests/util/libutil.la diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c index ee3fa408a310..b442d583d528 100644 --- a/tests/proptest/proptest.c +++ b/tests/proptest/proptest.c @@ -45,44 +45,6 @@ static inline int64_t U642I64(uint64_t val) int fd; drmModeResPtr res = NULL; -const char *connector_type_str(uint32_t type) -{ - switch (type) { - case DRM_MODE_CONNECTOR_Unknown: - return "Unknown"; - case DRM_MODE_CONNECTOR_VGA: - return "VGA"; - case DRM_MODE_CONNECTOR_DVII: - return "DVI-I"; - case DRM_MODE_CONNECTOR_DVID: - return "DVI-D"; - case DRM_MODE_CONNECTOR_DVIA: - return "DVI-A"; - case DRM_MODE_CONNECTOR_Composite: - return "Composite"; - case DRM_MODE_CONNECTOR_SVIDEO: - return "SVIDEO"; - case DRM_MODE_CONNECTOR_LVDS: - return "LVDS"; - case DRM_MODE_CONNECTOR_Component: - return "Component"; - case DRM_MODE_CONNECTOR_9PinDIN: - return "9PinDin"; - case DRM_MODE_CONNECTOR_DisplayPort: - return "DisplayPort"; - case DRM_MODE_CONNECTOR_HDMIA: - return "HDMI-A"; - case DRM_MODE_CONNECTOR_HDMIB: - return "HDMI-B"; - case DRM_MODE_CONNECTOR_TV: - return "TV"; - case DRM_MODE_CONNECTOR_eDP: - return "eDP"; - default: - return "Invalid"; - } -} - /* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c */ static void dump_blob(uint32_t blob_id) @@ -226,7 +188,7 @@ static void listConnectorProperties(void) } printf("Connector %u (%s-%u)\n", c->connector_id, - connector_type_str(c->connector_type), + util_lookup_connector_type_name(c->connector_type), c->connector_type_id); listObjectProperties(c->connector_id, diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am index 1a2519fbea89..c00574484867 100644 --- a/tests/util/Makefile.am +++ b/tests/util/Makefile.am @@ -12,6 +12,8 @@ libutil_la_SOURCES = \ common.h \ format.c \ format.h \ + kms.c \ + kms.h \ pattern.c \ pattern.h diff --git a/tests/util/kms.c b/tests/util/kms.c new file mode 100644 index 000000000000..a271ca047c4e --- /dev/null +++ b/tests/util/kms.c @@ -0,0 +1,122 @@ +/* + * Copyright 2008 Tungsten Graphics + * Jakob Bornecrantz <jakob@tungstengraphics.com> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@intel.com> + * + * 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 OR COPYRIGHT HOLDERS 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. + */ + +/* + * This fairly simple test program dumps output in a similar format to the + * "xrandr" tool everyone knows & loves. It's necessarily slightly different + * since the kernel separates outputs into encoder and connector structures, + * each with their own unique ID. The program also allows test testing of the + * memory management and mode setting APIs by allowing the user to specify a + * connector and mode to use for mode setting. If all works as expected, a + * blue background should be painted on the monitor attached to the specified + * connector after the selected mode is set. + * + * TODO: use cairo to write the mode info on the selected output once + * the mode has been programmed, along with possible test patterns. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdint.h> +#include <stdlib.h> + +#include "xf86drmMode.h" + +#include "common.h" + +struct type_name { + unsigned int type; + const char *name; +}; + +static const char *util_lookup_type_name(unsigned int type, + const struct type_name *table, + unsigned int count) +{ + unsigned int i; + + for (i = 0; i < count; i++) + if (table[i].type == type) + return table[i].name; + + return NULL; +} + +static const struct type_name encoder_type_names[] = { + { DRM_MODE_ENCODER_NONE, "none" }, + { DRM_MODE_ENCODER_DAC, "DAC" }, + { DRM_MODE_ENCODER_TMDS, "TMDS" }, + { DRM_MODE_ENCODER_LVDS, "LVDS" }, + { DRM_MODE_ENCODER_TVDAC, "TVDAC" }, + { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, + { DRM_MODE_ENCODER_DSI, "DSI" }, + { DRM_MODE_ENCODER_DPMST, "DisplayPort MST" }, +}; + +const char *util_lookup_encoder_type_name(unsigned int type) +{ + return util_lookup_type_name(type, encoder_type_names, + ARRAY_SIZE(encoder_type_names)); +} + +static const struct type_name connector_status_names[] = { + { DRM_MODE_CONNECTED, "connected" }, + { DRM_MODE_DISCONNECTED, "disconnected" }, + { DRM_MODE_UNKNOWNCONNECTION, "unknown" }, +}; + +const char *util_lookup_connector_status_name(unsigned int status) +{ + return util_lookup_type_name(status, connector_status_names, + ARRAY_SIZE(connector_status_names)); +} + +static const struct type_name connector_type_names[] = { + { DRM_MODE_CONNECTOR_Unknown, "unknown" }, + { DRM_MODE_CONNECTOR_VGA, "VGA" }, + { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, + { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, + { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, + { DRM_MODE_CONNECTOR_Composite, "composite" }, + { DRM_MODE_CONNECTOR_SVIDEO, "s-video" }, + { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, + { DRM_MODE_CONNECTOR_Component, "component" }, + { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" }, + { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, + { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, + { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, + { DRM_MODE_CONNECTOR_TV, "TV" }, + { DRM_MODE_CONNECTOR_eDP, "eDP" }, + { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, + { DRM_MODE_CONNECTOR_DSI, "DSI" }, +}; + +const char *util_lookup_connector_type_name(unsigned int type) +{ + return util_lookup_type_name(type, connector_type_names, + ARRAY_SIZE(connector_type_names)); +} diff --git a/tests/util/kms.h b/tests/util/kms.h new file mode 100644 index 000000000000..fa9ab69983ac --- /dev/null +++ b/tests/util/kms.h @@ -0,0 +1,33 @@ +/* + * Copyright 2008 Tungsten Graphics + * Jakob Bornecrantz <jakob@tungstengraphics.com> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@intel.com> + * + * 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 OR COPYRIGHT HOLDERS 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 UTIL_KMS_H +#define UTIL_KMS_H + +const char *util_lookup_encoder_type_name(unsigned int type); +const char *util_lookup_connector_status_name(unsigned int type); +const char *util_lookup_connector_type_name(unsigned int type); + +#endif /* UTIL_KMS_H */