1997-08-14 13:57:45 +00:00
|
|
|
/*-
|
1999-01-10 12:04:56 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999 Nicolas Souchu
|
1997-08-14 13:57:45 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2003-08-24 17:55:58 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2000-01-14 00:18:06 +00:00
|
|
|
#include "opt_ppb_1284.h"
|
|
|
|
|
1997-08-14 13:57:45 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-01-14 00:18:06 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
1997-08-14 13:57:45 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbconf.h>
|
1997-08-16 14:05:38 +00:00
|
|
|
#include <dev/ppbus/ppb_1284.h>
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
#include "ppbus_if.h"
|
|
|
|
|
|
|
|
#define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev))
|
|
|
|
|
2000-12-08 20:09:00 +00:00
|
|
|
static MALLOC_DEFINE(M_PPBUSDEV, "ppbusdev", "Parallel Port bus device");
|
1999-01-10 12:04:56 +00:00
|
|
|
|
1997-08-14 13:57:45 +00:00
|
|
|
|
|
|
|
/*
|
2000-01-14 00:18:06 +00:00
|
|
|
* Device methods
|
1997-08-14 13:57:45 +00:00
|
|
|
*/
|
2000-01-14 00:18:06 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ppbus_print_child(device_t bus, device_t dev)
|
|
|
|
{
|
|
|
|
struct ppb_device *ppbdev;
|
|
|
|
|
|
|
|
bus_print_child_header(bus, dev);
|
|
|
|
|
|
|
|
ppbdev = (struct ppb_device *)device_get_ivars(dev);
|
|
|
|
|
|
|
|
if (ppbdev->flags != 0)
|
|
|
|
printf(" flags 0x%x", ppbdev->flags);
|
|
|
|
|
|
|
|
printf(" on %s%d\n", device_get_name(bus), device_get_unit(bus));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ppbus_probe(device_t dev)
|
|
|
|
{
|
|
|
|
device_set_desc(dev, "Parallel port bus");
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
1997-08-14 13:57:45 +00:00
|
|
|
|
|
|
|
/*
|
2000-01-23 14:41:04 +00:00
|
|
|
* ppbus_add_child()
|
1997-08-14 13:57:45 +00:00
|
|
|
*
|
2000-01-14 00:18:06 +00:00
|
|
|
* Add a ppbus device, allocate/initialize the ivars
|
1997-08-14 13:57:45 +00:00
|
|
|
*/
|
2000-01-23 14:41:04 +00:00
|
|
|
static device_t
|
|
|
|
ppbus_add_child(device_t dev, int order, const char *name, int unit)
|
1997-08-14 13:57:45 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_device *ppbdev;
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
/* allocate ivars for the new ppbus child */
|
2000-12-08 21:51:06 +00:00
|
|
|
ppbdev = malloc(sizeof(struct ppb_device), M_PPBUSDEV,
|
|
|
|
M_NOWAIT | M_ZERO);
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!ppbdev)
|
2000-01-23 14:41:04 +00:00
|
|
|
return NULL;
|
2000-01-14 00:18:06 +00:00
|
|
|
|
|
|
|
/* initialize the ivars */
|
|
|
|
ppbdev->name = name;
|
|
|
|
|
|
|
|
/* add the device as a child to the ppbus bus with the allocated
|
|
|
|
* ivars */
|
2000-01-23 14:41:04 +00:00
|
|
|
child = device_add_child_ordered(dev, order, name, unit);
|
2000-01-14 00:18:06 +00:00
|
|
|
device_set_ivars(child, ppbdev);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-23 14:41:04 +00:00
|
|
|
return child;
|
2000-01-14 00:18:06 +00:00
|
|
|
}
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
static int
|
|
|
|
ppbus_read_ivar(device_t bus, device_t dev, int index, uintptr_t* val)
|
2000-01-23 14:41:04 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case PPBUS_IVAR_MODE:
|
|
|
|
/* XXX yet device mode = ppbus mode = chipset mode */
|
|
|
|
*val = (u_long)ppb_get_mode(bus);
|
|
|
|
ppbdev->mode = (u_short)*val;
|
|
|
|
break;
|
|
|
|
case PPBUS_IVAR_AVM:
|
|
|
|
*val = (u_long)ppbdev->avm;
|
|
|
|
break;
|
|
|
|
case PPBUS_IVAR_IRQ:
|
|
|
|
BUS_READ_IVAR(device_get_parent(bus), bus, PPC_IVAR_IRQ, val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENOENT);
|
1997-08-14 13:57:45 +00:00
|
|
|
}
|
2000-01-14 00:18:06 +00:00
|
|
|
|
|
|
|
return (0);
|
1997-08-14 13:57:45 +00:00
|
|
|
}
|
2000-01-14 00:18:06 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ppbus_write_ivar(device_t bus, device_t dev, int index, u_long val)
|
|
|
|
{
|
|
|
|
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case PPBUS_IVAR_MODE:
|
|
|
|
/* XXX yet device mode = ppbus mode = chipset mode */
|
|
|
|
ppb_set_mode(bus,val);
|
|
|
|
ppbdev->mode = ppb_get_mode(bus);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#define PPB_PNP_PRINTER 0
|
|
|
|
#define PPB_PNP_MODEM 1
|
|
|
|
#define PPB_PNP_NET 2
|
|
|
|
#define PPB_PNP_HDC 3
|
|
|
|
#define PPB_PNP_PCMCIA 4
|
|
|
|
#define PPB_PNP_MEDIA 5
|
|
|
|
#define PPB_PNP_FDC 6
|
|
|
|
#define PPB_PNP_PORTS 7
|
|
|
|
#define PPB_PNP_SCANNER 8
|
|
|
|
#define PPB_PNP_DIGICAM 9
|
|
|
|
|
|
|
|
#ifndef DONTPROBE_1284
|
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
static char *pnp_tokens[] = {
|
|
|
|
"PRINTER", "MODEM", "NET", "HDC", "PCMCIA", "MEDIA",
|
|
|
|
"FDC", "PORTS", "SCANNER", "DIGICAM", "", NULL };
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#if 0
|
1997-08-16 14:05:38 +00:00
|
|
|
static char *pnp_classes[] = {
|
|
|
|
"printer", "modem", "network device",
|
|
|
|
"hard disk", "PCMCIA", "multimedia device",
|
|
|
|
"floppy disk", "ports", "scanner",
|
|
|
|
"digital camera", "unknown device", NULL };
|
1999-01-10 12:04:56 +00:00
|
|
|
#endif
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* search_token()
|
|
|
|
*
|
|
|
|
* Search the first occurence of a token within a string
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
search_token(char *str, int slen, char *token)
|
|
|
|
{
|
2001-06-12 07:01:27 +00:00
|
|
|
int tlen, i;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
#define UNKNOWN_LENGTH -1
|
|
|
|
|
|
|
|
if (slen == UNKNOWN_LENGTH)
|
|
|
|
/* get string's length */
|
2001-04-01 07:36:28 +00:00
|
|
|
slen = strlen(str);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
/* get token's length */
|
2001-04-01 07:36:28 +00:00
|
|
|
tlen = strlen(token);
|
1997-08-16 14:05:38 +00:00
|
|
|
if (tlen == 0)
|
|
|
|
return (str);
|
|
|
|
|
|
|
|
for (i = 0; i <= slen-tlen; i++) {
|
2001-04-01 07:36:28 +00:00
|
|
|
if (strncmp(str + i, token, tlen) == 0)
|
1997-08-16 14:05:38 +00:00
|
|
|
return (&str[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_pnp_detect()
|
|
|
|
*
|
|
|
|
* Returns the class id. of the peripherial, -1 otherwise
|
|
|
|
*/
|
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_pnp_detect(device_t bus)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
1999-01-10 12:04:56 +00:00
|
|
|
char *token, *class = 0;
|
1997-08-16 14:05:38 +00:00
|
|
|
int i, len, error;
|
1998-08-03 19:14:33 +00:00
|
|
|
int class_id = -1;
|
1997-08-16 14:05:38 +00:00
|
|
|
char str[PPB_PnP_STRING_SIZE+1];
|
2000-01-14 00:18:06 +00:00
|
|
|
int unit = device_get_unit(bus);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
printf("Probing for PnP devices on ppbus%d:\n", unit);
|
1998-09-13 18:26:26 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = ppb_1284_read_id(bus, PPB_NIBBLE, str,
|
1999-01-10 12:04:56 +00:00
|
|
|
PPB_PnP_STRING_SIZE, &len)))
|
|
|
|
goto end_detect;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("ppb: <PnP> %d characters: ", len);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
printf("%c(0x%x) ", str[i], str[i]);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
/* replace ';' characters by '\0' */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
str[i] = (str[i] == ';') ? '\0' : str[i];
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
if ((token = search_token(str, len, "MFG")) != NULL ||
|
|
|
|
(token = search_token(str, len, "MANUFACTURER")) != NULL)
|
2000-01-14 00:18:06 +00:00
|
|
|
printf("ppbus%d: <%s", unit,
|
1997-08-16 14:05:38 +00:00
|
|
|
search_token(token, UNKNOWN_LENGTH, ":") + 1);
|
|
|
|
else
|
2000-01-14 00:18:06 +00:00
|
|
|
printf("ppbus%d: <unknown", unit);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
if ((token = search_token(str, len, "MDL")) != NULL ||
|
|
|
|
(token = search_token(str, len, "MODEL")) != NULL)
|
1997-08-16 14:05:38 +00:00
|
|
|
printf(" %s",
|
|
|
|
search_token(token, UNKNOWN_LENGTH, ":") + 1);
|
|
|
|
else
|
|
|
|
printf(" unknown");
|
|
|
|
|
|
|
|
if ((token = search_token(str, len, "VER")) != NULL)
|
|
|
|
printf("/%s",
|
|
|
|
search_token(token, UNKNOWN_LENGTH, ":") + 1);
|
|
|
|
|
|
|
|
if ((token = search_token(str, len, "REV")) != NULL)
|
|
|
|
printf(".%s",
|
|
|
|
search_token(token, UNKNOWN_LENGTH, ":") + 1);
|
|
|
|
|
|
|
|
printf(">");
|
|
|
|
|
|
|
|
if ((token = search_token(str, len, "CLS")) != NULL) {
|
|
|
|
class = search_token(token, UNKNOWN_LENGTH, ":") + 1;
|
|
|
|
printf(" %s", class);
|
|
|
|
}
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
if ((token = search_token(str, len, "CMD")) != NULL ||
|
|
|
|
(token = search_token(str, len, "COMMAND")) != NULL)
|
1997-08-16 14:05:38 +00:00
|
|
|
printf(" %s",
|
|
|
|
search_token(token, UNKNOWN_LENGTH, ":") + 1);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (class)
|
|
|
|
/* identify class ident */
|
|
|
|
for (i = 0; pnp_tokens[i] != NULL; i++) {
|
|
|
|
if (search_token(class, len, pnp_tokens[i]) != NULL) {
|
1998-08-03 19:14:33 +00:00
|
|
|
class_id = i;
|
|
|
|
goto end_detect;
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-03 19:14:33 +00:00
|
|
|
class_id = PPB_PnP_UNKNOWN;
|
|
|
|
|
|
|
|
end_detect:
|
1999-01-10 12:04:56 +00:00
|
|
|
return (class_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_scan_bus()
|
|
|
|
*
|
|
|
|
* Scan the ppbus for IEEE1284 compliant devices
|
|
|
|
*/
|
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_scan_bus(device_t bus)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_data * ppb = (struct ppb_data *)device_get_softc(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
int error = 0;
|
2000-01-14 00:18:06 +00:00
|
|
|
int unit = device_get_unit(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* try all IEEE1284 modes, for one device only
|
|
|
|
*
|
|
|
|
* XXX We should implement the IEEE1284.3 standard to detect
|
|
|
|
* daisy chained devices
|
|
|
|
*/
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
if ((ppb->state == PPB_ERROR) && (ppb->error == PPB_NOT_IEEE1284))
|
|
|
|
goto end_scan;
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
printf("ppbus%d: IEEE1284 device found ", unit);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_NIBBLE, 0))) {
|
1999-01-10 12:04:56 +00:00
|
|
|
printf("/NIBBLE");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_PS2, 0))) {
|
1999-01-10 12:04:56 +00:00
|
|
|
printf("/PS2");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_ECP, 0))) {
|
1999-01-10 12:04:56 +00:00
|
|
|
printf("/ECP");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_ECP, PPB_USE_RLE))) {
|
1999-01-10 12:04:56 +00:00
|
|
|
printf("/ECP_RLE");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_EPP, 0))) {
|
1999-01-10 12:04:56 +00:00
|
|
|
printf("/EPP");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
1999-01-11 21:22:41 +00:00
|
|
|
/* try more IEEE1284 modes */
|
|
|
|
if (bootverbose) {
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_NIBBLE,
|
1999-01-11 21:22:41 +00:00
|
|
|
PPB_REQUEST_ID))) {
|
|
|
|
printf("/NIBBLE_ID");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-11 21:22:41 +00:00
|
|
|
}
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_PS2,
|
1999-01-11 21:22:41 +00:00
|
|
|
PPB_REQUEST_ID))) {
|
|
|
|
printf("/PS2_ID");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-11 21:22:41 +00:00
|
|
|
}
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_ECP,
|
1999-01-11 21:22:41 +00:00
|
|
|
PPB_REQUEST_ID))) {
|
|
|
|
printf("/ECP_ID");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-11 21:22:41 +00:00
|
|
|
}
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_ECP,
|
1999-01-11 21:22:41 +00:00
|
|
|
PPB_REQUEST_ID | PPB_USE_RLE))) {
|
|
|
|
printf("/ECP_RLE_ID");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-11 21:22:41 +00:00
|
|
|
}
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(error = ppb_1284_negociate(bus, PPB_COMPATIBLE,
|
1999-01-10 12:04:56 +00:00
|
|
|
PPB_EXTENSIBILITY_LINK))) {
|
1999-01-11 21:22:41 +00:00
|
|
|
printf("/Extensibility Link");
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-11 21:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* detect PnP devices */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb->class_id = ppb_pnp_detect(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
end_scan:
|
|
|
|
return (error);
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#endif /* !DONTPROBE_1284 */
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
static int
|
|
|
|
ppbus_attach(device_t dev)
|
1997-08-14 13:57:45 +00:00
|
|
|
{
|
|
|
|
|
2000-01-23 14:41:04 +00:00
|
|
|
/* Locate our children */
|
|
|
|
bus_generic_probe(dev);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
#ifndef DONTPROBE_1284
|
|
|
|
/* detect IEEE1284 compliant devices */
|
|
|
|
ppb_scan_bus(dev);
|
|
|
|
#endif /* !DONTPROBE_1284 */
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
/* launch attachement of the added children */
|
|
|
|
bus_generic_attach(dev);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
return 0;
|
1997-08-14 13:57:45 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 12:31:34 +00:00
|
|
|
static int
|
|
|
|
ppbus_detach(device_t dev)
|
|
|
|
{
|
|
|
|
device_t *children;
|
|
|
|
int nchildren, i;
|
|
|
|
|
|
|
|
/* detach & delete all children */
|
|
|
|
if (!device_get_children(dev, &children, &nchildren)) {
|
|
|
|
for (i = 0; i < nchildren; i++)
|
|
|
|
if (children[i])
|
|
|
|
device_delete_child(dev, children[i]);
|
|
|
|
free(children, M_TEMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
static int
|
|
|
|
ppbus_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
|
|
|
|
void (*ihand)(void *), void *arg, void **cookiep)
|
1998-08-03 19:14:33 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
int error;
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(child);
|
1998-08-03 19:14:33 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
/* a device driver must own the bus to register an interrupt */
|
|
|
|
if (ppb->ppb_owner != child)
|
|
|
|
return (EINVAL);
|
1998-08-03 19:14:33 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
|
|
|
|
ihand, arg, cookiep)))
|
|
|
|
return (error);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
/* store the resource and the cookie for eventually forcing
|
|
|
|
* handler unregistration
|
|
|
|
*/
|
|
|
|
ppbdev->intr_cookie = *cookiep;
|
|
|
|
ppbdev->intr_resource = r;
|
1997-08-14 13:57:45 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
static int
|
|
|
|
ppbus_teardown_intr(device_t bus, device_t child, struct resource *r, void *ih)
|
1997-08-14 13:57:45 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(child);
|
|
|
|
|
|
|
|
/* a device driver must own the bus to unregister an interrupt */
|
|
|
|
if ((ppb->ppb_owner != child) || (ppbdev->intr_cookie != ih) ||
|
|
|
|
(ppbdev->intr_resource != r))
|
|
|
|
return (EINVAL);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppbdev->intr_cookie = 0;
|
|
|
|
ppbdev->intr_resource = 0;
|
1997-08-14 13:57:45 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
/* pass unregistration to the upper layer */
|
|
|
|
return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, ih));
|
1997-08-14 13:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-16 14:05:38 +00:00
|
|
|
* ppb_request_bus()
|
1997-08-14 13:57:45 +00:00
|
|
|
*
|
1997-08-16 14:05:38 +00:00
|
|
|
* Allocate the device to perform transfers.
|
1997-08-14 13:57:45 +00:00
|
|
|
*
|
1997-08-16 14:05:38 +00:00
|
|
|
* how : PPB_WAIT or PPB_DONTWAIT
|
1997-08-14 13:57:45 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_request_bus(device_t bus, device_t dev, int how)
|
1997-08-14 13:57:45 +00:00
|
|
|
{
|
1997-08-16 14:05:38 +00:00
|
|
|
int s, error = 0;
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
while (!error) {
|
|
|
|
s = splhigh();
|
|
|
|
if (ppb->ppb_owner) {
|
|
|
|
splx(s);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
switch (how) {
|
|
|
|
case (PPB_WAIT | PPB_INTR):
|
|
|
|
error = tsleep(ppb, PPBPRI|PCATCH, "ppbreq", 0);
|
|
|
|
break;
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
case (PPB_WAIT | PPB_NOINTR):
|
|
|
|
error = tsleep(ppb, PPBPRI, "ppbreq", 0);
|
|
|
|
break;
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
default:
|
|
|
|
return (EWOULDBLOCK);
|
|
|
|
break;
|
|
|
|
}
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
} else {
|
|
|
|
ppb->ppb_owner = dev;
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1998-08-03 19:14:33 +00:00
|
|
|
/* restore the context of the device
|
|
|
|
* The first time, ctx.valid is certainly false
|
|
|
|
* then do not change anything. This is usefull for
|
|
|
|
* drivers that do not set there operating mode
|
|
|
|
* during attachement
|
|
|
|
*/
|
2000-01-14 00:18:06 +00:00
|
|
|
if (ppbdev->ctx.valid)
|
|
|
|
ppb_set_mode(bus, ppbdev->ctx.mode);
|
1998-08-03 19:14:33 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
1997-08-14 13:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-16 14:05:38 +00:00
|
|
|
* ppb_release_bus()
|
1997-08-14 13:57:45 +00:00
|
|
|
*
|
2000-05-05 14:10:25 +00:00
|
|
|
* Release the device allocated with ppb_request_bus()
|
1997-08-14 13:57:45 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_release_bus(device_t bus, device_t dev)
|
1997-08-14 13:57:45 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
int s, error;
|
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
|
|
|
|
|
|
|
|
if (ppbdev->intr_resource != 0)
|
|
|
|
/* force interrupt handler unregistration when the ppbus is released */
|
|
|
|
if ((error = BUS_TEARDOWN_INTR(bus, dev, ppbdev->intr_resource,
|
|
|
|
ppbdev->intr_cookie)))
|
|
|
|
return (error);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
s = splhigh();
|
|
|
|
if (ppb->ppb_owner != dev) {
|
|
|
|
splx(s);
|
1997-08-14 13:57:45 +00:00
|
|
|
return (EACCES);
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
ppb->ppb_owner = 0;
|
|
|
|
splx(s);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
1998-08-03 19:14:33 +00:00
|
|
|
/* save the context of the device */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppbdev->ctx.mode = ppb_get_mode(bus);
|
1998-08-03 19:14:33 +00:00
|
|
|
|
|
|
|
/* ok, now the context of the device is valid */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppbdev->ctx.valid = 1;
|
1998-08-03 19:14:33 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
/* wakeup waiting processes */
|
|
|
|
wakeup(ppb);
|
1997-08-14 13:57:45 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2000-01-14 00:18:06 +00:00
|
|
|
|
2000-01-23 14:41:04 +00:00
|
|
|
static devclass_t ppbus_devclass;
|
|
|
|
|
|
|
|
static device_method_t ppbus_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_probe, ppbus_probe),
|
|
|
|
DEVMETHOD(device_attach, ppbus_attach),
|
2006-04-15 12:31:34 +00:00
|
|
|
DEVMETHOD(device_detach, ppbus_detach),
|
2000-01-23 14:41:04 +00:00
|
|
|
|
|
|
|
/* bus interface */
|
|
|
|
DEVMETHOD(bus_add_child, ppbus_add_child),
|
|
|
|
DEVMETHOD(bus_print_child, ppbus_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, ppbus_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, ppbus_write_ivar),
|
|
|
|
DEVMETHOD(bus_setup_intr, ppbus_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, ppbus_teardown_intr),
|
|
|
|
DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ppbus_driver = {
|
|
|
|
"ppbus",
|
|
|
|
ppbus_methods,
|
|
|
|
sizeof(struct ppb_data),
|
|
|
|
};
|
2000-01-14 00:18:06 +00:00
|
|
|
DRIVER_MODULE(ppbus, ppc, ppbus_driver, ppbus_devclass, 0, 0);
|