mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
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)
This commit is contained in:
parent
4845f7a4ca
commit
ffb8f86a9c
@ -2,10 +2,10 @@ package tty
|
|||||||
|
|
||||||
import "gopheros/device"
|
import "gopheros/device"
|
||||||
|
|
||||||
// HWProbes returns a slice of device.ProbeFn that can be used by the hal
|
var (
|
||||||
// package to probe for TTY device hardware.
|
// ProbeFuncs is a slice of device probe functions
|
||||||
func HWProbes() []device.ProbeFn {
|
// that is used by the hal package to probe for TTY
|
||||||
return []device.ProbeFn{
|
// hardware. Each driver should use an init() block
|
||||||
probeForVT,
|
// to append its probe function to this list.
|
||||||
}
|
ProbeFuncs []device.ProbeFn
|
||||||
}
|
)
|
||||||
|
@ -260,6 +260,8 @@ func (t *VT) DriverVersion() (uint16, uint16, uint16) {
|
|||||||
// DriverInit initializes this driver.
|
// DriverInit initializes this driver.
|
||||||
func (t *VT) DriverInit() *kernel.Error { return nil }
|
func (t *VT) DriverInit() *kernel.Error { return nil }
|
||||||
|
|
||||||
func probeForVT() device.Driver {
|
func init() {
|
||||||
|
ProbeFuncs = append(ProbeFuncs, func() device.Driver {
|
||||||
return NewVT(DefaultTabWidth, DefaultScrollback)
|
return NewVT(DefaultTabWidth, DefaultScrollback)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,9 @@ import "gopheros/kernel/hal/multiboot"
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
getFramebufferInfoFn = multiboot.GetFramebufferInfo
|
getFramebufferInfoFn = multiboot.GetFramebufferInfo
|
||||||
)
|
|
||||||
|
|
||||||
// HWProbes returns a slice of device.ProbeFn that can be used by the hal
|
// ProbeFuncs is a slice of device probe functions that is used by
|
||||||
// package to probe for console device hardware.
|
// the hal package to probe for console device hardware. Each driver
|
||||||
func HWProbes() []device.ProbeFn {
|
// should use an init() block to append its probe function to this list.
|
||||||
return []device.ProbeFn{
|
ProbeFuncs []device.ProbeFn
|
||||||
probeForVgaTextConsole,
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -199,8 +199,8 @@ func (cons *VgaTextConsole) DriverVersion() (uint16, uint16, uint16) {
|
|||||||
// DriverInit initializes this driver.
|
// DriverInit initializes this driver.
|
||||||
func (cons *VgaTextConsole) DriverInit() *kernel.Error { return nil }
|
func (cons *VgaTextConsole) DriverInit() *kernel.Error { return nil }
|
||||||
|
|
||||||
// probeForVgaTextConsole checks for the presence of a vga text console.
|
func init() {
|
||||||
func probeForVgaTextConsole() device.Driver {
|
ProbeFuncs = append(ProbeFuncs, func() device.Driver {
|
||||||
var drv device.Driver
|
var drv device.Driver
|
||||||
|
|
||||||
fbInfo := getFramebufferInfoFn()
|
fbInfo := getFramebufferInfoFn()
|
||||||
@ -209,4 +209,5 @@ func probeForVgaTextConsole() device.Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return drv
|
return drv
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ func ActiveTTY() tty.Device {
|
|||||||
// DetectHardware probes for hardware devices and initializes the appropriate
|
// DetectHardware probes for hardware devices and initializes the appropriate
|
||||||
// drivers.
|
// drivers.
|
||||||
func DetectHardware() {
|
func DetectHardware() {
|
||||||
consoles := probe(console.HWProbes())
|
consoles := probe(console.ProbeFuncs)
|
||||||
if len(consoles) != 0 {
|
if len(consoles) != 0 {
|
||||||
devices.activeConsole = consoles[0].(console.Device)
|
devices.activeConsole = consoles[0].(console.Device)
|
||||||
}
|
}
|
||||||
|
|
||||||
ttys := probe(tty.HWProbes())
|
ttys := probe(tty.ProbeFuncs)
|
||||||
if len(ttys) != 0 {
|
if len(ttys) != 0 {
|
||||||
devices.activeTTY = ttys[0].(tty.Device)
|
devices.activeTTY = ttys[0].(tty.Device)
|
||||||
devices.activeTTY.AttachTo(devices.activeConsole)
|
devices.activeTTY.AttachTo(devices.activeConsole)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user