1 /* $NetBSD: board_prop.c,v 1.2 2011/01/18 01:02:52 matt Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Shigeyuki Fukushima. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials provided 15 * with the distribution. 16 * 3. The name of the author may not be used to endorse or promote 17 * products derived from this software without specific prior 18 * written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> 34 __KERNEL_RCSID(0, "$NetBSD: board_prop.c,v 1.2 2011/01/18 01:02:52 matt Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/cpu.h> 39 40 #include <prop/proplib.h> 41 42 #include <powerpc/booke/cpuvar.h> 43 44 prop_dictionary_t board_properties; 45 46 void 47 board_info_init(void) 48 { 49 50 /* 51 * Set up the board properties dictionary. 52 */ 53 if (board_properties != NULL) 54 return; 55 board_properties = prop_dictionary_create(); 56 KASSERT(board_properties != NULL); 57 } 58 59 bool 60 board_info_get_bool(const char *name) 61 { 62 KASSERT(board_properties != NULL); 63 prop_bool_t pb = prop_dictionary_get(board_properties, name); 64 if (pb == NULL) 65 return false; 66 const bool value = prop_bool_true(pb); 67 /* XXX -- do we need object release pb? */ 68 return value; 69 } 70 71 void 72 board_info_add_bool(const char *name) 73 { 74 KASSERT(board_properties != NULL); 75 prop_bool_t pb = prop_bool_create(true); 76 KASSERT(pb != NULL); 77 if (prop_dictionary_set(board_properties, name, pb) == false) 78 panic("%s: setting %s", __func__, name); 79 prop_object_release(pb); 80 } 81 82 uint64_t 83 board_info_get_number(const char *name) 84 { 85 KASSERT(board_properties != NULL); 86 prop_number_t pn = prop_dictionary_get(board_properties, name); 87 KASSERT(pn != NULL); 88 const uint64_t number = prop_number_unsigned_integer_value(pn); 89 /* XXX -- do we need object release pn? */ 90 return number; 91 } 92 93 void 94 board_info_add_number(const char *name, uint64_t number) 95 { 96 KASSERT(board_properties != NULL); 97 prop_number_t pn = prop_number_create_integer(number); 98 KASSERT(pn != NULL); 99 if (prop_dictionary_set(board_properties, name, pn) == false) 100 panic("%s: setting %s failed", __func__, name); 101 prop_object_release(pn); 102 } 103 104 void 105 board_info_add_data(const char *name, const void *data, size_t len) 106 { 107 KASSERT(board_properties != NULL); 108 prop_data_t pd = prop_data_create_data(data, len); 109 KASSERT(pd != NULL); 110 if (prop_dictionary_set(board_properties, name, pd) == false) 111 panic("%s: setting %s failed", __func__, name); 112 prop_object_release(pd); 113 } 114 115 const void * 116 board_info_get_data(const char *name, size_t *lenp) 117 { 118 KASSERT(board_properties != NULL); 119 prop_data_t pd = prop_dictionary_get(board_properties, name); 120 KASSERT(pd != NULL); 121 *lenp = prop_data_size(pd); 122 /* XXX -- do we need object release pn? */ 123 return prop_data_data(pd); 124 } 125 126 void 127 board_info_add_string(const char *name, const char *data) 128 { 129 KASSERT(board_properties != NULL); 130 prop_string_t ps = prop_string_create_cstring(data); 131 KASSERT(ps != NULL); 132 if (prop_dictionary_set(board_properties, name, ps) == false) 133 panic("%s: setting %s failed", __func__, name); 134 prop_object_release(ps); 135 } 136 137 void 138 board_info_add_object(const char *name, void *obj) 139 { 140 if (prop_dictionary_set(board_properties, name, obj) == false) 141 panic("%s: setting %s failed", __func__, name); 142 } 143 144 void * 145 board_info_get_object(const char *name) 146 { 147 return prop_dictionary_get(board_properties, name); 148 } 149