multiple socs.
From Patrick Wildt in bitrig with some additional changes.
-/* $OpenBSD: armv7.c,v 1.9 2015/05/15 15:35:43 jsg Exp $ */
+/* $OpenBSD: armv7.c,v 1.10 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
* Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se>
#include <machine/bus.h>
#include <arm/armv7/armv7var.h>
#include <armv7/armv7/armv7var.h>
-
-#include "imx.h"
-#include "omap.h"
-#include "sunxi.h"
+#include <armv7/armv7/armv7_machdep.h>
struct arm32_bus_dma_tag armv7_bus_dma_tag = {
0,
extern char *hw_prod;
-struct board_dev * (*board_attach[])(void) = {
-#if NIMX > 0
- imx_board_attach,
-#endif
-#if NOMAP > 0
- omap_board_attach,
-#endif
-#if NSUNXI > 0
- sunxi_board_attach,
-#endif
-};
-
void
armv7_attach(struct device *parent, struct device *self, void *aux)
{
struct armv7_softc *sc = (struct armv7_softc *)self;
struct board_dev *bd;
- int i;
- for (i = 0; i < nitems(board_attach); i++) {
- sc->sc_board_devs = board_attach[i]();
- if (sc->sc_board_devs != NULL)
- break;
- }
+ platform_board_init();
+ sc->sc_board_devs = platform_board_devs();
if (hw_prod)
printf(": %s\n", hw_prod);
-/* $OpenBSD: armv7_machdep.c,v 1.23 2015/05/19 00:05:59 jsg Exp $ */
+/* $OpenBSD: armv7_machdep.c,v 1.24 2015/05/19 03:30:54 jsg Exp $ */
/* $NetBSD: lubbock_machdep.c,v 1.2 2003/07/15 00:25:06 lukem Exp $ */
/*
if (set_cpufuncs())
panic("cpu not recognized!");
- platform_disable_l2_if_needed();
-
/*
* Temporarily replace bus_space_map() functions so that
* console devices can get mapped.
armv7_a4x_bs_tag.bs_map = bootstrap_bs_map;
tmp_bs_tag.bs_map = bootstrap_bs_map;
+ platform_init();
+ platform_disable_l2_if_needed();
+
/* setup a serial console for very early boot */
consinit();
/* Talk to the user */
- printf("\n%s booting ...\n", platform_boot_name);
+ printf("\n%s booting ...\n", platform_boot_name());
printf("arg0 %p arg1 %p arg2 %p\n", arg0, arg1, arg2);
parse_uboot_tags(arg2);
-/* $OpenBSD: armv7_machdep.h,v 1.3 2015/05/19 00:05:59 jsg Exp $ */
+/* $OpenBSD: armv7_machdep.h,v 1.4 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
#ifndef __PLATFORMVAR_H__
#define __PLATFORMVAR_H__
+void platform_init(void);
+void platform_board_init();
void platform_powerdown(void);
void platform_watchdog_reset(void);
void platform_init_cons(void);
-const char *platform_board_name(void);
void platform_disable_l2_if_needed(void);
-extern const char *platform_boot_name;
+void platform_board_init(void);
+const char *platform_boot_name(void);
+const char *platform_board_name(void);
+struct board_dev *platform_board_devs();
+
+struct armv7_platform {
+ const char *boot_name;
+ const char *(*board_name)(void);
+ struct board_dev *devs;
+ void (*board_init)(void);
+ void (*smc_write)(bus_space_tag_t, bus_space_handle_t, bus_size_t,
+ uint32_t, uint32_t);
+ void (*init_cons)(void);
+ void (*watchdog_reset)(void);
+ void (*powerdown)(void);
+ void (*disable_l2_if_needed)(void);
+};
#endif /* __PLATFORMVAR_H__ */
-/* $OpenBSD: armv7var.h,v 1.5 2015/05/15 15:35:43 jsg Exp $ */
+/* $OpenBSD: armv7var.h,v 1.6 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
* Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se>
#define BOARD_ID_IMX6_CUBOXI 4821
extern uint32_t board_id;
-/* different arch init */
-void am335x_init(void);
-void imx6_init(void);
-void omap3_init(void);
-void omap4_init(void);
-void sxia1x_init(void);
-void sxia20_init(void);
-
-struct board_dev *imx_board_attach(void);
-struct board_dev *omap_board_attach(void);
-struct board_dev *sunxi_board_attach(void);
-
#endif /* __ARMV7VAR_H__ */
-/* $OpenBSD: autoconf.c,v 1.2 2015/05/15 15:35:43 jsg Exp $ */
+/* $OpenBSD: autoconf.c,v 1.3 2015/05/19 03:30:54 jsg Exp $ */
/* $NetBSD: autoconf.c,v 1.2 2001/09/05 16:17:36 matt Exp $ */
/*
#include <machine/bootconfig.h>
#include <machine/intr.h>
+#include <machine/bus.h>
#include <armv7/armv7/armv7_machdep.h>
--- /dev/null
+/* $OpenBSD: platform.c,v 1.1 2015/05/19 03:30:54 jsg Exp $ */
+/*
+ * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include <machine/bus.h>
+
+#include <armv7/armv7/armv7var.h>
+#include <armv7/armv7/armv7_machdep.h>
+#include <arm/cortex/smc.h>
+
+#include "imx.h"
+#include "omap.h"
+#include "sunxi.h"
+
+static struct armv7_platform *platform;
+
+struct armv7_platform *imx_platform_match(void);
+struct armv7_platform *omap_platform_match(void);
+struct armv7_platform *sunxi_platform_match(void);
+
+struct armv7_platform * (*plat_match[])(void) = {
+#if NIMX > 0
+ imx_platform_match,
+#endif
+#if NOMAP > 0
+ omap_platform_match,
+#endif
+#if NSUNXI > 0
+ sunxi_platform_match,
+#endif
+};
+
+void
+platform_init(void)
+{
+ int i;
+
+ for (i = 0; i < nitems(plat_match); i++) {
+ platform = plat_match[i]();
+ if (platform != NULL)
+ break;
+ }
+ if (platform == NULL)
+ panic("no matching armv7 platform");
+}
+
+const char *
+platform_boot_name(void)
+{
+ return platform->boot_name;
+}
+
+void
+platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
+ uint32_t op, uint32_t val)
+{
+ platform->smc_write(iot, ioh, off, op, val);
+}
+
+void
+platform_init_cons(void)
+{
+ platform->init_cons();
+}
+
+void
+platform_watchdog_reset(void)
+{
+ platform->watchdog_reset();
+}
+
+void
+platform_powerdown(void)
+{
+ platform->powerdown();
+}
+
+const char *
+platform_board_name(void)
+{
+ return (platform->board_name());
+}
+
+void
+platform_disable_l2_if_needed(void)
+{
+ platform->disable_l2_if_needed();
+}
+
+struct board_dev *
+platform_board_devs()
+{
+ return (platform->devs);
+}
+
+void
+platform_board_init()
+{
+ platform->board_init();
+}
-# $OpenBSD: files.armv7,v 1.10 2014/07/11 21:54:37 tedu Exp $
+# $OpenBSD: files.armv7,v 1.11 2015/05/19 03:30:54 jsg Exp $
maxpartitions 16
maxusers 2 8 64
file arch/armv7/armv7/armv7.c
file arch/armv7/armv7/armv7_machdep.c
file arch/armv7/armv7/autoconf.c
+file arch/armv7/armv7/platform.c
file arch/arm/arm/disksubr.c disk
include "dev/sdmmc/files.sdmmc"
-/* $OpenBSD: exynos.c,v 1.2 2015/05/15 15:35:43 jsg Exp $ */
+/* $OpenBSD: exynos.c,v 1.3 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
* Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se>
return (0);
}
+void exynos5_init();
+
struct cfattach exynos_ca = {
sizeof(struct armv7_softc), exynos_match, armv7_attach, NULL,
config_activate_children
};
struct board_dev *
-exynos_board_attach(void)
+exynos_board_devs(void)
+{
+ int i;
+
+ for (i = 0; exynos_boards[i].name != NULL; i++) {
+ if (exynos_boards[i].board_id == board_id)
+ return (exynos_boards[i].devs);
+ }
+ return (NULL);
+}
+
+void
+exynos_board_init(void)
{
int i;
for (i = 0; exynos_boards[i].name != NULL; i++) {
if (exynos_boards[i].board_id == board_id) {
exynos_boards[i].init();
- return (exynos_boards[i].devs);
break;
}
}
- return (NULL);
}
const char *
-/* $OpenBSD */
+/* $OpenBSD: exynos_machdep.c,v 1.3 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
*
extern void exdog_reset(void);
extern char *exynos_board_name(void);
-extern int32_t agtimer_frequency;
+extern struct board_dev *exynos_board_devs(void);
+extern void exynos_board_init(void);
extern int comcnspeed;
extern int comcnmode;
}
const char *
-platform_board_name(void)
+exynos_platform_board_name(void)
{
return (exynos_board_name());
}
}
+void
+exynos_platform_board_init(void)
+{
+ exynos_board_init();
+}
+
struct armv7_platform exynos_platform = {
.boot_name = "OpenBSD/exynos",
+ .board_name = exynos_platform_board_name,
+ .board_init = exynos_platform_board_init,
.smc_write = exynos_platform_smc_write,
.init_cons = exynos_platform_init_cons,
.watchdog_reset = exynos_platform_watchdog_reset,
.powerdown = exynos_platform_powerdown,
- .print_board_type = exynos_platform_print_board_type,
.disable_l2_if_needed = exynos_platform_disable_l2_if_needed,
};
+
+struct armv7_platform *
+exynos_platform_match(void)
+{
+ struct board_dev *devs;
+
+ devs = exynos_board_devs();
+ if (devs == NULL)
+ return (NULL);
+
+ exynos_platform.devs = devs;
+ return (&exynos_platform);
+}
-/* $OpenBSD: imx.c,v 1.6 2015/05/17 12:28:03 jsg Exp $ */
+/* $OpenBSD: imx.c,v 1.7 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
* Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se>
#include <armv7/armv7/armv7var.h>
+void imx6_init();
+
struct cfattach imx_ca = {
sizeof(struct armv7_softc), armv7_match, armv7_attach, NULL,
config_activate_children
};
struct board_dev *
-imx_board_attach(void)
+imx_board_devs(void)
+{
+ int i;
+
+ for (i = 0; imx_boards[i].name != NULL; i++) {
+ if (imx_boards[i].board_id == board_id)
+ return (imx_boards[i].devs);
+ }
+ return (NULL);
+}
+
+void
+imx_board_init(void)
{
int i;
for (i = 0; imx_boards[i].name != NULL; i++) {
if (imx_boards[i].board_id == board_id) {
imx_boards[i].init();
- return (imx_boards[i].devs);
break;
}
}
- return (NULL);
}
const char *
-/* $OpenBSD: imx_machdep.c,v 1.14 2015/05/19 00:05:59 jsg Exp $ */
+/* $OpenBSD: imx_machdep.c,v 1.15 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
extern void imxdog_reset(void);
extern char *imx_board_name(void);
-extern int32_t amptimer_frequency;
+extern struct board_dev *imx_board_devs(void);
+extern void imx_board_init(void);
extern int comcnspeed;
extern int comcnmode;
-const char *platform_boot_name = "OpenBSD/imx";
-
void
-platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
+imx_platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
uint32_t op, uint32_t val)
{
bus_space_write_4(iot, ioh, off, val);
}
void
-platform_init_cons(void)
+imx_platform_init_cons(void)
{
paddr_t paddr;
}
void
-platform_watchdog_reset(void)
+imx_platform_watchdog_reset(void)
{
imxdog_reset();
}
void
-platform_powerdown(void)
+imx_platform_powerdown(void)
{
}
const char *
-platform_board_name(void)
+imx_platform_board_name(void)
{
return (imx_board_name());
}
void
-platform_disable_l2_if_needed(void)
+imx_platform_disable_l2_if_needed(void)
+{
+
+}
+
+void
+imx_platform_board_init(void)
{
+ imx_board_init();
+}
+
+struct armv7_platform imx_platform = {
+ .boot_name = "OpenBSD/imx",
+ .board_name = imx_platform_board_name,
+ .board_init = imx_platform_board_init,
+ .smc_write = imx_platform_smc_write,
+ .init_cons = imx_platform_init_cons,
+ .watchdog_reset = imx_platform_watchdog_reset,
+ .powerdown = imx_platform_powerdown,
+ .disable_l2_if_needed = imx_platform_disable_l2_if_needed,
+};
+
+struct armv7_platform *
+imx_platform_match(void)
+{
+ struct board_dev *devs;
+
+ devs = imx_board_devs();
+ if (devs == NULL)
+ return (NULL);
+ imx_platform.devs = devs;
+ return (&imx_platform);
}
-/* $OpenBSD: omap.c,v 1.5 2015/05/15 15:35:43 jsg Exp $ */
+/* $OpenBSD: omap.c,v 1.6 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
*
#include <armv7/armv7/armv7var.h>
+void omap3_init();
+void omap4_init();
+void am335x_init();
+
struct cfattach omap_ca = {
sizeof(struct armv7_softc), armv7_match, armv7_attach
};
};
struct board_dev *
-omap_board_attach(void)
+omap_board_devs(void)
+{
+ int i;
+
+ for (i = 0; omap_boards[i].name != NULL; i++) {
+ if (omap_boards[i].board_id == board_id)
+ return (omap_boards[i].devs);
+ }
+ return (NULL);
+}
+
+void
+omap_board_init(void)
{
int i;
for (i = 0; omap_boards[i].name != NULL; i++) {
if (omap_boards[i].board_id == board_id) {
omap_boards[i].init();
- return (omap_boards[i].devs);
break;
}
}
- return (NULL);
}
const char *
-/* $OpenBSD: omap_machdep.c,v 1.5 2015/05/19 00:05:59 jsg Exp $ */
+/* $OpenBSD: omap_machdep.c,v 1.6 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
extern void omap4_smc_call(uint32_t, uint32_t);
extern void omdog_reset(void);
extern char *omap_board_name(void);
+extern struct board_dev *omap_board_devs(void);
+extern void omap_board_init(void);
extern int comcnspeed;
extern int comcnmode;
-const char *platform_boot_name = "OpenBSD/omap";
-
void
-platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
- uint32_t op, uint32_t val)
+omap_platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh,
+ bus_size_t off, uint32_t op, uint32_t val)
{
switch (op) {
case 0x100: /* PL310 DEBUG */
}
void
-platform_init_cons(void)
+omap_platform_init_cons(void)
{
paddr_t paddr;
}
void
-platform_watchdog_reset(void)
+omap_platform_watchdog_reset(void)
{
omdog_reset();
}
void
-platform_powerdown(void)
+omap_platform_powerdown(void)
{
}
const char *
-platform_board_name(void)
+omap_platform_board_name(void)
{
return (omap_board_name());
}
void
-platform_disable_l2_if_needed(void)
+omap_platform_disable_l2_if_needed(void)
{
switch (board_id) {
case BOARD_ID_OMAP4_PANDA:
break;
}
}
+
+void
+omap_platform_board_init(void)
+{
+ omap_board_init();
+}
+
+struct armv7_platform omap_platform = {
+ .boot_name = "OpenBSD/omap",
+ .board_name = omap_platform_board_name,
+ .board_init = omap_platform_board_init,
+ .smc_write = omap_platform_smc_write,
+ .init_cons = omap_platform_init_cons,
+ .watchdog_reset = omap_platform_watchdog_reset,
+ .powerdown = omap_platform_powerdown,
+ .disable_l2_if_needed = omap_platform_disable_l2_if_needed,
+};
+
+struct armv7_platform *
+omap_platform_match(void)
+{
+ struct board_dev *devs;
+
+ devs = omap_board_devs();
+ if (devs == NULL)
+ return (NULL);
+
+ omap_platform.devs = devs;
+ return (&omap_platform);
+}
-/* $OpenBSD: sunxi.c,v 1.4 2015/05/15 15:35:43 jsg Exp $ */
+/* $OpenBSD: sunxi.c,v 1.5 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
*
#include <armv7/armv7/armv7var.h>
#include <armv7/sunxi/sunxireg.h>
+void sxia1x_init();
+void sxia20_init();
+
struct cfattach sunxi_ca = {
sizeof(struct armv7_softc), armv7_match, armv7_attach
};
{ 0, NULL, NULL, NULL },
};
-
struct board_dev *
-sunxi_board_attach(void)
+sunxi_board_devs(void)
{
- struct board_dev *devs = NULL;
- bus_space_handle_t ioh;
int i;
+ for (i = 0; sunxi_boards[i].name != NULL; i++) {
+ if (sunxi_boards[i].board_id == board_id)
+ return (sunxi_boards[i].devs);
+ }
+ return (NULL);
+}
+
+void
+sunxi_board_init(void)
+{
+ bus_space_handle_t ioh;
+ int i, match = 0;
+
for (i = 0; sunxi_boards[i].name != NULL; i++) {
if (sunxi_boards[i].board_id == board_id) {
sunxi_boards[i].init();
- devs = sunxi_boards[i].devs;
+ match = 1;
break;
}
}
- if (devs) {
+ if (match) {
if (bus_space_map(&armv7_bs_tag, SYSCTRL_ADDR, SYSCTRL_SIZE, 0,
&ioh))
panic("sunxi_attach: bus_space_map failed!");
bus_space_write_4(&armv7_bs_tag, ioh, 4,
bus_space_read_4(&armv7_bs_tag, ioh, 4) | (5 << 2));
}
-
- return (devs);
}
const char *
-/* $OpenBSD: sunxi_machdep.c,v 1.7 2015/05/19 00:05:59 jsg Exp $ */
+/* $OpenBSD: sunxi_machdep.c,v 1.8 2015/05/19 03:30:54 jsg Exp $ */
/*
* Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
extern int sxiuartcnattach(bus_space_tag_t, bus_addr_t, int, long, tcflag_t);
extern void sxidog_reset(void);
extern char *sunxi_board_name(void);
+extern struct board_dev *sunxi_board_devs(void);
+extern void sunxi_board_init(void);
extern int comcnspeed;
extern int comcnmode;
-const char *platform_boot_name = "OpenBSD/sunxi";
-
void
-platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
- uint32_t op, uint32_t val)
+sunxi_platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh,
+ bus_size_t off, uint32_t op, uint32_t val)
{
}
void
-platform_init_cons(void)
+sunxi_platform_init_cons(void)
{
paddr_t paddr;
}
void
-platform_watchdog_reset(void)
+sunxi_platform_watchdog_reset(void)
{
sxidog_reset();
}
void
-platform_powerdown(void)
+sunxi_platform_powerdown(void)
{
}
const char *
-platform_board_name(void)
+sunxi_platform_board_name(void)
{
return (sunxi_board_name());
}
void
-platform_disable_l2_if_needed(void)
+sunxi_platform_disable_l2_if_needed(void)
{
}
+void
+sunxi_platform_board_init(void)
+{
+ sunxi_board_init();
+}
+
+struct armv7_platform sunxi_platform = {
+ .boot_name = "OpenBSD/sunxi",
+ .board_name = sunxi_platform_board_name,
+ .board_init = sunxi_platform_board_init,
+ .smc_write = sunxi_platform_smc_write,
+ .init_cons = sunxi_platform_init_cons,
+ .watchdog_reset = sunxi_platform_watchdog_reset,
+ .powerdown = sunxi_platform_powerdown,
+ .disable_l2_if_needed = sunxi_platform_disable_l2_if_needed,
+};
+
+struct armv7_platform *
+sunxi_platform_match(void)
+{
+ struct board_dev *devs;
+
+ devs = sunxi_board_devs();
+ if (devs == NULL)
+ return (NULL);
+
+ sunxi_platform.devs = devs;
+ return (&sunxi_platform);
+}