xref: /openbsd/sys/dev/pci/gcu.c (revision 8529ddd3)
1 /*	$OpenBSD: gcu.c,v 1.4 2015/03/19 00:18:11 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * Driver for a GCU device that apears on embeded intel systems, like 80579
21  */
22 
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/device.h>
26 
27 #include <dev/pci/pcireg.h>
28 #include <dev/pci/pcivar.h>
29 
30 #include <dev/pci/pcidevs.h>
31 #include <dev/pci/gcu_var.h>
32 
33 int gcu_probe(struct device *, void *, void *);
34 void gcu_attach(struct device *, struct device *, void *);
35 int gcu_detach(struct device *, int);
36 
37 const struct pci_matchid gcu_devices[] = {
38 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_EP80579_GCU }
39 };
40 
41 struct cfdriver gcu_cd = {
42 	NULL, "gcu", DV_IFNET
43 };
44 
45 struct cfattach gcu_ca = {
46 	sizeof(struct gcu_softc), gcu_probe, gcu_attach
47 };
48 
49 int
50 gcu_probe(struct device *parent, void *match, void *aux)
51 {
52 	return (pci_matchbyid((struct pci_attach_args *)aux, gcu_devices,
53 	    nitems(gcu_devices)));
54 }
55 
56 void
57 gcu_attach(struct device *parent, struct device *self, void *aux)
58 {
59 	struct gcu_softc *sc = (struct gcu_softc *)self;
60 	struct pci_attach_args *pa = aux;
61 	int val;
62 
63 	val = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START);
64 	if (PCI_MAPREG_TYPE(val) != PCI_MAPREG_TYPE_MEM) {
65 		printf(": mmba is not mem space\n");
66 		return;
67 	}
68 
69 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_MEM_TYPE(val), 0, &sc->tag,
70 	    &sc->handle, &sc->addr, &sc->size, 0)) {
71 		printf(": cannot find mem space\n");
72 		return;
73 	}
74 
75 	mtx_init(&sc->mdio_mtx, IPL_NET);
76 
77 	printf("\n");
78 }
79