xref: /freebsd/sys/dev/ppbus/ppi.c (revision e51b0386a671abbf7a2075a7db6c3d8b62af021f)
1ed381522SMike Smith /*-
2ed381522SMike Smith  * Copyright (c) 1997 Nicolas Souchu
3ed381522SMike Smith  * All rights reserved.
4ed381522SMike Smith  *
5ed381522SMike Smith  * Redistribution and use in source and binary forms, with or without
6ed381522SMike Smith  * modification, are permitted provided that the following conditions
7ed381522SMike Smith  * are met:
8ed381522SMike Smith  * 1. Redistributions of source code must retain the above copyright
9ed381522SMike Smith  *    notice, this list of conditions and the following disclaimer.
10ed381522SMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
11ed381522SMike Smith  *    notice, this list of conditions and the following disclaimer in the
12ed381522SMike Smith  *    documentation and/or other materials provided with the distribution.
13ed381522SMike Smith  *
14ed381522SMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15ed381522SMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16ed381522SMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17ed381522SMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18ed381522SMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19ed381522SMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20ed381522SMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21ed381522SMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22ed381522SMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23ed381522SMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24ed381522SMike Smith  * SUCH DAMAGE.
25ed381522SMike Smith  *
26e51b0386SMike Smith  *	$Id: ppi.c,v 1.1 1997/08/14 13:57:43 msmith Exp $
27ed381522SMike Smith  *
28ed381522SMike Smith  */
29e51b0386SMike Smith #include "ppi.h"
30e51b0386SMike Smith 
31e51b0386SMike Smith #if NPPI > 0
32e51b0386SMike Smith 
33ed381522SMike Smith #include <sys/types.h>
34ed381522SMike Smith 
35ed381522SMike Smith #ifdef KERNEL
36ed381522SMike Smith #include <sys/param.h>
37ed381522SMike Smith #include <sys/systm.h>
38ed381522SMike Smith #include <sys/conf.h>
39ed381522SMike Smith #include <sys/proc.h>
40ed381522SMike Smith #include <sys/buf.h>
41ed381522SMike Smith #include <sys/kernel.h>
42ed381522SMike Smith #include <sys/uio.h>
43ed381522SMike Smith #include <sys/syslog.h>
44ed381522SMike Smith #include <sys/malloc.h>
45ed381522SMike Smith 
46ed381522SMike Smith #include <machine/stdarg.h>
47ed381522SMike Smith #include <machine/clock.h>
48ed381522SMike Smith 
49ed381522SMike Smith #include <i386/isa/isa.h>
50ed381522SMike Smith #include <i386/isa/isa_device.h>
51ed381522SMike Smith 
52ed381522SMike Smith #include <sys/kernel.h>
53ed381522SMike Smith #endif /*KERNEL */
54ed381522SMike Smith 
55ed381522SMike Smith #include <dev/ppbus/ppbconf.h>
56ed381522SMike Smith 
57e51b0386SMike Smith struct ppi_data {
58e51b0386SMike Smith 
59e51b0386SMike Smith 	int ppi_unit;
60e51b0386SMike Smith 
61e51b0386SMike Smith 	struct ppb_device ppi_dev;
62e51b0386SMike Smith };
63e51b0386SMike Smith 
64ed381522SMike Smith #define MAXPPI	8			/* XXX not much better! */
65e51b0386SMike Smith static int 	nppi = 0;
66ed381522SMike Smith static struct ppi_data *ppidata[MAXPPI];
67ed381522SMike Smith 
68ed381522SMike Smith /*
69ed381522SMike Smith  * Make ourselves visible as a ppbus driver
70ed381522SMike Smith  */
71ed381522SMike Smith 
72ed381522SMike Smith static struct ppb_device	*ppiprobe(struct ppb_data *ppb);
73ed381522SMike Smith static int			ppiattach(struct ppb_device *dev);
74ed381522SMike Smith static void			ppiintr(int unit);
75ed381522SMike Smith 
76ed381522SMike Smith static struct ppb_driver ppidriver = {
77ed381522SMike Smith     ppiprobe, ppiattach, "ppi"
78ed381522SMike Smith };
79ed381522SMike Smith DATA_SET(ppbdriver_set, ppidriver);
80ed381522SMike Smith 
81ed381522SMike Smith 
82ed381522SMike Smith static	d_open_t	ppiopen;
83ed381522SMike Smith static	d_close_t	ppiclose;
84ed381522SMike Smith static	d_ioctl_t	ppiioctl;
85ed381522SMike Smith 
86ed381522SMike Smith #define CDEV_MAJOR 14			/* XXX */
87ed381522SMike Smith static struct cdevsw ppi_cdevsw =
88e51b0386SMike Smith 	{ ppiopen,	ppiclose,	noread,		nowrite,	/* 14 */
89ed381522SMike Smith 	  ppiioctl,	nullstop,	nullreset,	nodevtotty,
90ed381522SMike Smith 	  seltrue,	nommap,		nostrat,	"ppi",	NULL,	-1 };
91ed381522SMike Smith 
92ed381522SMike Smith /*
93ed381522SMike Smith  * ppiprobe()
94ed381522SMike Smith  */
95ed381522SMike Smith static struct ppb_device *
96ed381522SMike Smith ppiprobe(struct ppb_data *ppb)
97ed381522SMike Smith {
98ed381522SMike Smith 	struct ppi_data *ppi;
99ed381522SMike Smith 
100ed381522SMike Smith 	ppi = (struct ppi_data *) malloc(sizeof(struct ppi_data),
101ed381522SMike Smith 							M_TEMP, M_NOWAIT);
102ed381522SMike Smith 	if (!ppi) {
103ed381522SMike Smith 		printf("ppi: cannot malloc!\n");
104ed381522SMike Smith 		return 0;
105ed381522SMike Smith 	}
106ed381522SMike Smith 	bzero(ppi, sizeof(struct ppi_data));
107ed381522SMike Smith 
108ed381522SMike Smith 	ppidata[nppi] = ppi;
109ed381522SMike Smith 
110ed381522SMike Smith 	/*
111ed381522SMike Smith 	 * ppi dependent initialisation.
112ed381522SMike Smith 	 */
113ed381522SMike Smith 	ppi->ppi_unit = nppi;
114ed381522SMike Smith 
115ed381522SMike Smith 	/*
116ed381522SMike Smith 	 * ppbus dependent initialisation.
117ed381522SMike Smith 	 */
118ed381522SMike Smith 	ppi->ppi_dev.id_unit = ppi->ppi_unit;
119ed381522SMike Smith 	ppi->ppi_dev.ppb = ppb;
120ed381522SMike Smith 	ppi->ppi_dev.intr = ppiintr;
121ed381522SMike Smith 
122ed381522SMike Smith 	/* Ok, go to next device on next probe */
123ed381522SMike Smith 	nppi ++;
124ed381522SMike Smith 
125ed381522SMike Smith 	return &ppi->ppi_dev;
126ed381522SMike Smith }
127ed381522SMike Smith 
128ed381522SMike Smith static int
129ed381522SMike Smith ppiattach(struct ppb_device *dev)
130ed381522SMike Smith {
131ed381522SMike Smith 	struct ppi_data *ppi = ppidata[dev->id_unit];
132ed381522SMike Smith 
133ed381522SMike Smith 	/*
134ed381522SMike Smith 	 * Report ourselves
135ed381522SMike Smith 	 */
136ed381522SMike Smith 	printf("ppi%d: <generic parallel i/o> on ppbus %d\n",
137ed381522SMike Smith 	       dev->id_unit, dev->ppb->ppb_link->adapter_unit);
138ed381522SMike Smith 
139ed381522SMike Smith 	return (1);
140ed381522SMike Smith }
141ed381522SMike Smith 
142ed381522SMike Smith static void
143ed381522SMike Smith ppiintr(int unit)
144ed381522SMike Smith {
145ed381522SMike Smith 	return;
146ed381522SMike Smith }
147ed381522SMike Smith 
148ed381522SMike Smith static int
149ed381522SMike Smith ppiopen(dev_t dev, int flags, int fmt, struct proc *p)
150ed381522SMike Smith {
151e51b0386SMike Smith 	u_int unit = minor(dev);
152e51b0386SMike Smith 
153e51b0386SMike Smith 	if (unit >= nppi)
154e51b0386SMike Smith 		return (ENXIO);
155e51b0386SMike Smith 
156e51b0386SMike Smith 	printf("ppi open!\n");
157e51b0386SMike Smith 
158ed381522SMike Smith 	return (EOPNOTSUPP);
159ed381522SMike Smith }
160ed381522SMike Smith 
161ed381522SMike Smith static int
162ed381522SMike Smith ppiclose(dev_t dev, int flags, int fmt, struct proc *p)
163ed381522SMike Smith {
164ed381522SMike Smith 	return (EOPNOTSUPP);
165ed381522SMike Smith }
166ed381522SMike Smith 
167ed381522SMike Smith static int
168ed381522SMike Smith ppiioctl(dev_t dev, int cmd, caddr_t data, int flags, struct proc *p)
169ed381522SMike Smith {
170ed381522SMike Smith 	return (EOPNOTSUPP);
171ed381522SMike Smith }
172ed381522SMike Smith 
173e51b0386SMike Smith #ifdef PPI_MODULE
174e51b0386SMike Smith 
175e51b0386SMike Smith #include <sys/exec.h>
176e51b0386SMike Smith #include <sys/sysent.h>
177e51b0386SMike Smith #include <sys/lkm.h>
178e51b0386SMike Smith 
179e51b0386SMike Smith MOD_DEV(ppi, LM_DT_CHAR, CDEV_MAJOR, &ppi_cdevsw);
180e51b0386SMike Smith 
181e51b0386SMike Smith static int
182e51b0386SMike Smith ppi_load(struct lkm_table *lkmtp, int cmd)
183e51b0386SMike Smith {
184e51b0386SMike Smith 	struct ppb_data *ppb;
185e51b0386SMike Smith 	struct ppb_device *dev;
186e51b0386SMike Smith 	int i;
187e51b0386SMike Smith 
188e51b0386SMike Smith 	for (ppb = ppb_next_bus(NULL); ppb; ppb = ppb_next_bus(ppb)) {
189e51b0386SMike Smith 
190e51b0386SMike Smith 		dev = ppiprobe(ppb);
191e51b0386SMike Smith 		ppiattach(dev);
192e51b0386SMike Smith 
193e51b0386SMike Smith 		ppb_attach_device(dev);
194e51b0386SMike Smith 	}
195e51b0386SMike Smith 
196e51b0386SMike Smith 	return (0);
197e51b0386SMike Smith }
198e51b0386SMike Smith 
199e51b0386SMike Smith static int
200e51b0386SMike Smith ppi_unload(struct lkm_table *lkmtp, int cmd)
201e51b0386SMike Smith {
202e51b0386SMike Smith 	int i;
203e51b0386SMike Smith 
204e51b0386SMike Smith 	for (i = nppi-1; i > 0; i--) {
205e51b0386SMike Smith 		ppb_remove_device(&ppidata[i]->ppi_dev);
206e51b0386SMike Smith 		free(ppidata[i], M_TEMP);
207e51b0386SMike Smith 	}
208e51b0386SMike Smith 
209e51b0386SMike Smith 	return (0);
210e51b0386SMike Smith }
211e51b0386SMike Smith 
212e51b0386SMike Smith int
213e51b0386SMike Smith ppi_mod(struct lkm_table *lkmtp, int cmd, int ver)
214e51b0386SMike Smith {
215e51b0386SMike Smith 	DISPATCH(lkmtp, cmd, ver, ppi_load, ppi_unload, lkm_nullcmd);
216e51b0386SMike Smith }
217e51b0386SMike Smith 
218e51b0386SMike Smith #endif /* PPI_MODULE */
219e51b0386SMike Smith 
220ed381522SMike Smith static ppi_devsw_installed = 0;
221ed381522SMike Smith 
222ed381522SMike Smith static void ppi_drvinit(void *unused)
223ed381522SMike Smith {
224ed381522SMike Smith 	dev_t dev;
225ed381522SMike Smith 
226ed381522SMike Smith 	if (!ppi_devsw_installed ) {
227ed381522SMike Smith 		dev = makedev(CDEV_MAJOR, 0);
228ed381522SMike Smith 		cdevsw_add(&dev, &ppi_cdevsw, NULL);
229ed381522SMike Smith 		ppi_devsw_installed = 1;
230ed381522SMike Smith     	}
231ed381522SMike Smith }
232ed381522SMike Smith 
233ed381522SMike Smith SYSINIT(ppidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,ppi_drvinit,NULL)
234e51b0386SMike Smith 
235e51b0386SMike Smith #endif /* NPPI */
236