1102714Sphk/*	$NetBSD: puc.c,v 1.7 2000/07/29 17:43:38 jlam Exp $	*/
2102714Sphk
3102714Sphk/*-
4102714Sphk * Copyright (c) 2002 JF Hay.  All rights reserved.
5102714Sphk * Copyright (c) 2000 M. Warner Losh.  All rights reserved.
6102714Sphk *
7102714Sphk * Redistribution and use in source and binary forms, with or without
8102714Sphk * modification, are permitted provided that the following conditions
9102714Sphk * are met:
10102714Sphk * 1. Redistributions of source code must retain the above copyright
11140040Simp *    notice, this list of conditions and the following disclaimer.
12102714Sphk * 2. Redistributions in binary form must reproduce the above copyright
13102714Sphk *    notice, this list of conditions and the following disclaimer in the
14102714Sphk *    documentation and/or other materials provided with the distribution.
15102714Sphk *
16140040Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17140040Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18140040Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19140040Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20140040Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21140040Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22140040Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23140040Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24140040Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25140040Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26140040Simp * SUCH DAMAGE.
27102714Sphk */
28102714Sphk
29139749Simp/*-
30102714Sphk * Copyright (c) 1996, 1998, 1999
31102714Sphk *	Christopher G. Demetriou.  All rights reserved.
32102714Sphk *
33102714Sphk * Redistribution and use in source and binary forms, with or without
34102714Sphk * modification, are permitted provided that the following conditions
35102714Sphk * are met:
36102714Sphk * 1. Redistributions of source code must retain the above copyright
37102714Sphk *    notice, this list of conditions and the following disclaimer.
38102714Sphk * 2. Redistributions in binary form must reproduce the above copyright
39102714Sphk *    notice, this list of conditions and the following disclaimer in the
40102714Sphk *    documentation and/or other materials provided with the distribution.
41102714Sphk * 3. All advertising materials mentioning features or use of this software
42102714Sphk *    must display the following acknowledgement:
43102714Sphk *      This product includes software developed by Christopher G. Demetriou
44102714Sphk *	for the NetBSD Project.
45102714Sphk * 4. The name of the author may not be used to endorse or promote products
46102714Sphk *    derived from this software without specific prior written permission
47102714Sphk *
48102714Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
49102714Sphk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50102714Sphk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51102714Sphk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
52102714Sphk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53102714Sphk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54102714Sphk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55102714Sphk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56102714Sphk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
57102714Sphk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58102714Sphk */
59102714Sphk
60102714Sphk#include <sys/cdefs.h>
61102714Sphk__FBSDID("$FreeBSD$");
62102714Sphk
63102714Sphk#include <sys/param.h>
64102714Sphk#include <sys/systm.h>
65102714Sphk#include <sys/kernel.h>
66129879Sphk#include <sys/module.h>
67102714Sphk#include <sys/bus.h>
68102714Sphk#include <sys/conf.h>
69102714Sphk#include <sys/malloc.h>
70102714Sphk
71102714Sphk#include <machine/bus.h>
72102714Sphk#include <machine/resource.h>
73102714Sphk#include <sys/rman.h>
74102714Sphk
75102714Sphk#include <dev/pci/pcireg.h>
76102714Sphk#include <dev/pci/pcivar.h>
77102714Sphk
78160030Sobrien#include <dev/puc/puc_cfg.h>
79158124Smarcel#include <dev/puc/puc_bfe.h>
80102714Sphk
81158124Smarcelstatic const struct puc_cfg *
82158124Smarcelpuc_pci_match(device_t dev, const struct puc_cfg *desc)
83119814Smarcel{
84172617Sdes	uint16_t vendor, device;
85172617Sdes	uint16_t subvendor, subdevice;
86119814Smarcel
87158124Smarcel	vendor = pci_get_vendor(dev);
88158124Smarcel	device = pci_get_device(dev);
89172617Sdes	subvendor = pci_get_subvendor(dev);
90172617Sdes	subdevice = pci_get_subdevice(dev);
91172617Sdes
92172617Sdes	while (desc->vendor != 0xffff) {
93172617Sdes		if (desc->vendor == vendor && desc->device == device) {
94172617Sdes			/* exact match */
95172617Sdes			if (desc->subvendor == subvendor &&
96172617Sdes		            desc->subdevice == subdevice)
97172617Sdes				return (desc);
98172617Sdes			/* wildcard match */
99172617Sdes			if (desc->subvendor == 0xffff)
100172617Sdes				return (desc);
101172617Sdes		}
102158124Smarcel		desc++;
103172617Sdes	}
104172617Sdes
105172617Sdes	/* no match */
106172617Sdes	return (NULL);
107119814Smarcel}
108119814Smarcel
109102714Sphkstatic int
110102714Sphkpuc_pci_probe(device_t dev)
111102714Sphk{
112158124Smarcel	const struct puc_cfg *desc;
113102714Sphk
114119539Sjhb	if ((pci_read_config(dev, PCIR_HDRTYPE, 1) & PCIM_HDRTYPE) != 0)
115102714Sphk		return (ENXIO);
116102714Sphk
117158124Smarcel	desc = puc_pci_match(dev, puc_pci_devices);
118102714Sphk	if (desc == NULL)
119102714Sphk		return (ENXIO);
120158124Smarcel	return (puc_bfe_probe(dev, desc));
121102714Sphk}
122102714Sphk
123102714Sphkstatic device_method_t puc_pci_methods[] = {
124102714Sphk    /* Device interface */
125102714Sphk    DEVMETHOD(device_probe,		puc_pci_probe),
126158124Smarcel    DEVMETHOD(device_attach,		puc_bfe_attach),
127158124Smarcel    DEVMETHOD(device_detach,		puc_bfe_detach),
128102714Sphk
129158124Smarcel    DEVMETHOD(bus_alloc_resource,	puc_bus_alloc_resource),
130158124Smarcel    DEVMETHOD(bus_release_resource,	puc_bus_release_resource),
131158124Smarcel    DEVMETHOD(bus_get_resource,		puc_bus_get_resource),
132158124Smarcel    DEVMETHOD(bus_read_ivar,		puc_bus_read_ivar),
133158124Smarcel    DEVMETHOD(bus_setup_intr,		puc_bus_setup_intr),
134158124Smarcel    DEVMETHOD(bus_teardown_intr,	puc_bus_teardown_intr),
135223091Sjhb    DEVMETHOD(bus_print_child,		puc_bus_print_child),
136223091Sjhb    DEVMETHOD(bus_child_pnpinfo_str,	puc_bus_child_pnpinfo_str),
137223091Sjhb    DEVMETHOD(bus_child_location_str,	puc_bus_child_location_str),
138227843Smarius
139227843Smarius    DEVMETHOD_END
140102714Sphk};
141102714Sphk
142102714Sphkstatic driver_t puc_pci_driver = {
143158124Smarcel	puc_driver_name,
144102714Sphk	puc_pci_methods,
145102714Sphk	sizeof(struct puc_softc),
146102714Sphk};
147102714Sphk
148102714SphkDRIVER_MODULE(puc, pci, puc_pci_driver, puc_devclass, 0, 0);
149