xref: /openbsd-src/sys/dev/pci/gcu.c (revision 0f9e9ec23bb2b65cc62a3d17df12827a45dae80c)
1 /*	$OpenBSD: gcu.c,v 1.7 2024/05/13 01:15:51 jsg 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 appears on embedded 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 
36 const struct pci_matchid gcu_devices[] = {
37 	{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_EP80579_GCU }
38 };
39 
40 struct cfdriver gcu_cd = {
41 	NULL, "gcu", DV_IFNET
42 };
43 
44 const struct cfattach gcu_ca = {
45 	sizeof(struct gcu_softc), gcu_probe, gcu_attach
46 };
47 
48 int
gcu_probe(struct device * parent,void * match,void * aux)49 gcu_probe(struct device *parent, void *match, void *aux)
50 {
51 	return (pci_matchbyid((struct pci_attach_args *)aux, gcu_devices,
52 	    nitems(gcu_devices)));
53 }
54 
55 void
gcu_attach(struct device * parent,struct device * self,void * aux)56 gcu_attach(struct device *parent, struct device *self, void *aux)
57 {
58 	struct gcu_softc *sc = (struct gcu_softc *)self;
59 	struct pci_attach_args *pa = aux;
60 	int val;
61 
62 	val = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START);
63 	if (PCI_MAPREG_TYPE(val) != PCI_MAPREG_TYPE_MEM) {
64 		printf(": mmba is not mem space\n");
65 		return;
66 	}
67 
68 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_MEM_TYPE(val), 0, &sc->tag,
69 	    &sc->handle, &sc->addr, &sc->size, 0)) {
70 		printf(": cannot find mem space\n");
71 		return;
72 	}
73 
74 	mtx_init(&sc->mdio_mtx, IPL_NET);
75 
76 	printf("\n");
77 }
78