@@ -44,16 +44,7 @@ impl DrmNode {
44
44
return Err ( CreateDrmNodeError :: NotDrmNode ) ;
45
45
}
46
46
47
- // The type of the DRM node is determined by the minor number ranges:
48
- // 0 - 63 -> Primary
49
- // 64 - 127 -> Control
50
- // 128 - 255 -> Render
51
- let ty = match minor ( dev) >> 6 {
52
- 0 => NodeType :: Primary ,
53
- 1 => NodeType :: Control ,
54
- 2 => NodeType :: Render ,
55
- _ => return Err ( CreateDrmNodeError :: NotDrmNode ) ,
56
- } ;
47
+ let ty = NodeType :: from_dev_id ( dev) ?;
57
48
58
49
Ok ( DrmNode { dev, ty } )
59
50
}
@@ -151,14 +142,32 @@ impl NodeType {
151
142
}
152
143
}
153
144
145
+ pub fn from_dev_id ( dev : dev_t ) -> Result < Self , CreateDrmNodeError > {
146
+ // The type of the DRM node is determined by the minor number ranges:
147
+ // 0 - 63 -> Primary
148
+ // 64 - 127 -> Control
149
+ // 128 - 255 -> Render
150
+ Ok ( match minor ( dev) >> 6 {
151
+ 0 => Self :: Primary ,
152
+ 1 => Self :: Control ,
153
+ 2 => Self :: Render ,
154
+ _ => return Err ( CreateDrmNodeError :: NotDrmNode ) ,
155
+ } )
156
+ }
157
+
154
158
#[ cfg( not( target_os = "linux" ) ) ]
155
- fn minor_base ( & self ) -> u32 {
159
+ fn minor_index ( & self ) -> u32 {
156
160
match self {
157
161
NodeType :: Primary => 0 ,
158
- NodeType :: Control => 64 ,
159
- NodeType :: Render => 128 ,
162
+ NodeType :: Control => 1 ,
163
+ NodeType :: Render => 2 ,
160
164
}
161
165
}
166
+
167
+ #[ cfg( not( target_os = "linux" ) ) ]
168
+ fn minor_base ( & self ) -> u32 {
169
+ self . minor_index ( ) << 6
170
+ }
162
171
}
163
172
164
173
impl Display for NodeType {
0 commit comments