1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/* $NetBSD: spkr_pcppi.c,v 1.11 2017/06/14 05:01:35 pgoyette Exp $ */
/*
* Copyright (c) 1990 Eric S. Raymond (esr@snark.thyrsus.com)
* Copyright (c) 1990 Andrew A. Chernov (ache@astral.msk.su)
* Copyright (c) 1990 Lennart Augustsson (lennart@augustsson.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Eric S. Raymond
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* spkr.c -- device driver for console speaker on 80386
*
* v1.1 by Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990
* modified for 386bsd by Andrew A. Chernov <ache@astral.msk.su>
* 386bsd only clean version, all SYSV stuff removed
* use hz value from param.c
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: spkr_pcppi.c,v 1.11 2017/06/14 05:01:35 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/uio.h>
#include <sys/proc.h>
#include <sys/ioctl.h>
#include <sys/conf.h>
#include <sys/bus.h>
#include <dev/isa/pcppivar.h>
#include <dev/spkrvar.h>
#include <dev/spkrio.h>
struct spkr_pcppi_softc {
struct spkr_softc sc_spkr;
pcppi_tag_t sc_pcppicookie;
void (*sc_bell_func)(pcppi_tag_t, int, int, int);
};
static int spkr_pcppi_probe(device_t, cfdata_t, void *);
static void spkr_pcppi_attach(device_t, device_t, void *);
static int spkr_pcppi_detach(device_t, int);
static int spkr_pcppi_rescan(device_t, const char *, const int *);
static void spkr_pcppi_childdet(device_t, device_t);
CFATTACH_DECL3_NEW(spkr_pcppi, sizeof(struct spkr_pcppi_softc),
spkr_pcppi_probe, spkr_pcppi_attach, spkr_pcppi_detach, NULL,
spkr_pcppi_rescan, spkr_pcppi_childdet, 0);
#define SPKRPRI (PZERO - 1)
/* emit tone of frequency hz for given number of ticks */
static void
spkr_pcppi_tone(device_t self, u_int xhz, u_int ticks)
{
#ifdef SPKRDEBUG
aprint_debug_dev(self, "%s: %u %u\n", __func__, xhz, ticks);
#endif /* SPKRDEBUG */
struct spkr_pcppi_softc *sc = device_private(self);
(*sc->sc_bell_func)(sc->sc_pcppicookie, xhz, ticks, PCPPI_BELL_SLEEP);
}
/* rest for given number of ticks */
static void
spkr_pcppi_rest(device_t self, int ticks)
{
/*
* Set timeout to endrest function, then give up the timeslice.
* This is so other processes can execute while the rest is being
* waited out.
*/
#ifdef SPKRDEBUG
aprint_debug_dev(self, "%s: %d\n", __func__, ticks);
#endif /* SPKRDEBUG */
if (ticks > 0)
tsleep(self, SPKRPRI | PCATCH, device_xname(self), ticks);
}
static int
spkr_pcppi_probe(device_t parent, cfdata_t cf, void *aux)
{
return 1;
}
static void
spkr_pcppi_attach(device_t parent, device_t self, void *aux)
{
struct pcppi_attach_args *pa = aux;
struct spkr_pcppi_softc *sc = device_private(self);
aprint_naive("\n");
aprint_normal(": PC Speaker\n");
sc->sc_pcppicookie = pa->pa_cookie;
sc->sc_bell_func = pa->pa_bell_func;
spkr_attach(self, spkr_pcppi_tone, spkr_pcppi_rest);
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
}
static int
spkr_pcppi_detach(device_t self, int flags)
{
struct spkr_pcppi_softc *sc = device_private(self);
int error;
if ((error = spkr_detach(self, flags)) != 0)
return error;
sc->sc_pcppicookie = NULL;
pmf_device_deregister(self);
return 0;
}
static int
spkr_pcppi_rescan(device_t self, const char *iattr, const int *locators)
{
return spkr_rescan(self, iattr, locators);
}
static void
spkr_pcppi_childdet(device_t self, device_t child)
{
spkr_childdet(self, child);
}
|