diff mbox series

[1/8] card: Add a method to retrieve the device minor

Message ID 20200806021807.21863-2-laurent.pinchart@ideasonboard.com (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series kmsxx: Various fixes and improvements | expand

Commit Message

Laurent Pinchart Aug. 6, 2020, 2:17 a.m. UTC
The device minor number is needed to access the debugfs directory
corresponding to the device. Make it available to users through a
get_minor() method on the Card object.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 kms++/inc/kms++/card.h |  3 +++
 kms++/src/card.cpp     | 11 +++++++++++
 py/pykms/pykmsbase.cpp |  1 +
 3 files changed, 15 insertions(+)

Comments

Tomi Valkeinen Aug. 6, 2020, 7:46 a.m. UTC | #1
On 06/08/2020 05:17, Laurent Pinchart wrote:
> The device minor number is needed to access the debugfs directory
> corresponding to the device. Make it available to users through a
> get_minor() method on the Card object.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  kms++/inc/kms++/card.h |  3 +++
>  kms++/src/card.cpp     | 11 +++++++++++
>  py/pykms/pykmsbase.cpp |  1 +
>  3 files changed, 15 insertions(+)
> 
> diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
> index 5c1cf7cfcedc..0a11747f7985 100644
> --- a/kms++/inc/kms++/card.h
> +++ b/kms++/inc/kms++/card.h
> @@ -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,7 +85,9 @@ private:
>  	std::vector<Framebuffer*> m_framebuffers;
>  
>  	int m_fd;
> +	unsigned int m_minor;
>  	bool m_is_master;
> +	std::string m_device;

This looks like an extra change.

 Tomi
Sergey Shtylyov Aug. 6, 2020, 9:55 a.m. UTC | #2
Hello!

On 06.08.2020 5:17, Laurent Pinchart wrote:

> The device minor number is needed to access the debugfs directory
> corresponding to the device. Make it available to users through a
> get_minor() method on the Card object.

    Didn't you call it dev_minor() below?

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[...]
> diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
> index 5c1cf7cfcedc..0a11747f7985 100644
> --- a/kms++/inc/kms++/card.h
> +++ b/kms++/inc/kms++/card.h
> @@ -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,7 +85,9 @@ private:
>   	std::vector<Framebuffer*> m_framebuffers;
>   
>   	int m_fd;
> +	unsigned int m_minor;
>   	bool m_is_master;
> +	std::string m_device;
>   
>   	bool m_has_atomic;
>   	bool m_has_universal_planes;
[...]

MBR, Sergei
Laurent Pinchart Aug. 10, 2020, 5:54 a.m. UTC | #3
Hi Tomi,

On Thu, Aug 06, 2020 at 10:46:43AM +0300, Tomi Valkeinen wrote:
> On 06/08/2020 05:17, Laurent Pinchart wrote:
> > The device minor number is needed to access the debugfs directory
> > corresponding to the device. Make it available to users through a
> > get_minor() method on the Card object.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  kms++/inc/kms++/card.h |  3 +++
> >  kms++/src/card.cpp     | 11 +++++++++++
> >  py/pykms/pykmsbase.cpp |  1 +
> >  3 files changed, 15 insertions(+)
> > 
> > diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
> > index 5c1cf7cfcedc..0a11747f7985 100644
> > --- a/kms++/inc/kms++/card.h
> > +++ b/kms++/inc/kms++/card.h
> > @@ -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,7 +85,9 @@ private:
> >  	std::vector<Framebuffer*> m_framebuffers;
> >  
> >  	int m_fd;
> > +	unsigned int m_minor;
> >  	bool m_is_master;
> > +	std::string m_device;
> 
> This looks like an extra change.

Oops, indeed.

Should I submit a v2 of the whole series to address your other concerns,
or do you plan to already merge some of the patches ? In the latter
case, feel free to give this small issue when applying :-) (along with
s/get_minor/dev_minor/ in the commit message as pointed our by Sergei).
Tomi Valkeinen Aug. 10, 2020, 6:48 a.m. UTC | #4
On 10/08/2020 08:54, Laurent Pinchart wrote:

> Should I submit a v2 of the whole series to address your other concerns,
> or do you plan to already merge some of the patches ? In the latter
> case, feel free to give this small issue when applying :-) (along with
> s/get_minor/dev_minor/ in the commit message as pointed our by Sergei).

I fixed these, and pushed the series. We can ponder about the YUV bpps on top.

 Tomi
diff mbox series

Patch

diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
index 5c1cf7cfcedc..0a11747f7985 100644
--- a/kms++/inc/kms++/card.h
+++ b/kms++/inc/kms++/card.h
@@ -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,7 +85,9 @@  private:
 	std::vector<Framebuffer*> m_framebuffers;
 
 	int m_fd;
+	unsigned int m_minor;
 	bool m_is_master;
+	std::string m_device;
 
 	bool m_has_atomic;
 	bool m_has_universal_planes;
diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp
index 527aca6cd127..3a7ab700ed49 100644
--- a/kms++/src/card.cpp
+++ b/kms++/src/card.cpp
@@ -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;
 
diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp
index c039833a41fb..fc72d056627f 100644
--- a/py/pykms/pykmsbase.cpp
+++ b/py/pykms/pykmsbase.cpp
@@ -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: