diff options
author | Liav A <liavalb@gmail.com> | 2021-02-05 08:18:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-05 08:54:02 +0100 |
commit | f2faf11d614d1db373a2c9d0ad47540cd549239b (patch) | |
tree | e8820ad9292bcde957c8c397e6b47e047b8c513b | |
parent | 5bb35da7848d88fd4b2f04ddab9ac9548d2cd273 (diff) | |
download | serenity-f2faf11d614d1db373a2c9d0ad47540cd549239b.zip |
Kernel: Try to detect Sound Blaster 16 before creating an instance
We shouldn't create a SB16 instance without checking if the Sound
Blaster 16 card is actually installed in the system.
-rw-r--r-- | Kernel/Devices/SB16.cpp | 13 | ||||
-rw-r--r-- | Kernel/Devices/SB16.h | 3 | ||||
-rw-r--r-- | Kernel/init.cpp | 2 |
3 files changed, 16 insertions, 2 deletions
diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index b5354b7843..5b3a90131a 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -89,6 +89,19 @@ SB16::~SB16() { } +void SB16::detect() +{ + IO::out8(0x226, 1); + IO::delay(32); + IO::out8(0x226, 0); + + auto data = dsp_read(); + if (data != 0xaa) { + return; + } + SB16::create(); +} + void SB16::create() { s_the.ensure_instance(); diff --git a/Kernel/Devices/SB16.h b/Kernel/Devices/SB16.h index fd53065d21..c30f5a7765 100644 --- a/Kernel/Devices/SB16.h +++ b/Kernel/Devices/SB16.h @@ -42,6 +42,7 @@ public: SB16(); virtual ~SB16() override; + static void detect(); static void create(); static SB16& the(); @@ -69,7 +70,7 @@ private: void dma_start(uint32_t length); void set_sample_rate(uint16_t hz); void dsp_write(u8 value); - u8 dsp_read(); + static u8 dsp_read(); u8 get_irq_line(); void set_irq_register(u8 irq_number); void set_irq_line(u8 irq_number); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index f6177c17d3..429a1216ee 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -268,7 +268,7 @@ void init_stage2(void*) new FullDevice; new RandomDevice; PTYMultiplexer::initialize(); - new SB16; + SB16::detect(); VMWareBackdoor::the(); // don't wait until first mouse packet bool force_pio = kernel_command_line().contains("force_pio"); |