pci_subr.c revision 1.8 1 1.8 cgd /* $NetBSD: pci_subr.c,v 1.8 1995/05/23 03:43:06 cgd Exp $ */
2 1.3 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1994 Charles Hannum. All rights reserved.
5 1.1 mycroft *
6 1.1 mycroft * Redistribution and use in source and binary forms, with or without
7 1.1 mycroft * modification, are permitted provided that the following conditions
8 1.1 mycroft * are met:
9 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.1 mycroft * notice, this list of conditions and the following disclaimer.
11 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.1 mycroft * documentation and/or other materials provided with the distribution.
14 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.1 mycroft * must display the following acknowledgement:
16 1.1 mycroft * This product includes software developed by Charles Hannum.
17 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.1 mycroft * derived from this software without specific prior written permission.
19 1.1 mycroft *
20 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 mycroft */
31 1.1 mycroft
32 1.1 mycroft /*
33 1.1 mycroft * PCI autoconfiguration support
34 1.8 cgd * XXX probably should be moved to pci_subr.c?
35 1.1 mycroft */
36 1.1 mycroft
37 1.1 mycroft #include <sys/types.h>
38 1.1 mycroft #include <sys/param.h>
39 1.1 mycroft #include <sys/device.h>
40 1.1 mycroft
41 1.7 cgd #include <dev/pci/pcivar.h>
42 1.7 cgd #include <dev/pci/pcireg.h>
43 1.1 mycroft
44 1.1 mycroft int
45 1.1 mycroft pciprint(aux, pci)
46 1.1 mycroft void *aux;
47 1.1 mycroft char *pci;
48 1.1 mycroft {
49 1.1 mycroft register struct pci_attach_args *pa = aux;
50 1.1 mycroft
51 1.6 mycroft printf(" bus %d device %d", pa->pa_bus, pa->pa_device);
52 1.6 mycroft return (UNCONF);
53 1.6 mycroft }
54 1.6 mycroft
55 1.6 mycroft int
56 1.6 mycroft pcisubmatch(parent, match, aux)
57 1.6 mycroft struct device *parent;
58 1.6 mycroft void *match, *aux;
59 1.6 mycroft {
60 1.6 mycroft struct cfdata *cf = match;
61 1.6 mycroft struct pci_attach_args *pa = aux;
62 1.6 mycroft
63 1.6 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_bus)
64 1.6 mycroft return 0;
65 1.6 mycroft if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_device)
66 1.6 mycroft return 0;
67 1.6 mycroft return ((*cf->cf_driver->cd_match)(parent, match, aux));
68 1.1 mycroft }
69 1.1 mycroft
70 1.8 cgd /*
71 1.8 cgd * Try to find and attach the PCI device at the give bus and device number.
72 1.8 cgd * Return 1 if successful, 0 if unsuccessful.
73 1.8 cgd */
74 1.8 cgd int
75 1.8 cgd pci_attach_subdev(pcidev, bus, device)
76 1.8 cgd struct device *pcidev;
77 1.8 cgd int bus, device;
78 1.1 mycroft {
79 1.8 cgd pcitag_t tag;
80 1.8 cgd pcireg_t id, class;
81 1.8 cgd struct pci_attach_args pa;
82 1.8 cgd struct cfdata *cf;
83 1.8 cgd
84 1.8 cgd tag = pci_make_tag(bus, device, 0);
85 1.8 cgd id = pci_conf_read(tag, PCI_ID_REG);
86 1.8 cgd if (id == 0 || id == 0xffffffff)
87 1.8 cgd return (0);
88 1.8 cgd class = pci_conf_read(tag, PCI_CLASS_REG);
89 1.8 cgd
90 1.8 cgd pa.pa_bus = bus;
91 1.8 cgd pa.pa_device = device;
92 1.8 cgd pa.pa_tag = tag;
93 1.8 cgd pa.pa_id = id;
94 1.8 cgd pa.pa_class = class;
95 1.8 cgd
96 1.8 cgd if ((cf = config_search(pcisubmatch, pcidev, &pa)) != NULL)
97 1.8 cgd config_attach(pcidev, cf, &pa, pciprint);
98 1.8 cgd else {
99 1.8 cgd printf("%s bus %d device %d: identifier %08x class %08x%s",
100 1.8 cgd pcidev->dv_xname, bus, device, id, class,
101 1.8 cgd " not configured\n");
102 1.8 cgd return (0);
103 1.8 cgd }
104 1.1 mycroft
105 1.8 cgd return (1);
106 1.1 mycroft }
107