summaryrefslogtreecommitdiff
path: root/kms++/src
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2019-01-11 12:09:40 +0200
committerTomi Valkeinen <tomi.valkeinen@ti.com>2019-01-14 09:27:28 +0200
commit82b200e00c2c7dbeae108b21b2bba39305300d4a (patch)
tree9b2c3970fa97256a15ce520fdb0da0d4682036ac /kms++/src
parent6126525e3921d2ccc54ca393e6a24d4bd0f08429 (diff)
card: add open_modesetting_card()
Add open_modesetting_card() which iterates the DRM cards and returns the first one that has crtcs and connectors. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'kms++/src')
-rw-r--r--kms++/src/card.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp
index 4632f22..04750af 100644
--- a/kms++/src/card.cpp
+++ b/kms++/src/card.cpp
@@ -7,6 +7,7 @@
#include <algorithm>
#include <cerrno>
#include <algorithm>
+#include <sys/stat.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
@@ -18,6 +19,25 @@ using namespace std;
namespace kms
{
+unique_ptr<Card> Card::open_modesetting_card()
+{
+ for (uint32_t i = 0; ; ++i) {
+ string path = "/dev/dri/card" + to_string(i);
+
+ struct stat buffer;
+ if (stat(path.c_str(), &buffer))
+ break;
+
+ unique_ptr<Card> card = unique_ptr<Card>(new Card(path));
+
+ if (card->get_connectors().size() > 0 &&
+ card->get_crtcs().size() > 0)
+ return card;
+ }
+
+ throw runtime_error("No modesetting DRM card found");
+}
+
static int open_device_by_path(string path)
{
int fd = open(path.c_str(), O_RDWR | O_CLOEXEC);