From 49dd9242f778217f84fdcd0f4846ea296bf46aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Wed, 29 Apr 2015 17:00:04 +0200 Subject: [PATCH] dde_bsd: add audio drivers ported from OpenBSD These audio drivers enable support for Intel HD Audio (Azalia) and Ensoniq AudioPCI (ES1370) compatible soundcards. They are ported from OpenBSD 5.7. Fixes #1498. --- repos/dde_bsd/Makefile | 24 + repos/dde_bsd/README | 29 + repos/dde_bsd/audio.list | 18 + repos/dde_bsd/include/audio/audio.h | 40 ++ repos/dde_bsd/lib/mk/audio.inc | 77 ++ repos/dde_bsd/lib/mk/x86_32/audio.mk | 5 + repos/dde_bsd/lib/mk/x86_64/audio.mk | 5 + repos/dde_bsd/patches/oppress_warning.patch | 14 + repos/dde_bsd/ports/dde_bsd.hash | 1 + repos/dde_bsd/ports/dde_bsd.port | 25 + repos/dde_bsd/run/audio_out.run | 166 +++++ repos/dde_bsd/src/drivers/audio_out/main.cc | 297 ++++++++ repos/dde_bsd/src/drivers/audio_out/target.mk | 5 + repos/dde_bsd/src/lib/audio/bsd.h | 51 ++ repos/dde_bsd/src/lib/audio/bsd_emul.c | 141 ++++ repos/dde_bsd/src/lib/audio/bus.cc | 564 +++++++++++++++ repos/dde_bsd/src/lib/audio/driver.cc | 168 +++++ repos/dde_bsd/src/lib/audio/dummies.cc | 67 ++ .../dde_bsd/src/lib/audio/include/bsd_emul.h | 670 ++++++++++++++++++ .../src/lib/audio/include/extern_c_begin.h | 26 + .../src/lib/audio/include/extern_c_end.h | 20 + repos/dde_bsd/src/lib/audio/include/list.h | 99 +++ .../dde_bsd/src/lib/audio/include/scheduler.h | 179 +++++ .../audio/include/x86_32/platform/platform.h | 43 ++ .../audio/include/x86_64/platform/platform.h | 44 ++ repos/dde_bsd/src/lib/audio/irq.cc | 172 +++++ repos/dde_bsd/src/lib/audio/mem.cc | 386 ++++++++++ repos/dde_bsd/src/lib/audio/misc.cc | 127 ++++ repos/dde_bsd/src/lib/audio/scheduler.cc | 256 +++++++ repos/dde_bsd/src/lib/audio/timer.cc | 139 ++++ repos/dde_bsd/src/lib/audio/x86_32/setjmp.S | 79 +++ repos/dde_bsd/src/lib/audio/x86_64/setjmp.S | 93 +++ tool/builddir/etc/build.conf.drivers_x86 | 5 + 33 files changed, 4035 insertions(+) create mode 100644 repos/dde_bsd/Makefile create mode 100644 repos/dde_bsd/README create mode 100644 repos/dde_bsd/audio.list create mode 100644 repos/dde_bsd/include/audio/audio.h create mode 100644 repos/dde_bsd/lib/mk/audio.inc create mode 100644 repos/dde_bsd/lib/mk/x86_32/audio.mk create mode 100644 repos/dde_bsd/lib/mk/x86_64/audio.mk create mode 100644 repos/dde_bsd/patches/oppress_warning.patch create mode 100644 repos/dde_bsd/ports/dde_bsd.hash create mode 100644 repos/dde_bsd/ports/dde_bsd.port create mode 100644 repos/dde_bsd/run/audio_out.run create mode 100644 repos/dde_bsd/src/drivers/audio_out/main.cc create mode 100644 repos/dde_bsd/src/drivers/audio_out/target.mk create mode 100644 repos/dde_bsd/src/lib/audio/bsd.h create mode 100644 repos/dde_bsd/src/lib/audio/bsd_emul.c create mode 100644 repos/dde_bsd/src/lib/audio/bus.cc create mode 100644 repos/dde_bsd/src/lib/audio/driver.cc create mode 100644 repos/dde_bsd/src/lib/audio/dummies.cc create mode 100644 repos/dde_bsd/src/lib/audio/include/bsd_emul.h create mode 100644 repos/dde_bsd/src/lib/audio/include/extern_c_begin.h create mode 100644 repos/dde_bsd/src/lib/audio/include/extern_c_end.h create mode 100644 repos/dde_bsd/src/lib/audio/include/list.h create mode 100644 repos/dde_bsd/src/lib/audio/include/scheduler.h create mode 100644 repos/dde_bsd/src/lib/audio/include/x86_32/platform/platform.h create mode 100644 repos/dde_bsd/src/lib/audio/include/x86_64/platform/platform.h create mode 100644 repos/dde_bsd/src/lib/audio/irq.cc create mode 100644 repos/dde_bsd/src/lib/audio/mem.cc create mode 100644 repos/dde_bsd/src/lib/audio/misc.cc create mode 100644 repos/dde_bsd/src/lib/audio/scheduler.cc create mode 100644 repos/dde_bsd/src/lib/audio/timer.cc create mode 100644 repos/dde_bsd/src/lib/audio/x86_32/setjmp.S create mode 100644 repos/dde_bsd/src/lib/audio/x86_64/setjmp.S diff --git a/repos/dde_bsd/Makefile b/repos/dde_bsd/Makefile new file mode 100644 index 000000000..36e0de04a --- /dev/null +++ b/repos/dde_bsd/Makefile @@ -0,0 +1,24 @@ +# +# \brief Download, and unpack BSD kernel sources +# \author Josef Soentgen +# \date 2014-11-09 +# + +VERBOSE ?= @ +ECHO := @echo + +# +# Print help information by default +# +help:: + +prepare: + $(VERBOSE)../../tool/ports/prepare_port dde_bsd + +help:: + $(ECHO) + $(ECHO) "Prepare the dde_bsd repository" + $(ECHO) + $(ECHO) "--- available commands ---" + $(ECHO) "prepare - checkout upstream source codes" + $(ECHO) diff --git a/repos/dde_bsd/README b/repos/dde_bsd/README new file mode 100644 index 000000000..50be665b9 --- /dev/null +++ b/repos/dde_bsd/README @@ -0,0 +1,29 @@ +This repository contains device drivers ported from OpenBSD. + +Audio +##### + +The audio driver is ported from OpenBSD 5.7 and includes support for +Intel HD Audio as well as for Ensoniq AudioPCI (ES1370) compatible +soundcards. The HDA driver works on real hardware and Virtualbox +whereas the ES1370 driver is only used in Qemu. + + +Usage +===== + +You have to prepare the contrib sources for this repository by +executing _tool/ports/prepare_port dde_bsd_. Also you need to make +sure to add the 'dde_bsd' repository to the REPOSITORIES variable +in your 'etc/build.conf'. + + +Example +======= + +The driver can be tested by executing the run script 'run/audio_out.run'. +This example plays a sample file in a loop. The file format is header less +two channel float 32 at 44100 Hz. You may use the 'sox' utility to create +these audio files: + +! sox -c 2 -r 44100 foo.wav foo.f32 diff --git a/repos/dde_bsd/audio.list b/repos/dde_bsd/audio.list new file mode 100644 index 000000000..ae457ecf8 --- /dev/null +++ b/repos/dde_bsd/audio.list @@ -0,0 +1,18 @@ +./sys/dev/audio.c +./sys/dev/audio_if.h +./sys/dev/pci/azalia.c +./sys/dev/pci/azalia.h +./sys/dev/pci/azalia_codec.c +./sys/dev/pci/eap.c +./sys/dev/pci/eapreg.h +./sys/dev/pci/pcidevs.h +./sys/dev/pci/pcidevs_data.h +./sys/dev/auconv.c +./sys/dev/auconv.h +./sys/dev/mulaw.c +./sys/dev/mulaw.h +./sys/dev/ic/ac97.c +./sys/dev/ic/ac97.h +./sys/sys/audioio.h +./sys/sys/device.h +./sys/sys/queue.h diff --git a/repos/dde_bsd/include/audio/audio.h b/repos/dde_bsd/include/audio/audio.h new file mode 100644 index 000000000..3c3c255a7 --- /dev/null +++ b/repos/dde_bsd/include/audio/audio.h @@ -0,0 +1,40 @@ +/* + * \brief Audio library interface + * \author Josef Soentgen + * \date 2014-12-27 + * + * This header declares the private Audio namespace. It contains + * functions called by the driver frontend that are implemented + * by the driver library. + */ + +/* + * Copyright (C) 2014 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _AUDIO__AUDIO_H_ +#define _AUDIO__AUDIO_H_ + +#include + +/***************************** + ** private Audio namespace ** + *****************************/ + +namespace Audio { + + enum Channel_number { LEFT, RIGHT, MAX_CHANNELS, INVALID = MAX_CHANNELS }; + + void init_driver(Server::Entrypoint &ep); + + bool driver_active(); + + void dma_notifier(Genode::Signal_context_capability cap); + + int play(short *data, Genode::size_t size); +} + +#endif /* _AUDIO__AUDIO_H_ */ diff --git a/repos/dde_bsd/lib/mk/audio.inc b/repos/dde_bsd/lib/mk/audio.inc new file mode 100644 index 000000000..fe9e966c1 --- /dev/null +++ b/repos/dde_bsd/lib/mk/audio.inc @@ -0,0 +1,77 @@ +LIB_DIR = $(REP_DIR)/src/lib/audio +LIB_INC_DIR = $(LIB_DIR)/include + +AUDIO_CONTRIB_DIR := $(call select_from_ports,dde_bsd)/src/lib/audio + +INC_DIR += $(LIB_DIR) +INC_DIR += $(LIB_INC_DIR) +INC_DIR += $(AUDIO_CONTRIB_DIR) + +SRC_CC += bus.cc dummies.cc driver.cc irq.cc mem.cc misc.cc scheduler.cc timer.cc +SRC_C += bsd_emul.c +SRC_S += setjmp.S + +CC_OPT += -Wno-unused-but-set-variable + +# disable builtins +CC_OPT += -fno-builtin-printf -fno-builtin-snprintf -fno-builtin-vsnprintf \ + -fno-builtin-malloc -fno-builtin-free -fno-builtin-log -fno-builtin-log2 + +CC_OPT += -D_KERNEL + +# enable when debugging +# CC_OPT += -DAUDIO_DEBUG +# CC_OPT += -DAZALIA_DEBUG +# CC_OPT += -DDIAGNOSTIC + +# audio interface +SRC_C += dev/audio.c dev/auconv.c + +# AC97 codec +SRC_C += dev/ic/ac97.c + +# HDA driver +SRC_C += dev/pci/azalia.c dev/pci/azalia_codec.c + +# ES1370 +SRC_C += dev/pci/eap.c + +SRC_C += dev/mulaw.c + +# +# Determine the header files included by the contrib code. For each +# of these header files we create a symlink to 'bsd_emul.h'. +# +GEN_INCLUDES := $(shell grep -rh "^\#include .*" $(AUDIO_CONTRIB_DIR) |\ + sed "s/^\#include [^<\"]*[<\"]\([^>\"]*\)[>\"].*/\1/" | sort | uniq) + +# +# Filter out original BSD headers that exist in the contrib directory +# +NO_GEN_INCLUDES := $(shell cd $(AUDIO_CONTRIB_DIR); find -name "*.h" | sed "s/.\///" | sed "s/.*include\///") +GEN_INCLUDES := $(filter-out $(NO_GEN_INCLUDES),$(GEN_INCLUDES)) + +# +# Put BSD headers in 'GEN_INC' dir +# +GEN_INC := $(shell pwd)/include + +$(shell mkdir -p $(GEN_INC)) + +GEN_INCLUDES := $(addprefix $(GEN_INC)/,$(GEN_INCLUDES)) +INC_DIR += $(GEN_INC) + +# +# Make sure to create the header symlinks prior building +# +$(SRC_C:.c=.o) $(SRC_CC:.cc=.o): $(GEN_INCLUDES) + +$(GEN_INCLUDES): + $(VERBOSE)mkdir -p $(dir $@) + $(VERBOSE)ln -s $(LIB_INC_DIR)/bsd_emul.h $@ + +vpath %.c $(AUDIO_CONTRIB_DIR) +vpath %.c $(LIB_DIR) +vpath %.cc $(LIB_DIR) + +# vi: set ft=make : diff --git a/repos/dde_bsd/lib/mk/x86_32/audio.mk b/repos/dde_bsd/lib/mk/x86_32/audio.mk new file mode 100644 index 000000000..06b76f674 --- /dev/null +++ b/repos/dde_bsd/lib/mk/x86_32/audio.mk @@ -0,0 +1,5 @@ +INC_DIR += $(LIB_INC_DIR)/x86_32 $(LIB_INC_DIR)/x86 + +include $(REP_DIR)/lib/mk/audio.inc + +vpath %.S $(LIB_DIR)/x86_32 diff --git a/repos/dde_bsd/lib/mk/x86_64/audio.mk b/repos/dde_bsd/lib/mk/x86_64/audio.mk new file mode 100644 index 000000000..d032c47c7 --- /dev/null +++ b/repos/dde_bsd/lib/mk/x86_64/audio.mk @@ -0,0 +1,5 @@ +INC_DIR += $(LIB_INC_DIR)/x86_64 $(LIB_INC_DIR)/x86 + +include $(REP_DIR)/lib/mk/audio.inc + +vpath %.S $(LIB_DIR)/x86_64 diff --git a/repos/dde_bsd/patches/oppress_warning.patch b/repos/dde_bsd/patches/oppress_warning.patch new file mode 100644 index 000000000..0b3e1ec97 --- /dev/null +++ b/repos/dde_bsd/patches/oppress_warning.patch @@ -0,0 +1,14 @@ +dev/audio.c:XXX:Y: warning: ‘type’ may be used uninitialized in this function [-Wmaybe-uninitialized] +diff --git a/dev/audio.c b/dev/audio.c +index a9fa22b..da8a783 100644 +--- a/dev/audio.c ++++ b/dev/audio.c +@@ -639,7 +639,7 @@ int + audioprint(void *aux, const char *pnp) + { + struct audio_attach_args *arg = aux; +- const char *type; ++ const char *type = "never printed"; + + if (pnp != NULL) { + switch (arg->type) { diff --git a/repos/dde_bsd/ports/dde_bsd.hash b/repos/dde_bsd/ports/dde_bsd.hash new file mode 100644 index 000000000..c5c5d906e --- /dev/null +++ b/repos/dde_bsd/ports/dde_bsd.hash @@ -0,0 +1 @@ +74279f98408dcf0fcd90849659e73fd1cbb82e78 diff --git a/repos/dde_bsd/ports/dde_bsd.port b/repos/dde_bsd/ports/dde_bsd.port new file mode 100644 index 000000000..deb2f0328 --- /dev/null +++ b/repos/dde_bsd/ports/dde_bsd.port @@ -0,0 +1,25 @@ +LICENSE := BSD +VERSION := 1 +DOWNLOADS := audio.archive + +# +# Audio drivers from OpenBSD 5.7 +# +SRC_DIR_AUDIO := src/lib/audio +VERSION_AUDIO := 5.7 +URL(audio) := http://openbsd.cs.fau.de/pub/OpenBSD/$(VERSION_AUDIO)/sys.tar.gz +SHA(audio) := 1a60125a7fce6524b0d62643db47acca0b11506a +DIR(audio) := $(SRC_DIR_AUDIO) +TAR_OPT(audio) := --strip-components=2 --files-from $(REP_DIR)/audio.list +HASH_INPUT += $(REP_DIR)/audio.list + +# +# Patches +# +PATCHES := $(addprefix patches/,$(notdir $(wildcard $(REP_DIR)/patches/*.patch))) + +AUDIO_OPT := -p1 -d$(SRC_DIR_AUDIO) +PATCH_OPT(patches/oppress_warning.patch) := $(AUDIO_OPT) +PATCH_OPT(patches/eap_c.patch) := $(AUDIO_OPT) + +# vi: set ft=make : diff --git a/repos/dde_bsd/run/audio_out.run b/repos/dde_bsd/run/audio_out.run new file mode 100644 index 000000000..3ca1d7912 --- /dev/null +++ b/repos/dde_bsd/run/audio_out.run @@ -0,0 +1,166 @@ +assert_spec x86 + +# +# Check used commands +# + +set wget [check_installed wget] + +# +# Configure +# + +set use_mixer 0 + +# +# Build +# + +set build_components { + core init + drivers/timer + drivers/audio_out + drivers/pci + test/audio_out +} + +lappend_if [have_spec acpi] build_components drivers/acpi +lappend_if [have_spec pci] build_components drivers/pci/device_pd +lappend_if $use_mixer build_components server/mixer + +build $build_components + +create_boot_directory + +# +# Config +# + +append config { + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_spec acpi] config { + + + + + + + + + + + + + + + + + + } + +append_if [expr ![have_spec acpi] && [have_spec pci]] config { + + + + + + + + + } + +append_if $use_mixer config { + + + + + + + + } + +append config { + + + + + + + + + + sample.raw + + } +append_if $use_mixer config { + } +append config { + + + +} + +install_config $config + + +# +# Get sample file +# + +if {[info exists env(GENODE_SAMPLE_RAW)]} { + catch { exec $wget $::env(GENODE_SAMPLE_RAW) -O bin/sample.raw } +} + +if {![file exists bin/sample.raw]} { + puts "" + puts "The sample file is missing. Please take a look at" + puts "repos/dde_bsd/README, create 'sample.raw' and put" + puts "the file into './bin'. afterwards" + puts "" + exit 1 +} + +# +# Boot modules +# + +set boot_modules { + core init timer audio_out_drv test-audio_out sample.raw } + +lappend_if $use_mixer boot_modules mixer + +# platform-specific modules +lappend_if [have_spec acpi] boot_modules acpi_drv +lappend_if [have_spec pci] boot_modules pci_drv +lappend_if [have_spec nova] boot_modules pci_device_pd + +build_boot_image $boot_modules + +append qemu_args " -m 128 -nographic -soundhw es1370 " + +# +# For obvious reasons the timeout depends on the total +# length of the used sample file. +# +run_genode_until {.*played.*1 time\(s\)} 60 diff --git a/repos/dde_bsd/src/drivers/audio_out/main.cc b/repos/dde_bsd/src/drivers/audio_out/main.cc new file mode 100644 index 000000000..d4d74df69 --- /dev/null +++ b/repos/dde_bsd/src/drivers/audio_out/main.cc @@ -0,0 +1,297 @@ +/* + * \brief Startup audio driver library + * \author Josef Soentgen + * \date 2014-11-09 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include