card: Add a method to retrieve the device minor
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Thu, 6 Aug 2020 02:17:59 +0000 (05:17 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Mon, 10 Aug 2020 06:44:27 +0000 (09:44 +0300)
The device minor number is needed to access the debugfs directory
corresponding to the device. Make it available to users through a
dev_minor() method on the Card object.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
kms++/inc/kms++/card.h
kms++/src/card.cpp
py/pykms/pykmsbase.cpp

index 5c1cf7c..8af0969 100644 (file)
@@ -35,6 +35,7 @@ public:
        Card& operator=(const Card& other) = delete;
 
        int fd() const { return m_fd; }
+       unsigned int dev_minor() const { return m_minor; }
 
        void drop_master();
 
@@ -84,6 +85,7 @@ private:
        std::vector<Framebuffer*> m_framebuffers;
 
        int m_fd;
+       unsigned int m_minor;
        bool m_is_master;
 
        bool m_has_atomic;
index 527aca6..3a7ab70 100644 (file)
@@ -9,6 +9,10 @@
 #include <algorithm>
 #include <glob.h>
 
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <sys/types.h>
+
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
@@ -183,8 +187,15 @@ void Card::setup()
        m_version.desc = string(ver->desc, ver->desc_len);
        drmFreeVersion(ver);
 
+       struct stat stats;
        int r;
 
+       r = fstat(m_fd, &stats);
+       if (r < 0)
+               throw invalid_argument("Can't stat device (" + string(strerror(errno)) + ")");
+
+       m_minor = minor(stats.st_dev);
+
        r = drmSetMaster(m_fd);
        m_is_master = r == 0;
 
index c039833..fc72d05 100644 (file)
@@ -24,6 +24,7 @@ void init_pykmsbase(py::module &m)
                        .def(py::init<const string&>())
                        .def(py::init<const string&, uint32_t>())
                        .def_property_readonly("fd", &Card::fd)
+                       .def_property_readonly("minor", &Card::dev_minor)
                        .def_property_readonly("get_first_connected_connector", &Card::get_first_connected_connector)
 
                        // XXX pybind11 can't handle vector<T*> where T is non-copyable, and complains: