~emersion/drmdb

ebbf025729f8a8b8308273bd3531fb704efb5161 — Simon Ser 2 years ago 6181131
Use hwids to print PCI name
5 files changed, 58 insertions(+), 0 deletions(-)

M go.mod
M go.sum
M public/assets/style.css
M public/devices.html
M server.go
M go.mod => go.mod +1 -0
@@ 4,6 4,7 @@ go 1.12

require (
	git.sr.ht/~emersion/go-drm v0.0.0-20190517194428-bdd0a2b572cc
	git.sr.ht/~emersion/go-hwids v0.0.0-20190518090256-f59e5efa82bd
	github.com/labstack/echo/v4 v4.1.5
	golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c // indirect
	golang.org/x/sys v0.0.0-20190506115046-ca7f33d4116e // indirect

M go.sum => go.sum +2 -0
@@ 1,5 1,7 @@
git.sr.ht/~emersion/go-drm v0.0.0-20190517194428-bdd0a2b572cc h1:XG3wv1onpi6MTNnDZrncUMaI5E7zabqqcoalvO6iqHM=
git.sr.ht/~emersion/go-drm v0.0.0-20190517194428-bdd0a2b572cc/go.mod h1:zEYzVXwxcVK/GyMUXkivzLZYeO/1PUIp7//W9gwbvlc=
git.sr.ht/~emersion/go-hwids v0.0.0-20190518090256-f59e5efa82bd h1:oNlwNNmZsVAB9ucZwP9FR9sa9N0NRMruE7bCxHudyqI=
git.sr.ht/~emersion/go-hwids v0.0.0-20190518090256-f59e5efa82bd/go.mod h1:jHwpYaHgpEBE1rOTTLurgzObr9WvtH6DZXtrERSorI8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=

M public/assets/style.css => public/assets/style.css +4 -0
@@ 39,6 39,10 @@ td.status-unsupported {
    color: red;
}

td.status-unknown {
    color: gray;
}

td.pre {
    font-family: monospace;
}

M public/devices.html => public/devices.html +12 -0
@@ 8,6 8,8 @@
    <thead>
        <tr>
            <th>PCI ID</th>
            <th>Vendor</th>
            <th>Name</th>
            <th>Driver</th>
        </tr>
    </thead>


@@ 15,6 17,16 @@
        {{range .Devices}}
        <tr>
            <td class="pre">{{printf "%04X:%04X" .Vendor .Device}}</td>
            {{if .VendorName}}
            <td>{{.VendorName}}</td>
            {{else}}
            <td class="status-unknown">?</td>
            {{end}}
            {{if .DeviceName}}
            <td>{{.DeviceName}}</td>
            {{else}}
            <td class="status-unknown">?</td>
            {{end}}
            <td class="pre">{{.Driver}}</td>
        </tr>
        {{end}}

M server.go => server.go +39 -0
@@ 11,6 11,7 @@ import (
	"git.sr.ht/~emersion/drmdb/drmtree"
	"git.sr.ht/~emersion/go-drm"
	"github.com/labstack/echo/v4"
	"git.sr.ht/~emersion/go-hwids"
)

type Template struct {


@@ 40,6 41,7 @@ type propertyData struct {

type pciDeviceData struct {
	Vendor, Device uint32
	VendorName, DeviceName string
	Driver string
}



@@ 71,6 73,36 @@ func walkNodeProps(n *drmtree.Node, f func(drm.AnyID, string, *drmtree.Property)
	return nil
}

func loadPCIIDs() (vendors map[uint16]string, devices map[uint32]string, err error) {
	vendors = make(map[uint16]string)
	devices = make(map[uint32]string)

	db, err := hwids.OpenPCI()
	if err != nil {
		return nil, nil, err
	}
	defer db.Close()

	for {
		id, err := db.NextID()
		if err == io.EOF {
			break
		} else if err != nil {
			return nil, nil, err
		}

		switch id.Type {
		case hwids.PCIVendor:
			vendors[id.Vendor] = id.VendorName
		case hwids.PCIDevice:
			k := uint32(id.Vendor) << 16 | uint32(id.Device)
			devices[k] = id.DeviceName
		}
	}

	return vendors, devices, db.Close()
}

func New() *echo.Echo {
	e := echo.New()



@@ 82,6 114,11 @@ func New() *echo.Echo {
		t: template.Must(template.ParseGlob("public/*.html")),
	}

	pciVendors, pciDevices, err := loadPCIIDs()
	if err != nil {
		e.Logger.Error("Failed to load PCI IDs:", err)
	}

	e.GET("/", func(c echo.Context) error {
		return c.Render(http.StatusOK, "index.html", &indexData{
			Host: c.Request().Host,


@@ 155,6 192,8 @@ func New() *echo.Echo {
			devices[k] = pciDeviceData{
				Vendor: pci.Vendor,
				Device: pci.Device,
				VendorName: pciVendors[uint16(pci.Vendor)],
				DeviceName: pciDevices[pci.Vendor << 16 | pci.Device],
				Driver: n.Driver.Name,
			}
			return nil