1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00
serenity/Kernel/Devices/Audio/IntelHDA/Controller.h
Liav A 4921561687 Kernel/Audio: Simplify initialization sequence for drivers
Instead of enumerating all available controllers and then ask each to
find its audio channels, we change the initialization sequence to match
what happens in the Networking subsystem and Graphics subsystem - we
essentially probe for a matching driver on a PCI device, create a device
instance, and immediately initialize it.

This in fact allows us to immediately find any hardware initialization
issues and report it, and then dropping the created instance, as usually
being done in other initialization paths in the Kernel.

This also opens the opportunity to propagate errors when failed to
initialize an AudioChannel instance, and it will be addressed in a
future commit.
2023-04-14 19:23:12 +02:00

85 lines
2.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2023, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Vector.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Devices/Audio/Channel.h>
#include <Kernel/Devices/Audio/Controller.h>
#include <Kernel/Devices/Audio/IntelHDA/OutputPath.h>
#include <Kernel/Devices/Audio/IntelHDA/RingBuffer.h>
#include <Kernel/IOWindow.h>
#include <Kernel/Library/LockRefPtr.h>
namespace Kernel::Audio::IntelHDA {
// Specification: https://www.intel.com/content/dam/www/public/us/en/documents/product-specifications/high-definition-audio-specification.pdf
class Codec;
class Controller final
: public AudioController
, public PCI::Device {
public:
static ErrorOr<bool> probe(PCI::DeviceIdentifier const&);
static ErrorOr<NonnullRefPtr<AudioController>> create(PCI::DeviceIdentifier const&);
virtual ~Controller() = default;
// ^PCI::Device
virtual StringView device_name() const override { return "IntelHDA"sv; }
ErrorOr<u32> send_command(u8 codec_address, u8 node_id, CodecControlVerb verb, u16 payload);
private:
static constexpr size_t fixed_audio_channel_index = 0;
// 3.3: High Definition Audio Controller Register Set
enum ControllerRegister : u8 {
GlobalCapabilities = 0x00,
VersionMinor = 0x02,
VersionMajor = 0x03,
GlobalControl = 0x08,
StateChangeStatus = 0x0e,
CommandOutboundRingBufferOffset = 0x40,
ResponseInboundRingBufferOffset = 0x50,
StreamsOffset = 0x80,
};
// 3.3.7: GCTL Global Control
enum GlobalControlFlag : u32 {
ControllerReset = 1u << 0,
AcceptUnsolicitedResponseEnable = 1u << 8,
};
Controller(PCI::DeviceIdentifier const&, NonnullOwnPtr<IOWindow>);
ErrorOr<void> initialize_codec(u8 codec_address);
ErrorOr<void> configure_output_route();
ErrorOr<void> reset();
// ^AudioController
virtual LockRefPtr<AudioChannel> audio_channel(u32 index) const override;
virtual ErrorOr<size_t> write(size_t channel_index, UserOrKernelBuffer const& data, size_t length) override;
virtual ErrorOr<void> initialize(Badge<AudioManagement>) override;
virtual ErrorOr<void> set_pcm_output_sample_rate(size_t channel_index, u32 samples_per_second_rate) override;
virtual ErrorOr<u32> get_pcm_output_sample_rate(size_t channel_index) override;
NonnullOwnPtr<IOWindow> m_controller_io_window;
u8 m_number_of_output_streams;
u8 m_number_of_input_streams;
u8 m_number_of_bidirectional_streams;
OwnPtr<CommandOutboundRingBuffer> m_command_buffer;
OwnPtr<ResponseInboundRingBuffer> m_response_buffer;
Vector<NonnullRefPtr<Codec>> m_codecs {};
OwnPtr<OutputPath> m_output_path;
LockRefPtr<AudioChannel> m_audio_channel;
};
}