~emersion/go-drm

ref: c0c2450906d94f52d69c264e485731cbaf1a63f4 go-drm/node_linux.go -rw-r--r-- 456 bytes
c0c24509Simon Ser Improve format/modifier pretty-printing 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package drm

import (
	"fmt"
	"syscall"
)

func (n *Node) getDevice() (Device, error) {
	var stat syscall.Stat_t
	if err := syscall.Fstat(int(n.fd), &stat); err != nil {
		return nil, err
	}

	if !isDRM(&stat) {
		return nil, fmt.Errorf("drm: not a DRM device")
	}

	bus, err := getSubsystemType(stat.Rdev)
	if err != nil {
		return nil, err
	}

	switch bus {
	case BusPCI:
		return getPCIDevice(stat.Rdev)
	default:
		return &unknownDevice{bus}, nil
	}
}