From b8cbdd99fad603615556068b8463fc45e3794fe8 Mon Sep 17 00:00:00 2001 From: kettenis Date: Wed, 3 Jan 2018 04:15:51 +0000 Subject: [PATCH] Add remap_bynode() since I use it in the rkpcie(4) implementation. --- sys/dev/ofw/ofw_misc.c | 17 ++++++++++++++++- sys/dev/ofw/ofw_misc.h | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c index 60d33f58931..06d74753316 100644 --- a/sys/dev/ofw/ofw_misc.c +++ b/sys/dev/ofw/ofw_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_misc.c,v 1.2 2017/05/05 17:38:22 kettenis Exp $ */ +/* $OpenBSD: ofw_misc.c,v 1.3 2018/01/03 04:15:51 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -25,6 +25,7 @@ #include struct regmap { + int rm_node; uint32_t rm_phandle; bus_space_tag_t rm_tag; bus_space_handle_t rm_handle; @@ -45,6 +46,7 @@ regmap_register(int node, bus_space_tag_t tag, bus_space_handle_t handle, phandle = OF_getpropint(node, "phandle", 0); if (phandle) { rm = malloc(sizeof(struct regmap), M_DEVBUF, M_WAITOK); + rm->rm_node = node; rm->rm_phandle = phandle; rm->rm_tag = tag; rm->rm_handle = handle; @@ -53,6 +55,19 @@ regmap_register(int node, bus_space_tag_t tag, bus_space_handle_t handle, } } +struct regmap * +regmap_bynode(int node) +{ + struct regmap *rm; + + LIST_FOREACH(rm, ®maps, rm_list) { + if (rm->rm_node == node) + return rm; + } + + return NULL; +} + struct regmap * regmap_byphandle(uint32_t phandle) { diff --git a/sys/dev/ofw/ofw_misc.h b/sys/dev/ofw/ofw_misc.h index 37bd01105ec..add4cdf303a 100644 --- a/sys/dev/ofw/ofw_misc.h +++ b/sys/dev/ofw/ofw_misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_misc.h,v 1.1 2017/03/09 20:01:10 kettenis Exp $ */ +/* $OpenBSD: ofw_misc.h,v 1.2 2018/01/03 04:15:51 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -21,6 +21,7 @@ void regmap_register(int, bus_space_tag_t, bus_space_handle_t, bus_size_t); struct regmap; +struct regmap *regmap_bynode(int); struct regmap *regmap_byphandle(uint32_t); uint32_t regmap_read_4(struct regmap *, bus_size_t); -- 2.20.1