qemufwcfg_fdt.c revision 1.1.2.2 1 1.1.2.2 pgoyette /* $NetBSD: qemufwcfg_fdt.c,v 1.1.2.2 2018/06/25 07:25:49 pgoyette Exp $ */
2 1.1.2.2 pgoyette
3 1.1.2.2 pgoyette /*-
4 1.1.2.2 pgoyette * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1.2.2 pgoyette * All rights reserved.
6 1.1.2.2 pgoyette *
7 1.1.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 pgoyette * modification, are permitted provided that the following conditions
9 1.1.2.2 pgoyette * are met:
10 1.1.2.2 pgoyette * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 pgoyette * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 pgoyette * documentation and/or other materials provided with the distribution.
15 1.1.2.2 pgoyette *
16 1.1.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1.2.2 pgoyette * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1.2.2 pgoyette * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.2.2 pgoyette * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1.2.2 pgoyette * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1.2.2 pgoyette * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1.2.2 pgoyette * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1.2.2 pgoyette * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1.2.2 pgoyette * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.2.2 pgoyette * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.2.2 pgoyette * SUCH DAMAGE.
27 1.1.2.2 pgoyette */
28 1.1.2.2 pgoyette
29 1.1.2.2 pgoyette #include <sys/cdefs.h>
30 1.1.2.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: qemufwcfg_fdt.c,v 1.1.2.2 2018/06/25 07:25:49 pgoyette Exp $");
31 1.1.2.2 pgoyette
32 1.1.2.2 pgoyette #include <sys/param.h>
33 1.1.2.2 pgoyette #include <sys/device.h>
34 1.1.2.2 pgoyette #include <sys/systm.h>
35 1.1.2.2 pgoyette #include <sys/mutex.h>
36 1.1.2.2 pgoyette #include <sys/bus.h>
37 1.1.2.2 pgoyette
38 1.1.2.2 pgoyette #include <dev/fdt/fdtvar.h>
39 1.1.2.2 pgoyette
40 1.1.2.2 pgoyette #include <dev/ic/qemufwcfgvar.h>
41 1.1.2.2 pgoyette
42 1.1.2.2 pgoyette static int fwcfg_fdt_match(device_t, cfdata_t, void *);
43 1.1.2.2 pgoyette static void fwcfg_fdt_attach(device_t, device_t, void *);
44 1.1.2.2 pgoyette
45 1.1.2.2 pgoyette CFATTACH_DECL_NEW(qemufwcfg_fdt, sizeof(struct fwcfg_softc),
46 1.1.2.2 pgoyette fwcfg_fdt_match,
47 1.1.2.2 pgoyette fwcfg_fdt_attach,
48 1.1.2.2 pgoyette NULL,
49 1.1.2.2 pgoyette NULL
50 1.1.2.2 pgoyette );
51 1.1.2.2 pgoyette
52 1.1.2.2 pgoyette static const char * const compatible[] = {
53 1.1.2.2 pgoyette "qemu,fw-cfg-mmio",
54 1.1.2.2 pgoyette NULL
55 1.1.2.2 pgoyette };
56 1.1.2.2 pgoyette
57 1.1.2.2 pgoyette
58 1.1.2.2 pgoyette static int
59 1.1.2.2 pgoyette fwcfg_fdt_match(device_t parent, cfdata_t match, void *opaque)
60 1.1.2.2 pgoyette {
61 1.1.2.2 pgoyette struct fdt_attach_args * const faa = opaque;
62 1.1.2.2 pgoyette
63 1.1.2.2 pgoyette return of_match_compatible(faa->faa_phandle, compatible);
64 1.1.2.2 pgoyette }
65 1.1.2.2 pgoyette
66 1.1.2.2 pgoyette static void
67 1.1.2.2 pgoyette fwcfg_fdt_attach(device_t parent, device_t self, void *opaque)
68 1.1.2.2 pgoyette {
69 1.1.2.2 pgoyette struct fwcfg_softc *sc = device_private(self);
70 1.1.2.2 pgoyette struct fdt_attach_args * const faa = opaque;
71 1.1.2.2 pgoyette bus_addr_t base;
72 1.1.2.2 pgoyette bus_size_t size;
73 1.1.2.2 pgoyette
74 1.1.2.2 pgoyette if (fdtbus_get_reg(faa->faa_phandle, 0, &base, &size) != 0) {
75 1.1.2.2 pgoyette aprint_error_dev(self, "couldn't get registers\n");
76 1.1.2.2 pgoyette return;
77 1.1.2.2 pgoyette }
78 1.1.2.2 pgoyette
79 1.1.2.2 pgoyette sc->sc_dev = self;
80 1.1.2.2 pgoyette sc->sc_bst = faa->faa_bst;
81 1.1.2.2 pgoyette
82 1.1.2.2 pgoyette if (bus_space_map(sc->sc_bst, base, size, 0, &sc->sc_bsh) != 0) {
83 1.1.2.2 pgoyette aprint_error_dev(self, "couldn't map registers\n");
84 1.1.2.2 pgoyette return;
85 1.1.2.2 pgoyette }
86 1.1.2.2 pgoyette
87 1.1.2.2 pgoyette aprint_naive("\n");
88 1.1.2.2 pgoyette aprint_normal("\n");
89 1.1.2.2 pgoyette
90 1.1.2.2 pgoyette fwcfg_attach(sc);
91 1.1.2.2 pgoyette
92 1.1.2.2 pgoyette pmf_device_register(self, NULL, NULL);
93 1.1.2.2 pgoyette }
94