-/* $OpenBSD: sbi.h,v 1.3 2021/06/27 15:02:25 kettenis Exp $ */
+/* $OpenBSD: sbi.h,v 1.4 2021/07/02 08:44:37 kettenis Exp $ */
/*-
* Copyright (c) 2016-2017 Ruslan Bukin <br@bsdpad.com>
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#ifndef _MACHINE_SBI_H_
extern u_long sbi_impl_id;
extern u_long sbi_impl_version;
+static __inline u_int
+sbi_get_mvendorid(void)
+{
+ return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MVENDORID).value);
+}
+
+
+static __inline u_long
+sbi_get_marchid(void)
+{
+ return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MARCHID).value);
+}
+
+static __inline u_long
+sbi_get_mimpid(void)
+{
+ return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MIMPID).value);
+}
+
static __inline long
sbi_probe_extension(long id)
{
-/* $OpenBSD: cpu.c,v 1.9 2021/06/29 21:27:53 kettenis Exp $ */
+/* $OpenBSD: cpu.c,v 1.10 2021/07/02 08:44:37 kettenis Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
#include <dev/ofw/ofw_clock.h>
#include <dev/ofw/fdt.h>
-register_t mvendorid, marchid, mimpid;
+/* CPU Identification */
+
+#define CPU_VENDOR_SIFIVE 0x489
+
+#define CPU_ARCH_U5 0x0000000000000001
+#define CPU_ARCH_U7 0x8000000000000007
+
+/* Architectures */
+struct arch {
+ uint64_t id;
+ char *name;
+};
+
+struct arch cpu_arch_none[] = {
+ { 0, NULL }
+};
+
+struct arch cpu_arch_sifive[] = {
+ { CPU_ARCH_U5, "U5" },
+ { CPU_ARCH_U7, "U7" },
+ { 0, NULL }
+};
+
+/* Vendors */
+const struct vendor {
+ uint32_t id;
+ char *name;
+ struct arch *archlist;
+} cpu_vendors[] = {
+ { CPU_VENDOR_SIFIVE, "SiFive", cpu_arch_sifive },
+ { 0, NULL }
+};
+
char cpu_model[64];
int cpu_node;
cpu_identify(struct cpu_info *ci)
{
char isa[32];
- int len;
+ uint64_t marchid, mimpid;
+ uint32_t mvendorid;
+ const char *vendor_name = NULL;
+ const char *arch_name = NULL;
+ struct arch *archlist = cpu_arch_none;
+ int i, len;
+
+ mvendorid = sbi_get_mvendorid();
+ marchid = sbi_get_marchid();
+ mimpid = sbi_get_mimpid();
+
+ for (i = 0; cpu_vendors[i].name; i++) {
+ if (mvendorid == cpu_vendors[i].id) {
+ vendor_name = cpu_vendors[i].name;
+ archlist = cpu_vendors[i].archlist;
+ break;
+ }
+ }
- len = OF_getprop(ci->ci_node, "riscv,isa", isa, sizeof(isa));
+ for (i = 0; archlist[i].name; i++) {
+ if (marchid == archlist[i].id) {
+ arch_name = archlist[i].name;
+ break;
+ }
+ }
- printf(": vendor %lx arch %lx imp %lx",
- mvendorid, marchid, mimpid);
+ if (vendor_name)
+ printf(": %s", vendor_name);
+ else
+ printf(": vendor %x", mvendorid);
+ if (arch_name)
+ printf(" %s", arch_name);
+ else
+ printf(" arch %llx", marchid);
+ printf(" imp %llx", mimpid);
+ len = OF_getprop(ci->ci_node, "riscv,isa", isa, sizeof(isa));
if (len != -1) {
printf(" %s", isa);
strlcpy(cpu_model, isa, sizeof(cpu_model));
-/* $OpenBSD: sbi.c,v 1.5 2021/06/27 15:02:25 kettenis Exp $ */
+/* $OpenBSD: sbi.c,v 1.6 2021/07/02 08:44:37 kettenis Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
u_long sbi_impl_id;
u_long sbi_impl_version;
-extern register_t mvendorid;
-extern register_t mimpid;
-extern register_t marchid;
-
static struct sbi_ret
sbi_get_spec_version(void)
{
return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_IMPL_VERSION));
}
-static struct sbi_ret
-sbi_get_mvendorid(void)
-{
- return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MVENDORID));
-}
-
-
-static struct sbi_ret
-sbi_get_marchid(void)
-{
- return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MARCHID));
-}
-
-static struct sbi_ret
-sbi_get_mimpid(void)
-{
- return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MIMPID));
-}
-
void
sbi_print_version(void)
{
sbi_impl_id = sbi_get_impl_id().value;
sbi_impl_version = sbi_get_impl_version().value;
- /* Set the hardware implementation info. */
- mvendorid = sbi_get_mvendorid().value;
- marchid = sbi_get_marchid().value;
- mimpid = sbi_get_mimpid().value;
-
/*
* Probe for legacy extensions. Currently we rely on all of them
* to be implemented, but this is not guaranteed by the spec.