From 3faf5c43a8b78fb682949d2e24b590cc9ab41df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 19 Jun 2020 14:38:37 +0200 Subject: [PATCH] dde_bsd: seperate PCI back end The supported drivers so far exclusively used PCI and for practical reasons the emulation environment was to tied to. To make future addition of drivers that employ other transport busses easier, split the bus handling into its own backend. This is preliminary clean-up work before introducing the USB audio driver. Issue #3929. --- repos/dde_bsd/lib/mk/dde_bsd_audio.inc | 19 +--- repos/dde_bsd/lib/mk/dde_bsd_audio_pci.mk | 49 +++++++++++ .../recipes/src/bsd_audio_drv/content.mk | 5 +- repos/dde_bsd/src/drivers/audio/target.mk | 2 +- repos/dde_bsd/src/lib/audio/bsd.h | 5 +- repos/dde_bsd/src/lib/audio/bsd_emul.c | 72 ++------------- repos/dde_bsd/src/lib/audio/bsd_emul_pci.c | 88 +++++++++++++++++++ repos/dde_bsd/src/lib/audio/driver.cc | 3 +- repos/dde_bsd/src/lib/audio/irq.cc | 3 +- .../dde_bsd/src/lib/audio/{bus.cc => pci.cc} | 0 repos/dde_bsd/src/lib/audio/timer.cc | 3 +- 11 files changed, 155 insertions(+), 94 deletions(-) create mode 100644 repos/dde_bsd/lib/mk/dde_bsd_audio_pci.mk create mode 100644 repos/dde_bsd/src/lib/audio/bsd_emul_pci.c rename repos/dde_bsd/src/lib/audio/{bus.cc => pci.cc} (100%) diff --git a/repos/dde_bsd/lib/mk/dde_bsd_audio.inc b/repos/dde_bsd/lib/mk/dde_bsd_audio.inc index 1840d97919..9653e62c8d 100644 --- a/repos/dde_bsd/lib/mk/dde_bsd_audio.inc +++ b/repos/dde_bsd/lib/mk/dde_bsd_audio.inc @@ -13,7 +13,7 @@ INC_DIR += $(AUDIO_CONTRIB_DIR) LIBS += dde_bsd_audio_include -SRC_CC += bus.cc dummies.cc driver.cc irq.cc mem.cc misc.cc scheduler.cc timer.cc +SRC_CC += dummies.cc driver.cc irq.cc mem.cc misc.cc scheduler.cc timer.cc SRC_C += bsd_emul.c SRC_S += setjmp.S @@ -30,26 +30,9 @@ CC_C_OPT += -Wno-maybe-uninitialized # enable when debugging #CC_OPT += -DAUDIO_DEBUG -#CC_OPT += -DAC97_DEBUG -#CC_OPT += -DAUICH_DEBUG -#CC_OPT += -DAZALIA_DEBUG -#CC_OPT += -DDIAGNOSTIC # audio interface SRC_C += dev/audio.c - -# AC97 codec -SRC_C += dev/ic/ac97.c - -# HDA driver -SRC_C += dev/pci/azalia.c dev/pci/azalia_codec.c - -# ICH driver -SRC_C += dev/pci/auich.c - -# ES1370 -SRC_C += dev/pci/eap.c - SRC_C += dev/mulaw.c vpath %.c $(AUDIO_CONTRIB_DIR) diff --git a/repos/dde_bsd/lib/mk/dde_bsd_audio_pci.mk b/repos/dde_bsd/lib/mk/dde_bsd_audio_pci.mk new file mode 100644 index 0000000000..6518114a49 --- /dev/null +++ b/repos/dde_bsd/lib/mk/dde_bsd_audio_pci.mk @@ -0,0 +1,49 @@ +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 + +# +# Set include paths up before adding the dde_bsd_audio_include library +# because it will use INC_DIR += and must be at the end +# +INC_DIR += $(LIB_DIR) +INC_DIR += $(LIB_INC_DIR) +INC_DIR += $(AUDIO_CONTRIB_DIR) + +LIBS += dde_bsd_audio_include + +SRC_C := bsd_emul_pci.c +SRC_CC += pci.cc + +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 += -DAC97_DEBUG +#CC_OPT += -DAUICH_DEBUG +#CC_OPT += -DAZALIA_DEBUG +#CC_OPT += -DDIAGNOSTIC + +# AC97 codec +SRC_C += dev/ic/ac97.c + +# HDA driver +SRC_C += dev/pci/azalia.c dev/pci/azalia_codec.c + +# ICH driver +SRC_C += dev/pci/auich.c + +# ES1370 +SRC_C += dev/pci/eap.c + +vpath %.c $(AUDIO_CONTRIB_DIR) +vpath %.c $(LIB_DIR) +vpath %.cc $(LIB_DIR) + +# vi: set ft=make : diff --git a/repos/dde_bsd/recipes/src/bsd_audio_drv/content.mk b/repos/dde_bsd/recipes/src/bsd_audio_drv/content.mk index 5be7b89dca..f104af33c5 100644 --- a/repos/dde_bsd/recipes/src/bsd_audio_drv/content.mk +++ b/repos/dde_bsd/recipes/src/bsd_audio_drv/content.mk @@ -1,6 +1,8 @@ PORT_DIR := $(call port_dir,$(REP_DIR)/ports/dde_bsd) -LIB_MK := $(addprefix lib/mk/, dde_bsd_audio.inc dde_bsd_audio_include.mk) \ +MK_FILES := dde_bsd_audio.inc dde_bsd_audio_include.mk dde_bsd_audio_pci.mk + +LIB_MK := $(addprefix lib/mk/, $(MK_FILES)) \ $(foreach SPEC,x86_32 x86_64,lib/mk/spec/$(SPEC)/dde_bsd_audio.mk) \ lib/import/import-dde_bsd_audio_include.mk @@ -21,6 +23,7 @@ MIRROR_FROM_PORT_DIR := $(addprefix src/lib/audio/, \ dev/audio.c \ dev/ic/ac97.h \ dev/ic/ac97.c \ + lib/libkern \ sys/device.h \ sys/audioio.h \ sys/queue.h) diff --git a/repos/dde_bsd/src/drivers/audio/target.mk b/repos/dde_bsd/src/drivers/audio/target.mk index a11773facc..5d0a08ddb2 100644 --- a/repos/dde_bsd/src/drivers/audio/target.mk +++ b/repos/dde_bsd/src/drivers/audio/target.mk @@ -1,7 +1,7 @@ REQUIRES = x86 pci TARGET = audio_drv SRC_CC = main.cc -LIBS = dde_bsd_audio base +LIBS = dde_bsd_audio dde_bsd_audio_pci base INC_DIR += $(REP_DIR)/include CC_CXX_WARN_STRICT = diff --git a/repos/dde_bsd/src/lib/audio/bsd.h b/repos/dde_bsd/src/lib/audio/bsd.h index 7ce60c147b..8f60c79df7 100644 --- a/repos/dde_bsd/src/lib/audio/bsd.h +++ b/repos/dde_bsd/src/lib/audio/bsd.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2017 Genode Labs GmbH + * Copyright (C) 2014-2020 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -19,9 +19,6 @@ #include #include -/* local includes */ -#include - namespace Bsd { int probe_drivers(Genode::Env&, Genode::Allocator&); diff --git a/repos/dde_bsd/src/lib/audio/bsd_emul.c b/repos/dde_bsd/src/lib/audio/bsd_emul.c index f888f928f1..16012527aa 100644 --- a/repos/dde_bsd/src/lib/audio/bsd_emul.c +++ b/repos/dde_bsd/src/lib/audio/bsd_emul.c @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2017 Genode Labs GmbH + * Copyright (C) 2014-2020 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -24,31 +24,11 @@ int hz = HZ; -/* ioconf.c */ +int enodev(void) { return ENODEV; } + + extern struct cfdriver audio_cd; extern struct cfattach audio_ca; -extern struct cfdriver azalia_cd; -extern struct cfattach azalia_ca; -extern struct cfdriver eap_cd; -extern struct cfattach eap_ca; -extern struct cfdriver auich_cd; -extern struct cfattach auich_ca; - - -/* original value */ -enum { PCI_BUS_PARENT = 56 }; -short pv[] = { -1, PCI_BUS_PARENT }; - - -struct cfdata cfdata[] = { - {&audio_ca, &audio_cd, 0, 0, 0, 0, pv+0, 0, 0}, - {&azalia_ca, &azalia_cd, 0, 0, 0, 0, pv+1, 0, 0}, - {&eap_ca, &eap_cd, 0, 0, 0, 0, pv+1, 0, 0}, - {&auich_ca, &auich_cd, 0, 0, 0, 0, pv+1, 0, 0}, -}; - - -int enodev(void) { return ENODEV; } /* global character device switch table */ @@ -75,49 +55,6 @@ struct cdevsw cdevsw[] = { int nchrdev = sizeof(cdevsw) / sizeof(struct cdevsw); -struct device pci_bus = { DV_DULL, { 0, 0 }, 0, 0, { 'p', 'c', 'i', '0'}, 0, 0, 0 }; - -/** - * This function is our little helper that matches and attaches - * the driver to the device. - */ -int probe_cfdata(struct pci_attach_args *pa) -{ - size_t ncd = sizeof(cfdata) / sizeof(struct cfdata); - - size_t i; - for (i = 0; i < ncd; i++) { - struct cfdata *cf = &cfdata[i]; - struct cfdriver *cd = cf->cf_driver; - - if (*cf->cf_parents != PCI_BUS_PARENT) - continue; - - struct cfattach *ca = cf->cf_attach; - if (!ca->ca_match) - continue; - - int rv = ca->ca_match(&pci_bus, 0, pa); - - if (rv) { - struct device *dev = (struct device *) malloc(ca->ca_devsize, - M_DEVBUF, M_NOWAIT|M_ZERO); - - dev->dv_cfdata = cf; - - snprintf(dev->dv_xname, sizeof(dev->dv_xname), "%s%d", cd->cd_name, - dev->dv_unit); - printf("%s at %s\n", dev->dv_xname, pci_bus.dv_xname); - ca->ca_attach(&pci_bus, dev, pa); - - return 1; - } - } - - return 0; -} - - struct device *config_found_sm(struct device *parent, void *aux, cfprint_t print, cfmatch_t submatch) { @@ -157,6 +94,7 @@ struct device *device_lookup(struct cfdriver *cd, int unit) return audio_cd.cd_devs[unit]; } + /***************** ** sys/ucred.h ** *****************/ diff --git a/repos/dde_bsd/src/lib/audio/bsd_emul_pci.c b/repos/dde_bsd/src/lib/audio/bsd_emul_pci.c new file mode 100644 index 0000000000..ad0886c663 --- /dev/null +++ b/repos/dde_bsd/src/lib/audio/bsd_emul_pci.c @@ -0,0 +1,88 @@ +/* + * \brief Audio driver BSD API emulation + * \author Josef Soentgen + * \date 2014-11-09 + */ + +/* + * Copyright (C) 2014-2020 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include + +#include +#include + + +/****************** + ** sys/kernel.h ** + ******************/ + +/* ioconf.c */ +extern struct cfdriver audio_cd; +extern struct cfattach audio_ca; +extern struct cfdriver azalia_cd; +extern struct cfattach azalia_ca; +extern struct cfdriver eap_cd; +extern struct cfattach eap_ca; +extern struct cfdriver auich_cd; +extern struct cfattach auich_ca; + + +/* original value */ +enum { PCI_BUS_PARENT = 56 }; +short pv[] = { -1, PCI_BUS_PARENT }; + + +struct cfdata cfdata[] = { + {&audio_ca, &audio_cd, 0, 0, 0, 0, pv+0, 0, 0}, + {&azalia_ca, &azalia_cd, 0, 0, 0, 0, pv+1, 0, 0}, + {&eap_ca, &eap_cd, 0, 0, 0, 0, pv+1, 0, 0}, + {&auich_ca, &auich_cd, 0, 0, 0, 0, pv+1, 0, 0}, +}; + + +struct device pci_bus = { DV_DULL, { 0, 0 }, 0, 0, { 'p', 'c', 'i', '0'}, 0, 0, 0 }; + +/** + * This function is our little helper that matches and attaches + * the driver to the device. + */ +int probe_cfdata(struct pci_attach_args *pa) +{ + size_t ncd = sizeof(cfdata) / sizeof(struct cfdata); + + size_t i; + for (i = 0; i < ncd; i++) { + struct cfdata *cf = &cfdata[i]; + struct cfdriver *cd = cf->cf_driver; + + if (*cf->cf_parents != PCI_BUS_PARENT) + continue; + + struct cfattach *ca = cf->cf_attach; + if (!ca->ca_match) + continue; + + int rv = ca->ca_match(&pci_bus, 0, pa); + + if (rv) { + struct device *dev = (struct device *) malloc(ca->ca_devsize, + M_DEVBUF, M_NOWAIT|M_ZERO); + + dev->dv_cfdata = cf; + + snprintf(dev->dv_xname, sizeof(dev->dv_xname), "%s%d", cd->cd_name, + dev->dv_unit); + printf("%s at %s\n", dev->dv_xname, pci_bus.dv_xname); + ca->ca_attach(&pci_bus, dev, pa); + + return 1; + } + } + + return 0; +} diff --git a/repos/dde_bsd/src/lib/audio/driver.cc b/repos/dde_bsd/src/lib/audio/driver.cc index 4f597699cf..2c4bc79b19 100644 --- a/repos/dde_bsd/src/lib/audio/driver.cc +++ b/repos/dde_bsd/src/lib/audio/driver.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2017 Genode Labs GmbH + * Copyright (C) 2014-2020 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -23,6 +23,7 @@ #include