sio_pci.c revision 85365
185365Simp/*
285365Simp * Copyright (c) 2001 M. Warner Losh.  All rights reserved.
385365Simp *
485365Simp * Redistribution and use in source and binary forms, with or without
585365Simp * modification, are permitted provided that the following conditions
685365Simp * are met:
785365Simp * 1. Redistributions of source code must retain the above copyright
885365Simp *    notice, this list of conditions and the following disclaimer.
985365Simp * 2. Redistributions in binary form must reproduce the above copyright
1085365Simp *    notice, this list of conditions and the following disclaimer in the
1185365Simp *    documentation and/or other materials provided with the distribution.
1285365Simp *
1385365Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1485365Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1585365Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1685365Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1785365Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1885365Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1985365Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2085365Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2185365Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2285365Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2385365Simp *
2485365Simp * $FreeBSD: head/sys/dev/sio/sio_pci.c 85365 2001-10-23 15:17:33Z imp $
2585365Simp */
2685365Simp
2785365Simp#include <sys/param.h>
2885365Simp#include <sys/systm.h>
2985365Simp#include <sys/bus.h>
3085365Simp#include <sys/conf.h>
3185365Simp#include <sys/kernel.h>
3285365Simp#include <sys/lock.h>
3385365Simp#include <sys/malloc.h>
3485365Simp#include <sys/mutex.h>
3585365Simp#include <sys/module.h>
3685365Simp#include <sys/tty.h>
3785365Simp#include <machine/clock.h>
3885365Simp#include <machine/bus_pio.h>
3985365Simp#include <machine/bus.h>
4085365Simp#include <sys/timepps.h>
4185365Simp
4285365Simp#include <dev/sio/siovar.h>
4385365Simp
4485365Simp#include <pci/pcireg.h>
4585365Simp#include <pci/pcivar.h>
4685365Simp
4785365Simpstatic	int	sio_pci_attach __P((device_t dev));
4885365Simpstatic	void	sio_pci_kludge_unit __P((device_t dev));
4985365Simpstatic	int	sio_pci_probe __P((device_t dev));
5085365Simp
5185365Simpstatic device_method_t sio_pci_methods[] = {
5285365Simp	/* Device interface */
5385365Simp	DEVMETHOD(device_probe,		sio_pci_probe),
5485365Simp	DEVMETHOD(device_attach,	sio_pci_attach),
5585365Simp
5685365Simp	{ 0, 0 }
5785365Simp};
5885365Simp
5985365Simpstatic driver_t sio_pci_driver = {
6085365Simp	sio_driver_name,
6185365Simp	sio_pci_methods,
6285365Simp	sizeof(struct com_s),
6385365Simp};
6485365Simp
6585365Simpstruct pci_ids {
6685365Simp	u_int32_t	type;
6785365Simp	const char	*desc;
6885365Simp	int		rid;
6985365Simp};
7085365Simp
7185365Simpstatic struct pci_ids pci_ids[] = {
7285365Simp	{ 0x100812b9, "3COM PCI FaxModem", 0x10 },
7385365Simp	{ 0x2000131f, "CyberSerial (1-port) 16550", 0x10 },
7485365Simp	{ 0x01101407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
7585365Simp	{ 0x01111407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
7685365Simp	{ 0x048011c1, "Lucent kermit based PCI Modem", 0x14 },
7785365Simp	{ 0x95211415, "Oxford Semiconductor PCI Dual Port Serial", 0x10 },
7885365Simp	{ 0x0000151f, "SmartLink 5634PCV SurfRider", 0x10 },
7985365Simp	/* { 0xXXXXXXXX, "Xircom Cardbus modem", 0x10 }, */
8085365Simp	{ 0x00000000, NULL, 0 }
8185365Simp};
8285365Simp
8385365Simpstatic int
8485365Simpsio_pci_attach(dev)
8585365Simp	device_t	dev;
8685365Simp{
8785365Simp	u_int32_t	type;
8885365Simp	struct pci_ids	*id;
8985365Simp
9085365Simp	type = pci_get_devid(dev);
9185365Simp	id = pci_ids;
9285365Simp	while (id->type && id->type != type)
9385365Simp		id++;
9485365Simp	if (id->desc == NULL)
9585365Simp		return (ENXIO);
9685365Simp	sio_pci_kludge_unit(dev);
9785365Simp	return (sioattach(dev, id->rid));
9885365Simp}
9985365Simp
10085365Simp/*
10185365Simp * Don't cut and paste this to other drivers.  It is a horrible kludge
10285365Simp * which will fail to work and also be unnecessary in future versions.
10385365Simp */
10485365Simpstatic void
10585365Simpsio_pci_kludge_unit(dev)
10685365Simp	device_t dev;
10785365Simp{
10885365Simp	devclass_t	dc;
10985365Simp	int		err;
11085365Simp	int		start;
11185365Simp	int		unit;
11285365Simp
11385365Simp	unit = 0;
11485365Simp	start = 0;
11585365Simp	while (resource_int_value("sio", unit, "port", &start) == 0 &&
11685365Simp	    start > 0)
11785365Simp		unit++;
11885365Simp	if (device_get_unit(dev) < unit) {
11985365Simp		dc = device_get_devclass(dev);
12085365Simp		while (devclass_get_device(dc, unit))
12185365Simp			unit++;
12285365Simp		device_printf(dev, "moving to sio%d\n", unit);
12385365Simp		err = device_set_unit(dev, unit);	/* EVIL DO NOT COPY */
12485365Simp		if (err)
12585365Simp			device_printf(dev, "error moving device %d\n", err);
12685365Simp	}
12785365Simp}
12885365Simp
12985365Simpstatic int
13085365Simpsio_pci_probe(dev)
13185365Simp	device_t	dev;
13285365Simp{
13385365Simp	u_int32_t	type;
13485365Simp	struct pci_ids	*id;
13585365Simp
13685365Simp	type = pci_get_devid(dev);
13785365Simp	id = pci_ids;
13885365Simp	while (id->type && id->type != type)
13985365Simp		id++;
14085365Simp	if (id->desc == NULL)
14185365Simp		return (ENXIO);
14285365Simp	device_set_desc(dev, id->desc);
14385365Simp	return (sioprobe(dev, id->rid, 0));
14485365Simp}
14585365Simp
14685365SimpDRIVER_MODULE(sio, pci, sio_pci_driver, sio_devclass, 0, 0);
14785365SimpDRIVER_MODULE(sio, cardbus, sio_pci_driver, sio_devclass, 0, 0);
148