summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2004-12-20 12:29:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2004-12-20 12:29:41 +0000
commit3e3869cfef1a8e75c93b0337c3e50d80fb063881 (patch)
tree342bb2ce1f238f5748765d46b6ce6c1442ed3a32 /sys/dev
parent58752baf6c05162c1e86192572fb1b9df4719351 (diff)
firmware loading from the filesystem. pci subsystem type things
are still done early, but audio subsystem setup is deferred till after root is mounted. tested by mcbride
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/microcode/Makefile4
-rw-r--r--sys/dev/microcode/yds/Makefile28
-rw-r--r--sys/dev/microcode/yds/build.c59
-rw-r--r--sys/dev/microcode/yds/yds-license8
-rw-r--r--sys/dev/pci/yds.c84
-rw-r--r--sys/dev/pci/ydsreg.h93
-rw-r--r--sys/dev/pci/ydsvar.h95
7 files changed, 242 insertions, 129 deletions
diff --git a/sys/dev/microcode/Makefile b/sys/dev/microcode/Makefile
index 9b5e36e5d36..ff73b6fe833 100644
--- a/sys/dev/microcode/Makefile
+++ b/sys/dev/microcode/Makefile
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile,v 1.8 2004/12/19 16:06:50 deraadt Exp $
+# $OpenBSD: Makefile,v 1.9 2004/12/20 12:29:40 deraadt Exp $
-SUBDIR= atmel tigon neomagic symbol kue typhoon uyap cirruslogic
+SUBDIR= atmel tigon neomagic symbol kue typhoon uyap cirruslogic yds
.include <bsd.subdir.mk>
diff --git a/sys/dev/microcode/yds/Makefile b/sys/dev/microcode/yds/Makefile
new file mode 100644
index 00000000000..f76c30932f6
--- /dev/null
+++ b/sys/dev/microcode/yds/Makefile
@@ -0,0 +1,28 @@
+# $OpenBSD: Makefile,v 1.1 2004/12/20 12:29:40 deraadt Exp $
+
+NOPROG=
+NOMAN=
+
+# PCI capable systems only
+.if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \
+ (${MACHINE} == "alpha") || (${MACHINE} == "sparc64") || \
+ (${MACHINE_ARCH} == "powerpc") || (${MACHINE} == "cats") || \
+ (${MACHINE} == "hppa") || (${MACHINE} == "hppa64") || \
+ (${MACHINE} == "sgi")
+
+FIRM= yds
+
+CLEANFILES+= ${FIRM} build
+
+all: build
+ ${.OBJDIR}/build
+
+afterinstall:
+ ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \
+ ${FIRM} ${DESTDIR}/etc/firmware
+ ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \
+ ${.CURDIR}/yds-license ${DESTDIR}/etc/firmware
+.endif
+
+.include <bsd.prog.mk>
+
diff --git a/sys/dev/microcode/yds/build.c b/sys/dev/microcode/yds/build.c
new file mode 100644
index 00000000000..21900cd56a7
--- /dev/null
+++ b/sys/dev/microcode/yds/build.c
@@ -0,0 +1,59 @@
+/* $OpenBSD: build.c,v 1.1 2004/12/20 12:29:40 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sys/types.h>
+#include <dev/pci/ydsvar.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include "yds_hwmcode.h"
+
+#define FILENAME "yds"
+
+int
+main(int argc, char *argv[])
+{
+ struct yds_firmware yfproto, *yf;
+ int len, fd, i;
+
+ len = sizeof(*yf) - sizeof(yfproto.data) +
+ sizeof(yds_dsp_mcode) + sizeof(yds_ds1_ctrl_mcode) +
+ sizeof(yds_ds1e_ctrl_mcode);
+
+ yf = (struct yds_firmware *)malloc(len);
+ bzero(yf, len);
+
+ yf->dsplen = sizeof(yds_dsp_mcode);
+ yf->ds1len = sizeof(yds_ds1_ctrl_mcode);
+ yf->ds1elen = sizeof(yds_ds1e_ctrl_mcode);
+
+ bcopy(yds_dsp_mcode, &yf->data[0], yf->dsplen);
+ bcopy(yds_ds1_ctrl_mcode, &yf->data[yf->dsplen], yf->ds1len);
+ bcopy(yds_ds1_ctrl_mcode, &yf->data[yf->dsplen + yf->ds1len],
+ yf->ds1elen);
+
+ printf("creating %s length %d [%d+%d+%d]\n",
+ FILENAME, len, yf->dsplen, yf->ds1len, yf->ds1elen);
+ fd = open(FILENAME, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ if (fd == -1)
+ err(1, FILENAME);
+
+ write(fd, yf, len);
+ free(yf);
+ close(fd);
+ return 0;
+}
diff --git a/sys/dev/microcode/yds/yds-license b/sys/dev/microcode/yds/yds-license
new file mode 100644
index 00000000000..2973aac22cf
--- /dev/null
+++ b/sys/dev/microcode/yds/yds-license
@@ -0,0 +1,8 @@
+ Copyright (c) 1997-1999 Yamaha Corporation. All Rights Reserved.
+
+ In private mail to deraadt@openbsd.org:
+ "Free distribution, No restriction for their distribution, We do not make
+ any support." -- suzuki-y@post.yamaha.co.jp
+
+
+This applies to the yds firmware.
diff --git a/sys/dev/pci/yds.c b/sys/dev/pci/yds.c
index 08a636ddb59..291b4fa4bf3 100644
--- a/sys/dev/pci/yds.c
+++ b/sys/dev/pci/yds.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: yds.c,v 1.23 2004/05/24 22:52:52 mickey Exp $ */
+/* $OpenBSD: yds.c,v 1.24 2004/12/20 12:29:36 deraadt Exp $ */
/* $NetBSD: yds.c,v 1.5 2001/05/21 23:55:04 minoura Exp $ */
/*
@@ -64,8 +64,6 @@
#include <machine/bus.h>
#include <machine/intr.h>
-#include <dev/microcode/yds/yds_hwmcode.h>
-
#include <dev/pci/ydsreg.h>
#include <dev/pci/ydsvar.h>
@@ -190,7 +188,7 @@ int yds_get_portnum_by_name(struct yds_softc *, char *, char *,
static u_int yds_get_dstype(int);
static int yds_download_mcode(struct yds_softc *);
static int yds_allocate_slots(struct yds_softc *);
-static void yds_configure_legacy(struct device *arg);
+static void yds_configure_legacy(struct yds_softc *arg);
static void yds_enable_dsp(struct yds_softc *);
static int yds_disable_dsp(struct yds_softc *);
static int yds_ready_codec(struct yds_codec_softc *);
@@ -201,6 +199,7 @@ static struct yds_dma *yds_find_dma(struct yds_softc *, void *);
void yds_powerhook(int, void *);
int yds_init(void *sc);
+void yds_attachhook(void *);
#ifdef AUDIO_DEBUG
static void yds_dump_play_slot(struct yds_softc *, int);
@@ -349,25 +348,31 @@ yds_download_mcode(sc)
u_int ctrl;
const u_int32_t *p;
size_t size;
- int dstype;
-
- static struct {
- const u_int32_t *mcode;
- size_t size;
- } ctrls[] = {
- {yds_ds1_ctrl_mcode, sizeof(yds_ds1_ctrl_mcode)},
- {yds_ds1e_ctrl_mcode, sizeof(yds_ds1e_ctrl_mcode)},
- };
+ u_char *buf;
+ size_t buflen;
+ int error;
+ struct yds_firmware *yf;
- if (sc->sc_flags & YDS_CAP_MCODE_1)
- dstype = YDS_DS_1;
- else if (sc->sc_flags & YDS_CAP_MCODE_1E)
- dstype = YDS_DS_1E;
- else
+ error = loadfirmware("yds", &buf, &buflen);
+ if (error)
+ return 1;
+ yf = (struct yds_firmware *)buf;
+
+ if (sc->sc_flags & YDS_CAP_MCODE_1) {
+ p = (u_int32_t *)&yf->data[yf->dsplen];
+ size = yf->ds1len;
+ } else if (sc->sc_flags & YDS_CAP_MCODE_1E) {
+ p = (u_int32_t *)&yf->data[yf->dsplen + yf->ds1len];
+ size = yf->ds1elen;
+ } else {
+ free(buf, M_DEVBUF);
return 1; /* unknown */
+ }
- if (yds_disable_dsp(sc))
+ if (yds_disable_dsp(sc)) {
+ free(buf, M_DEVBUF);
return 1;
+ }
/* Software reset */
YWRITE4(sc, YDS_MODE, YDS_MODE_RESET);
@@ -381,22 +386,18 @@ yds_download_mcode(sc)
YWRITE4(sc, YDS_WORK_BASE, 0);
ctrl = YREAD2(sc, YDS_GLOBAL_CONTROL);
- YWRITE2(sc, YDS_GLOBAL_CONTROL,
- ctrl & ~0x0007);
+ YWRITE2(sc, YDS_GLOBAL_CONTROL, ctrl & ~0x0007);
/* Download DSP microcode. */
- p = yds_dsp_mcode;
- size = sizeof(yds_dsp_mcode);
- YWRITEREGION4(sc, YDS_DSP_INSTRAM, p, size);
+ YWRITEREGION4(sc, YDS_DSP_INSTRAM, (u_int32_t *)&yf->data[0], yf->dsplen);
/* Download CONTROL microcode. */
- p = ctrls[dstype].mcode;
- size = ctrls[dstype].size;
YWRITEREGION4(sc, YDS_CTRL_INSTRAM, p, size);
yds_enable_dsp(sc);
- delay(10*1000); /* nessesary on my 724F (??) */
+ delay(10*1000); /* neccesary on my 724F (??) */
+ free(buf, M_DEVBUF);
return 0;
}
@@ -556,12 +557,11 @@ yds_match(parent, match, aux)
* to avoid conflict.
*/
static void
-yds_configure_legacy (arg)
- struct device *arg;
+yds_configure_legacy (sc)
+ struct yds_softc *sc;
#define FLEXIBLE (sc->sc_flags & YDS_CAP_LEGACY_FLEXIBLE)
#define SELECTABLE (sc->sc_flags & YDS_CAP_LEGACY_SELECTABLE)
{
- struct yds_softc *sc = (struct yds_softc*) arg;
pcireg_t reg;
struct device *dev;
int i;
@@ -668,9 +668,7 @@ yds_attach(parent, self, aux)
pci_intr_handle_t ih;
bus_size_t size;
pcireg_t reg;
- struct yds_codec_softc *codec;
- mixer_ctrl_t ctl;
- int i, r;
+ int i;
/* Map register to memory */
if (pci_mapreg_map(pa, YDS_PCI_MBA, PCI_MAPREG_TYPE_MEM, 0,
@@ -730,8 +728,21 @@ yds_attach(parent, self, aux)
for (i = 0x80; i < 0xc0; i += 2)
YWRITE2(sc, i, 0);
+ sc->sc_legacy_iot = pa->pa_iot;
+ mountroothook_establish(yds_attachhook, sc);
+}
+
+void
+yds_attachhook(void *xsc)
+{
+ struct yds_softc *sc = xsc;
+ struct yds_codec_softc *codec;
+ mixer_ctrl_t ctl;
+ int r, i;
+
/* Initialize the device */
- yds_init(sc);
+ if (yds_init(sc) == -1)
+ return;
/*
* Attach ac97 codec
@@ -801,12 +812,11 @@ yds_attach(parent, self, aux)
audio_attach_mi(&yds_hw_if, sc, &sc->sc_dev);
- sc->sc_legacy_iot = pa->pa_iot;
- config_defer((struct device*) sc, yds_configure_legacy);
-
/* Watch for power changes */
sc->suspend = PWR_RESUME;
sc->powerhook = powerhook_establish(yds_powerhook, sc);
+
+ yds_configure_legacy(sc);
}
int
diff --git a/sys/dev/pci/ydsreg.h b/sys/dev/pci/ydsreg.h
index b65b47d872f..4515a266a1e 100644
--- a/sys/dev/pci/ydsreg.h
+++ b/sys/dev/pci/ydsreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ydsreg.h,v 1.4 2004/02/19 11:08:11 markus Exp $ */
+/* $OpenBSD: ydsreg.h,v 1.5 2004/12/20 12:29:36 deraadt Exp $ */
/* $NetBSD$ */
/*
@@ -313,4 +313,95 @@ struct effect_slot_ctrl_bank {
u_int32_t temp;
};
+#define N_PLAY_SLOTS 2 /* We use only 2 (R and L) */
+#define N_PLAY_SLOT_CTRL 2
+#define WORK_SIZE 0x0400
+
+/*
+ * softc
+ */
+struct yds_dma {
+ bus_dmamap_t map;
+ caddr_t addr; /* VA */
+ bus_dma_segment_t segs[1];
+ int nsegs;
+ size_t size;
+ struct yds_dma *next;
+};
+
+struct yds_codec_softc {
+ struct device sc_dev; /* base device */
+ struct yds_softc *sc;
+ int id;
+ int status_data;
+ int status_addr;
+ struct ac97_host_if host_if;
+ struct ac97_codec_if *codec_if;
+};
+
+struct yds_softc {
+ struct device sc_dev; /* base device */
+ pci_chipset_tag_t sc_pc;
+ pcitag_t sc_pcitag;
+ pcireg_t sc_id;
+ int sc_revision;
+ void *sc_ih; /* interrupt vectoring */
+ bus_space_tag_t memt;
+ bus_space_handle_t memh;
+ bus_dma_tag_t sc_dmatag; /* DMA tag */
+ u_int sc_flags;
+
+ struct yds_codec_softc sc_codec[2]; /* Primary/Secondary AC97 */
+
+ struct yds_dma *sc_dmas; /* List of DMA handles */
+
+ /*
+ * Play/record status
+ */
+ struct {
+ void (*intr)(void *); /* rint/pint */
+ void *intr_arg; /* arg for intr */
+ u_int offset; /* filled up to here */
+ u_int blksize;
+ u_int factor; /* byte per sample */
+ u_int length; /* ring buffer length */
+ struct yds_dma *dma; /* DMA handle for ring buf */
+ } sc_play, sc_rec;
+
+ /*
+ * DSP control data
+ *
+ * Work space, play control data table, play slot control data,
+ * rec slot control data and effect slot control data are
+ * stored in a single memory segment in this order.
+ */
+ struct yds_dma sc_ctrldata;
+ /* KVA and offset in buffer of play ctrl data tbl */
+ u_int32_t *ptbl;
+ off_t ptbloff;
+ /* KVA and offset in buffer of rec slot ctrl data */
+ struct rec_slot_ctrl_bank *rbank;
+ off_t rbankoff;
+ /* Array of KVA pointers and offset of play slot control data */
+ struct play_slot_ctrl_bank *pbankp[N_PLAY_SLOT_CTRL_BANK
+ *N_PLAY_SLOTS];
+ off_t pbankoff;
+
+ /*
+ * Legacy support
+ */
+ bus_space_tag_t sc_legacy_iot;
+ bus_space_handle_t sc_opl_ioh;
+ struct device *sc_mpu;
+ bus_space_handle_t sc_mpu_ioh;
+
+ /*
+ * Suspend/resume support
+ */
+ void *powerhook;
+ int suspend;
+};
+#define sc_opl_iot sc_legacy_iot
+#define sc_mpu_iot sc_legacy_iot
+
#endif /* _DEV_PCI_YDSREG_H_ */
diff --git a/sys/dev/pci/ydsvar.h b/sys/dev/pci/ydsvar.h
index 647da9cced6..c8ec4836b19 100644
--- a/sys/dev/pci/ydsvar.h
+++ b/sys/dev/pci/ydsvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ydsvar.h,v 1.5 2003/05/14 09:04:59 jason Exp $ */
+/* $OpenBSD: ydsvar.h,v 1.6 2004/12/20 12:29:36 deraadt Exp $ */
/* $NetBSD$ */
/*
@@ -29,95 +29,12 @@
#ifndef _DEV_PCI_YDSVAR_H_
#define _DEV_PCI_YDSVAR_H_
-#define N_PLAY_SLOTS 2 /* We use only 2 (R and L) */
-#define N_PLAY_SLOT_CTRL 2
-#define WORK_SIZE 0x0400
-
-/*
- * softc
- */
-struct yds_dma {
- bus_dmamap_t map;
- caddr_t addr; /* VA */
- bus_dma_segment_t segs[1];
- int nsegs;
- size_t size;
- struct yds_dma *next;
+struct yds_firmware {
+ int dsplen;
+ int ds1len;
+ int ds1elen;
+ u_char data[4];
};
-struct yds_codec_softc {
- struct device sc_dev; /* base device */
- struct yds_softc *sc;
- int id;
- int status_data;
- int status_addr;
- struct ac97_host_if host_if;
- struct ac97_codec_if *codec_if;
-};
-
-struct yds_softc {
- struct device sc_dev; /* base device */
- pci_chipset_tag_t sc_pc;
- pcitag_t sc_pcitag;
- pcireg_t sc_id;
- int sc_revision;
- void *sc_ih; /* interrupt vectoring */
- bus_space_tag_t memt;
- bus_space_handle_t memh;
- bus_dma_tag_t sc_dmatag; /* DMA tag */
- u_int sc_flags;
-
- struct yds_codec_softc sc_codec[2]; /* Primary/Secondary AC97 */
-
- struct yds_dma *sc_dmas; /* List of DMA handles */
-
- /*
- * Play/record status
- */
- struct {
- void (*intr)(void *); /* rint/pint */
- void *intr_arg; /* arg for intr */
- u_int offset; /* filled up to here */
- u_int blksize;
- u_int factor; /* byte per sample */
- u_int length; /* ring buffer length */
- struct yds_dma *dma; /* DMA handle for ring buf */
- } sc_play, sc_rec;
-
- /*
- * DSP control data
- *
- * Work space, play control data table, play slot control data,
- * rec slot control data and effect slot control data are
- * stored in a single memory segment in this order.
- */
- struct yds_dma sc_ctrldata;
- /* KVA and offset in buffer of play ctrl data tbl */
- u_int32_t *ptbl;
- off_t ptbloff;
- /* KVA and offset in buffer of rec slot ctrl data */
- struct rec_slot_ctrl_bank *rbank;
- off_t rbankoff;
- /* Array of KVA pointers and offset of play slot control data */
- struct play_slot_ctrl_bank *pbankp[N_PLAY_SLOT_CTRL_BANK
- *N_PLAY_SLOTS];
- off_t pbankoff;
-
- /*
- * Legacy support
- */
- bus_space_tag_t sc_legacy_iot;
- bus_space_handle_t sc_opl_ioh;
- struct device *sc_mpu;
- bus_space_handle_t sc_mpu_ioh;
-
- /*
- * Suspend/resume support
- */
- void *powerhook;
- int suspend;
-};
-#define sc_opl_iot sc_legacy_iot
-#define sc_mpu_iot sc_legacy_iot
#endif /* _DEV_PCI_YDSVAR_H_ */