~emersion/drmdb

c2683b6f7f7d06f0158c523012b54b25846971b5 — Simon Ser 2 years ago 754750a
Show platform devices in /devices
2 files changed, 33 insertions(+), 26 deletions(-)

M public/devices.html
M server.go
M public/devices.html => public/devices.html +8 -6
@@ 7,7 7,8 @@
<table>
    <thead>
        <tr>
            <th>PCI ID</th>
            <th>ID</th>
            <th>Bus type</th>
            <th>Vendor</th>
            <th>Name</th>
            <th>Driver</th>


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

M server.go => server.go +25 -20
@@ 7,6 7,7 @@ import (
	"io"
	"net/http"
	"os"
	"strings"

	"git.sr.ht/~emersion/drmdb/drmtree"
	"git.sr.ht/~emersion/go-drm"


@@ 39,9 40,11 @@ type propertyData struct {
	Drivers map[string]bool
}

type pciDeviceData struct {
	Vendor, Device uint32
	VendorName, DeviceName string
type deviceData struct {
	ID string
	BusType drm.BusType
	Vendor string
	Name string
	Driver string
}



@@ 194,25 197,27 @@ func New() *echo.Echo {
	})

	e.GET("/devices", func(c echo.Context) error {
		devices := make(map[uint64]pciDeviceData)
		devices := make(map[string]deviceData)
		err := walk(func (n *drmtree.Node) error {
			pci, ok := n.Device.DeviceData.(*drmtree.DevicePCI)
			if !ok {
				return nil
			}

			k := uint64(pci.Vendor) << 32 | uint64(pci.Device)
			if _, ok := devices[k]; ok {
				return nil
			switch dev := n.Device.DeviceData.(type) {
			case *drmtree.DevicePCI:
				id := fmt.Sprintf("%04X:%04X", dev.Vendor, dev.Device)
				devices[id] = deviceData{
					ID: id,
					BusType: n.Device.BusType,
					Vendor: pciVendors[uint16(dev.Vendor)],
					Name: pciDevices[dev.Vendor << 16 | dev.Device],
					Driver: n.Driver.Name,
				}
			case *drmtree.DevicePlatform:
				id := strings.Join(dev.Compatible, " ")
				devices[id] = deviceData{
					ID: id,
					BusType: n.Device.BusType,
					Driver: n.Driver.Name,
				}
			}

			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
		})
		if err != nil {


@@ 220,7 225,7 @@ func New() *echo.Echo {
		}

		return c.Render(http.StatusOK, "devices.html", struct{
			Devices map[uint64]pciDeviceData
			Devices map[string]deviceData
		}{devices})
	})