Converted the isa probe and attach to new-bus so that this driver works

without the (defunct) isa compatibility shims.  The new-bus-specific
parts are very similar to the ones for the pci probe and attach.

This was held up too long waiting for a repo copy to src/sys/dev/cy,
so I decided to fix the files in their old place.  This gives easier
to read and merge diffs anyway.

The "count" line in src/sys/conf/files won't be changed until after
the repo copy, so old kernel configs that specify a count need not be
(and must not be) changed until then.  The count is just ignored in
the driver.  One unfinished detail is dynamic allocation of arrays
with <count> and (<count> * 32) entries, and iteration over the arrays.
This is now kludged with a fixed count of 10 (up to 10 cards with up
to 32 ports each).

Prodded by:	imp
Submitted by:	mostly by imp
Approved by:	imp
This commit is contained in:
Bruce Evans 2004-04-05 08:16:23 +00:00
parent cbf67506f6
commit 42d122e125
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=127885
5 changed files with 247 additions and 139 deletions

View File

@ -32,7 +32,6 @@
__FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include "cy.h"
/*
* TODO:
@ -81,15 +80,17 @@ __FBSDID("$FreeBSD$");
#include <sys/syslog.h>
#include <sys/tty.h>
#include <machine/bus.h>
#include <machine/psl.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <isa/isavar.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/cyreg.h>
#include <i386/isa/ic/cd1400.h>
#ifndef COMPAT_OLDISA
#error "The cy device requires the old isa compatibility shims"
#endif
#define NCY 10 /* KLUDGE */
/*
* Dictionary so that I can name everything *sio* or *com* to compare with
@ -117,7 +118,6 @@ __FBSDID("$FreeBSD$");
#define comstart cystart
#define comwakeup cywakeup
#define p_com_addr p_cy_addr
#define sioattach cyattach
#define sioclose cyclose
#define siodriver cydriver
#define siodtrwakeup cydtrwakeup
@ -126,7 +126,6 @@ __FBSDID("$FreeBSD$");
#define sioioctl cyioctl
#define sioopen cyopen
#define siopoll cypoll
#define sioprobe cyprobe
#define siosettimeout cysettimeout
#define siosetwater cysetwater
#define comstop cystop
@ -332,25 +331,26 @@ struct com_s {
u_char obuf2[256];
};
devclass_t cy_devclass;
/* PCI driver entry points. */
void *cyattach_common(cy_addr cy_iobase, int cy_align);
driver_intr_t siointr1;
static ointhand2_t cyointr;
static int cy_units(cy_addr cy_iobase, int cy_align);
static int sioattach(struct isa_device *dev);
static void cd1400_channel_cmd(struct com_s *com, int cmd);
static void cd1400_channel_cmd_wait(struct com_s *com);
static void cd_etc(struct com_s *com, int etc);
static int cd_getreg(struct com_s *com, int reg);
static void cd_setreg(struct com_s *com, int reg, int val);
static int cy_isa_attach(device_t dev);
static int cy_isa_probe(device_t dev);
static timeout_t siodtrwakeup;
static void comhardclose(struct com_s *com);
static void sioinput(struct com_s *com);
static int commctl(struct com_s *com, int bits, int how);
static int comparam(struct tty *tp, struct termios *t);
static void siopoll(void *arg);
static int sioprobe(struct isa_device *dev);
static void siosettimeout(void);
static int siosetwater(struct com_s *com, speed_t speed);
static int comspeed(speed_t speed, u_long cy_clock, int *prescaler_io);
@ -372,13 +372,21 @@ static int sio_inited;
static struct com_s *p_com_addr[NSIO];
#define com_addr(unit) (p_com_addr[unit])
struct isa_driver siodriver = {
INTR_TYPE_TTY | INTR_FAST,
sioprobe,
sioattach,
driver_name
static device_method_t cy_isa_methods[] = {
/* Device interface. */
DEVMETHOD(device_probe, cy_isa_probe),
DEVMETHOD(device_attach, cy_isa_attach),
{ 0, 0 }
};
COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
static driver_t cy_isa_driver = {
driver_name,
cy_isa_methods,
0,
};
DRIVER_MODULE(cy, isa, cy_isa_driver, cy_devclass, 0, 0);
static d_open_t sioopen;
static d_close_t sioclose;
@ -423,12 +431,23 @@ static int cy_total_devices;
static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
static int
sioprobe(dev)
struct isa_device *dev;
cy_isa_probe(device_t dev)
{
cy_addr iobase;
struct resource *mem_res;
cy_addr iobase;
int mem_rid;
iobase = (cy_addr)dev->id_maddr;
if (isa_get_logicalid(dev) != 0) /* skip PnP probes */
return (ENXIO);
mem_rid = 0;
mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
0ul, ~0ul, 0ul, RF_ACTIVE);
if (mem_res == NULL) {
device_printf(dev, "ioport resource allocation failed\n");
return (ENXIO);
}
iobase = rman_get_virtual(mem_res);
/* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
cy_inb(iobase, CY16_RESET, 0); /* XXX? */
@ -438,7 +457,8 @@ sioprobe(dev)
cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
DELAY(500);
return (cy_units(iobase, 0) == 0 ? 0 : -1);
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return (cy_units(iobase, 0) == 0 ? ENXIO : 0);
}
static int
@ -494,29 +514,51 @@ cy_units(cy_iobase, cy_align)
}
static int
sioattach(isdp)
struct isa_device *isdp;
cy_isa_attach(device_t dev)
{
int adapter;
struct com_s *com;
struct resource *irq_res, *mem_res;
void *irq_cookie, *vaddr, *vsc;
int irq_rid, mem_rid;
com = cyattach_common((cy_addr) isdp->id_maddr, 0);
if (com == NULL)
return (0);
adapter = com->unit / CY_MAX_PORTS;
irq_res = NULL;
mem_res = NULL;
/*
* XXX
* This kludge is to allow ISA/PCI device specifications in the
* kernel config file to be in any order.
*/
if (isdp->id_unit != adapter) {
printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
isdp->id_unit = adapter; /* XXX */
mem_rid = 0;
mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
0ul, ~0ul, 0ul, RF_ACTIVE);
if (mem_res == NULL) {
device_printf(dev, "memory resource allocation failed\n");
goto fail;
}
vaddr = rman_get_virtual(mem_res);
vsc = cyattach_common(vaddr, 0);
if (vsc == NULL) {
device_printf(dev, "no ports found!\n");
goto fail;
}
isdp->id_ointr = cyointr;
return (1);
irq_rid = 0;
irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
RF_SHAREABLE | RF_ACTIVE);
if (irq_res == NULL) {
device_printf(dev, "interrupt resource allocation failed\n");
goto fail;
}
if (bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST, cyintr,
vsc, &irq_cookie) != 0) {
device_printf(dev, "interrupt setup failed\n");
goto fail;
}
return (0);
fail:
if (irq_res != NULL)
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
if (mem_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return (ENXIO);
}
void *
@ -1106,12 +1148,6 @@ sioinput(com)
#endif
}
static void
cyointr(int unit)
{
siointr1(com_addr(unit * CY_MAX_PORTS));
}
void
siointr1(vcom)
void *vcom;

View File

@ -32,7 +32,6 @@
__FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include "cy.h"
/*
* TODO:
@ -81,15 +80,17 @@ __FBSDID("$FreeBSD$");
#include <sys/syslog.h>
#include <sys/tty.h>
#include <machine/bus.h>
#include <machine/psl.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <isa/isavar.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/cyreg.h>
#include <i386/isa/ic/cd1400.h>
#ifndef COMPAT_OLDISA
#error "The cy device requires the old isa compatibility shims"
#endif
#define NCY 10 /* KLUDGE */
/*
* Dictionary so that I can name everything *sio* or *com* to compare with
@ -117,7 +118,6 @@ __FBSDID("$FreeBSD$");
#define comstart cystart
#define comwakeup cywakeup
#define p_com_addr p_cy_addr
#define sioattach cyattach
#define sioclose cyclose
#define siodriver cydriver
#define siodtrwakeup cydtrwakeup
@ -126,7 +126,6 @@ __FBSDID("$FreeBSD$");
#define sioioctl cyioctl
#define sioopen cyopen
#define siopoll cypoll
#define sioprobe cyprobe
#define siosettimeout cysettimeout
#define siosetwater cysetwater
#define comstop cystop
@ -332,25 +331,26 @@ struct com_s {
u_char obuf2[256];
};
devclass_t cy_devclass;
/* PCI driver entry points. */
void *cyattach_common(cy_addr cy_iobase, int cy_align);
driver_intr_t siointr1;
static ointhand2_t cyointr;
static int cy_units(cy_addr cy_iobase, int cy_align);
static int sioattach(struct isa_device *dev);
static void cd1400_channel_cmd(struct com_s *com, int cmd);
static void cd1400_channel_cmd_wait(struct com_s *com);
static void cd_etc(struct com_s *com, int etc);
static int cd_getreg(struct com_s *com, int reg);
static void cd_setreg(struct com_s *com, int reg, int val);
static int cy_isa_attach(device_t dev);
static int cy_isa_probe(device_t dev);
static timeout_t siodtrwakeup;
static void comhardclose(struct com_s *com);
static void sioinput(struct com_s *com);
static int commctl(struct com_s *com, int bits, int how);
static int comparam(struct tty *tp, struct termios *t);
static void siopoll(void *arg);
static int sioprobe(struct isa_device *dev);
static void siosettimeout(void);
static int siosetwater(struct com_s *com, speed_t speed);
static int comspeed(speed_t speed, u_long cy_clock, int *prescaler_io);
@ -372,13 +372,21 @@ static int sio_inited;
static struct com_s *p_com_addr[NSIO];
#define com_addr(unit) (p_com_addr[unit])
struct isa_driver siodriver = {
INTR_TYPE_TTY | INTR_FAST,
sioprobe,
sioattach,
driver_name
static device_method_t cy_isa_methods[] = {
/* Device interface. */
DEVMETHOD(device_probe, cy_isa_probe),
DEVMETHOD(device_attach, cy_isa_attach),
{ 0, 0 }
};
COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
static driver_t cy_isa_driver = {
driver_name,
cy_isa_methods,
0,
};
DRIVER_MODULE(cy, isa, cy_isa_driver, cy_devclass, 0, 0);
static d_open_t sioopen;
static d_close_t sioclose;
@ -423,12 +431,23 @@ static int cy_total_devices;
static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
static int
sioprobe(dev)
struct isa_device *dev;
cy_isa_probe(device_t dev)
{
cy_addr iobase;
struct resource *mem_res;
cy_addr iobase;
int mem_rid;
iobase = (cy_addr)dev->id_maddr;
if (isa_get_logicalid(dev) != 0) /* skip PnP probes */
return (ENXIO);
mem_rid = 0;
mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
0ul, ~0ul, 0ul, RF_ACTIVE);
if (mem_res == NULL) {
device_printf(dev, "ioport resource allocation failed\n");
return (ENXIO);
}
iobase = rman_get_virtual(mem_res);
/* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
cy_inb(iobase, CY16_RESET, 0); /* XXX? */
@ -438,7 +457,8 @@ sioprobe(dev)
cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
DELAY(500);
return (cy_units(iobase, 0) == 0 ? 0 : -1);
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return (cy_units(iobase, 0) == 0 ? ENXIO : 0);
}
static int
@ -494,29 +514,51 @@ cy_units(cy_iobase, cy_align)
}
static int
sioattach(isdp)
struct isa_device *isdp;
cy_isa_attach(device_t dev)
{
int adapter;
struct com_s *com;
struct resource *irq_res, *mem_res;
void *irq_cookie, *vaddr, *vsc;
int irq_rid, mem_rid;
com = cyattach_common((cy_addr) isdp->id_maddr, 0);
if (com == NULL)
return (0);
adapter = com->unit / CY_MAX_PORTS;
irq_res = NULL;
mem_res = NULL;
/*
* XXX
* This kludge is to allow ISA/PCI device specifications in the
* kernel config file to be in any order.
*/
if (isdp->id_unit != adapter) {
printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
isdp->id_unit = adapter; /* XXX */
mem_rid = 0;
mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
0ul, ~0ul, 0ul, RF_ACTIVE);
if (mem_res == NULL) {
device_printf(dev, "memory resource allocation failed\n");
goto fail;
}
vaddr = rman_get_virtual(mem_res);
vsc = cyattach_common(vaddr, 0);
if (vsc == NULL) {
device_printf(dev, "no ports found!\n");
goto fail;
}
isdp->id_ointr = cyointr;
return (1);
irq_rid = 0;
irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
RF_SHAREABLE | RF_ACTIVE);
if (irq_res == NULL) {
device_printf(dev, "interrupt resource allocation failed\n");
goto fail;
}
if (bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST, cyintr,
vsc, &irq_cookie) != 0) {
device_printf(dev, "interrupt setup failed\n");
goto fail;
}
return (0);
fail:
if (irq_res != NULL)
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
if (mem_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return (ENXIO);
}
void *
@ -1106,12 +1148,6 @@ sioinput(com)
#endif
}
static void
cyointr(int unit)
{
siointr1(com_addr(unit * CY_MAX_PORTS));
}
void
siointr1(vcom)
void *vcom;

View File

@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$");
#define PLX_9060 0x0c
#define PLX_9080 0x0d
extern devclass_t cy_devclass;
void *cyattach_common(u_char volatile *iobase, int cy_align);
driver_intr_t cyintr;
@ -86,8 +88,6 @@ static driver_t cy_pci_driver = {
0,
};
static devclass_t cy_devclass;
DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
MODULE_DEPEND(cy, pci, 1, 1, 1);

View File

@ -32,7 +32,6 @@
__FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include "cy.h"
/*
* TODO:
@ -81,15 +80,17 @@ __FBSDID("$FreeBSD$");
#include <sys/syslog.h>
#include <sys/tty.h>
#include <machine/bus.h>
#include <machine/psl.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <isa/isavar.h>
#include <i386/isa/isa_device.h>
#include <i386/isa/cyreg.h>
#include <i386/isa/ic/cd1400.h>
#ifndef COMPAT_OLDISA
#error "The cy device requires the old isa compatibility shims"
#endif
#define NCY 10 /* KLUDGE */
/*
* Dictionary so that I can name everything *sio* or *com* to compare with
@ -117,7 +118,6 @@ __FBSDID("$FreeBSD$");
#define comstart cystart
#define comwakeup cywakeup
#define p_com_addr p_cy_addr
#define sioattach cyattach
#define sioclose cyclose
#define siodriver cydriver
#define siodtrwakeup cydtrwakeup
@ -126,7 +126,6 @@ __FBSDID("$FreeBSD$");
#define sioioctl cyioctl
#define sioopen cyopen
#define siopoll cypoll
#define sioprobe cyprobe
#define siosettimeout cysettimeout
#define siosetwater cysetwater
#define comstop cystop
@ -332,25 +331,26 @@ struct com_s {
u_char obuf2[256];
};
devclass_t cy_devclass;
/* PCI driver entry points. */
void *cyattach_common(cy_addr cy_iobase, int cy_align);
driver_intr_t siointr1;
static ointhand2_t cyointr;
static int cy_units(cy_addr cy_iobase, int cy_align);
static int sioattach(struct isa_device *dev);
static void cd1400_channel_cmd(struct com_s *com, int cmd);
static void cd1400_channel_cmd_wait(struct com_s *com);
static void cd_etc(struct com_s *com, int etc);
static int cd_getreg(struct com_s *com, int reg);
static void cd_setreg(struct com_s *com, int reg, int val);
static int cy_isa_attach(device_t dev);
static int cy_isa_probe(device_t dev);
static timeout_t siodtrwakeup;
static void comhardclose(struct com_s *com);
static void sioinput(struct com_s *com);
static int commctl(struct com_s *com, int bits, int how);
static int comparam(struct tty *tp, struct termios *t);
static void siopoll(void *arg);
static int sioprobe(struct isa_device *dev);
static void siosettimeout(void);
static int siosetwater(struct com_s *com, speed_t speed);
static int comspeed(speed_t speed, u_long cy_clock, int *prescaler_io);
@ -372,13 +372,21 @@ static int sio_inited;
static struct com_s *p_com_addr[NSIO];
#define com_addr(unit) (p_com_addr[unit])
struct isa_driver siodriver = {
INTR_TYPE_TTY | INTR_FAST,
sioprobe,
sioattach,
driver_name
static device_method_t cy_isa_methods[] = {
/* Device interface. */
DEVMETHOD(device_probe, cy_isa_probe),
DEVMETHOD(device_attach, cy_isa_attach),
{ 0, 0 }
};
COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
static driver_t cy_isa_driver = {
driver_name,
cy_isa_methods,
0,
};
DRIVER_MODULE(cy, isa, cy_isa_driver, cy_devclass, 0, 0);
static d_open_t sioopen;
static d_close_t sioclose;
@ -423,12 +431,23 @@ static int cy_total_devices;
static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
static int
sioprobe(dev)
struct isa_device *dev;
cy_isa_probe(device_t dev)
{
cy_addr iobase;
struct resource *mem_res;
cy_addr iobase;
int mem_rid;
iobase = (cy_addr)dev->id_maddr;
if (isa_get_logicalid(dev) != 0) /* skip PnP probes */
return (ENXIO);
mem_rid = 0;
mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
0ul, ~0ul, 0ul, RF_ACTIVE);
if (mem_res == NULL) {
device_printf(dev, "ioport resource allocation failed\n");
return (ENXIO);
}
iobase = rman_get_virtual(mem_res);
/* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
cy_inb(iobase, CY16_RESET, 0); /* XXX? */
@ -438,7 +457,8 @@ sioprobe(dev)
cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
DELAY(500);
return (cy_units(iobase, 0) == 0 ? 0 : -1);
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return (cy_units(iobase, 0) == 0 ? ENXIO : 0);
}
static int
@ -494,29 +514,51 @@ cy_units(cy_iobase, cy_align)
}
static int
sioattach(isdp)
struct isa_device *isdp;
cy_isa_attach(device_t dev)
{
int adapter;
struct com_s *com;
struct resource *irq_res, *mem_res;
void *irq_cookie, *vaddr, *vsc;
int irq_rid, mem_rid;
com = cyattach_common((cy_addr) isdp->id_maddr, 0);
if (com == NULL)
return (0);
adapter = com->unit / CY_MAX_PORTS;
irq_res = NULL;
mem_res = NULL;
/*
* XXX
* This kludge is to allow ISA/PCI device specifications in the
* kernel config file to be in any order.
*/
if (isdp->id_unit != adapter) {
printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
isdp->id_unit = adapter; /* XXX */
mem_rid = 0;
mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
0ul, ~0ul, 0ul, RF_ACTIVE);
if (mem_res == NULL) {
device_printf(dev, "memory resource allocation failed\n");
goto fail;
}
vaddr = rman_get_virtual(mem_res);
vsc = cyattach_common(vaddr, 0);
if (vsc == NULL) {
device_printf(dev, "no ports found!\n");
goto fail;
}
isdp->id_ointr = cyointr;
return (1);
irq_rid = 0;
irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
RF_SHAREABLE | RF_ACTIVE);
if (irq_res == NULL) {
device_printf(dev, "interrupt resource allocation failed\n");
goto fail;
}
if (bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST, cyintr,
vsc, &irq_cookie) != 0) {
device_printf(dev, "interrupt setup failed\n");
goto fail;
}
return (0);
fail:
if (irq_res != NULL)
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
if (mem_res != NULL)
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return (ENXIO);
}
void *
@ -1106,12 +1148,6 @@ sioinput(com)
#endif
}
static void
cyointr(int unit)
{
siointr1(com_addr(unit * CY_MAX_PORTS));
}
void
siointr1(vcom)
void *vcom;

View File

@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$");
#define PLX_9060 0x0c
#define PLX_9080 0x0d
extern devclass_t cy_devclass;
void *cyattach_common(u_char volatile *iobase, int cy_align);
driver_intr_t cyintr;
@ -86,8 +88,6 @@ static driver_t cy_pci_driver = {
0,
};
static devclass_t cy_devclass;
DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
MODULE_DEPEND(cy, pci, 1, 1, 1);