From ffb8f86a9ca8a5946b8f18e90cc9758ebad74c73 Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Sat, 8 Jul 2017 12:25:21 +0100 Subject: [PATCH] Each driver should manually register a probe function for use by hal This commit removes the HWProbes() function from the console and tty packages and replaces it with a global ProbeFuncs slice which is fetched by the hal package when the hardware autodetection code runs. Each driver should provide an init() function that appends a probe function to the global ProbeFuncs slice. This approach allows us to support conditional compilation of drivers in the future (e.g. using build tags) --- src/gopheros/device/tty/probe.go | 14 +++++++------- src/gopheros/device/tty/vt.go | 6 ++++-- src/gopheros/device/video/console/probe.go | 13 +++++-------- src/gopheros/device/video/console/vga_text.go | 17 +++++++++-------- src/gopheros/kernel/hal/hal.go | 4 ++-- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/gopheros/device/tty/probe.go b/src/gopheros/device/tty/probe.go index 6911b0b..ebc070a 100644 --- a/src/gopheros/device/tty/probe.go +++ b/src/gopheros/device/tty/probe.go @@ -2,10 +2,10 @@ package tty import "gopheros/device" -// HWProbes returns a slice of device.ProbeFn that can be used by the hal -// package to probe for TTY device hardware. -func HWProbes() []device.ProbeFn { - return []device.ProbeFn{ - probeForVT, - } -} +var ( + // ProbeFuncs is a slice of device probe functions + // that is used by the hal package to probe for TTY + // hardware. Each driver should use an init() block + // to append its probe function to this list. + ProbeFuncs []device.ProbeFn +) diff --git a/src/gopheros/device/tty/vt.go b/src/gopheros/device/tty/vt.go index a2f896c..4dda34c 100644 --- a/src/gopheros/device/tty/vt.go +++ b/src/gopheros/device/tty/vt.go @@ -260,6 +260,8 @@ func (t *VT) DriverVersion() (uint16, uint16, uint16) { // DriverInit initializes this driver. func (t *VT) DriverInit() *kernel.Error { return nil } -func probeForVT() device.Driver { - return NewVT(DefaultTabWidth, DefaultScrollback) +func init() { + ProbeFuncs = append(ProbeFuncs, func() device.Driver { + return NewVT(DefaultTabWidth, DefaultScrollback) + }) } diff --git a/src/gopheros/device/video/console/probe.go b/src/gopheros/device/video/console/probe.go index a2a47d3..1981378 100644 --- a/src/gopheros/device/video/console/probe.go +++ b/src/gopheros/device/video/console/probe.go @@ -5,12 +5,9 @@ import "gopheros/kernel/hal/multiboot" var ( getFramebufferInfoFn = multiboot.GetFramebufferInfo -) -// HWProbes returns a slice of device.ProbeFn that can be used by the hal -// package to probe for console device hardware. -func HWProbes() []device.ProbeFn { - return []device.ProbeFn{ - probeForVgaTextConsole, - } -} + // ProbeFuncs is a slice of device probe functions that is used by + // the hal package to probe for console device hardware. Each driver + // should use an init() block to append its probe function to this list. + ProbeFuncs []device.ProbeFn +) diff --git a/src/gopheros/device/video/console/vga_text.go b/src/gopheros/device/video/console/vga_text.go index 55e5589..fffa4ec 100644 --- a/src/gopheros/device/video/console/vga_text.go +++ b/src/gopheros/device/video/console/vga_text.go @@ -199,14 +199,15 @@ func (cons *VgaTextConsole) DriverVersion() (uint16, uint16, uint16) { // DriverInit initializes this driver. func (cons *VgaTextConsole) DriverInit() *kernel.Error { return nil } -// probeForVgaTextConsole checks for the presence of a vga text console. -func probeForVgaTextConsole() device.Driver { - var drv device.Driver +func init() { + ProbeFuncs = append(ProbeFuncs, func() device.Driver { + var drv device.Driver - fbInfo := getFramebufferInfoFn() - if fbInfo.Type == multiboot.FramebufferTypeEGA { - drv = NewVgaTextConsole(fbInfo.Width, fbInfo.Height, uintptr(fbInfo.PhysAddr)) - } + fbInfo := getFramebufferInfoFn() + if fbInfo.Type == multiboot.FramebufferTypeEGA { + drv = NewVgaTextConsole(fbInfo.Width, fbInfo.Height, uintptr(fbInfo.PhysAddr)) + } - return drv + return drv + }) } diff --git a/src/gopheros/kernel/hal/hal.go b/src/gopheros/kernel/hal/hal.go index 036be4e..3f5d06f 100644 --- a/src/gopheros/kernel/hal/hal.go +++ b/src/gopheros/kernel/hal/hal.go @@ -23,12 +23,12 @@ func ActiveTTY() tty.Device { // DetectHardware probes for hardware devices and initializes the appropriate // drivers. func DetectHardware() { - consoles := probe(console.HWProbes()) + consoles := probe(console.ProbeFuncs) if len(consoles) != 0 { devices.activeConsole = consoles[0].(console.Device) } - ttys := probe(tty.HWProbes()) + ttys := probe(tty.ProbeFuncs) if len(ttys) != 0 { devices.activeTTY = ttys[0].(tty.Device) devices.activeTTY.AttachTo(devices.activeConsole)