xref: /openbsd/sys/arch/armv7/armv7/armv7.c (revision 1e299ff1)
1 /* $OpenBSD: armv7.c,v 1.19 2021/04/02 03:02:46 tb Exp $ */
2 /*
3  * Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.org>
4  * Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se>
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 #include <sys/param.h>
20 #include <sys/systm.h>
21 
22 #define _ARM32_BUS_DMA_PRIVATE
23 #include <machine/bus.h>
24 #include <arm/armv7/armv7var.h>
25 #include <armv7/armv7/armv7var.h>
26 #include <armv7/armv7/armv7_machdep.h>
27 
28 struct arm32_bus_dma_tag armv7_bus_dma_tag = {
29 	NULL,
30 	_bus_dmamap_create,
31 	_bus_dmamap_destroy,
32 	_bus_dmamap_load,
33 	_bus_dmamap_load_mbuf,
34 	_bus_dmamap_load_uio,
35 	_bus_dmamap_load_raw,
36 	_bus_dmamap_load_buffer,
37 	_bus_dmamap_unload,
38 	_bus_dmamap_sync,
39 	_bus_dmamem_alloc,
40 	_bus_dmamem_free,
41 	_bus_dmamem_map,
42 	_bus_dmamem_unmap,
43 	_bus_dmamem_mmap,
44 };
45 
46 struct armv7_dev *armv7_devs = NULL;
47 
48 #define DEVNAME(sc)	(sc)->sc_dv.dv_xname
49 
50 /*
51  * We do direct configuration of devices on this SoC "bus", so we
52  * never call the child device's match function at all (it can be
53  * NULL in the struct cfattach).
54  */
55 int
armv7_submatch(struct device * parent,void * child,void * aux)56 armv7_submatch(struct device *parent, void *child, void *aux)
57 {
58 	struct cfdata *cf = child;
59 	struct armv7_attach_args *aa = aux;
60 
61 	if (strcmp(cf->cf_driver->cd_name, aa->aa_dev->name) == 0)
62 		return (1);
63 
64 	/* "These are not the droids you are looking for." */
65 	return (0);
66 }
67 
68 void
armv7_set_devs(struct armv7_dev * devs)69 armv7_set_devs(struct armv7_dev *devs)
70 {
71 	armv7_devs = devs;
72 }
73 
74 struct armv7_dev *
armv7_find_dev(const char * name,int unit)75 armv7_find_dev(const char *name, int unit)
76 {
77 	struct armv7_dev *ad;
78 
79 	if (armv7_devs == NULL)
80 		panic("%s: armv7_devs == NULL", __func__);
81 
82 	for (ad = armv7_devs; ad->name != NULL; ad++) {
83 		if (ad->unit == unit && strcmp(ad->name, name) == 0)
84 			return (ad);
85 	}
86 
87 	return (NULL);
88 }
89 
90 void
armv7_attach(struct device * parent,struct device * self,void * aux)91 armv7_attach(struct device *parent, struct device *self, void *aux)
92 {
93 	struct armv7_softc *sc = (struct armv7_softc *)self;
94 	struct board_dev *bd;
95 
96 	printf("\n");
97 
98 	sc->sc_board_devs = platform_board_devs();
99 
100 	/* Directly configure on-board devices (dev* in config file). */
101 	for (bd = sc->sc_board_devs; bd->name != NULL; bd++) {
102 		struct armv7_dev *ad = armv7_find_dev(bd->name, bd->unit);
103 		struct armv7_attach_args aa;
104 
105 		if (ad == NULL) {
106 			printf("%s: device %s unit %d not found\n",
107 			    DEVNAME(sc), bd->name, bd->unit);
108 			continue;
109 		}
110 
111 		memset(&aa, 0, sizeof(aa));
112 		aa.aa_dev = ad;
113 		aa.aa_iot = &armv7_bs_tag;
114 		aa.aa_dmat = &armv7_bus_dma_tag;
115 
116 		if (config_found_sm(self, &aa, NULL, armv7_submatch) == NULL)
117 			printf("%s: device %s unit %d not configured\n",
118 			    DEVNAME(sc), bd->name, bd->unit);
119 	}
120 }
121