From 8479b6c3250af3441cffe85e4a9784f9896ade5e Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Mon, 26 Nov 2018 16:59:49 -0500 Subject: [PATCH] remove picl libs & bins --- FEATURES.txt | 1 + exception_lists/check_rtime | 15 - exception_lists/interface_check | 2 - share/man/man5/filesystem.5 | 10 - share/man/man7d/bscv.7d | 2 +- usr/src/.gitignore | 33 - usr/src/cmd/Makefile | 2 - usr/src/cmd/Makefile.check | 1 - usr/src/cmd/picl/Makefile | 48 - usr/src/cmd/picl/picld/Makefile | 65 - usr/src/cmd/picl/picld/picl.xml | 96 - usr/src/cmd/picl/picld/picld.c | 1224 ------- usr/src/cmd/picl/plugins/Makefile | 57 - usr/src/cmd/picl/plugins/Makefile.com | 61 - usr/src/cmd/picl/plugins/Makefile.targ | 48 - usr/src/cmd/picl/plugins/common/Makefile | 46 - usr/src/cmd/picl/plugins/common/devtree/Makefile | 101 - .../cmd/picl/plugins/common/devtree/picldevtree.c | 3757 -------------------- .../cmd/picl/plugins/common/devtree/picldevtree.h | 192 - usr/src/cmd/picl/plugins/common/frutree/Makefile | 95 - .../cmd/picl/plugins/common/frutree/piclfrutree.c | 128 - usr/src/cmd/picl/plugins/common/memcfg/Makefile | 90 - .../cmd/picl/plugins/common/memcfg/piclmemcfg.h | 51 - .../picl/plugins/common/memcfg/piclmemcfg_comm.c | 948 ----- usr/src/cmd/picl/plugins/common/piclevent/Makefile | 126 - .../cmd/picl/plugins/common/piclevent/picl_slm.c | 433 --- .../cmd/picl/plugins/common/piclevent/piclevent.c | 250 -- .../cmd/picl/plugins/common/piclevent/piclevent.h | 46 - usr/src/cmd/picl/plugins/inc/picldefs.h | 366 -- usr/src/cmd/picl/plugins/lib/Makefile | 47 - .../cmd/picl/plugins/lib/picld_pluginutil/Makefile | 47 - .../picl/plugins/lib/picld_pluginutil/Makefile.com | 69 - .../plugins/lib/picld_pluginutil/i386/Makefile | 40 - .../picl/plugins/lib/picld_pluginutil/mapfile-vers | 46 - .../lib/picld_pluginutil/picld_pluginutil.c | 1698 --------- .../lib/picld_pluginutil/picld_pluginutil.h | 43 - .../lib/picld_pluginutil/picld_pluginutil_impl.h | 162 - usr/src/cmd/picl/prtpicl/Makefile | 48 - usr/src/cmd/picl/prtpicl/prtpicl.c | 574 --- usr/src/cmd/svc/profile/generic_limited_net.xml | 3 - usr/src/cmd/svc/profile/generic_open.xml | 3 - usr/src/lib/Makefile | 5 - usr/src/lib/libpicl/Makefile | 66 - usr/src/lib/libpicl/Makefile.com | 53 - usr/src/lib/libpicl/amd64/Makefile | 32 - usr/src/lib/libpicl/i386/Makefile | 31 - usr/src/lib/libpicl/mapfile-vers | 73 - usr/src/lib/libpicl/picl.c | 869 ----- usr/src/lib/libpicl/picl.h | 188 - usr/src/lib/libpicl/picl2door.h | 436 --- usr/src/lib/libpicltree/Makefile | 65 - usr/src/lib/libpicltree/Makefile.com | 43 - usr/src/lib/libpicltree/i386/Makefile | 31 - usr/src/lib/libpicltree/mapfile-vers | 110 - usr/src/lib/libpicltree/picltree.c | 3658 ------------------- usr/src/lib/libpicltree/picltree.h | 176 - usr/src/lib/libpicltree/ptree_impl.h | 252 -- usr/src/pkg/manifests/service-picl.inc | 60 - usr/src/pkg/manifests/system-core-os.mf | 1 - usr/src/pkg/manifests/system-header-header-picl.mf | 39 +- 60 files changed, 5 insertions(+), 17257 deletions(-) delete mode 100644 usr/src/cmd/picl/Makefile delete mode 100644 usr/src/cmd/picl/picld/Makefile delete mode 100644 usr/src/cmd/picl/picld/picl.xml delete mode 100644 usr/src/cmd/picl/picld/picld.c delete mode 100644 usr/src/cmd/picl/plugins/Makefile delete mode 100644 usr/src/cmd/picl/plugins/Makefile.com delete mode 100644 usr/src/cmd/picl/plugins/Makefile.targ delete mode 100644 usr/src/cmd/picl/plugins/common/Makefile delete mode 100644 usr/src/cmd/picl/plugins/common/devtree/Makefile delete mode 100644 usr/src/cmd/picl/plugins/common/devtree/picldevtree.c delete mode 100644 usr/src/cmd/picl/plugins/common/devtree/picldevtree.h delete mode 100644 usr/src/cmd/picl/plugins/common/frutree/Makefile delete mode 100644 usr/src/cmd/picl/plugins/common/frutree/piclfrutree.c delete mode 100644 usr/src/cmd/picl/plugins/common/memcfg/Makefile delete mode 100644 usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg.h delete mode 100644 usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c delete mode 100644 usr/src/cmd/picl/plugins/common/piclevent/Makefile delete mode 100644 usr/src/cmd/picl/plugins/common/piclevent/picl_slm.c delete mode 100644 usr/src/cmd/picl/plugins/common/piclevent/piclevent.c delete mode 100644 usr/src/cmd/picl/plugins/common/piclevent/piclevent.h delete mode 100644 usr/src/cmd/picl/plugins/inc/picldefs.h delete mode 100644 usr/src/cmd/picl/plugins/lib/Makefile delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile.com delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/i386/Makefile delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/mapfile-vers delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.c delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.h delete mode 100644 usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil_impl.h delete mode 100644 usr/src/cmd/picl/prtpicl/Makefile delete mode 100644 usr/src/cmd/picl/prtpicl/prtpicl.c delete mode 100644 usr/src/lib/libpicl/Makefile delete mode 100644 usr/src/lib/libpicl/Makefile.com delete mode 100644 usr/src/lib/libpicl/amd64/Makefile delete mode 100644 usr/src/lib/libpicl/i386/Makefile delete mode 100644 usr/src/lib/libpicl/mapfile-vers delete mode 100644 usr/src/lib/libpicl/picl.c delete mode 100644 usr/src/lib/libpicl/picl.h delete mode 100644 usr/src/lib/libpicl/picl2door.h delete mode 100644 usr/src/lib/libpicltree/Makefile delete mode 100644 usr/src/lib/libpicltree/Makefile.com delete mode 100644 usr/src/lib/libpicltree/i386/Makefile delete mode 100644 usr/src/lib/libpicltree/mapfile-vers delete mode 100644 usr/src/lib/libpicltree/picltree.c delete mode 100644 usr/src/lib/libpicltree/picltree.h delete mode 100644 usr/src/lib/libpicltree/ptree_impl.h delete mode 100644 usr/src/pkg/manifests/service-picl.inc rewrite usr/src/pkg/manifests/system-header-header-picl.mf (95%) diff --git a/FEATURES.txt b/FEATURES.txt index 33e09d425e..48665ab0fa 100644 --- a/FEATURES.txt +++ b/FEATURES.txt @@ -10,6 +10,7 @@ was changed. release -------------- - libfruraw, libnvfru, libfru, libfrureg, libfruutils + - libpicl, libpicltree, picld(8), etc. - pyzfs & pysolaris - locator(8) diff --git a/exception_lists/check_rtime b/exception_lists/check_rtime index 7c9624c041..c6a5843669 100644 --- a/exception_lists/check_rtime +++ b/exception_lists/check_rtime @@ -52,12 +52,6 @@ SKIP ^usr/MACH(lib)/lddstub$ # lddstub has no dependencies SKIP ^usr/MACH(lib)/libssagent\.so\.1$ # 4328854 SKIP ^usr/lib/MACH(iconv)/geniconvtbl.so$ # 4384329 -# picl file exclusions (4385799) -SKIP ^usr/platform/.*/libpsvcplugin_psr\.so\.1 -SKIP ^usr/platform/.*/libpsvcpolicy_psr\.so\.1 -SKIP ^usr/platform/.*/libpsvcpolicy\.so\.1 -SKIP ^usr/lib/sysevent/modules/picl_slm.so$ - # Objects that are allowed to have executable data segments EXEC_DATA ^MACH(lib)/ld\.so\.1$ EXEC_DATA ^lib/libc\.so\.1$ # 6524709, 32-bit, needed for x86 only @@ -88,9 +82,6 @@ STAB ^platform/MACH(kernel)/unix$ # Files that are allowed undefined references UNDEF_REF ^usr/lib/libnisdb\.so\.2$ -# Objects allowed to have unused dependencies -UNUSED_DEPS ^usr/lib/picl/plugins/ # require devtree dependencies - # libnetsnmphelpers.so is empty in some net-snmp versions UNUSED_OBJ unused object=.*/libnetsnmphelpers\.so\..* UNREF_OBJ unreferenced object=.*/libnetsnmphelpers\.so\..* @@ -102,11 +93,6 @@ UNUSED_RPATH /usr/lib/inet/ppp.*\ from\ .*pppd UNUSED_RPATH /usr/platform/.*rsmlib.*\ from\ .*librsm\.so\.2 UNUSED_RPATH \$ORIGIN.*\ from\ .*fcode.so -# Unused runpaths in picl code -UNUSED_RPATH /usr/platform/.*\ from\ .*/usr/platform -UNUSED_RPATH /usr/lib/picl/.*\ from\ .*/usr/platform -UNUSED_RPATH /usr/platform/.*\ from\ .*/usr/lib/picl - # Unused runpaths in non-OSNET objects we can't change UNUSED_RPATH /usr/lib/mps.*\ from\ .*libnss3\.so UNUSED_RPATH /usr/lib/mps.*\ from\ .*libnssutil3\.so @@ -156,7 +142,6 @@ UNREF_OBJ /libstdc\+\+\.so\.6;\ unused\ dependency\ of # gcc build UNREF_OBJ /libgcc_s\.so\.1;\ unused\ dependency\ of # gcc build UNREF_OBJ /libgcc_s\.so\.1.*\ of\ .*libstdc\+\+\.so\.6 # omnios gcc mix UNREF_OBJ /libm\.so\.2.*\ of\ .*libstdc\+\+\.so\.6 # gcc build -UNREF_OBJ /lib.*\ of\ .*/lib/picl/plugins/ # picl UNREF_OBJ /lib.*\ of\ .*kcfd # interposer UNREF_OBJ /libpkcs11\.so\.1; .*\ of\ .*libkmf\.so\.1 # interposed # Referenced by the Studio build, not the GCC build. GCC eliminates the unused diff --git a/exception_lists/interface_check b/exception_lists/interface_check index cf7b60fdf8..e6fbc1f3cc 100644 --- a/exception_lists/interface_check +++ b/exception_lists/interface_check @@ -53,7 +53,6 @@ PLUGIN ^usr/lib/iconv PLUGIN ^usr/lib/inet/ppp PLUGIN ^usr/lib/mdb PLUGIN ^usr/lib/pci -PLUGIN ^usr/lib/picl/plugins PLUGIN ^usr/lib/python2.[467] PLUGIN ^usr/lib/rcm/modules PLUGIN ^usr/lib/scsi/plugins @@ -78,7 +77,6 @@ NOVERDEF ^usr/MACH(lib)/sn1_brand\.so\.1$ NOVERDEF ^usr/lib/fs/[^/]*/fstyp\.so\.1$ NOVERDEF ^usr/lib/libwrap\.so\.1\.0$ NOVERDEF ^usr/lib/locale/MACH(iso_8859_1)/iso_8859_1\.so\.3$ -NOVERDEF ^usr/lib/picl/plugins$ # Objects that are allowed to deviate from our standard version diff --git a/share/man/man5/filesystem.5 b/share/man/man5/filesystem.5 index 42b5b48227..6056c6a052 100644 --- a/share/man/man5/filesystem.5 +++ b/share/man/man5/filesystem.5 @@ -1618,16 +1618,6 @@ Auxiliary NFS-related programs and daemons. .sp .ne 2 .na -\fB\fB/usr/lib/picl\fR\fR -.ad -.sp .6 -.RS 4n -Platform Information and Control Library. -.RE - -.sp -.ne 2 -.na \fB\fB/usr/lib/pool\fR\fR .ad .sp .6 diff --git a/share/man/man7d/bscv.7d b/share/man/man7d/bscv.7d index 5d56207d66..c65a60e8f3 100644 --- a/share/man/man7d/bscv.7d +++ b/share/man/man7d/bscv.7d @@ -16,7 +16,7 @@ information between Solaris and the Blade support chip. .sp .LP These drivers do not export public interfaces. Instead they make information -available via picl, prtdiag, and related tools. In addition, these +available via prtdiag, and related tools. In addition, these drivers log Blade support chip environmental event information into system logs. .SH FILES diff --git a/usr/src/.gitignore b/usr/src/.gitignore index 568488603f..82996e42f9 100644 --- a/usr/src/.gitignore +++ b/usr/src/.gitignore @@ -1958,31 +1958,6 @@ cmd/pgrep/pkill cmd/pgrep/ppgrep.po cmd/pgrep/psexp.po cmd/pgstat/pgstat -cmd/picl/picld/picld -cmd/picl/picld/picld.po -cmd/picl/plugins/common/devtree/libpicldevtree.so -cmd/picl/plugins/common/devtree/libpicldevtree.so.1 -cmd/picl/plugins/common/devtree/picldevtree.po -cmd/picl/plugins/common/devtree/pics/ -cmd/picl/plugins/common/frutree/libpiclfrutree.so -cmd/picl/plugins/common/frutree/libpiclfrutree.so.1 -cmd/picl/plugins/common/frutree/piclfrutree.po -cmd/picl/plugins/common/frutree/pics/ -cmd/picl/plugins/common/memcfg/libpiclmemcfg.so -cmd/picl/plugins/common/memcfg/libpiclmemcfg.so.1 -cmd/picl/plugins/common/memcfg/piclmemcfg_comm.po -cmd/picl/plugins/common/memcfg/pics/ -cmd/picl/plugins/common/piclevent/libpiclevent.so -cmd/picl/plugins/common/piclevent/libpiclevent.so.1 -cmd/picl/plugins/common/piclevent/picl_slm.so -cmd/picl/plugins/common/piclevent/piclevent.po -cmd/picl/plugins/common/piclevent/pics/ -cmd/picl/plugins/lib/picld_pluginutil/i386/libpicld_pluginutil.so -cmd/picl/plugins/lib/picld_pluginutil/i386/libpicld_pluginutil.so.1 -cmd/picl/plugins/lib/picld_pluginutil/i386/picld_pluginutil.po -cmd/picl/plugins/lib/picld_pluginutil/i386/pics/ -cmd/picl/prtpicl/prtpicl -cmd/picl/prtpicl/prtpicl.po cmd/platexec/platexec cmd/plimit/amd64/plimit cmd/plimit/i386/plimit @@ -3809,14 +3784,6 @@ lib/libpctx/amd64/libpctx.so.1 lib/libpctx/amd64/pics/ lib/libpctx/i386/libpctx.so.1 lib/libpctx/i386/pics/ -lib/libpicl/amd64/libpicl.so.1 -lib/libpicl/amd64/picl.po -lib/libpicl/amd64/pics/ -lib/libpicl/i386/libpicl.so.1 -lib/libpicl/i386/picl.po -lib/libpicl/i386/pics/ -lib/libpicltree/i386/libpicltree.so.1 -lib/libpicltree/i386/pics/ lib/libpool/amd64/libpool.so.1 lib/libpool/amd64/pics/ lib/libpool/i386/libpool.so.1 diff --git a/usr/src/cmd/Makefile b/usr/src/cmd/Makefile index e79fa7bde0..c2757d2556 100644 --- a/usr/src/cmd/Makefile +++ b/usr/src/cmd/Makefile @@ -266,7 +266,6 @@ COMMON_SUBDIRS= \ pginfo \ pgstat \ pgrep \ - picl \ plimit \ policykit \ pools \ @@ -530,7 +529,6 @@ MSGSUBDIRS= \ pfexec \ pg \ pgrep \ - picl \ pools \ power \ pr \ diff --git a/usr/src/cmd/Makefile.check b/usr/src/cmd/Makefile.check index e34cdb0aa1..c4f7a11407 100644 --- a/usr/src/cmd/Makefile.check +++ b/usr/src/cmd/Makefile.check @@ -105,7 +105,6 @@ MANIFEST_SUBDIRS= \ krb5/krb5kdc \ krb5/kwarn \ krb5/slave \ - picl/picld \ rcap/rcapd \ rpcsvc/rpc.bootparamd \ smbsrv/smbd \ diff --git a/usr/src/cmd/picl/Makefile b/usr/src/cmd/picl/Makefile deleted file mode 100644 index 0edabe18aa..0000000000 --- a/usr/src/cmd/picl/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1999-2000 by Sun Microsystems, Inc. -# All rights reserved. -# -# cmd/picl/Makefile -# - -SUBDIRS= picld plugins prtpicl - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -.KEEP_STATE: - -all clean clobber _msg : $(SUBDIRS) - -install: $(SUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/picld/Makefile b/usr/src/cmd/picl/picld/Makefile deleted file mode 100644 index 23c149645f..0000000000 --- a/usr/src/cmd/picl/picld/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= picld - -MANIFEST= picl.xml - -include ../../Makefile.cmd - -ROOTMANIFESTDIR= $(ROOTSVCSYSTEM) - -ROOTLIBPICLD= $(ROOTLIB)/picl -ROOTLIBPICLDDAEMON= $(PROG:%=$(ROOTLIBPICLD)/%) - -$(ROOTLIBPICLD) := FILEMODE= 755 - -CPPFLAGS += -I../../../lib/libpicltree -I../../../lib/libpicl - -LDLIBS += -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -lpicltree - - - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTLIBPICLD) $(ROOTLIBPICLDDAEMON) $(ROOTMANIFEST) - -check: $(CHKMANIFEST) - -clean: - - -$(ROOTLIBPICLD): - $(INS.dir) - -$(ROOTLIBPICLD)/%: % - $(INS.file) - -include ../../Makefile.targ - -FRC: diff --git a/usr/src/cmd/picl/picld/picl.xml b/usr/src/cmd/picl/picld/picl.xml deleted file mode 100644 index 1a3a7b5378..0000000000 --- a/usr/src/cmd/picl/picld/picl.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/usr/src/cmd/picl/picld/picld.c b/usr/src/cmd/picl/picld/picld.c deleted file mode 100644 index 947c14fb7b..0000000000 --- a/usr/src/cmd/picl/picld/picld.c +++ /dev/null @@ -1,1224 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * PICL daemon - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "picl2door.h" -#include -#include "ptree_impl.h" - -/* - * Log text messages - */ -#define MUST_BE_ROOT gettext("this program must be run as root\n") -#define CD_ROOT_FAILED gettext("chdir to root failed\n") -#define INIT_FAILED gettext("ptree initialization failed\n") -#define DAEMON_RUNNING gettext("PICL daemon already running\n") -#define DOOR_FAILED gettext("Failed creating picld door\n") -#define SIGACT_FAILED \ - gettext("Failed to install signal handler for %s: %s\n") - -/* - * Constants - */ -#define PICLD "picld" -#define DOS_PICL_REQUESTS_LIMIT 10000 -#define SLIDING_INTERVAL_MILLISECONDS 1000 -#define PICLD_MAJOR_REV 0x1 -#define PICLD_MINOR_REV 0x0 -#define DOS_SLEEPTIME_MS 1000 -#define MAX_POOL_SIZE _POSIX_THREAD_THREADS_MAX -#define MAX_CONCURRENT_WAITS (_POSIX_THREAD_THREADS_MAX - 2) -#define MAX_USER_WAITS 4 - -/* - * Macros - */ -#define PICLD_VERSION(x, y) ((x << 8) | y) -#define PICL_CLIENT_REV(x) (x & 0xff) -#define MILLI_TO_NANO(x) (x * 1000000) - -extern char **environ; - -/* - * Module Variables - */ -static int logflag = 1; -static int doreinit = 0; -static int door_id = -1; -static pthread_mutex_t door_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t door_cv = PTHREAD_COND_INITIALIZER; -static int service_requests = 0; -static hrtime_t orig_time; -static hrtime_t sliding_interval_ms; -static uint32_t dos_req_limit; -static uint32_t dos_ms; -static pthread_mutex_t dos_mutex = PTHREAD_MUTEX_INITIALIZER; -static rwlock_t init_lk; -static int pool_count = 0; -static pthread_mutex_t pool_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t wait_req_mutex = PTHREAD_MUTEX_INITIALIZER; -static int wait_count = 0; -static struct { - uid_t uid; - int count; -} user_count[MAX_CONCURRENT_WAITS]; - -/* - * This returns an error message to libpicl - */ -static void -picld_return_error(picl_callnumber_t cnum, picl_errno_t err) -{ - picl_reterror_t ret_error; - - ret_error.cnum = PICL_CNUM_ERROR; - ret_error.in_cnum = cnum; - ret_error.errnum = err; - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret_error, sizeof (picl_reterror_t), NULL, - 0); -} - -/* - * picld_init is called when a picl_initialize request is received - */ -static void -picld_init(picl_service_t *req) -{ - picl_retinit_t ret_init; - int clmajrev; - - clmajrev = PICL_CLIENT_REV(req->req_init.clrev); - - if (clmajrev < PICL_VERSION_1) - picld_return_error(req->req_init.cnum, PICL_NOTSUPPORTED); - - ret_init.cnum = req->req_init.cnum; - ret_init.rev = PICLD_VERSION(PICLD_MAJOR_REV, PICLD_MINOR_REV); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret_init, sizeof (picl_retinit_t), NULL, 0); -} - -/* - * picld_fini is called when a picl_shutdown request is received - */ -static void -picld_fini(picl_service_t *in) -{ - picl_retfini_t ret; - - ret.cnum = in->req_fini.cnum; - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retfini_t), NULL, 0); -} - -static void -picld_ping(picl_service_t *in) -{ - picl_retping_t ret; - - ret.cnum = in->req_ping.cnum; - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retping_t), NULL, 0); -} - -static int -check_user(uid_t uid) -{ - int i; - uid_t tmp_uid; - int free_idx = -1; - - if (uid == 0) - return (PICL_SUCCESS); - for (i = 0; i < MAX_CONCURRENT_WAITS; i++) { - if ((tmp_uid = user_count[i].uid) == uid) { - if (user_count[i].count == MAX_USER_WAITS) - return (PICL_FAILURE); - user_count[i].count++; - return (PICL_SUCCESS); - } - if ((free_idx == -1) && (tmp_uid == 0)) - free_idx = i; - } - if (free_idx != -1) { - user_count[free_idx].uid = uid; - user_count[free_idx].count = 1; - return (PICL_SUCCESS); - } - return (PICL_FAILURE); -} - -static void -done_user(uid_t uid) -{ - int i; - - if (uid == 0) - return; - for (i = 0; i < MAX_CONCURRENT_WAITS; i++) { - if (user_count[i].uid == uid) { - if (--user_count[i].count == 0) - user_count[i].uid = 0; - return; - } - } -} - -static int -enter_picld_wait(uid_t uid) -{ - int rv; - - if (pthread_mutex_lock(&wait_req_mutex) != 0) - return (PICL_FAILURE); - if ((wait_count < MAX_CONCURRENT_WAITS) && - (check_user(uid) == PICL_SUCCESS)) { - rv = PICL_SUCCESS; - wait_count++; - } else { - rv = PICL_FAILURE; - } - (void) pthread_mutex_unlock(&wait_req_mutex); - return (rv); -} - -static void -exit_picld_wait(uid_t uid) -{ - (void) pthread_mutex_lock(&wait_req_mutex); - done_user(uid); - wait_count--; - (void) pthread_mutex_unlock(&wait_req_mutex); -} - -/* - * picld_wait is called when a picl_wait request is received - */ -static void -picld_wait(picl_service_t *in) -{ - picl_retwait_t ret; - int err; - ucred_t *puc = NULL; - uid_t uid; - - ret.cnum = in->req_wait.cnum; - if (door_ucred(&puc) != 0) - ret.retcode = PICL_FAILURE; - else { - uid = ucred_geteuid(puc); - if (enter_picld_wait(uid) == PICL_FAILURE) - ret.retcode = PICL_FAILURE; - else { - err = xptree_refresh_notify(in->req_wait.secs); - ret.retcode = err; - exit_picld_wait(uid); - } - ucred_free(puc); - } - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retwait_t), NULL, 0); -} - -/* - * This function returns the handle of the root node of the PICL tree - */ -static void -picld_getroot(picl_service_t *in) -{ - picl_retroot_t ret; - int err; - - ret.cnum = PICL_CNUM_GETROOT; - err = ptree_get_root(&ret.rnode); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - cvt_ptree2picl(&ret.rnode); - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retroot_t), NULL, 0); -} - -/* - * This function returns the value of the PICL property - */ -static void -picld_get_attrval(picl_service_t *in) -{ - picl_retattrval_t *ret; - int err; - size_t vbufsize; - size_t len; - door_cred_t cred; - picl_prophdl_t ptreeh; - ptree_propinfo_t pinfo; - - if (door_cred(&cred) < 0) - picld_return_error(in->in.cnum, PICL_FAILURE); - - err = cvt_picl2ptree(in->req_attrval.attr, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - err = ptree_get_propinfo(ptreeh, &pinfo); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - if (!(pinfo.piclinfo.accessmode & PICL_READ)) - picld_return_error(in->in.cnum, PICL_NOTREADABLE); - - vbufsize = pinfo.piclinfo.size; - vbufsize = MIN((size_t)in->req_attrval.bufsize, vbufsize); - - len = sizeof (picl_retattrval_t) + vbufsize; - ret = alloca(len); - if (ret == NULL) - picld_return_error(in->in.cnum, PICL_FAILURE); - ret->cnum = PICL_CNUM_GETATTRVAL; - ret->attr = in->req_attrval.attr; - ret->nbytes = (uint32_t)vbufsize; - err = xptree_get_propval_with_cred(ptreeh, ret->ret_buf, vbufsize, - cred); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - /* - * adjust returned bytes for charstrings - */ - if (pinfo.piclinfo.type == PICL_PTYPE_CHARSTRING) - ret->nbytes = (uint32_t)strlen(ret->ret_buf) + 1; - - /* - * convert handle values to picl handles - */ - if ((pinfo.piclinfo.type == PICL_PTYPE_TABLE) || - (pinfo.piclinfo.type == PICL_PTYPE_REFERENCE)) - cvt_ptree2picl(&ret->ret_nodeh); - (void) rw_unlock(&init_lk); - (void) door_return((char *)ret, sizeof (picl_retattrval_t) + - (size_t)ret->nbytes, NULL, 0); -} - -/* - * This function returns the value of the PICL property specified by - * its name. - */ -static void -picld_get_attrval_by_name(picl_service_t *in) -{ - picl_retattrvalbyname_t *ret; - int err; - size_t vbufsize; - size_t len; - door_cred_t cred; - picl_nodehdl_t ptreeh; - ptree_propinfo_t pinfo; - - if (door_cred(&cred) < 0) - picld_return_error(in->in.cnum, PICL_FAILURE); - - err = cvt_picl2ptree(in->req_attrvalbyname.nodeh, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - err = xptree_get_propinfo_by_name(ptreeh, - in->req_attrvalbyname.propname, &pinfo); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - if (!(pinfo.piclinfo.accessmode & PICL_READ)) - picld_return_error(in->in.cnum, PICL_NOTREADABLE); - - /* - * allocate the minimum of piclinfo.size and input bufsize - */ - vbufsize = pinfo.piclinfo.size; - vbufsize = MIN((size_t)in->req_attrvalbyname.bufsize, vbufsize); - len = sizeof (picl_retattrvalbyname_t) + vbufsize; - ret = alloca(len); - if (ret == NULL) - picld_return_error(in->in.cnum, PICL_FAILURE); - ret->cnum = PICL_CNUM_GETATTRVALBYNAME; - ret->nodeh = in->req_attrvalbyname.nodeh; - (void) strcpy(ret->propname, in->req_attrvalbyname.propname); - ret->nbytes = (uint32_t)vbufsize; - - err = xptree_get_propval_by_name_with_cred(ptreeh, - in->req_attrvalbyname.propname, ret->ret_buf, vbufsize, - cred); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - /* - * adjust returned value size for charstrings - */ - if (pinfo.piclinfo.type == PICL_PTYPE_CHARSTRING) - ret->nbytes = (uint32_t)strlen(ret->ret_buf) + 1; - - if ((pinfo.piclinfo.type == PICL_PTYPE_TABLE) || - (pinfo.piclinfo.type == PICL_PTYPE_REFERENCE)) - cvt_ptree2picl(&ret->ret_nodeh); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)ret, sizeof (picl_retattrvalbyname_t) + - (size_t)ret->nbytes, NULL, 0); -} - -/* - * This function sets a property value - */ -static void -picld_set_attrval(picl_service_t *in) -{ - picl_retsetattrval_t ret; - int err; - door_cred_t cred; - picl_prophdl_t ptreeh; - ptree_propinfo_t pinfo; - - if (door_cred(&cred) < 0) - picld_return_error(in->in.cnum, PICL_FAILURE); - - err = cvt_picl2ptree(in->req_setattrval.attr, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - err = ptree_get_propinfo(ptreeh, &pinfo); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - if (!(pinfo.piclinfo.accessmode & PICL_WRITE)) - picld_return_error(in->in.cnum, PICL_NOTWRITABLE); - /* - * For non-volatile prop, only super user can set its value. - */ - if (!(pinfo.piclinfo.accessmode & PICL_VOLATILE) && - (cred.dc_euid != SUPER_USER)) - picld_return_error(in->in.cnum, PICL_PERMDENIED); - - ret.cnum = PICL_CNUM_SETATTRVAL; - ret.attr = in->req_setattrval.attr; - - err = xptree_update_propval_with_cred(ptreeh, in->req_setattrval.valbuf, - (size_t)in->req_setattrval.bufsize, cred); - - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retsetattrval_t), NULL, - 0); -} - -/* - * This function sets the value of a property specified by its name. - */ -static void -picld_set_attrval_by_name(picl_service_t *in) -{ - picl_retsetattrvalbyname_t ret; - int err; - door_cred_t cred; - picl_prophdl_t ptreeh; - ptree_propinfo_t pinfo; - - if (door_cred(&cred) < 0) - picld_return_error(in->in.cnum, PICL_FAILURE); - - err = cvt_picl2ptree(in->req_setattrvalbyname.nodeh, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - err = xptree_get_propinfo_by_name(ptreeh, - in->req_setattrvalbyname.propname, &pinfo); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - if (!(pinfo.piclinfo.accessmode & PICL_WRITE)) - picld_return_error(in->in.cnum, PICL_NOTWRITABLE); - - /* - * For non-volatile prop, only super user can set its value. - */ - if (!(pinfo.piclinfo.accessmode & PICL_VOLATILE) && - (cred.dc_euid != SUPER_USER)) - picld_return_error(in->in.cnum, PICL_PERMDENIED); - - ret.cnum = PICL_CNUM_SETATTRVALBYNAME; - ret.nodeh = in->req_setattrvalbyname.nodeh; - (void) strcpy(ret.propname, in->req_setattrvalbyname.propname); - - err = xptree_update_propval_by_name_with_cred(ptreeh, - in->req_setattrvalbyname.propname, - in->req_setattrvalbyname.valbuf, - (size_t)in->req_setattrvalbyname.bufsize, - cred); - - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retsetattrvalbyname_t), - NULL, 0); -} - -/* - * This function returns the property information - */ -static void -picld_get_attrinfo(picl_service_t *in) -{ - picl_retattrinfo_t ret; - int err; - ptree_propinfo_t pinfo; - picl_prophdl_t ptreeh; - - err = cvt_picl2ptree(in->req_attrinfo.attr, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_GETATTRINFO; - ret.attr = in->req_attrinfo.attr; - - err = ptree_get_propinfo(ptreeh, &pinfo); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.type = pinfo.piclinfo.type; - ret.accessmode = pinfo.piclinfo.accessmode; - ret.size = (uint32_t)pinfo.piclinfo.size; - (void) strcpy(ret.name, pinfo.piclinfo.name); - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retattrinfo_t), NULL, 0); -} - -/* - * This function returns the node's first property handle - */ -static void -picld_get_first_attr(picl_service_t *in) -{ - picl_retfirstattr_t ret; - int err; - picl_prophdl_t ptreeh; - - err = cvt_picl2ptree(in->req_firstattr.nodeh, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_GETFIRSTATTR; - ret.nodeh = in->req_firstattr.nodeh; - - err = ptree_get_first_prop(ptreeh, &ret.attr); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - cvt_ptree2picl(&ret.attr); - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retfirstattr_t), NULL, 0); -} - -/* - * This function returns the next property handle in list - */ -static void -picld_get_next_attr(picl_service_t *in) -{ - picl_retnextattr_t ret; - int err; - picl_prophdl_t ptreeh; - - err = cvt_picl2ptree(in->req_nextattr.attr, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_GETNEXTATTR; - ret.attr = in->req_nextattr.attr; - - err = ptree_get_next_prop(ptreeh, &ret.nextattr); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - cvt_ptree2picl(&ret.nextattr); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retnextattr_t), NULL, 0); -} - -/* - * This function returns the handle of a property specified by its name - */ -static void -picld_get_attr_by_name(picl_service_t *in) -{ - picl_retattrbyname_t ret; - int err; - picl_prophdl_t ptreeh; - - err = cvt_picl2ptree(in->req_attrbyname.nodeh, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_GETATTRBYNAME; - ret.nodeh = in->req_attrbyname.nodeh; - (void) strcpy(ret.propname, in->req_attrbyname.propname); - - err = ptree_get_prop_by_name(ptreeh, ret.propname, &ret.attr); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - cvt_ptree2picl(&ret.attr); - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retattrbyname_t), NULL, - 0); -} - -/* - * This function gets the next property on the same row in the table - */ -static void -picld_get_attr_by_row(picl_service_t *in) -{ - picl_retattrbyrow_t ret; - int err; - picl_prophdl_t ptreeh; - - err = cvt_picl2ptree(in->req_attrbyrow.attr, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_GETATTRBYROW; - ret.attr = in->req_attrbyrow.attr; - - err = ptree_get_next_by_row(ptreeh, &ret.rowattr); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - cvt_ptree2picl(&ret.rowattr); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retattrbyrow_t), NULL, 0); -} - -/* - * This function returns the handle of the next property in the same column - * of the table. - */ -static void -picld_get_attr_by_col(picl_service_t *in) -{ - picl_retattrbycol_t ret; - int err; - picl_prophdl_t ptreeh; - - err = cvt_picl2ptree(in->req_attrbycol.attr, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_GETATTRBYCOL; - ret.attr = in->req_attrbycol.attr; - - err = ptree_get_next_by_col(ptreeh, &ret.colattr); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - cvt_ptree2picl(&ret.colattr); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (picl_retattrbycol_t), NULL, 0); -} - -/* - * This function finds the node in the PICLTREE that matches the given - * criteria and returns its handle. - */ -static void -picld_find_node(picl_service_t *in) -{ - picl_retfindnode_t ret; - int err; - picl_nodehdl_t ptreeh; - - err = cvt_picl2ptree(in->req_findnode.nodeh, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_FINDNODE; - - err = ptree_find_node(ptreeh, in->req_findnode.propname, - in->req_findnode.ptype, in->req_findnode.valbuf, - in->req_findnode.valsize, &ret.rnodeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - cvt_ptree2picl(&ret.rnodeh); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (ret), NULL, 0); -} - -/* - * This function finds the property/node that corresponds to the given path - * and returns its handle - */ -static void -picld_get_node_by_path(picl_service_t *in) -{ - picl_retnodebypath_t ret; - int err; - - ret.cnum = PICL_CNUM_NODEBYPATH; - err = ptree_get_node_by_path(in->req_nodebypath.pathbuf, &ret.nodeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - cvt_ptree2picl(&ret.nodeh); - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (ret), NULL, 0); -} - -/* - * This function returns finds the frutree parent node for a given node - * and returns its handle - */ -static void -picld_get_frutree_parent(picl_service_t *in) -{ - picl_retfruparent_t ret; - int err; - picl_nodehdl_t ptreeh; - - err = cvt_picl2ptree(in->req_fruparent.devh, &ptreeh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - - ret.cnum = PICL_CNUM_FRUTREEPARENT; - - err = ptree_get_frutree_parent(ptreeh, &ret.fruh); - if (err != PICL_SUCCESS) - picld_return_error(in->in.cnum, err); - cvt_ptree2picl(&ret.fruh); - - (void) rw_unlock(&init_lk); - (void) door_return((char *)&ret, sizeof (ret), NULL, 0); -} - -/* - * This function is called when an unknown client request is received. - */ -static void -picld_unknown_service(picl_service_t *in) -{ - picld_return_error(in->in.cnum, PICL_UNKNOWNSERVICE); -} - -static void -check_denial_of_service(int cnum) -{ - hrtime_t window; - hrtime_t current; - int dos_flag; - - current = gethrtime(); - dos_flag = 0; - - if (pthread_mutex_lock(&dos_mutex) != 0) - picld_return_error(cnum, PICL_FAILURE); - - ++service_requests; - window = current - orig_time; - if (window > MILLI_TO_NANO(sliding_interval_ms)) { - orig_time = current; - service_requests = 1; - } - - if (service_requests > dos_req_limit) - dos_flag = 1; - - if (pthread_mutex_unlock(&dos_mutex) != 0) - picld_return_error(cnum, PICL_FAILURE); - - if (dos_flag) - (void) poll(NULL, 0, dos_ms); -} - -/* ARGSUSED */ -static void -picld_door_handler(void *cookie, char *argp, size_t asize, - door_desc_t *dp, uint_t n_desc) -{ - picl_service_t *req; - - /*LINTED*/ - req = (picl_service_t *)argp; - - if (req == NULL) - (void) door_return((char *)req, 0, NULL, 0); - - check_denial_of_service(req->in.cnum); - - (void) rw_rdlock(&init_lk); - switch (req->in.cnum) { /* client call number */ - case PICL_CNUM_INIT: - /*LINTED*/ - picld_init((picl_service_t *)argp); - break; - case PICL_CNUM_FINI: - /*LINTED*/ - picld_fini((picl_service_t *)argp); - break; - case PICL_CNUM_GETROOT: - /*LINTED*/ - picld_getroot((picl_service_t *)argp); - break; - case PICL_CNUM_GETATTRVAL: - /*LINTED*/ - picld_get_attrval((picl_service_t *)argp); - break; - case PICL_CNUM_GETATTRVALBYNAME: - /*LINTED*/ - picld_get_attrval_by_name((picl_service_t *)argp); - break; - case PICL_CNUM_GETATTRINFO: - /*LINTED*/ - picld_get_attrinfo((picl_service_t *)argp); - break; - case PICL_CNUM_GETFIRSTATTR: - /*LINTED*/ - picld_get_first_attr((picl_service_t *)argp); - break; - case PICL_CNUM_GETNEXTATTR: - /*LINTED*/ - picld_get_next_attr((picl_service_t *)argp); - break; - case PICL_CNUM_GETATTRBYNAME: - /*LINTED*/ - picld_get_attr_by_name((picl_service_t *)argp); - break; - case PICL_CNUM_GETATTRBYROW: - /*LINTED*/ - picld_get_attr_by_row((picl_service_t *)argp); - break; - case PICL_CNUM_GETATTRBYCOL: - /*LINTED*/ - picld_get_attr_by_col((picl_service_t *)argp); - break; - case PICL_CNUM_SETATTRVAL: - /*LINTED*/ - picld_set_attrval((picl_service_t *)argp); - break; - case PICL_CNUM_SETATTRVALBYNAME: - /*LINTED*/ - picld_set_attrval_by_name((picl_service_t *)argp); - break; - case PICL_CNUM_PING: - /*LINTED*/ - picld_ping((picl_service_t *)argp); - break; - case PICL_CNUM_WAIT: - /*LINTED*/ - picld_wait((picl_service_t *)argp); - break; - case PICL_CNUM_FINDNODE: - /*LINTED*/ - picld_find_node((picl_service_t *)argp); - break; - case PICL_CNUM_NODEBYPATH: - /*LINTED*/ - picld_get_node_by_path((picl_service_t *)argp); - break; - case PICL_CNUM_FRUTREEPARENT: - /*LINTED*/ - picld_get_frutree_parent((picl_service_t *)argp); - break; - default: - /*LINTED*/ - picld_unknown_service((picl_service_t *)argp); - break; - }; - /*NOTREACHED*/ -} - -/* ARGSUSED */ -static void -hup_handler(int sig, siginfo_t *siginfo, void *sigctx) -{ - doreinit = 1; -} - -/* - * "ping" to see if a daemon is already running - */ -static int -daemon_exists(void) -{ - door_arg_t darg; - picl_reqping_t req_ping; - picl_retping_t ret_ping; - int doorh; - door_info_t dinfo; - - doorh = open(PICLD_DOOR, O_RDONLY); - if (doorh < 0) - return (0); - - if (door_info(doorh, &dinfo) < 0) { - (void) close(doorh); - return (0); - } - - if ((dinfo.di_attributes & DOOR_REVOKED) || - (dinfo.di_data != (uintptr_t)PICLD_DOOR_COOKIE)) { - (void) close(doorh); - return (0); - } - - if (dinfo.di_target != getpid()) { - (void) close(doorh); - return (1); - } - - req_ping.cnum = PICL_CNUM_PING; - - darg.data_ptr = (char *)&req_ping; - darg.data_size = sizeof (picl_reqping_t); - darg.desc_ptr = NULL; - darg.desc_num = 0; - darg.rbuf = (char *)&ret_ping; - darg.rsize = sizeof (picl_retping_t); - - if (door_call(doorh, &darg) < 0) { - (void) close(doorh); - return (0); - } - - (void) close(doorh); - return (1); -} - -/* - * picld_create_server_thread - binds the running thread to the private - * door pool, and sets the required cancellation state. - */ -/* ARGSUSED */ -static void * -picld_create_server_thread(void *arg) -{ - /* - * wait for door descriptor to be initialized - */ - (void) pthread_mutex_lock(&door_mutex); - while (door_id == -1) { - (void) pthread_cond_wait(&door_cv, &door_mutex); - } - (void) pthread_mutex_unlock(&door_mutex); - - /* - * Bind this thread to the door's private thread pool - */ - if (door_bind(door_id) < 0) { - perror("door_bind"); - } - - /* - * Disable thread cancellation mechanism - */ - (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - (void) door_return(NULL, 0, NULL, 0); /* wait for door invocation */ - return (NULL); -} - -/* - * picld_server_create_fn - creates threads for the private door pool - * - */ -/* ARGSUSED */ -static void -picld_server_create_fn(door_info_t *dip) -{ - pthread_attr_t attr; - - /* - * For the non-private pool do nothing. It's used for events which are - * single threaded anyway. The single thread servicing that pool is - * created when the event plugin creates its door. Note that the event - * plugin runs before setup_door instantiates picld_server_create_fn as - * the new create_proc so the door library default create_proc is used. - */ - if (dip == NULL) - return; - - (void) pthread_mutex_lock(&pool_mutex); - if (pool_count < MAX_POOL_SIZE) { - (void) pthread_attr_init(&attr); - (void) pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); - (void) pthread_attr_setdetachstate(&attr, - PTHREAD_CREATE_DETACHED); - if (pthread_create(NULL, &attr, picld_create_server_thread, - NULL)) { - perror("pthread_create"); - } else { - pool_count++; - } - } - (void) pthread_mutex_unlock(&pool_mutex); -} - -/* - * Create the picld door - */ -static int -setup_door(void) -{ - struct stat stbuf; - - (void) door_server_create(picld_server_create_fn); - (void) pthread_mutex_lock(&door_mutex); - /* - * Create the door - */ - door_id = door_create(picld_door_handler, PICLD_DOOR_COOKIE, - DOOR_REFUSE_DESC | DOOR_NO_CANCEL | DOOR_PRIVATE); - - if (door_id < 0) { - (void) pthread_mutex_unlock(&door_mutex); - return (-1); - } else { - (void) pthread_cond_signal(&door_cv); - (void) pthread_mutex_unlock(&door_mutex); - } - - if (stat(PICLD_DOOR, &stbuf) < 0) { - int newfd; - mode_t old_mask; - /* ensure that the door file is world-readable */ - old_mask = umask(0); - newfd = creat(PICLD_DOOR, 0444); - /* restore the file mode creation mask */ - (void) umask(old_mask); - if (newfd < 0) - return (-1); - (void) close(newfd); - } - - if (fattach(door_id, PICLD_DOOR) < 0) { - if ((errno != EBUSY) || - (fdetach(PICLD_DOOR) < 0) || - (fattach(door_id, PICLD_DOOR) < 0)) - return (-1); - } - return (0); -} - -/* - * Main function of picl daemon - */ -int -main(int argc, char **argv) -{ - struct sigaction act; - int c; - sigset_t ublk; - - - (void) setlocale(LC_ALL, ""); - (void) textdomain(TEXT_DOMAIN); - - if (getuid() != 0) { - syslog(LOG_CRIT, MUST_BE_ROOT); - return (0); - } - - (void) rwlock_init(&init_lk, USYNC_THREAD, NULL); - doreinit = 0; - logflag = 1; - dos_req_limit = DOS_PICL_REQUESTS_LIMIT; - sliding_interval_ms = SLIDING_INTERVAL_MILLISECONDS; - dos_ms = DOS_SLEEPTIME_MS; - verbose_level = 0; - - /* - * parse arguments - */ - while ((c = getopt(argc, argv, "is:t:l:r:v:d:")) != EOF) { - switch (c) { - case 'd': - dos_ms = strtol(optarg, (char **)NULL, 0); - break; - case 'i': - logflag = 0; - break; - case 's': - sliding_interval_ms = strtoll(optarg, (char **)NULL, 0); - break; - case 't': - dos_req_limit = strtol(optarg, (char **)NULL, 0); - break; - case 'v': - verbose_level = strtol(optarg, (char **)NULL, 0); - logflag = 0; - break; - default: - break; - } - } - - orig_time = gethrtime(); - - /* - * is there a daemon already running? - */ - - if (daemon_exists()) { - syslog(LOG_CRIT, DAEMON_RUNNING); - exit(1); - } - - /* - * Mask off/block SIGALRM signal so that the environmental plug-in - * (piclenvd) can use it to simulate sleep() without being affected - * by time being set back. No other PICL plug-in should use SIGALRM - * or alarm() for now. - */ - (void) sigemptyset(&ublk); - (void) sigaddset(&ublk, SIGALRM); - (void) sigprocmask(SIG_BLOCK, &ublk, NULL); - - /* - * Ignore SIGHUP until all the initialization is done. - */ - act.sa_handler = SIG_IGN; - (void) sigemptyset(&act.sa_mask); - act.sa_flags = 0; - if (sigaction(SIGHUP, &act, NULL) == -1) - syslog(LOG_ERR, SIGACT_FAILED, strsignal(SIGHUP), - strerror(errno)); - - if (logflag != 0) { /* daemonize */ - pid_t pid; - - pid = fork(); - if (pid < 0) - exit(1); - if (pid > 0) - /* parent */ - exit(0); - - /* child */ - if (chdir("/") == -1) { - syslog(LOG_CRIT, CD_ROOT_FAILED); - exit(1); - } - - (void) setsid(); - closefrom(0); - (void) open("/dev/null", O_RDWR, 0); - (void) dup2(STDIN_FILENO, STDOUT_FILENO); - (void) dup2(STDIN_FILENO, STDERR_FILENO); - openlog(PICLD, LOG_PID, LOG_DAEMON); - } - - /* - * Initialize the PICL Tree - */ - if (xptree_initialize(0) != PICL_SUCCESS) { - syslog(LOG_CRIT, INIT_FAILED); - exit(1); - } - - if (setup_door()) { - syslog(LOG_CRIT, DOOR_FAILED); - exit(1); - } - - /* - * setup signal handlers for post-init - */ - act.sa_sigaction = hup_handler; - (void) sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - if (sigaction(SIGHUP, &act, NULL) == -1) - syslog(LOG_ERR, SIGACT_FAILED, strsignal(SIGHUP), - strerror(errno)); - - /* - * wait for requests - */ - for (;;) { - (void) pause(); - if (doreinit) { - /* - * Block SIGHUP during reinitialization. - * Also mask off/block SIGALRM signal so that the - * environmental plug-in (piclenvd) can use it to - * simulate sleep() without being affected by time - * being set back. No ohter PICL plug-in should use - * SIGALRM or alarm() for now. - */ - (void) sigemptyset(&ublk); - (void) sigaddset(&ublk, SIGHUP); - (void) sigaddset(&ublk, SIGALRM); - (void) sigprocmask(SIG_BLOCK, &ublk, NULL); - (void) sigdelset(&ublk, SIGALRM); - doreinit = 0; - (void) rw_wrlock(&init_lk); - xptree_destroy(); - (void) xptree_reinitialize(); - (void) rw_unlock(&init_lk); - (void) sigprocmask(SIG_UNBLOCK, &ublk, NULL); - } - } -} diff --git a/usr/src/cmd/picl/plugins/Makefile b/usr/src/cmd/picl/plugins/Makefile deleted file mode 100644 index fe1027675b..0000000000 --- a/usr/src/cmd/picl/plugins/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/Makefile -# -COMMON_SUBDIRS= lib .WAIT common .WAIT - -i86_SUBDIRS= - -i86_MSGSUBDIRS= - -SUBDIRS= $(COMMON_SUBDIRS) $($(MACH)_SUBDIRS) - -MSGSUBDIRS= $(COMMON_SUBDIRS) $($(MACH)_MSGSUBDIRS) - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -.KEEP_STATE: - -all clean clobber : $(SUBDIRS) - -_msg: $(MSGSUBDIRS) - -install: $(SUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/Makefile.com b/usr/src/cmd/picl/plugins/Makefile.com deleted file mode 100644 index 4c8fb623b3..0000000000 --- a/usr/src/cmd/picl/plugins/Makefile.com +++ /dev/null @@ -1,61 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -# There should be a mapfile here -MAPFILES = - -CPPFLAGS += -I$(SRC)/lib/libpicl -I$(SRC)/lib/libpicltree -CPPFLAGS += -I$(SRC)/cmd/picl/plugins/inc -CERRWARN += -Wno-parentheses -CERRWARN += -Wno-char-subscripts -CERRWARN += -Wno-uninitialized -CERRWARN += -Wno-switch -CERRWARN += -Wno-unused-function -CERRWARN += -Wno-unused-variable - -# Some picl plugins have dependencies to which they make no reference. These -# dependencies are expected to be loaded so that their .init's fire and thus -# populate the picl database before the dependency itself adds to the database. -# Turn off lazy loading so that all plugin dependencies are loaded. -DYNFLAGS += $(ZNOLAZYLOAD) - -ROOTLIBDIR := DIRMODE= 0755 - -FILEMODE= 0755 -DIRMODE= 0755 - -ROOT_PLATFORM := DIRMODE= 0755 - -ROOT_PLAT_LIBDIR = $(ROOT_PLATFORM)/lib -ROOT_PLAT_LIBDIR := DIRMODE= 0755 - -ROOT_PLAT_PICLDIR = $(ROOT_PLAT_LIBDIR)/picl -ROOT_PLAT_PICLDIR := DIRMODE= 0755 - -ROOT_PLAT_PLUGINDIR = $(ROOT_PLAT_PICLDIR)/plugins -ROOT_PLAT_PLUGINDIR := DIRMODE= 0755 - -USR_LIB_PICLDIR = $(ROOT)/usr/lib/picl -USR_LIB_PLUGINDIR = $(USR_LIB_PICLDIR)/plugins diff --git a/usr/src/cmd/picl/plugins/Makefile.targ b/usr/src/cmd/picl/plugins/Makefile.targ deleted file mode 100644 index 4002c5d313..0000000000 --- a/usr/src/cmd/picl/plugins/Makefile.targ +++ /dev/null @@ -1,48 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright (c) 1999-2000 by Sun Microsystems, Inc. -# All rights reserved. -# -# -# cmd/picl/plugins/Makefile.targ -# -#ident "%Z%%M% %I% %E% SMI" - -$(ROOT_PLATFORM): - $(INS.dir) - -$(ROOT_PLAT_LIBDIR): $(ROOT_PLATFORM) - $(INS.dir) - -$(ROOT_PLAT_PICLDIR): $(ROOT_PLAT_LIBDIR) - $(INS.dir) - -$(ROOT_PLAT_PLUGINDIR): $(ROOT_PLAT_PICLDIR) - $(INS.dir) - -$(USR_LIB_PICLDIR): - $(INS.dir) - -$(USR_LIB_PLUGINDIR): $(USR_LIB_PICLDIR) - $(INS.dir) - diff --git a/usr/src/cmd/picl/plugins/common/Makefile b/usr/src/cmd/picl/plugins/common/Makefile deleted file mode 100644 index eb8be563f7..0000000000 --- a/usr/src/cmd/picl/plugins/common/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1999-2000 by Sun Microsystems, Inc. -# All rights reserved. -# -# cmd/picl/plugins/common/Makefile -# - -SUBDIRS= piclevent .WAIT devtree .WAIT memcfg .WAIT frutree .WAIT - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -.KEEP_STATE: - -all install clean clobber _msg : $(SUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/common/devtree/Makefile b/usr/src/cmd/picl/plugins/common/devtree/Makefile deleted file mode 100644 index 74829ed81b..0000000000 --- a/usr/src/cmd/picl/plugins/common/devtree/Makefile +++ /dev/null @@ -1,101 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# - -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# Copyright 2015 RackTop Systems. -# - -LIBRARY= libpicldevtree.a -VERS= .1 - -OBJECTS= picldevtree.o - -# include library definitions -include $(SRC)/lib/Makefile.lib - -include $(SRC)/cmd/picl/plugins/Makefile.com - -SRCS= $(OBJECTS:%.o=%.c) - -LIBS = $(DYNLIB) - -ROOTLIBDIR = $(USR_LIB_PLUGINDIR) -ROOTETC = $(ROOT)/etc -ROOTLIB = $(ROOT)/usr/lib - -CLOBBERFILES += $(LIBLINKS) - -CPPFLAGS += -I$(SRC)/lib/libsysevent -I$(SRC)/uts/common - -CFLAGS += $(C_PICFLAGS) -LDLIBS += -L$(SRC)/lib/libsysevent -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -lc -lkstat -ldevinfo -lpicltree -lnvpair -LDLIBS += -L../piclevent -L$(ROOT)/usr/lib/picl/plugins -lpiclevent -LDLIBS += -R/usr/platform/lib/picl/plugins -LDLIBS += -R/usr/platform/sun4u/lib/picl/plugins -LDLIBS += -R/usr/lib/picl/plugins - - -.KEEP_STATE: - -SUBDIRS= - -POFILE= picldevtree.po - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -all: $(LIBS) $(LIBLINKS) - -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - - -$(MSGDOMAIN): - $(INS.dir) - -$(LIBLINKS): FRC - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -# include library targets -include $(SRC)/cmd/picl/plugins/Makefile.targ -include $(SRC)/lib/Makefile.targ - -%.so: %.o - $(LINK.c) -o $@ $(GSHARED) -h $@ $< $(LDLIBS) - -%.o: %.c - $(COMPILE.c) -o $@ $< - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/common/devtree/picldevtree.c b/usr/src/cmd/picl/plugins/common/devtree/picldevtree.c deleted file mode 100644 index 723eaa72f6..0000000000 --- a/usr/src/cmd/picl/plugins/common/devtree/picldevtree.c +++ /dev/null @@ -1,3757 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * PICL plug-in that creates device tree nodes for all platforms - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "picldevtree.h" - -/* - * Plugin registration entry points - */ -static void picldevtree_register(void); -static void picldevtree_init(void); -static void picldevtree_fini(void); - -static void picldevtree_evhandler(const char *ename, const void *earg, - size_t size, void *cookie); - -#pragma init(picldevtree_register) - -/* - * Log message texts - */ -#define DEVINFO_PLUGIN_INIT_FAILED gettext("SUNW_picldevtree failed!\n") -#define PICL_EVENT_DROPPED \ - gettext("SUNW_picldevtree '%s' event dropped.\n") - -/* - * Macro to get PCI device id (from IEEE 1275 spec) - */ -#define PCI_DEVICE_ID(x) (((x) >> 11) & 0x1f) -/* - * Local variables - */ -static picld_plugin_reg_t my_reg_info = { - PICLD_PLUGIN_VERSION_1, - PICLD_PLUGIN_CRITICAL, - "SUNW_picldevtree", - picldevtree_init, - picldevtree_fini -}; - -/* - * Debug enabling environment variable - */ -#define SUNW_PICLDEVTREE_PLUGIN_DEBUG "SUNW_PICLDEVTREE_PLUGIN_DEBUG" -static int picldevtree_debug = 0; - -static conf_entries_t *conf_name_class_map = NULL; -static builtin_map_t sun4u_map[] = { - /* MAX_NAMEVAL_SIZE */ - { "SUNW,bpp", PICL_CLASS_PARALLEL}, - { "parallel", PICL_CLASS_PARALLEL}, - { "floppy", PICL_CLASS_FLOPPY}, - { "memory", PICL_CLASS_MEMORY}, - { "ebus", PICL_CLASS_EBUS}, - { "i2c", PICL_CLASS_I2C}, - { "usb", PICL_CLASS_USB}, - { "isa", PICL_CLASS_ISA}, - { "dma", PICL_CLASS_DMA}, - { "keyboard", PICL_CLASS_KEYBOARD}, - { "mouse", PICL_CLASS_MOUSE}, - { "fan-control", PICL_CLASS_FAN_CONTROL}, - { "sc", PICL_CLASS_SYSTEM_CONTROLLER}, - { "dimm", PICL_CLASS_SEEPROM}, - { "dimm-fru", PICL_CLASS_SEEPROM}, - { "cpu", PICL_CLASS_SEEPROM}, - { "cpu-fru", PICL_CLASS_SEEPROM}, - { "flashprom", PICL_CLASS_FLASHPROM}, - { "temperature", PICL_CLASS_TEMPERATURE_DEVICE}, - { "motherboard", PICL_CLASS_SEEPROM}, - { "motherboard-fru", PICL_CLASS_SEEPROM}, - { "motherboard-fru-prom", PICL_CLASS_SEEPROM}, - { "pmu", PICL_CLASS_PMU}, - { "sound", PICL_CLASS_SOUND}, - { "firewire", PICL_CLASS_FIREWIRE}, - { "i2c-at34c02", PICL_CLASS_SEEPROM}, - { "hardware-monitor", PICL_CLASS_HARDWARE_MONITOR}, - { "", ""} -}; -static builtin_map_t i86pc_map[] = { - /* MAX_NAMEVAL_SIZE */ - { "cpus", PICL_CLASS_I86CPUS}, - { "cpu", PICL_CLASS_CPU}, - { "memory", PICL_CLASS_MEMORY}, - { "asy", PICL_CLASS_SERIAL}, - { "", ""} -}; -static pname_type_map_t pname_type_map[] = { - { "reg", PICL_PTYPE_BYTEARRAY}, - { "device_type", PICL_PTYPE_CHARSTRING}, - { "ranges", PICL_PTYPE_BYTEARRAY}, - { "status", PICL_PTYPE_CHARSTRING}, - { "compatible", PICL_PTYPE_CHARSTRING}, - { "interrupts", PICL_PTYPE_BYTEARRAY}, - { "model", PICL_PTYPE_CHARSTRING}, - { "address", PICL_PTYPE_BYTEARRAY}, - { "vendor-id", PICL_PTYPE_UNSIGNED_INT}, - { "device-id", PICL_PTYPE_UNSIGNED_INT}, - { "revision-id", PICL_PTYPE_UNSIGNED_INT}, - { "class-code", PICL_PTYPE_UNSIGNED_INT}, - { "min-grant", PICL_PTYPE_UNSIGNED_INT}, - { "max-latency", PICL_PTYPE_UNSIGNED_INT}, - { "devsel-speed", PICL_PTYPE_UNSIGNED_INT}, - { "subsystem-id", PICL_PTYPE_UNSIGNED_INT}, - { "subsystem-vendor-id", PICL_PTYPE_UNSIGNED_INT}, - { "assigned-addresses", PICL_PTYPE_BYTEARRAY}, - { "configuration#", PICL_PTYPE_UNSIGNED_INT}, - { "assigned-address", PICL_PTYPE_UNSIGNED_INT}, - { "#address-cells", PICL_PTYPE_UNSIGNED_INT}, - { "#size-cells", PICL_PTYPE_UNSIGNED_INT}, - { "clock-frequency", PICL_PTYPE_UNSIGNED_INT}, - { "scsi-initiator-id", PICL_PTYPE_UNSIGNED_INT}, - { "differential", PICL_PTYPE_UNSIGNED_INT}, - { "idprom", PICL_PTYPE_BYTEARRAY}, - { "bus-range", PICL_PTYPE_BYTEARRAY}, - { "alternate-reg", PICL_PTYPE_BYTEARRAY}, - { "power-consumption", PICL_PTYPE_BYTEARRAY}, - { "slot-names", PICL_PTYPE_BYTEARRAY}, - { "burst-sizes", PICL_PTYPE_UNSIGNED_INT}, - { "up-burst-sizes", PICL_PTYPE_UNSIGNED_INT}, - { "slot-address-bits", PICL_PTYPE_UNSIGNED_INT}, - { "eisa-slots", PICL_PTYPE_BYTEARRAY}, - { "dma", PICL_PTYPE_BYTEARRAY}, - { "slot-names-index", PICL_PTYPE_UNSIGNED_INT}, - { "pnp-csn", PICL_PTYPE_UNSIGNED_INT}, - { "pnp-data", PICL_PTYPE_BYTEARRAY}, - { "description", PICL_PTYPE_CHARSTRING}, - { "pnp-id", PICL_PTYPE_CHARSTRING}, - { "max-frame-size", PICL_PTYPE_UNSIGNED_INT}, - { "address-bits", PICL_PTYPE_UNSIGNED_INT}, - { "local-mac-address", PICL_PTYPE_BYTEARRAY}, - { "mac-address", PICL_PTYPE_BYTEARRAY}, - { "character-set", PICL_PTYPE_CHARSTRING}, - { "available", PICL_PTYPE_BYTEARRAY}, - { "port-wwn", PICL_PTYPE_BYTEARRAY}, - { "node-wwn", PICL_PTYPE_BYTEARRAY}, - { "width", PICL_PTYPE_UNSIGNED_INT}, - { "linebytes", PICL_PTYPE_UNSIGNED_INT}, - { "height", PICL_PTYPE_UNSIGNED_INT}, - { "banner-name", PICL_PTYPE_CHARSTRING}, - { "reset-reason", PICL_PTYPE_CHARSTRING}, - { "implementation#", PICL_PTYPE_UNSIGNED_INT}, - { "version#", PICL_PTYPE_UNSIGNED_INT}, - { "icache-size", PICL_PTYPE_UNSIGNED_INT}, - { "icache-line-size", PICL_PTYPE_UNSIGNED_INT}, - { "icache-associativity", PICL_PTYPE_UNSIGNED_INT}, - { "l1-icache-size", PICL_PTYPE_UNSIGNED_INT}, - { "l1-icache-line-size", PICL_PTYPE_UNSIGNED_INT}, - { "l1-icache-associativity", PICL_PTYPE_UNSIGNED_INT}, - { "#itlb-entries", PICL_PTYPE_UNSIGNED_INT}, - { "dcache-size", PICL_PTYPE_UNSIGNED_INT}, - { "dcache-line-size", PICL_PTYPE_UNSIGNED_INT}, - { "dcache-associativity", PICL_PTYPE_UNSIGNED_INT}, - { "l1-dcache-size", PICL_PTYPE_UNSIGNED_INT}, - { "l1-dcache-line-size", PICL_PTYPE_UNSIGNED_INT}, - { "l1-dcache-associativity", PICL_PTYPE_UNSIGNED_INT}, - { "#dtlb-entries", PICL_PTYPE_UNSIGNED_INT}, - { "ecache-size", PICL_PTYPE_UNSIGNED_INT}, - { "ecache-line-size", PICL_PTYPE_UNSIGNED_INT}, - { "ecache-associativity", PICL_PTYPE_UNSIGNED_INT}, - { "l2-cache-size", PICL_PTYPE_UNSIGNED_INT}, - { "l2-cache-line-size", PICL_PTYPE_UNSIGNED_INT}, - { "l2-cache-associativity", PICL_PTYPE_UNSIGNED_INT}, - { "l2-cache-sharing", PICL_PTYPE_BYTEARRAY}, - { "mask#", PICL_PTYPE_UNSIGNED_INT}, - { "manufacturer#", PICL_PTYPE_UNSIGNED_INT}, - { "sparc-version", PICL_PTYPE_UNSIGNED_INT}, - { "version", PICL_PTYPE_CHARSTRING}, - { "cpu-model", PICL_PTYPE_UNSIGNED_INT}, - { "memory-layout", PICL_PTYPE_BYTEARRAY}, - { "#interrupt-cells", PICL_PTYPE_UNSIGNED_INT}, - { "interrupt-map", PICL_PTYPE_BYTEARRAY}, - { "interrupt-map-mask", PICL_PTYPE_BYTEARRAY} -}; - -#define PNAME_MAP_SIZE sizeof (pname_type_map) / sizeof (pname_type_map_t) - -static builtin_map_t *builtin_map_ptr = NULL; -static int builtin_map_size = 0; -static char mach_name[SYS_NMLN]; -static di_prom_handle_t ph = DI_PROM_HANDLE_NIL; -static int snapshot_stale; - -/* - * UnitAddress mapping table - */ -static unitaddr_func_t encode_default_unitaddr; -static unitaddr_func_t encode_optional_unitaddr; -static unitaddr_func_t encode_scsi_unitaddr; -static unitaddr_func_t encode_upa_unitaddr; -static unitaddr_func_t encode_gptwo_jbus_unitaddr; -static unitaddr_func_t encode_pci_unitaddr; - -static unitaddr_map_t unitaddr_map_table[] = { - {PICL_CLASS_JBUS, encode_gptwo_jbus_unitaddr, 0}, - {PICL_CLASS_GPTWO, encode_gptwo_jbus_unitaddr, 0}, - {PICL_CLASS_PCI, encode_pci_unitaddr, 0}, - {PICL_CLASS_PCIEX, encode_pci_unitaddr, 0}, - {PICL_CLASS_UPA, encode_upa_unitaddr, 0}, - {PICL_CLASS_SCSI, encode_scsi_unitaddr, 0}, - {PICL_CLASS_SCSI2, encode_scsi_unitaddr, 0}, - {PICL_CLASS_EBUS, encode_default_unitaddr, 2}, - {PICL_CLASS_SBUS, encode_default_unitaddr, 2}, - {PICL_CLASS_I2C, encode_default_unitaddr, 2}, - {PICL_CLASS_USB, encode_default_unitaddr, 1}, - {PICL_CLASS_PMU, encode_optional_unitaddr, 2}, - {NULL, encode_default_unitaddr, 0} -}; - -static int add_unitaddr_prop_to_subtree(picl_nodehdl_t nodeh); -static int get_unitaddr(picl_nodehdl_t parh, picl_nodehdl_t nodeh, - char *unitaddr, size_t ualen); -static void set_pci_pciex_deviceid(picl_nodehdl_t plafh); - -/* - * The mc event completion handler. - * The arguments are event name buffer and a packed nvlist buffer - * with the size specifying the size of unpacked nvlist. These - * buffers are deallcoated here. - * - * Also, if a memory controller node is being removed then destroy the - * PICL subtree associated with that memory controller. - */ -static void -mc_completion_handler(char *ename, void *earg, size_t size) -{ - picl_nodehdl_t mch; - nvlist_t *unpack_nvl; - - if (strcmp(ename, PICLEVENT_MC_REMOVED) == 0 && - nvlist_unpack(earg, size, &unpack_nvl, 0) == 0) { - mch = (uintptr_t)NULL; - (void) nvlist_lookup_uint64(unpack_nvl, - PICLEVENTARG_NODEHANDLE, &mch); - if (mch != (uintptr_t)NULL) { - if (picldevtree_debug) - syslog(LOG_INFO, - "picldevtree: destroying_node:%llx\n", - mch); - (void) ptree_destroy_node(mch); - } - nvlist_free(unpack_nvl); - } - - free(ename); - free(earg); -} - -/* - * Functions to post memory controller change event - */ -static int -post_mc_event(char *ename, picl_nodehdl_t mch) -{ - nvlist_t *nvl; - size_t nvl_size; - char *pack_buf; - char *ev_name; - - ev_name = strdup(ename); - if (ev_name == NULL) - return (-1); - - if (nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0)) { - free(ev_name); - return (-1); - } - - pack_buf = NULL; - if (nvlist_add_uint64(nvl, PICLEVENTARG_NODEHANDLE, mch) || - nvlist_pack(nvl, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, 0)) { - free(ev_name); - nvlist_free(nvl); - return (-1); - } - - if (picldevtree_debug) - syslog(LOG_INFO, - "picldevtree: posting MC event ename:%s nodeh:%llx\n", - ev_name, mch); - if (ptree_post_event(ev_name, pack_buf, nvl_size, - mc_completion_handler) != PICL_SUCCESS) { - free(ev_name); - nvlist_free(nvl); - return (-1); - } - nvlist_free(nvl); - return (0); -} - -/* - * Lookup a name in the name to class map tables - */ -static int -lookup_name_class_map(char *classbuf, const char *nm) -{ - conf_entries_t *ptr; - int i; - - /* - * check name to class mapping in conf file - */ - ptr = conf_name_class_map; - - while (ptr != NULL) { - if (strcmp(ptr->name, nm) == 0) { - (void) strlcpy(classbuf, ptr->piclclass, - PICL_CLASSNAMELEN_MAX); - return (0); - } - ptr = ptr->next; - } - - /* - * check name to class mapping in builtin table - */ - if (builtin_map_ptr == NULL) - return (-1); - - for (i = 0; i < builtin_map_size; ++i) - if (strcmp(builtin_map_ptr[i].name, nm) == 0) { - (void) strlcpy(classbuf, builtin_map_ptr[i].piclclass, - PICL_CLASSNAMELEN_MAX); - return (0); - } - return (-1); -} - -/* - * Lookup a prop name in the pname to class map table - */ -static int -lookup_pname_type_map(const char *pname, picl_prop_type_t *type) -{ - int i; - - for (i = 0; i < PNAME_MAP_SIZE; ++i) - if (strcmp(pname_type_map[i].pname, pname) == 0) { - *type = pname_type_map[i].type; - return (0); - } - - return (-1); -} - -/* - * Return the number of strings in the buffer - */ -static int -get_string_count(char *strdat, int length) -{ - int count; - char *lastnull; - char *nullptr; - - count = 1; - for (lastnull = &strdat[length - 1], nullptr = strchr(strdat, '\0'); - nullptr != lastnull; nullptr = strchr(nullptr+1, '\0')) - count++; - - return (count); -} - -/* - * Return 1 if the node has a "reg" property - */ -static int -has_reg_prop(di_node_t dn) -{ - int *pdata; - int dret; - - dret = di_prop_lookup_ints(DDI_DEV_T_ANY, dn, OBP_REG, &pdata); - if (dret > 0) - return (1); - - if (!ph) - return (0); - dret = di_prom_prop_lookup_ints(ph, dn, OBP_REG, &pdata); - return (dret < 0 ? 0 : 1); -} - -/* - * This function copies a PROM node's device_type property value into the - * buffer given by outbuf. The buffer size is PICL_CLASSNAMELEN_MAX. - * - * We reclassify device_type 'fru-prom' to PICL class 'seeprom' - * for FRUID support. - */ -static int -get_device_type(char *outbuf, di_node_t dn) -{ - char *pdata; - char *pdatap; - int dret; - int i; - - dret = di_prop_lookup_strings(DDI_DEV_T_ANY, dn, OBP_DEVICETYPE, - &pdata); - if (dret <= 0) { - if (!ph) - return (-1); - - dret = di_prom_prop_lookup_strings(ph, dn, OBP_DEVICETYPE, - &pdata); - if (dret <= 0) { - return (-1); - } - } - - if (dret != 1) { - /* - * multiple strings - */ - pdatap = pdata; - for (i = 0; i < (dret - 1); ++i) { - pdatap += strlen(pdatap); - *pdatap = '-'; /* replace '\0' with '-' */ - pdatap++; - } - } - if (strcasecmp(pdata, "fru-prom") == 0) { - /* - * Use PICL 'seeprom' class for fru-prom device types - */ - (void) strlcpy(outbuf, PICL_CLASS_SEEPROM, - PICL_CLASSNAMELEN_MAX); - } else { - (void) strlcpy(outbuf, pdata, PICL_CLASSNAMELEN_MAX); - } - return (0); -} - -/* - * Get the minor node name in the class buffer passed - */ -static int -get_minor_class(char *classbuf, di_node_t dn) -{ - di_minor_t mi_node; - char *mi_nodetype; - char *mi_name; - - /* get minor node type */ - mi_node = di_minor_next(dn, DI_MINOR_NIL); - if (mi_node == DI_MINOR_NIL) - return (-1); - - mi_nodetype = di_minor_nodetype(mi_node); - if (mi_nodetype == NULL) { /* no type info, return name */ - mi_name = di_minor_name(mi_node); - if (mi_name == NULL) - return (-1); - (void) strlcpy(classbuf, mi_name, PICL_CLASSNAMELEN_MAX); - return (0); - } - -#define DDI_NODETYPE(x, y) (strncmp(x, y, (sizeof (y) - 1)) == 0) - - /* - * convert the string to the picl class for non-peudo nodes - */ - if (DDI_NODETYPE(mi_nodetype, DDI_PSEUDO)) - return (-1); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_BLOCK_WWN)) - (void) strcpy(classbuf, PICL_CLASS_BLOCK); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_BLOCK_CHAN)) - (void) strcpy(classbuf, PICL_CLASS_BLOCK); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_CD)) - (void) strcpy(classbuf, PICL_CLASS_CDROM); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_CD_CHAN)) - (void) strcpy(classbuf, PICL_CLASS_CDROM); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_FD)) - (void) strcpy(classbuf, PICL_CLASS_FLOPPY); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_BLOCK_FABRIC)) - (void) strcpy(classbuf, PICL_CLASS_FABRIC); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_BLOCK_SAS)) - (void) strcpy(classbuf, PICL_CLASS_SAS); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_BLOCK)) - (void) strcpy(classbuf, PICL_CLASS_BLOCK); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_MOUSE)) - (void) strcpy(classbuf, PICL_CLASS_MOUSE); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_KEYBOARD)) - (void) strcpy(classbuf, PICL_CLASS_KEYBOARD); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_ATTACHMENT_POINT)) - (void) strcpy(classbuf, PICL_CLASS_ATTACHMENT_POINT); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_TAPE)) - (void) strcpy(classbuf, PICL_CLASS_TAPE); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_SCSI_ENCLOSURE)) - (void) strcpy(classbuf, PICL_CLASS_SCSI); - else if (DDI_NODETYPE(mi_nodetype, DDI_NT_ENCLOSURE)) { - char *colon; - - if ((colon = strchr(mi_nodetype, ':')) == NULL) - return (-1); - ++colon; - (void) strcpy(classbuf, colon); - } else { /* unrecognized type, return name */ - mi_name = di_minor_name(mi_node); - if (mi_name == NULL) - return (-1); - (void) strlcpy(classbuf, mi_name, PICL_CLASSNAMELEN_MAX); - } - return (0); -} - -/* - * Derive PICL class using the compatible property of the node - * We use the map table to map compatible property value to - * class. - */ -static int -get_compatible_class(char *outbuf, di_node_t dn) -{ - char *pdata; - char *pdatap; - int dret; - int i; - - dret = di_prop_lookup_strings(DDI_DEV_T_ANY, dn, OBP_COMPATIBLE, - &pdata); - if (dret <= 0) { - if (!ph) - return (-1); - - dret = di_prom_prop_lookup_strings(ph, dn, OBP_COMPATIBLE, - &pdata); - if (dret <= 0) { - return (-1); - } - } - - pdatap = pdata; - for (i = 0; i < dret; ++i) { - if (lookup_name_class_map(outbuf, pdatap) == 0) - return (0); - pdatap += strlen(pdatap); - pdatap++; - } - return (-1); -} - -/* - * For a given device node find the PICL class to use. Returns NULL - * for non device node - */ -static int -get_node_class(char *classbuf, di_node_t dn, const char *nodename) -{ - if (get_device_type(classbuf, dn) == 0) { - if (di_nodeid(dn) == DI_PROM_NODEID) { - /* - * discard place holder nodes - */ - if ((strcmp(classbuf, DEVICE_TYPE_BLOCK) == 0) || - (strcmp(classbuf, DEVICE_TYPE_BYTE) == 0) || - (strcmp(classbuf, DEVICE_TYPE_SES) == 0) || - (strcmp(classbuf, DEVICE_TYPE_FP) == 0) || - (strcmp(classbuf, DEVICE_TYPE_DISK) == 0)) - return (-1); - - return (0); - } - return (0); /* return device_type value */ - } - - if (get_compatible_class(classbuf, dn) == 0) { - return (0); /* derive class using compatible prop */ - } - - if (lookup_name_class_map(classbuf, nodename) == 0) - return (0); /* derive class using name prop */ - - if (has_reg_prop(dn)) { /* use default obp-device */ - (void) strcpy(classbuf, PICL_CLASS_OBP_DEVICE); - return (0); - } - - return (get_minor_class(classbuf, dn)); -} - -/* - * Add a table property containing nrows with one column - */ -static int -add_string_list_prop(picl_nodehdl_t nodeh, char *name, char *strlist, - unsigned int nrows) -{ - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - picl_prophdl_t tblh; - int err; - unsigned int i; - unsigned int j; - picl_prophdl_t *proprow; - int len; - -#define NCOLS_IN_STRING_TABLE 1 - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_TABLE, PICL_READ, sizeof (picl_prophdl_t), name, - NULL, NULL); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_table(&tblh); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_and_add_prop(nodeh, &propinfo, &tblh, &proph); - if (err != PICL_SUCCESS) - return (err); - - proprow = alloca(sizeof (picl_prophdl_t) * nrows); - if (proprow == NULL) { - (void) ptree_destroy_prop(proph); - return (PICL_FAILURE); - } - - for (j = 0; j < nrows; ++j) { - len = strlen(strlist) + 1; - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, len, name, - NULL, NULL); - if (err != PICL_SUCCESS) - break; - err = ptree_create_prop(&propinfo, strlist, &proprow[j]); - if (err != PICL_SUCCESS) - break; - strlist += len; - err = ptree_add_row_to_table(tblh, NCOLS_IN_STRING_TABLE, - &proprow[j]); - if (err != PICL_SUCCESS) - break; - } - - if (err != PICL_SUCCESS) { - for (i = 0; i < j; ++i) - (void) ptree_destroy_prop(proprow[i]); - (void) ptree_delete_prop(proph); - (void) ptree_destroy_prop(proph); - return (err); - } - - return (PICL_SUCCESS); -} - -/* - * return 1 if this node has this property with the given value - */ -static int -compare_string_propval(picl_nodehdl_t nodeh, const char *pname, - const char *pval) -{ - char *pvalbuf; - int err; - int len; - ptree_propinfo_t pinfo; - picl_prophdl_t proph; - - err = ptree_get_prop_by_name(nodeh, pname, &proph); - if (err != PICL_SUCCESS) /* prop doesn't exist */ - return (0); - - err = ptree_get_propinfo(proph, &pinfo); - if (pinfo.piclinfo.type != PICL_PTYPE_CHARSTRING) - return (0); /* not string prop */ - - len = strlen(pval) + 1; - - pvalbuf = alloca(len); - if (pvalbuf == NULL) - return (0); - - err = ptree_get_propval(proph, pvalbuf, len); - if ((err == PICL_SUCCESS) && (strcmp(pvalbuf, pval) == 0)) - return (1); /* prop match */ - - return (0); -} - -/* - * This function recursively searches the tree for a node that has - * the specified string property name and value - */ -static int -find_node_by_string_prop(picl_nodehdl_t rooth, const char *pname, - const char *pval, picl_nodehdl_t *nodeh) -{ - picl_nodehdl_t childh; - int err; - - for (err = ptree_get_propval_by_name(rooth, PICL_PROP_CHILD, &childh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = ptree_get_propval_by_name(childh, PICL_PROP_PEER, &childh, - sizeof (picl_nodehdl_t))) { - if (err != PICL_SUCCESS) - return (err); - - if (compare_string_propval(childh, pname, pval)) { - *nodeh = childh; - return (PICL_SUCCESS); - } - - if (find_node_by_string_prop(childh, pname, pval, nodeh) == - PICL_SUCCESS) - return (PICL_SUCCESS); - } - - return (PICL_FAILURE); -} - -/* - * check if this is a string prop - * If the length is less than or equal to 4, assume it's not a string list. - * If there is any non-ascii or non-print char, it's not a string prop - * If \0 is in the first char or any two consecutive \0's exist, - * it's a bytearray prop. - * Return value: 0 means it's not a string prop, 1 means it's a string prop - */ -static int -is_string_propval(unsigned char *pdata, int len) -{ - int i; - int lastindex; - int prevnull = -1; - - switch (len) { - case 1: - if (!isascii(pdata[0]) || !isprint(pdata[0])) - return (0); - return (1); - case 2: - case 3: - case 4: - lastindex = len; - if (pdata[len-1] == '\0') - lastindex = len - 1; - - for (i = 0; i < lastindex; i++) - if (!isascii(pdata[i]) || !isprint(pdata[i])) - return (0); - - return (1); - - default: - if (len <= 0) - return (0); - for (i = 0; i < len; i++) { - if (!isascii(pdata[i]) || !isprint(pdata[i])) { - if (pdata[i] != '\0') - return (0); - /* - * if the null char is in the first char - * or two consecutive nulls' exist, - * it's a bytearray prop - */ - if ((i == 0) || ((i - prevnull) == 1)) - return (0); - - prevnull = i; - } - } - break; - } - - return (1); -} - -/* - * This function counts the number of strings in the value buffer pdata - * and creates a property. - * If there is only one string in the buffer, pdata, a charstring property - * type is created and added. - * If there are more than one string in the buffer, pdata, then a table - * of charstrings is added. - */ -static int -process_charstring_data(picl_nodehdl_t nodeh, char *pname, unsigned char *pdata, - int retval) -{ - int err; - int strcount; - char *strdat; - ptree_propinfo_t propinfo; - - /* - * append the null char at the end of string when there is - * no null terminator - */ - if (pdata[retval - 1] != '\0') { - strdat = alloca(retval + 1); - (void) memcpy(strdat, pdata, retval); - strdat[retval] = '\0'; - retval++; - } else { - strdat = alloca(retval); - (void) memcpy(strdat, pdata, retval); - } - - /* - * If it's a string list, create a table prop - */ - strcount = get_string_count(strdat, retval); - if (strcount > 1) { - err = add_string_list_prop(nodeh, pname, - strdat, strcount); - if (err != PICL_SUCCESS) - return (err); - } else { - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(strdat) + 1, pname, NULL, - NULL); - if (err != PICL_SUCCESS) - return (err); - (void) ptree_create_and_add_prop(nodeh, &propinfo, - strdat, NULL); - } - return (PICL_SUCCESS); -} - -/* - * Add the OBP properties as properties of the PICL node - */ -static int -add_openprom_props(picl_nodehdl_t nodeh, di_node_t di_node) -{ - di_prom_prop_t promp; - char *pname; - unsigned char *pdata; - int retval; - ptree_propinfo_t propinfo; - int err; - picl_prop_type_t type; - - if (!ph) - return (PICL_FAILURE); - - for (promp = di_prom_prop_next(ph, di_node, DI_PROM_PROP_NIL); - promp != DI_PROM_PROP_NIL; - promp = di_prom_prop_next(ph, di_node, promp)) { - - pname = di_prom_prop_name(promp); - - retval = di_prom_prop_data(promp, &pdata); - if (retval < 0) { - return (PICL_SUCCESS); - } - if (retval == 0) { - err = ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, PICL_PTYPE_VOID, - PICL_READ, (size_t)0, pname, NULL, NULL); - if (err != PICL_SUCCESS) { - return (err); - } - (void) ptree_create_and_add_prop(nodeh, &propinfo, NULL, - NULL); - continue; - } - - /* - * Get the prop type from pname map table - */ - if (lookup_pname_type_map(pname, &type) == 0) { - if (type == PICL_PTYPE_CHARSTRING) { - err = process_charstring_data(nodeh, pname, - pdata, retval); - if (err != PICL_SUCCESS) { - return (err); - } - continue; - } - - err = ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, type, PICL_READ, - retval, pname, NULL, NULL); - if (err != PICL_SUCCESS) { - return (err); - } - (void) ptree_create_and_add_prop(nodeh, &propinfo, - pdata, NULL); - } else if (!is_string_propval(pdata, retval)) { - switch (retval) { - case sizeof (uint8_t): - /*FALLTHROUGH*/ - case sizeof (uint16_t): - /*FALLTHROUGH*/ - case sizeof (uint32_t): - type = PICL_PTYPE_UNSIGNED_INT; - break; - default: - type = PICL_PTYPE_BYTEARRAY; - break; - } - err = ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, type, PICL_READ, - retval, pname, NULL, NULL); - if (err != PICL_SUCCESS) { - return (err); - } - (void) ptree_create_and_add_prop(nodeh, &propinfo, - pdata, NULL); - } else { - err = process_charstring_data(nodeh, pname, pdata, - retval); - if (err != PICL_SUCCESS) { - return (err); - } - } - } - - return (PICL_SUCCESS); -} - -static void -add_boolean_prop(picl_nodehdl_t nodeh, ptree_propinfo_t propinfo, char *di_val) -{ - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_VOID, PICL_READ, (size_t)0, di_val, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, NULL, NULL); -} - -static void -add_uints_prop(picl_nodehdl_t nodeh, ptree_propinfo_t propinfo, char *di_val, - int *idata, int len) -{ - if (len == 1) - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (int), di_val, - NULL, NULL); - else - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_BYTEARRAY, PICL_READ, len * sizeof (int), di_val, - NULL, NULL); - - (void) ptree_create_and_add_prop(nodeh, &propinfo, idata, NULL); -} - -static void -add_strings_prop(picl_nodehdl_t nodeh, ptree_propinfo_t propinfo, char *di_val, - char *sdata, int len) -{ - if (len == 1) { - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(sdata) + 1, di_val, - NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, sdata, NULL); - } else { - (void) add_string_list_prop(nodeh, di_val, sdata, len); - } -} - -static void -add_bytes_prop(picl_nodehdl_t nodeh, ptree_propinfo_t propinfo, char *di_val, - unsigned char *bdata, int len) -{ - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_BYTEARRAY, PICL_READ, len, di_val, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, bdata, NULL); -} - -static const char * -path_state_name(di_path_state_t st) -{ - switch (st) { - case DI_PATH_STATE_ONLINE: - return ("online"); - case DI_PATH_STATE_STANDBY: - return ("standby"); - case DI_PATH_STATE_OFFLINE: - return ("offline"); - case DI_PATH_STATE_FAULT: - return ("faulted"); - } - return ("unknown"); -} - -/* - * This function is the volatile property handler for the multipath node - * "State" property. It must locate the associated devinfo node in order to - * determine the current state. Since the devinfo node can have multiple - * paths the devfs_path is used to locate the correct path. - */ -static int -get_path_state_name(ptree_rarg_t *rarg, void *vbuf) -{ - int err; - picl_nodehdl_t parh; - char devfs_path[PATH_MAX]; - di_node_t di_node; - di_node_t di_root; - di_path_t pi = DI_PATH_NIL; - picl_nodehdl_t mpnode; - - (void) strlcpy(vbuf, "unknown", MAX_STATE_SIZE); - - mpnode = rarg->nodeh; - - /* - * The parent node represents the vHCI. - */ - err = ptree_get_propval_by_name(mpnode, PICL_PROP_PARENT, &parh, - sizeof (picl_nodehdl_t)); - if (err != PICL_SUCCESS) { - return (PICL_SUCCESS); - } - - /* - * The PICL_PROP_DEVFS_PATH property will be used to locate the - * devinfo node for the vHCI driver. - */ - err = ptree_get_propval_by_name(parh, PICL_PROP_DEVFS_PATH, devfs_path, - sizeof (devfs_path)); - if (err != PICL_SUCCESS) { - return (PICL_SUCCESS); - } - /* - * Find the di_node for the vHCI driver. It will be used to scan - * the path information nodes. - */ - di_root = di_init("/", DINFOCACHE); - if (di_root == DI_NODE_NIL) { - return (PICL_SUCCESS); - } - di_node = di_lookup_node(di_root, devfs_path); - if (di_node == DI_NODE_NIL) { - di_fini(di_root); - return (PICL_SUCCESS); - } - - /* - * The devfs_path will be used below to match the - * proper path information node. - */ - err = ptree_get_propval_by_name(mpnode, PICL_PROP_DEVFS_PATH, - devfs_path, sizeof (devfs_path)); - if (err != PICL_SUCCESS) { - di_fini(di_root); - return (PICL_SUCCESS); - } - - /* - * Scan the path information nodes looking for the matching devfs - * path. When found obtain the state information. - */ - while ((pi = di_path_next_phci(di_node, pi)) != DI_PATH_NIL) { - char *di_path; - di_node_t phci_node = di_path_phci_node(pi); - - if (phci_node == DI_PATH_NIL) - continue; - - di_path = di_devfs_path(phci_node); - if (di_path) { - if (strcmp(di_path, devfs_path) != 0) { - di_devfs_path_free(di_path); - continue; - } - (void) strlcpy(vbuf, path_state_name(di_path_state(pi)), - MAX_STATE_SIZE); - di_devfs_path_free(di_path); - break; - } - } - - di_fini(di_root); - return (PICL_SUCCESS); -} - -static void -add_di_path_prop(picl_nodehdl_t nodeh, di_path_prop_t di_path_prop) -{ - int di_ptype; - char *di_val; - ptree_propinfo_t propinfo; - int *idata; - char *sdata; - unsigned char *bdata; - int len; - - di_ptype = di_path_prop_type(di_path_prop); - di_val = di_path_prop_name(di_path_prop); - - switch (di_ptype) { - case DI_PROP_TYPE_BOOLEAN: - add_boolean_prop(nodeh, propinfo, di_val); - break; - case DI_PROP_TYPE_INT: - case DI_PROP_TYPE_INT64: - len = di_path_prop_ints(di_path_prop, &idata); - if (len < 0) - /* Received error, so ignore prop */ - break; - add_uints_prop(nodeh, propinfo, di_val, idata, len); - break; - case DI_PROP_TYPE_STRING: - len = di_path_prop_strings(di_path_prop, &sdata); - if (len <= 0) - break; - add_strings_prop(nodeh, propinfo, di_val, sdata, len); - break; - case DI_PROP_TYPE_BYTE: - len = di_path_prop_bytes(di_path_prop, &bdata); - if (len < 0) - break; - add_bytes_prop(nodeh, propinfo, di_val, bdata, len); - break; - case DI_PROP_TYPE_UNKNOWN: - /* - * Unknown type, we'll try and guess what it should be. - */ - len = di_path_prop_strings(di_path_prop, &sdata); - if ((len > 0) && (sdata[0] != 0)) { - add_strings_prop(nodeh, propinfo, di_val, sdata, - len); - break; - } - len = di_path_prop_ints(di_path_prop, &idata); - if (len > 0) { - add_uints_prop(nodeh, propinfo, di_val, - idata, len); - break; - } - len = di_path_prop_bytes(di_path_prop, &bdata); - if (len > 0) - add_bytes_prop(nodeh, propinfo, - di_val, bdata, len); - else if (len == 0) - add_boolean_prop(nodeh, propinfo, - di_val); - break; - case DI_PROP_TYPE_UNDEF_IT: - break; - default: - break; - } -} - -/* - * Add nodes for path information (PSARC/1999/647, PSARC/2008/437) - */ -static void -construct_mpath_node(picl_nodehdl_t parh, di_node_t di_node) -{ - di_path_t pi = DI_PATH_NIL; - - while ((pi = di_path_next_phci(di_node, pi)) != DI_PATH_NIL) { - di_node_t phci_node = di_path_phci_node(pi); - di_path_prop_t di_path_prop; - picl_nodehdl_t nodeh; - ptree_propinfo_t propinfo; - int err; - int instance; - char *di_val; - - if (phci_node == DI_PATH_NIL) - continue; - - err = ptree_create_and_add_node(parh, PICL_CLASS_MULTIPATH, - PICL_CLASS_MULTIPATH, &nodeh); - if (err != PICL_SUCCESS) - continue; - - instance = di_instance(phci_node); - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, sizeof (instance), - PICL_PROP_INSTANCE, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, &instance, - NULL); - - di_val = di_devfs_path(phci_node); - if (di_val) { - (void) ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(di_val) + 1, PICL_PROP_DEVFS_PATH, - NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, - &propinfo, di_val, NULL); - di_devfs_path_free(di_val); - } - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, (PICL_READ|PICL_VOLATILE), - MAX_STATE_SIZE, PICL_PROP_STATE, get_path_state_name, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, NULL, NULL); - - for (di_path_prop = di_path_prop_next(pi, DI_PROP_NIL); - di_path_prop != DI_PROP_NIL; - di_path_prop = di_path_prop_next(pi, di_path_prop)) { - add_di_path_prop(nodeh, di_path_prop); - } - } -} - -/* - * Add properties provided by libdevinfo - */ -static void -add_devinfo_props(picl_nodehdl_t nodeh, di_node_t di_node) -{ - int instance; - char *di_val; - di_prop_t di_prop; - int di_ptype; - ptree_propinfo_t propinfo; - char *sdata; - unsigned char *bdata; - int *idata; - int len; - - instance = di_instance(di_node); - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, sizeof (instance), PICL_PROP_INSTANCE, - NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, &instance, NULL); - - di_val = di_bus_addr(di_node); - if (di_val) { - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(di_val) + 1, - PICL_PROP_BUS_ADDR, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, di_val, - NULL); - } - - di_val = di_binding_name(di_node); - if (di_val) { - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(di_val) + 1, - PICL_PROP_BINDING_NAME, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, di_val, - NULL); - } - - di_val = di_driver_name(di_node); - if (di_val) { - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(di_val) + 1, - PICL_PROP_DRIVER_NAME, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, di_val, - NULL); - } - - di_val = di_devfs_path(di_node); - if (di_val) { - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(di_val) + 1, - PICL_PROP_DEVFS_PATH, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &propinfo, di_val, - NULL); - di_devfs_path_free(di_val); - } - - for (di_prop = di_prop_next(di_node, DI_PROP_NIL); - di_prop != DI_PROP_NIL; - di_prop = di_prop_next(di_node, di_prop)) { - - di_val = di_prop_name(di_prop); - di_ptype = di_prop_type(di_prop); - - switch (di_ptype) { - case DI_PROP_TYPE_BOOLEAN: - add_boolean_prop(nodeh, propinfo, di_val); - break; - case DI_PROP_TYPE_INT: - len = di_prop_ints(di_prop, &idata); - if (len < 0) - /* Received error, so ignore prop */ - break; - add_uints_prop(nodeh, propinfo, di_val, idata, len); - break; - case DI_PROP_TYPE_STRING: - len = di_prop_strings(di_prop, &sdata); - if (len < 0) - break; - add_strings_prop(nodeh, propinfo, di_val, sdata, len); - break; - case DI_PROP_TYPE_BYTE: - len = di_prop_bytes(di_prop, &bdata); - if (len < 0) - break; - add_bytes_prop(nodeh, propinfo, di_val, bdata, len); - break; - case DI_PROP_TYPE_UNKNOWN: - /* - * Unknown type, we'll try and guess what it should be. - */ - len = di_prop_strings(di_prop, &sdata); - if ((len > 0) && (sdata[0] != 0)) { - add_strings_prop(nodeh, propinfo, di_val, sdata, - len); - break; - } - len = di_prop_ints(di_prop, &idata); - if (len > 0) { - add_uints_prop(nodeh, propinfo, di_val, - idata, len); - break; - } - len = di_prop_rawdata(di_prop, &bdata); - if (len > 0) - add_bytes_prop(nodeh, propinfo, - di_val, bdata, len); - else if (len == 0) - add_boolean_prop(nodeh, propinfo, - di_val); - break; - case DI_PROP_TYPE_UNDEF_IT: - break; - default: - break; - } - } -} - -/* - * This function creates the /obp node in the PICL tree for OBP nodes - * without a device type class. - */ -static int -construct_picl_openprom(picl_nodehdl_t rooth, picl_nodehdl_t *obph) -{ - picl_nodehdl_t tmph; - int err; - - err = ptree_create_and_add_node(rooth, PICL_NODE_OBP, - PICL_CLASS_PICL, &tmph); - - if (err != PICL_SUCCESS) - return (err); - *obph = tmph; - return (PICL_SUCCESS); -} - -/* - * This function creates the /platform node in the PICL tree and - * its properties. It sets the "platform-name" property to the - * platform name - */ -static int -construct_picl_platform(picl_nodehdl_t rooth, di_node_t di_root, - picl_nodehdl_t *piclh) -{ - int err; - picl_nodehdl_t plafh; - char *nodename; - char nodeclass[PICL_CLASSNAMELEN_MAX]; - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - - nodename = di_node_name(di_root); - if (nodename == NULL) - return (PICL_FAILURE); - - err = 0; - if (di_nodeid(di_root) == DI_PROM_NODEID || - di_nodeid(di_root) == DI_SID_NODEID) - err = get_device_type(nodeclass, di_root); - - if (err < 0) - (void) strcpy(nodeclass, PICL_CLASS_UPA); /* default */ - - err = ptree_create_and_add_node(rooth, PICL_NODE_PLATFORM, - nodeclass, &plafh); - if (err != PICL_SUCCESS) - return (err); - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(nodename) + 1, - PICL_PROP_PLATFORM_NAME, NULL, NULL); - err = ptree_create_and_add_prop(plafh, &propinfo, nodename, &proph); - if (err != PICL_SUCCESS) - return (err); - - (void) add_devinfo_props(plafh, di_root); - - (void) add_openprom_props(plafh, di_root); - - *piclh = plafh; - - return (PICL_SUCCESS); -} - -/* - * This function creates a node in /obp tree for the libdevinfo handle. - */ -static int -construct_obp_node(picl_nodehdl_t parh, di_node_t dn, picl_nodehdl_t *chdh) -{ - int err; - char *nodename; - char nodeclass[PICL_CLASSNAMELEN_MAX]; - picl_nodehdl_t anodeh; - - nodename = di_node_name(dn); /* PICL_PROP_NAME */ - if (nodename == NULL) - return (PICL_FAILURE); - - if (strcmp(nodename, "pseudo") == 0) - return (PICL_FAILURE); - - if ((di_nodeid(dn) == DI_PROM_NODEID) && - (get_device_type(nodeclass, dn) == 0)) - return (PICL_FAILURE); - - err = ptree_create_and_add_node(parh, nodename, nodename, &anodeh); - if (err != PICL_SUCCESS) - return (err); - - add_devinfo_props(anodeh, dn); - - (void) add_openprom_props(anodeh, dn); - - *chdh = anodeh; - - return (PICL_SUCCESS); -} - -/* - * This function creates a PICL node in /platform tree for a device - */ -static int -construct_devtype_node(picl_nodehdl_t parh, char *nodename, - char *nodeclass, di_node_t dn, picl_nodehdl_t *chdh) -{ - int err; - picl_nodehdl_t anodeh; - - err = ptree_create_and_add_node(parh, nodename, nodeclass, &anodeh); - if (err != PICL_SUCCESS) - return (err); - - (void) add_devinfo_props(anodeh, dn); - (void) add_openprom_props(anodeh, dn); - construct_mpath_node(anodeh, dn); - - *chdh = anodeh; - return (err); -} - -/* - * Create a subtree of "picl" class nodes in /obp for these nodes - */ -static int -construct_openprom_tree(picl_nodehdl_t nodeh, di_node_t dinode) -{ - di_node_t cnode; - picl_nodehdl_t chdh; - int err; - - err = construct_obp_node(nodeh, dinode, &chdh); - if (err != PICL_SUCCESS) - return (err); - - for (cnode = di_child_node(dinode); cnode != DI_NODE_NIL; - cnode = di_sibling_node(cnode)) - (void) construct_openprom_tree(chdh, cnode); - - return (PICL_SUCCESS); - -} - -/* - * Process the libdevinfo device tree and create nodes in /platform or /obp - * PICL tree. - * - * This routine traverses the immediate children of "dinode" device and - * determines the node class for that child. If it finds a valid class - * name, then it builds a PICL node under /platform subtree and calls itself - * recursively to construct the subtree for that child node. Otherwise, if - * the parent_class is NULL, then it constructs a node and subtree under /obp - * subtree. - * - * Note that we skip the children nodes that don't have a valid class name - * and the parent_class is non NULL to prevent creation of any placeholder - * nodes (such as sd,...). - */ -static int -construct_devinfo_tree(picl_nodehdl_t plafh, picl_nodehdl_t obph, - di_node_t dinode, char *parent_class) -{ - di_node_t cnode; - picl_nodehdl_t chdh; - char nodeclass[PICL_CLASSNAMELEN_MAX]; - char *nodename; - int err; - - err = PICL_SUCCESS; - for (cnode = di_child_node(dinode); cnode != DI_NODE_NIL; - cnode = di_sibling_node(cnode)) { - nodename = di_node_name(cnode); /* PICL_PROP_NAME */ - if (nodename == NULL) - continue; - - err = get_node_class(nodeclass, cnode, nodename); - - if (err == 0) { - err = construct_devtype_node(plafh, nodename, - nodeclass, cnode, &chdh); - if (err != PICL_SUCCESS) - return (err); - err = construct_devinfo_tree(chdh, obph, cnode, - nodeclass); - } else if (parent_class == NULL) - err = construct_openprom_tree(obph, cnode); - else - continue; - /* - * if parent_class is non NULL, skip the children nodes - * that don't have a valid device class - eliminates - * placeholder nodes (sd,...) from being created. - */ - } - - return (err); - -} - -/* - * This function is called from the event handler called from the daemon - * on PICL events. - * - * This routine traverses the children of the "dinode" device and - * creates a PICL node for each child not found in the PICL tree and - * invokes itself recursively to create a subtree for the newly created - * child node. It also checks if the node being created is a meory - * controller. If so, it posts PICLEVENT_MC_ADDED PICL event to the PICL - * framework. - */ -static int -update_subtree(picl_nodehdl_t nodeh, di_node_t dinode) -{ - di_node_t cnode; - picl_nodehdl_t chdh; - picl_nodehdl_t nh; - char *nodename; - char nodeclass[PICL_CLASSNAMELEN_MAX]; - char *path_buf; - char buf[MAX_UNIT_ADDRESS_LEN]; - char unitaddr[MAX_UNIT_ADDRESS_LEN]; - char path_w_ua[MAXPATHLEN]; - char path_wo_ua[MAXPATHLEN]; - char *strp; - int gotit; - int err; - - for (cnode = di_child_node(dinode); cnode != DI_NODE_NIL; - cnode = di_sibling_node(cnode)) { - path_buf = di_devfs_path(cnode); - if (path_buf == NULL) - continue; - - nodename = di_node_name(cnode); - if (nodename == NULL) { - di_devfs_path_free(path_buf); - continue; - } - - err = get_node_class(nodeclass, cnode, nodename); - - if (err < 0) { - di_devfs_path_free(path_buf); - continue; - } - - /* - * this is quite complicated - both path_buf and any nodes - * already in the picl tree may, or may not, have the - * @ at the end of their names. So we must - * take path_buf and work out what the device path would - * be both with and without the unit_address, then search - * the picl tree for both forms. - */ - if (((strp = strrchr(path_buf, '/')) != NULL) && - strchr(strp, '@') == NULL) { - /* - * This is an unattached node - so the path is not - * unique. Need to find out which node it is. - * Find the unit_address from the OBP or devinfo - * properties. - */ - err = ptree_create_node(nodename, nodeclass, &chdh); - if (err != PICL_SUCCESS) - return (err); - - (void) add_devinfo_props(chdh, cnode); - (void) add_openprom_props(chdh, cnode); - - err = get_unitaddr(nodeh, chdh, unitaddr, - sizeof (unitaddr)); - if (err != PICL_SUCCESS) - return (err); - (void) ptree_destroy_node(chdh); - (void) snprintf(path_w_ua, sizeof (path_w_ua), "%s@%s", - path_buf, unitaddr); - (void) snprintf(path_wo_ua, sizeof (path_wo_ua), "%s", - path_buf); - } else { - /* - * this is an attached node - so the path is unique - */ - (void) snprintf(path_w_ua, sizeof (path_w_ua), "%s", - path_buf); - (void) snprintf(path_wo_ua, sizeof (path_wo_ua), "%s", - path_buf); - strp = strrchr(path_wo_ua, '@'); - *strp++ = '\0'; - (void) snprintf(unitaddr, sizeof (unitaddr), "%s", - strp); - } - /* - * first look for node with unit address in devfs_path - */ - if (ptree_find_node(nodeh, PICL_PROP_DEVFS_PATH, - PICL_PTYPE_CHARSTRING, path_w_ua, strlen(path_w_ua) + 1, - &nh) == PICL_SUCCESS) { - /* - * node already there - there's nothing we need to do - */ - if (picldevtree_debug > 1) - syslog(LOG_INFO, - "update_subtree: path:%s node exists\n", - path_buf); - di_devfs_path_free(path_buf); - continue; - } - /* - * now look for node without unit address in devfs_path. - * This might be just one out of several - * nodes - need to check all siblings - */ - err = ptree_get_propval_by_name(nodeh, PICL_PROP_CHILD, - &chdh, sizeof (chdh)); - if ((err != PICL_SUCCESS) && (err != PICL_PROPNOTFOUND)) - return (err); - gotit = 0; - while (err == PICL_SUCCESS) { - err = ptree_get_propval_by_name(chdh, - PICL_PROP_DEVFS_PATH, buf, sizeof (buf)); - if (err != PICL_SUCCESS) - return (err); - if (strcmp(buf, path_wo_ua) == 0) { - err = ptree_get_propval_by_name(chdh, - PICL_PROP_UNIT_ADDRESS, buf, sizeof (buf)); - if (err != PICL_SUCCESS) - return (err); - if (strcmp(buf, unitaddr) == 0) { - gotit = 1; - break; - } - } - err = ptree_get_propval_by_name(chdh, - PICL_PROP_PEER, &chdh, sizeof (chdh)); - if (err != PICL_SUCCESS) - break; - } - if (gotit) { - /* - * node already there - there's nothing we need to do - */ - if (picldevtree_debug > 1) - syslog(LOG_INFO, - "update_subtree: path:%s node exists\n", - path_buf); - di_devfs_path_free(path_buf); - continue; - } - -#define IS_MC(x) (strcmp(x, PICL_CLASS_MEMORY_CONTROLLER) == 0 ? 1 : 0) - - if (construct_devtype_node(nodeh, nodename, nodeclass, cnode, - &chdh) == PICL_SUCCESS) { - if (picldevtree_debug) - syslog(LOG_INFO, - "picldevtree: added node:%s path:%s\n", - nodename, path_buf); - if (IS_MC(nodeclass)) { - if (post_mc_event(PICLEVENT_MC_ADDED, chdh) != - PICL_SUCCESS) - syslog(LOG_WARNING, PICL_EVENT_DROPPED, - PICLEVENT_MC_ADDED); - } - - di_devfs_path_free(path_buf); - (void) update_subtree(chdh, cnode); - } - } - - return (PICL_SUCCESS); - -} - -/* - * Check for a stale OBP node. EINVAL is returned from the openprom(7D) driver - * if the nodeid stored in the snapshot is not valid. - */ -static int -check_stale_node(di_node_t node, void *arg) -{ - di_prom_prop_t promp; - - errno = 0; - promp = di_prom_prop_next(ph, node, DI_PROM_PROP_NIL); - if (promp == DI_PROM_PROP_NIL && errno == EINVAL) { - snapshot_stale = 1; - return (DI_WALK_TERMINATE); - } - return (DI_WALK_CONTINUE); -} - -/* - * Walk the snapshot and check the OBP properties of each node. - */ -static int -is_snapshot_stale(di_node_t root) -{ - snapshot_stale = 0; - di_walk_node(root, DI_WALK_CLDFIRST, NULL, check_stale_node); - return (snapshot_stale); -} - -/* - * This function processes the data from libdevinfo and creates nodes - * in the PICL tree. - */ -static int -libdevinfo_init(picl_nodehdl_t rooth) -{ - di_node_t di_root; - picl_nodehdl_t plafh; - picl_nodehdl_t obph; - int err; - - /* - * Use DINFOCACHE so that we obtain all attributes for all - * device instances (without necessarily doing a load/attach - * of all drivers). Once the (on-disk) cache file is built, it - * exists over a reboot and can be read into memory at a very - * low cost. - */ - if ((di_root = di_init("/", DINFOCACHE)) == DI_NODE_NIL) - return (PICL_FAILURE); - - if ((ph = di_prom_init()) == NULL) - return (PICL_FAILURE); - - /* - * Check if the snapshot cache contains stale OBP nodeid references. - * If it does release the snapshot and obtain a live snapshot from the - * kernel. - */ - if (is_snapshot_stale(di_root)) { - syslog(LOG_INFO, "picld detected stale snapshot cache"); - di_fini(di_root); - if ((di_root = di_init("/", DINFOCPYALL | DINFOFORCE)) == - DI_NODE_NIL) { - return (PICL_FAILURE); - } - } - - /* - * create platform PICL node using di_root node - */ - err = construct_picl_platform(rooth, di_root, &plafh); - if (err != PICL_SUCCESS) { - di_fini(di_root); - return (PICL_FAILURE); - } - - err = construct_picl_openprom(rooth, &obph); - if (err != PICL_SUCCESS) { - di_fini(di_root); - return (PICL_FAILURE); - } - - (void) construct_devinfo_tree(plafh, obph, di_root, NULL); - if (ph) { - di_prom_fini(ph); - ph = NULL; - } - di_fini(di_root); - return (err); -} - -/* - * This function returns the integer property value - */ -static int -get_int_propval_by_name(picl_nodehdl_t nodeh, char *pname, int *ival) -{ - int err; - - err = ptree_get_propval_by_name(nodeh, pname, ival, - sizeof (int)); - - return (err); -} - -/* - * This function returns the port ID (or CPU ID in the case of CMP cores) - * of the specific CPU node handle. If upa_portid exists, return its value. - * Otherwise, return portid/cpuid. - */ -static int -get_cpu_portid(picl_nodehdl_t modh, int *id) -{ - int err; - - if (strcmp(mach_name, "sun4u") == 0 || - strcmp(mach_name, "sun4v") == 0) { - err = get_int_propval_by_name(modh, OBP_PROP_UPA_PORTID, id); - if (err == PICL_SUCCESS) - return (err); - err = get_int_propval_by_name(modh, OBP_PROP_PORTID, id); - if (err == PICL_SUCCESS) - return (err); - return (get_int_propval_by_name(modh, OBP_PROP_CPUID, id)); - } - if (strcmp(mach_name, "i86pc") == 0) - return (get_int_propval_by_name(modh, OBP_REG, id)); - - return (PICL_FAILURE); -} - -/* - * This function is the volatile read access function of CPU state - * property - */ -static int -get_pi_state(ptree_rarg_t *rarg, void *vbuf) -{ - int id; - int err; - - err = get_int_propval_by_name(rarg->nodeh, PICL_PROP_ID, &id); - if (err != PICL_SUCCESS) - return (err); - - switch (p_online(id, P_STATUS)) { - case P_ONLINE: - (void) strlcpy(vbuf, PS_ONLINE, MAX_STATE_SIZE); - break; - case P_OFFLINE: - (void) strlcpy(vbuf, PS_OFFLINE, MAX_STATE_SIZE); - break; - case P_NOINTR: - (void) strlcpy(vbuf, PS_NOINTR, MAX_STATE_SIZE); - break; - case P_SPARE: - (void) strlcpy(vbuf, PS_SPARE, MAX_STATE_SIZE); - break; - case P_FAULTED: - (void) strlcpy(vbuf, PS_FAULTED, MAX_STATE_SIZE); - break; - case P_POWEROFF: - (void) strlcpy(vbuf, PS_POWEROFF, MAX_STATE_SIZE); - break; - default: - (void) strlcpy(vbuf, "unknown", MAX_STATE_SIZE); - break; - } - return (PICL_SUCCESS); -} - -/* - * This function is the volatile read access function of CPU processor_type - * property - */ -static int -get_processor_type(ptree_rarg_t *rarg, void *vbuf) -{ - processor_info_t cpu_info; - int id; - int err; - - err = get_int_propval_by_name(rarg->nodeh, PICL_PROP_ID, &id); - if (err != PICL_SUCCESS) - return (err); - - if (processor_info(id, &cpu_info) >= 0) { - (void) strlcpy(vbuf, cpu_info.pi_processor_type, PI_TYPELEN); - } - return (PICL_SUCCESS); -} - -/* - * This function is the volatile read access function of CPU fputypes - * property - */ -static int -get_fputypes(ptree_rarg_t *rarg, void *vbuf) -{ - processor_info_t cpu_info; - int id; - int err; - - err = get_int_propval_by_name(rarg->nodeh, PICL_PROP_ID, &id); - if (err != PICL_SUCCESS) - return (err); - - if (processor_info(id, &cpu_info) >= 0) { - (void) strlcpy(vbuf, cpu_info.pi_fputypes, PI_FPUTYPE); - } - return (PICL_SUCCESS); -} - -/* - * This function is the volatile read access function of CPU StateBegin - * property. To minimize overhead, use kstat_chain_update() to refresh - * the kstat header info as opposed to invoking kstat_open() every time. - */ -static int -get_pi_state_begin(ptree_rarg_t *rarg, void *vbuf) -{ - int err; - int cpu_id; - static kstat_ctl_t *kc = NULL; - static pthread_mutex_t kc_mutex = PTHREAD_MUTEX_INITIALIZER; - kstat_t *kp; - kstat_named_t *kn; - - err = get_int_propval_by_name(rarg->nodeh, PICL_PROP_ID, &cpu_id); - if (err != PICL_SUCCESS) - return (err); - - (void) pthread_mutex_lock(&kc_mutex); - if (kc == NULL) - kc = kstat_open(); - else if (kstat_chain_update(kc) == -1) { - (void) kstat_close(kc); - kc = kstat_open(); - } - - if (kc == NULL) { - (void) pthread_mutex_unlock(&kc_mutex); - return (PICL_FAILURE); - } - - /* Get the state_begin from kstat */ - if ((kp = kstat_lookup(kc, KSTAT_CPU_INFO, cpu_id, NULL)) == NULL || - kp->ks_type != KSTAT_TYPE_NAMED || kstat_read(kc, kp, 0) < 0) { - (void) pthread_mutex_unlock(&kc_mutex); - return (PICL_FAILURE); - } - - kn = kstat_data_lookup(kp, KSTAT_STATE_BEGIN); - if (kn) { - *(uint64_t *)vbuf = (uint64_t)kn->value.l; - err = PICL_SUCCESS; - } else - err = PICL_FAILURE; - - (void) pthread_mutex_unlock(&kc_mutex); - return (err); -} - -/* - * This function adds CPU information to the CPU nodes - */ -/* ARGSUSED */ -static int -add_processor_info(picl_nodehdl_t cpuh, void *args) -{ - int err; - int cpu_id; - ptree_propinfo_t propinfo; - ptree_propinfo_t pinfo; - - err = get_cpu_portid(cpuh, &cpu_id); - if (err != PICL_SUCCESS) - return (PICL_WALK_CONTINUE); - - /* - * Check to make sure that the CPU is still present, i.e. that it - * has not been DR'ed out of the system. - */ - if (p_online(cpu_id, P_STATUS) == -1) { - if (picldevtree_debug) - syslog(LOG_INFO, - "picldevtree: cpu %d (%llx) does not exist - " - "deleting node\n", cpu_id, cpuh); - - if (ptree_delete_node(cpuh) == PICL_SUCCESS) - (void) ptree_destroy_node(cpuh); - - return (PICL_WALK_CONTINUE); - } - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, sizeof (int), PICL_PROP_ID, NULL, NULL); - err = ptree_create_and_add_prop(cpuh, &propinfo, &cpu_id, NULL); - if (err != PICL_SUCCESS) - return (PICL_WALK_CONTINUE); - - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, (PICL_READ|PICL_VOLATILE), MAX_STATE_SIZE, - PICL_PROP_STATE, get_pi_state, NULL); - (void) ptree_create_and_add_prop(cpuh, &pinfo, NULL, NULL); - - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, (PICL_READ|PICL_VOLATILE), PI_TYPELEN, - PICL_PROP_PROCESSOR_TYPE, get_processor_type, NULL); - (void) ptree_create_and_add_prop(cpuh, &pinfo, NULL, NULL); - - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, (PICL_READ|PICL_VOLATILE), PI_FPUTYPE, - PICL_PROP_FPUTYPE, get_fputypes, NULL); - (void) ptree_create_and_add_prop(cpuh, &pinfo, NULL, NULL); - - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_TIMESTAMP, PICL_READ|PICL_VOLATILE, sizeof (uint64_t), - PICL_PROP_STATE_BEGIN, get_pi_state_begin, NULL); - (void) ptree_create_and_add_prop(cpuh, &pinfo, NULL, NULL); - - return (PICL_WALK_CONTINUE); -} - -/* - * This function sets up the "ID" property in every CPU nodes - * and adds processor info - */ -static int -setup_cpus(picl_nodehdl_t plafh) -{ - int err; - - err = ptree_walk_tree_by_class(plafh, PICL_CLASS_CPU, NULL, - add_processor_info); - - return (err); -} - -/* - * This function format's the manufacture's information for FFB display - * devices - */ -static void -fmt_manf_id(manuf_t manufid, int bufsz, char *outbuf) -{ - /* - * Format the manufacturer's info. Note a small inconsistency we - * have to work around - Brooktree has it's part number in decimal, - * while Mitsubishi has it's part number in hex. - */ - switch (manufid.fld.manf) { - case MANF_BROOKTREE: - (void) snprintf(outbuf, bufsz, "%s %d, version %d", - "Brooktree", manufid.fld.partno, manufid.fld.version); - break; - - case MANF_MITSUBISHI: - (void) snprintf(outbuf, bufsz, "%s %x, version %d", - "Mitsubishi", manufid.fld.partno, manufid.fld.version); - break; - - default: - (void) snprintf(outbuf, bufsz, - "JED code %d, Part num 0x%x, version %d", - manufid.fld.manf, manufid.fld.partno, manufid.fld.version); - } -} - -/* - * If it's an ffb device, open ffb devices and return PICL_SUCCESS - */ -static int -open_ffb_device(picl_nodehdl_t ffbh, int *fd) -{ - DIR *dirp; - char devfs_path[PATH_MAX]; - char dev_path[PATH_MAX]; - char *devp; - struct dirent *direntp; - int err; - int tmpfd; - - /* Get the devfs_path of the ffb devices */ - err = ptree_get_propval_by_name(ffbh, PICL_PROP_DEVFS_PATH, devfs_path, - sizeof (devfs_path)); - if (err != PICL_SUCCESS) - return (err); - - /* Get the device node name */ - devp = strrchr(devfs_path, '/'); - if (devp == NULL) - return (PICL_FAILURE); - *devp = '\0'; - ++devp; - - /* - * Check if device node name has the ffb string - * If not, assume it's not a ffb device. - */ - if (strstr(devp, FFB_NAME) == NULL) - return (PICL_FAILURE); - - /* - * Get the parent path of the ffb device node. - */ - (void) snprintf(dev_path, sizeof (dev_path), "%s/%s", "/devices", - devfs_path); - - /* - * Since we don't know ffb's minor nodename, - * we need to search all the devices under its - * parent dir by comparing the node name - */ - if ((dirp = opendir(dev_path)) == NULL) - return (PICL_FAILURE); - - while ((direntp = readdir(dirp)) != NULL) { - if (strstr(direntp->d_name, devp) != NULL) { - (void) strcat(dev_path, "/"); - (void) strcat(dev_path, direntp->d_name); - tmpfd = open(dev_path, O_RDWR); - if (tmpfd < 0) - continue; - *fd = tmpfd; - (void) closedir(dirp); - return (PICL_SUCCESS); - } - } - - (void) closedir(dirp); - return (PICL_FAILURE); -} - -/* - * This function recursively searches the tree for ffb display devices - * and add ffb config information - */ -static int -add_ffb_config_info(picl_nodehdl_t rooth) -{ - picl_nodehdl_t nodeh; - int err; - char piclclass[PICL_CLASSNAMELEN_MAX]; - char manfidbuf[FFB_MANUF_BUFSIZE]; - int fd; - int board_rev; - ffb_sys_info_t fsi; - ptree_propinfo_t pinfo; - - for (err = ptree_get_propval_by_name(rooth, PICL_PROP_CHILD, &nodeh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = ptree_get_propval_by_name(nodeh, PICL_PROP_PEER, - &nodeh, sizeof (picl_nodehdl_t))) { - - if (err != PICL_SUCCESS) - return (err); - - err = ptree_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME, - piclclass, PICL_CLASSNAMELEN_MAX); - - if ((err == PICL_SUCCESS) && - (strcmp(piclclass, PICL_CLASS_DISPLAY) == 0)) { - - err = open_ffb_device(nodeh, &fd); - if ((err == PICL_SUCCESS) && - (ioctl(fd, FFB_SYS_INFO, &fsi) >= 0)) { - (void) ptree_init_propinfo(&pinfo, - PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, - sizeof (int), PICL_PROP_FFB_BOARD_REV, - NULL, NULL); - board_rev = fsi.ffb_strap_bits.fld.board_rev; - (void) ptree_create_and_add_prop(nodeh, &pinfo, - &board_rev, NULL); - - fmt_manf_id(fsi.dac_version, - sizeof (manfidbuf), manfidbuf); - (void) ptree_init_propinfo(&pinfo, - PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(manfidbuf) + 1, - PICL_PROP_FFB_DAC_VER, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &pinfo, - manfidbuf, NULL); - - fmt_manf_id(fsi.fbram_version, - sizeof (manfidbuf), manfidbuf); - (void) ptree_init_propinfo(&pinfo, - PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(manfidbuf) + 1, - PICL_PROP_FFB_FBRAM_VER, NULL, - NULL); - (void) ptree_create_and_add_prop(nodeh, &pinfo, - manfidbuf, NULL); - (void) close(fd); - } - } else if (add_ffb_config_info(nodeh) != PICL_SUCCESS) - return (PICL_FAILURE); - } - return (PICL_SUCCESS); -} - -static conf_entries_t * -free_conf_entries(conf_entries_t *list) -{ - conf_entries_t *el; - conf_entries_t *del; - - if (list == NULL) - return (NULL); - el = list; - while (el != NULL) { - del = el; - el = el->next; - free(del->name); - free(del->piclclass); - free(del); - } - return (el); -} - -/* - * Reading config order: platform, common - */ -static conf_entries_t * -read_conf_file(char *fname, conf_entries_t *list) -{ - FILE *fp; - char lbuf[CONFFILE_LINELEN_MAX]; - char *nametok; - char *classtok; - conf_entries_t *el; - conf_entries_t *ptr; - - if (fname == NULL) - return (list); - - fp = fopen(fname, "r"); - - if (fp == NULL) - return (list); - - while (fgets(lbuf, CONFFILE_LINELEN_MAX, fp) != NULL) { - if ((lbuf[0] == CONFFILE_COMMENT_CHAR) || (lbuf[0] == '\n')) - continue; - - nametok = strtok(lbuf, " \t\n"); - if (nametok == NULL) - continue; - - classtok = strtok(NULL, " \t\n"); - if (classtok == NULL) - continue; - - el = malloc(sizeof (conf_entries_t)); - if (el == NULL) - break; - el->name = strdup(nametok); - el->piclclass = strdup(classtok); - if ((el->name == NULL) || (el->piclclass == NULL)) { - free(el); - return (list); - } - el->next = NULL; - - /* - * Add it to the end of list - */ - if (list == NULL) - list = el; - else { - ptr = list; - while (ptr->next != NULL) - ptr = ptr->next; - ptr->next = el; - } - - } - (void) fclose(fp); - return (list); -} - -/* - * Process the devtree conf file and set up the conf_name_class_map list - */ -static void -process_devtree_conf_file(void) -{ - char pname[PATH_MAX]; - - conf_name_class_map = NULL; - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_PLAT_PLUGIN_DIR, - DEVTREE_CONFFILE_NAME); - conf_name_class_map = read_conf_file(pname, conf_name_class_map); - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR, - DEVTREE_CONFFILE_NAME); - conf_name_class_map = read_conf_file(pname, conf_name_class_map); -} - -static asr_conf_entries_t *conf_name_asr_map = NULL; - -static void -free_asr_conf_entries(asr_conf_entries_t *list) { - asr_conf_entries_t *el; - asr_conf_entries_t *del; - - el = list; - while (el != NULL) { - del = el; - el = el->next; - free(del->name); - free(del->address); - free(del->status); - free(del->piclclass); - free(del->props); - free(del); - } -} - -/* - * Reading config order: platform, common - */ -static asr_conf_entries_t * -read_asr_conf_file(char *fname, asr_conf_entries_t *list) -{ - FILE *fp; - char lbuf[CONFFILE_LINELEN_MAX]; - char *nametok; - char *classtok; - char *statustok; - char *addresstok; - char *propstok; - asr_conf_entries_t *el; - asr_conf_entries_t *ptr; - - if (fname == NULL) - return (list); - - fp = fopen(fname, "r"); - if (fp == NULL) - return (list); - - while (fgets(lbuf, CONFFILE_LINELEN_MAX, fp) != NULL) { - if ((lbuf[0] == CONFFILE_COMMENT_CHAR) || (lbuf[0] == '\n')) - continue; - - nametok = strtok(lbuf, " \t\n"); - if (nametok == NULL) - continue; - - classtok = strtok(NULL, " \t\n"); - if (classtok == NULL) - continue; - - statustok = strtok(NULL, " \t\n"); - if (statustok == NULL) - continue; - - addresstok = strtok(NULL, " \t\n"); - if (addresstok == NULL) - continue; - - /* - * props are optional - */ - propstok = strtok(NULL, " \t\n"); - - el = malloc(sizeof (asr_conf_entries_t)); - if (el == NULL) - break; - el->name = strdup(nametok); - el->piclclass = strdup(classtok); - el->status = strdup(statustok); - el->address = strdup(addresstok); - if (propstok != NULL) - el->props = strdup(propstok); - else - el->props = NULL; - if ((el->name == NULL) || (el->piclclass == NULL) || - (el->address == NULL) || (el->status == NULL)) { - free(el->name); - free(el->address); - free(el->status); - free(el->piclclass); - free(el->props); - free(el); - break; - } - el->next = NULL; - - /* - * Add it to the end of list - */ - if (list == NULL) - list = el; - else { - ptr = list; - while (ptr->next != NULL) - ptr = ptr->next; - ptr->next = el; - } - - } - (void) fclose(fp); - return (list); -} - -/* - * Process the asr conf file - */ -static void -process_asrtree_conf_file(void) -{ - char pname[PATH_MAX]; - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_PLAT_PLUGIN_DIR, - ASRTREE_CONFFILE_NAME); - conf_name_asr_map = read_asr_conf_file(pname, conf_name_asr_map); - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR, - ASRTREE_CONFFILE_NAME); - conf_name_asr_map = read_asr_conf_file(pname, conf_name_asr_map); -} - -/* - * This function reads the export file list from ASR - */ -static int -get_asr_export_list(char **exportlist, int *exportlistlen) -{ - struct openpromio oppbuf; - struct openpromio *opp = &oppbuf; - int d; - int listsize; - - d = open("/dev/openprom", O_RDWR); - if (d < 0) - return (0); - - if (ioctl(d, OPROMEXPORTLEN, opp) == -1) { - (void) close(d); - return (0); - } - listsize = opp->oprom_size; - opp = (struct openpromio *)malloc(sizeof (struct openpromio) + - listsize); - if (opp == NULL) { - (void) close(d); - return (0); - } - (void) memset(opp, '\0', sizeof (struct openpromio) + listsize); - opp->oprom_size = listsize; - if (ioctl(d, OPROMEXPORT, opp) == -1) { - free(opp); - (void) close(d); - return (0); - } - *exportlist = malloc(listsize); - if (*exportlist == NULL) { - free(opp); - (void) close(d); - return (0); - } - (void) memcpy(*exportlist, opp->oprom_array, opp->oprom_size); - free(opp); - *exportlistlen = opp->oprom_size; - (void) close(d); - return (1); -} - -/* - * Parses properties string, fills in triplet structure with first - * type, name, val triplet and returns pointer to next property. - * Returns NULL if no valid triplet found - * CAUTION: drops \0 characters over separator characters: if you - * want to parse the string twice, you'll have to take a copy. - */ -static char * -parse_props_string(char *props, asr_prop_triplet_t *triplet) -{ - char *prop_name; - char *prop_val; - char *prop_next; - - prop_name = strchr(props, '?'); - if (prop_name == NULL) - return (NULL); - *prop_name++ = '\0'; - prop_val = strchr(prop_name, '='); - if (prop_val == NULL) - return (NULL); - *prop_val++ = '\0'; - triplet->proptype = props; - triplet->propname = prop_name; - triplet->propval = prop_val; - prop_next = strchr(prop_val, ':'); - if (prop_next == NULL) - return (prop_val - 1); - *prop_next++ = '\0'; - return (prop_next); -} - -static int -add_status_prop(picl_nodehdl_t chdh, char *status) -{ - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - int err; - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(status) + 1, - PICL_PROP_STATUS, NULL, NULL); - if (err != PICL_SUCCESS) - return (err); - err = ptree_create_and_add_prop(chdh, &propinfo, status, &proph); - return (err); -} - -static void -create_asr_node(char *parent, char *child, char *unitaddr, char *class, - char *status, char *props) -{ - char ptreepath[PATH_MAX]; - char nodename[PICL_PROPNAMELEN_MAX]; - char ua[MAX_UNIT_ADDRESS_LEN]; - char *props_copy = NULL; - char *next; - char *prop_string; - boolean_t found = B_FALSE; - picl_nodehdl_t nodeh; - picl_nodehdl_t chdh; - asr_prop_triplet_t triple; - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - int val; - int err; - - (void) strlcpy(ptreepath, PLATFORM_PATH, PATH_MAX); - (void) strlcat(ptreepath, parent, PATH_MAX); - - if (ptree_get_node_by_path(ptreepath, &nodeh) != PICL_SUCCESS) - return; - /* - * see if the required child node already exists - */ - for (err = ptree_get_propval_by_name(nodeh, PICL_PROP_CHILD, &chdh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (picl_nodehdl_t))) { - if (err != PICL_SUCCESS) - break; - err = ptree_get_propval_by_name(chdh, PICL_PROP_NAME, - (void *)nodename, PICL_PROPNAMELEN_MAX); - if (err != PICL_SUCCESS) - break; - if (strcmp(nodename, child) != 0) - continue; - /* - * found a candidate child node - */ - if (unitaddr) { - /* - * does it match the required unit address? - */ - err = ptree_get_propval_by_name(chdh, - PICL_PROP_UNIT_ADDRESS, ua, sizeof (ua)); - if (err == PICL_PROPNOTFOUND) - continue; - if (err != PICL_SUCCESS) - break; - if (strcmp(unitaddr, ua) != 0) - continue; - } - if (props == NULL) { - next = ""; - } else if (props_copy == NULL) { - props_copy = strdup(props); - if (props_copy == NULL) - return; - next = props_copy; - } - while ((next = parse_props_string(next, &triple)) != NULL) { - err = ptree_get_prop_by_name(chdh, triple.propname, - &proph); - if (err != PICL_SUCCESS) - break; - err = ptree_get_propinfo(proph, &propinfo); - if (err != PICL_SUCCESS) - break; - err = PICL_FAILURE; - switch (propinfo.piclinfo.type) { - case PICL_PTYPE_INT: - case PICL_PTYPE_UNSIGNED_INT: - if (strcmp(triple.proptype, "I") != 0) - break; - err = ptree_get_propval(proph, (void *)&val, - sizeof (val)); - if (err != PICL_SUCCESS) - break; - if (val != atoi(triple.propval)) - err = PICL_FAILURE; - break; - case PICL_PTYPE_CHARSTRING: - if (strcmp(triple.proptype, "S") != 0) - break; - prop_string = malloc(propinfo.piclinfo.size); - if (prop_string == NULL) - break; - err = ptree_get_propval(proph, - (void *)prop_string, - propinfo.piclinfo.size); - if (err != PICL_SUCCESS) { - free(prop_string); - break; - } - if (strcmp(prop_string, triple.propval) != 0) - err = PICL_FAILURE; - free(prop_string); - break; - default: - break; - } - if (err != PICL_SUCCESS) { - break; - } - } - if (next == NULL) { - found = B_TRUE; - break; - } - } - free(props_copy); - if (found) { - /* - * does the pre-existing node have a status property? - */ - err = ptree_get_propval_by_name(chdh, PICL_PROP_STATUS, - ua, sizeof (ua)); - if (err == PICL_PROPNOTFOUND) - (void) add_status_prop(chdh, status); - if (err != PICL_SUCCESS) - return; - if ((strcmp(ua, ASR_DISABLED) == 0) || - (strcmp(ua, ASR_FAILED) == 0) || - ((strcmp(status, ASR_DISABLED) != 0) && - (strcmp(status, ASR_FAILED) != 0))) { - return; - } - /* - * more urgent status now, so replace existing value - */ - err = ptree_get_prop_by_name(chdh, PICL_PROP_STATUS, &proph); - if (err != PICL_SUCCESS) - return; - (void) ptree_delete_prop(proph); - (void) ptree_destroy_prop(proph); - err = add_status_prop(chdh, status); - if (err != PICL_SUCCESS) - return; - return; - } - - /* - * typical case, node needs adding together with a set of properties - */ - if (ptree_create_and_add_node(nodeh, child, class, &chdh) == - PICL_SUCCESS) { - (void) add_status_prop(chdh, status); - if (unitaddr) { - (void) ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, PICL_PTYPE_CHARSTRING, - PICL_READ, strlen(unitaddr) + 1, - PICL_PROP_UNIT_ADDRESS, NULL, NULL); - (void) ptree_create_and_add_prop(chdh, &propinfo, - unitaddr, &proph); - (void) strlcpy(ptreepath, parent, PATH_MAX); - (void) strlcat(ptreepath, "/", PATH_MAX); - (void) strlcat(ptreepath, child, PATH_MAX); - (void) strlcat(ptreepath, "@", PATH_MAX); - (void) strlcat(ptreepath, unitaddr, PATH_MAX); - (void) ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, PICL_PTYPE_CHARSTRING, - PICL_READ, strlen(ptreepath) + 1, - PICL_PROP_DEVFS_PATH, NULL, NULL); - (void) ptree_create_and_add_prop(chdh, &propinfo, - ptreepath, &proph); - } - next = props; - while ((next = parse_props_string(next, &triple)) != NULL) { - /* - * only handle int and string properties for - * simplicity - */ - if (strcmp(triple.proptype, "I") == 0) { - (void) ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, - sizeof (int), triple.propname, NULL, NULL); - val = atoi(triple.propval); - (void) ptree_create_and_add_prop(chdh, - &propinfo, &val, &proph); - } else { - (void) ptree_init_propinfo(&propinfo, - PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, - strlen(triple.propval) + 1, - triple.propname, NULL, NULL); - (void) ptree_create_and_add_prop(chdh, - &propinfo, triple.propval, &proph); - } - } - } -} - -static void -add_asr_nodes() -{ - char *asrexport; - int asrexportlen; - asr_conf_entries_t *c = NULL; - int i; - char *key; - char *child; - char *unitaddr; - uint16_t count; - int disabled; - - if (get_asr_export_list(&asrexport, &asrexportlen) == 0) - return; - process_asrtree_conf_file(); - if (conf_name_asr_map == NULL) - return; - i = 0; - while (i < asrexportlen) { - key = &asrexport[i]; - i += strlen(key) + 1; - if (i >= asrexportlen) - break; - - /* - * next byte tells us whether failed by diags or manually - * disabled - */ - disabled = asrexport[i]; - i++; - if (i >= asrexportlen) - break; - - /* - * only type 1 supported - */ - if (asrexport[i] != 1) - break; - i++; - if (i >= asrexportlen) - break; - - /* - * next two bytes give size of reason string - */ - count = (asrexport[i] << 8) | asrexport[i + 1]; - i += count + 2; - if (i > asrexportlen) - break; - - /* - * now look for key in conf file info - */ - c = conf_name_asr_map; - while (c != NULL) { - if (strcmp(key, c->name) == 0) { - child = strrchr(c->address, '/'); - *child++ = '\0'; - unitaddr = strchr(child, '@'); - if (unitaddr) - *unitaddr++ = '\0'; - if (strcmp(c->status, ASR_DISABLED) == 0) { - create_asr_node(c->address, child, - unitaddr, c->piclclass, disabled ? - ASR_DISABLED : ASR_FAILED, - c->props); - } else { - create_asr_node(c->address, child, - unitaddr, c->piclclass, c->status, - c->props); - } - } - c = c->next; - } - } - - free_asr_conf_entries(conf_name_asr_map); - free(asrexport); -} - -/* - * This function adds information to the /platform node - */ -static int -add_platform_info(picl_nodehdl_t plafh) -{ - struct utsname uts_info; - int err; - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - - if (uname(&uts_info) < 0) - return (PICL_FAILURE); - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(uts_info.sysname) + 1, - PICL_PROP_SYSNAME, NULL, NULL); - err = ptree_create_and_add_prop(plafh, &propinfo, uts_info.sysname, - &proph); - if (err != PICL_SUCCESS) - return (err); - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(uts_info.nodename) + 1, - PICL_PROP_NODENAME, NULL, NULL); - err = ptree_create_and_add_prop(plafh, &propinfo, uts_info.nodename, - &proph); - if (err != PICL_SUCCESS) - return (err); - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(uts_info.release) + 1, - PICL_PROP_RELEASE, NULL, NULL); - err = ptree_create_and_add_prop(plafh, &propinfo, uts_info.release, - &proph); - if (err != PICL_SUCCESS) - return (err); - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(uts_info.version) + 1, - PICL_PROP_VERSION, NULL, NULL); - err = ptree_create_and_add_prop(plafh, &propinfo, uts_info.version, - &proph); - if (err != PICL_SUCCESS) - return (err); - - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(uts_info.machine) + 1, - PICL_PROP_MACHINE, NULL, NULL); - err = ptree_create_and_add_prop(plafh, &propinfo, uts_info.machine, - &proph); - return (err); -} - -/* - * Get first 32-bit value from the reg property - */ -static int -get_first_reg_word(picl_nodehdl_t nodeh, uint32_t *regval) -{ - int err; - uint32_t *regbuf; - picl_prophdl_t regh; - ptree_propinfo_t pinfo; - - err = ptree_get_prop_by_name(nodeh, OBP_REG, ®h); - if (err != PICL_SUCCESS) /* no reg property */ - return (err); - err = ptree_get_propinfo(regh, &pinfo); - if (err != PICL_SUCCESS) - return (err); - if (pinfo.piclinfo.size < sizeof (uint32_t)) /* too small */ - return (PICL_FAILURE); - regbuf = alloca(pinfo.piclinfo.size); - if (regbuf == NULL) - return (PICL_FAILURE); - err = ptree_get_propval(regh, regbuf, pinfo.piclinfo.size); - if (err != PICL_SUCCESS) - return (err); - *regval = *regbuf; /* get first 32-bit value */ - return (PICL_SUCCESS); -} - -/* - * Get device ID from the reg property - */ -static int -get_device_id(picl_nodehdl_t nodeh, uint32_t *dev_id) -{ - int err; - uint32_t regval; - - err = get_first_reg_word(nodeh, ®val); - if (err != PICL_SUCCESS) - return (err); - - *dev_id = PCI_DEVICE_ID(regval); - return (PICL_SUCCESS); -} - -/* - * add Slot property for children of SBUS node - */ -/* ARGSUSED */ -static int -add_sbus_slots(picl_nodehdl_t pcih, void *args) -{ - picl_nodehdl_t nodeh; - uint32_t slot; - int err; - ptree_propinfo_t pinfo; - - for (err = ptree_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = ptree_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh, - sizeof (picl_nodehdl_t))) { - if (err != PICL_SUCCESS) - return (err); - - if (get_first_reg_word(nodeh, &slot) != 0) - continue; - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (uint32_t), - PICL_PROP_SLOT, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &pinfo, &slot, NULL); - } - - return (PICL_WALK_CONTINUE); -} - -/* - * This function creates a Slot property for SBUS child nodes - * which can be correlated with the slot they are plugged into - * on the motherboard. - */ -static int -set_sbus_slot(picl_nodehdl_t plafh) -{ - int err; - - err = ptree_walk_tree_by_class(plafh, PICL_CLASS_SBUS, NULL, - add_sbus_slots); - - return (err); -} - -/* - * add DeviceID property for children of PCI/PCIEX node - */ -/* ARGSUSED */ -static int -add_pci_deviceids(picl_nodehdl_t pcih, void *args) -{ - picl_nodehdl_t nodeh; - uint32_t dev_id; - int err; - ptree_propinfo_t pinfo; - - for (err = ptree_get_propval_by_name(pcih, PICL_PROP_CHILD, &nodeh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = ptree_get_propval_by_name(nodeh, PICL_PROP_PEER, &nodeh, - sizeof (picl_nodehdl_t))) { - if (err != PICL_SUCCESS) - return (err); - - if (get_device_id(nodeh, &dev_id) != 0) - continue; - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (uint32_t), - PICL_PROP_DEVICE_ID, NULL, NULL); - (void) ptree_create_and_add_prop(nodeh, &pinfo, &dev_id, NULL); - } - - return (PICL_WALK_CONTINUE); -} - -/* - * This function creates a DeviceID property for PCI/PCIEX child nodes - * which can be correlated with the slot they are plugged into - * on the motherboard. - */ -static void -set_pci_pciex_deviceid(picl_nodehdl_t plafh) -{ - (void) ptree_walk_tree_by_class(plafh, PICL_CLASS_PCI, NULL, - add_pci_deviceids); - - (void) ptree_walk_tree_by_class(plafh, PICL_CLASS_PCIEX, NULL, - add_pci_deviceids); -} - -/* - * Default UnitAddress encode function - */ -static int -encode_default_unitaddr(char *buf, int sz, uint32_t *regprop, uint_t addrcells) -{ - int i, len; - - /* - * Encode UnitAddress as %a,%b,%c,...,%n - */ - if (addrcells < 1) - return (-1); - - len = snprintf(buf, sz, "%x", *regprop); - for (i = 1; i < addrcells && len < sz; i++) - len += snprintf(&buf[len], sz-len, ",%x", regprop[i]); - - return ((len >= sz) ? -1 : 0); -} - -/* - * UnitAddress encode function where the last component is not printed - * unless non-zero. - */ -static int -encode_optional_unitaddr(char *buf, int sz, uint32_t *regprop, uint_t addrcells) -{ - int retval; - - /* - * Encode UnitAddress as %a,%b,%c,...,%n where the last component - * is printed only if non-zero. - */ - if (addrcells > 1 && regprop[addrcells-1] == 0) - retval = encode_default_unitaddr(buf, sz, regprop, addrcells-1); - else - retval = encode_default_unitaddr(buf, sz, regprop, addrcells); - - return (retval); -} - - -/* - * UnitAddress encode function for SCSI class of devices - */ -static int -encode_scsi_unitaddr(char *buf, int sz, uint32_t *regprop, uint_t addrcells) -{ - int len, retval; - - /* - * #address-cells Format - * 2 second component printed only if non-zero - * - * 4 regprop: phys_hi phys_lo lun_hi lun_lo - * UnitAddr: w, - */ - - if (addrcells == 2) { - retval = encode_optional_unitaddr(buf, sz, regprop, addrcells); - } else if (addrcells == 4) { - len = snprintf(buf, sz, "w%08x%08x,%x", regprop[0], regprop[1], - regprop[3]); - retval = (len >= sz) ? -1 : 0; - } else - retval = -1; - - return (retval); -} - -/* - * UnitAddress encode function for UPA devices - */ -static int -encode_upa_unitaddr(char *buf, int sz, uint32_t *regprop, uint_t addrcells) -{ - int len; - - if (addrcells != 2) - return (-1); - - len = snprintf(buf, sz, "%x,%x", (regprop[0]/2)&0x1f, regprop[1]); - return ((len >= sz) ? -1 : 0); -} - -/* - * UnitAddress encode function for GPTWO, JBUS devices - */ -static int -encode_gptwo_jbus_unitaddr(char *buf, int sz, uint32_t *regprop, - uint_t addrcells) -{ - uint32_t hi, lo; - int len, id, off; - - if (addrcells != 2) - return (-1); - - hi = regprop[0]; - lo = regprop[1]; - - if (hi & 0x400) { - id = ((hi & 0x1) << 9) | (lo >> 23); /* agent id */ - off = lo & 0x7fffff; /* config offset */ - len = snprintf(buf, sz, "%x,%x", id, off); - } else { - len = snprintf(buf, sz, "m%x,%x", hi, lo); - } - return ((len >= sz) ? -1 : 0); -} - -/* - * UnitAddress encode function for PCI devices - */ -static int -encode_pci_unitaddr(char *buf, int sz, uint32_t *regprop, uint_t addrcells) -{ - typedef struct { - uint32_t n:1, /* relocatable */ - p:1, /* prefetchable */ - t:1, /* address region aliases */ - zero:3, /* must be zero */ - ss:2, /* address space type */ - bus:8, /* bus number */ - dev:5, /* device number */ - fn:3, /* function number */ - reg:8; /* register number */ - uint32_t phys_hi; /* high physical address */ - uint32_t phys_lo; /* low physical address */ - } pci_addrcell_t; - - pci_addrcell_t *p; - int len; - - if (addrcells != 3) - return (-1); - - p = (pci_addrcell_t *)regprop; - switch (p->ss) { - case 0: /* Config */ - if (p->fn) - len = snprintf(buf, sz, "%x,%x", p->dev, p->fn); - else - len = snprintf(buf, sz, "%x", p->dev); - break; - case 1: /* IO */ - len = snprintf(buf, sz, "i%x,%x,%x,%x", p->dev, p->fn, p->reg, - p->phys_lo); - break; - case 2: /* Mem32 */ - len = snprintf(buf, sz, "m%x,%x,%x,%x", p->dev, p->fn, p->reg, - p->phys_lo); - break; - case 3: /* Mem64 */ - len = snprintf(buf, sz, "x%x,%x,%x,%x%08x", p->dev, p->fn, - p->reg, p->phys_hi, p->phys_lo); - break; - } - return ((len >= sz) ? -1 : 0); -} - -/* - * Get #address-cells property value - */ -static uint_t -get_addrcells_prop(picl_nodehdl_t nodeh) -{ - int len, err; - uint32_t addrcells; - ptree_propinfo_t pinfo; - picl_prophdl_t proph; - - /* - * Get #address-cells property. If not present, use default value. - */ - err = ptree_get_prop_by_name(nodeh, OBP_PROP_ADDRESS_CELLS, &proph); - if (err == PICL_SUCCESS) - err = ptree_get_propinfo(proph, &pinfo); - - len = pinfo.piclinfo.size; - if (err == PICL_SUCCESS && len >= sizeof (uint8_t) && - len <= sizeof (addrcells)) { - err = ptree_get_propval(proph, &addrcells, len); - if (err == PICL_SUCCESS) { - if (len == sizeof (uint8_t)) - addrcells = *(uint8_t *)&addrcells; - else if (len == sizeof (uint16_t)) - addrcells = *(uint16_t *)&addrcells; - } else - addrcells = DEFAULT_ADDRESS_CELLS; - } else - addrcells = DEFAULT_ADDRESS_CELLS; - - return (addrcells); -} - -/* - * Get UnitAddress mapping entry for a node - */ -static unitaddr_map_t * -get_unitaddr_mapping(picl_nodehdl_t nodeh) -{ - int err; - unitaddr_map_t *uamap; - char clname[PICL_CLASSNAMELEN_MAX]; - - /* - * Get my classname and locate a function to translate "reg" prop - * into "UnitAddress" prop for my children. - */ - err = ptree_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME, clname, - sizeof (clname)); - if (err != PICL_SUCCESS) - (void) strcpy(clname, ""); /* NULL class name */ - - for (uamap = &unitaddr_map_table[0]; uamap->class != NULL; uamap++) - if (strcmp(clname, uamap->class) == 0) - break; - - return (uamap); -} - -/* - * Add UnitAddress property to the specified node - */ -static int -add_unitaddr_prop(picl_nodehdl_t nodeh, unitaddr_map_t *uamap, uint_t addrcells) -{ - int regproplen, err; - uint32_t *regbuf; - picl_prophdl_t regh; - ptree_propinfo_t pinfo; - char unitaddr[MAX_UNIT_ADDRESS_LEN]; - - err = ptree_get_prop_by_name(nodeh, OBP_REG, ®h); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_get_propinfo(regh, &pinfo); - if (err != PICL_SUCCESS) - return (PICL_FAILURE); - - if (pinfo.piclinfo.size < (addrcells * sizeof (uint32_t))) - return (PICL_FAILURE); - - regproplen = pinfo.piclinfo.size; - regbuf = alloca(regproplen); - if (regbuf == NULL) - return (PICL_FAILURE); - - err = ptree_get_propval(regh, regbuf, regproplen); - if (err != PICL_SUCCESS || uamap->func == NULL || - (uamap->addrcellcnt && uamap->addrcellcnt != addrcells) || - (uamap->func)(unitaddr, sizeof (unitaddr), regbuf, - addrcells) != 0) { - return (PICL_FAILURE); - } - - err = ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_CHARSTRING, PICL_READ, strlen(unitaddr)+1, - PICL_PROP_UNIT_ADDRESS, NULL, NULL); - if (err == PICL_SUCCESS) - err = ptree_create_and_add_prop(nodeh, &pinfo, unitaddr, NULL); - - return (err); -} - -/* - * work out UnitAddress property of the specified node - */ -static int -get_unitaddr(picl_nodehdl_t parh, picl_nodehdl_t nodeh, char *unitaddr, - size_t ualen) -{ - int regproplen, err; - uint32_t *regbuf; - picl_prophdl_t regh; - ptree_propinfo_t pinfo; - unitaddr_map_t *uamap; - uint32_t addrcells; - - addrcells = get_addrcells_prop(parh); - uamap = get_unitaddr_mapping(parh); - - err = ptree_get_prop_by_name(nodeh, OBP_REG, ®h); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_get_propinfo(regh, &pinfo); - if (err != PICL_SUCCESS) - return (err); - - if (pinfo.piclinfo.size < (addrcells * sizeof (uint32_t))) - return (PICL_FAILURE); - - regproplen = pinfo.piclinfo.size; - regbuf = alloca(regproplen); - if (regbuf == NULL) - return (PICL_FAILURE); - - err = ptree_get_propval(regh, regbuf, regproplen); - if (err != PICL_SUCCESS || uamap->func == NULL || - (uamap->addrcellcnt && uamap->addrcellcnt != addrcells) || - (uamap->func)(unitaddr, ualen, regbuf, addrcells) != 0) { - return (PICL_FAILURE); - } - return (PICL_SUCCESS); -} - -/* - * Add UnitAddress property to all children of the specified node - */ -static int -add_unitaddr_prop_to_subtree(picl_nodehdl_t nodeh) -{ - int err; - picl_nodehdl_t chdh; - unitaddr_map_t *uamap; - uint32_t addrcells; - - /* - * Get #address-cells and unit address mapping entry for my - * node's class - */ - addrcells = get_addrcells_prop(nodeh); - uamap = get_unitaddr_mapping(nodeh); - - /* - * Add UnitAddress property to my children and their subtree - */ - err = ptree_get_propval_by_name(nodeh, PICL_PROP_CHILD, &chdh, - sizeof (picl_nodehdl_t)); - - while (err == PICL_SUCCESS) { - (void) add_unitaddr_prop(chdh, uamap, addrcells); - (void) add_unitaddr_prop_to_subtree(chdh); - - err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (picl_nodehdl_t)); - } - - return (PICL_SUCCESS); -} - -static int -update_memory_size_prop(picl_nodehdl_t plafh) -{ - picl_nodehdl_t memh; - picl_prophdl_t proph; - ptree_propinfo_t pinfo; - int err, nspecs, snum, pval; - char *regbuf; - memspecs_t *mspecs; - uint64_t memsize; - - /* - * check if the #size-cells of the platform node is 2 - */ - err = ptree_get_propval_by_name(plafh, OBP_PROP_SIZE_CELLS, &pval, - sizeof (pval)); - - if (err == PICL_PROPNOTFOUND) - pval = SUPPORTED_NUM_CELL_SIZE; - else if (err != PICL_SUCCESS) - return (err); - - /* - * don't know how to handle other vals - */ - if (pval != SUPPORTED_NUM_CELL_SIZE) - return (PICL_FAILURE); - - err = ptree_get_node_by_path(MEMORY_PATH, &memh); - if (err != PICL_SUCCESS) - return (err); - - /* - * Get the REG property to calculate the size of memory - */ - err = ptree_get_prop_by_name(memh, OBP_REG, &proph); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_get_propinfo(proph, &pinfo); - if (err != PICL_SUCCESS) - return (err); - - regbuf = alloca(pinfo.piclinfo.size); - if (regbuf == NULL) - return (PICL_FAILURE); - - err = ptree_get_propval(proph, regbuf, pinfo.piclinfo.size); - if (err != PICL_SUCCESS) - return (err); - - mspecs = (memspecs_t *)regbuf; - nspecs = pinfo.piclinfo.size / sizeof (memspecs_t); - - memsize = 0; - for (snum = 0; snum < nspecs; ++snum) - memsize += mspecs[snum].size; - - err = ptree_get_prop_by_name(memh, PICL_PROP_SIZE, &proph); - if (err == PICL_SUCCESS) { - err = ptree_update_propval(proph, &memsize, sizeof (memsize)); - return (err); - } - - /* - * Add the size property - */ - (void) ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (memsize), - PICL_PROP_SIZE, NULL, NULL); - err = ptree_create_and_add_prop(memh, &pinfo, &memsize, NULL); - return (err); -} - -/* - * This function is executed as part of .init when the plugin is - * dlopen()ed - */ -static void -picldevtree_register(void) -{ - if (getenv(SUNW_PICLDEVTREE_PLUGIN_DEBUG)) - picldevtree_debug = 1; - (void) picld_plugin_register(&my_reg_info); -} - -/* - * This function is the init entry point of the plugin. - * It initializes the /platform tree based on libdevinfo - */ -static void -picldevtree_init(void) -{ - picl_nodehdl_t rhdl; - int err; - struct utsname utsname; - picl_nodehdl_t plafh; - - if (uname(&utsname) < 0) - return; - - (void) strcpy(mach_name, utsname.machine); - - if (strcmp(mach_name, "sun4u") == 0) { - builtin_map_ptr = sun4u_map; - builtin_map_size = sizeof (sun4u_map) / sizeof (builtin_map_t); - } else if (strcmp(mach_name, "sun4v") == 0) { - builtin_map_ptr = sun4u_map; - builtin_map_size = sizeof (sun4u_map) / sizeof (builtin_map_t); - } else if (strcmp(mach_name, "i86pc") == 0) { - builtin_map_ptr = i86pc_map; - builtin_map_size = sizeof (i86pc_map) / sizeof (builtin_map_t); - } else { - builtin_map_ptr = NULL; - builtin_map_size = 0; - } - - err = ptree_get_root(&rhdl); - if (err != PICL_SUCCESS) { - syslog(LOG_ERR, DEVINFO_PLUGIN_INIT_FAILED); - return; - } - - process_devtree_conf_file(); - - if (libdevinfo_init(rhdl) != PICL_SUCCESS) { - syslog(LOG_ERR, DEVINFO_PLUGIN_INIT_FAILED); - return; - } - - err = ptree_get_node_by_path(PLATFORM_PATH, &plafh); - if (err != PICL_SUCCESS) - return; - - (void) add_unitaddr_prop_to_subtree(plafh); - - add_asr_nodes(); - - (void) update_memory_size_prop(plafh); - - (void) setup_cpus(plafh); - - (void) add_ffb_config_info(plafh); - - (void) add_platform_info(plafh); - - set_pci_pciex_deviceid(plafh); - - (void) set_sbus_slot(plafh); - - (void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED, - picldevtree_evhandler, NULL); - (void) ptree_register_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED, - picldevtree_evhandler, NULL); - (void) ptree_register_handler(PICLEVENT_CPU_STATE_CHANGE, - picldevtree_evhandler, NULL); - (void) ptree_register_handler(PICLEVENT_DR_AP_STATE_CHANGE, - picldevtree_evhandler, NULL); -} - -/* - * This function is the fini entry point of the plugin - */ -static void -picldevtree_fini(void) -{ - /* First unregister the event handlers */ - (void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_ADDED, - picldevtree_evhandler, NULL); - (void) ptree_unregister_handler(PICLEVENT_SYSEVENT_DEVICE_REMOVED, - picldevtree_evhandler, NULL); - (void) ptree_unregister_handler(PICLEVENT_CPU_STATE_CHANGE, - picldevtree_evhandler, NULL); - (void) ptree_unregister_handler(PICLEVENT_DR_AP_STATE_CHANGE, - picldevtree_evhandler, NULL); - - conf_name_class_map = free_conf_entries(conf_name_class_map); -} - -/* - * This function is the event handler of this plug-in. - * - * It processes the following events: - * - * PICLEVENT_SYSEVENT_DEVICE_ADDED - * PICLEVENT_SYSEVENT_DEVICE_REMOVED - * PICLEVENT_CPU_STATE_CHANGE - * PICLEVENT_DR_AP_STATE_CHANGE - */ -/* ARGSUSED */ -static void -picldevtree_evhandler(const char *ename, const void *earg, size_t size, - void *cookie) -{ - char *devfs_path; - char ptreepath[PATH_MAX]; - char dipath[PATH_MAX]; - picl_nodehdl_t plafh; - picl_nodehdl_t nodeh; - nvlist_t *nvlp; - - if ((earg == NULL) || - (ptree_get_node_by_path(PLATFORM_PATH, &plafh) != PICL_SUCCESS)) - return; - - if (strcmp(ename, PICLEVENT_DR_AP_STATE_CHANGE) == 0) { - (void) setup_cpus(plafh); - if (picldevtree_debug > 1) - syslog(LOG_INFO, "picldevtree: event handler done\n"); - return; - } - - nvlp = NULL; - if (nvlist_unpack((char *)earg, size, &nvlp, 0) || - nvlist_lookup_string(nvlp, PICLEVENTARG_DEVFS_PATH, &devfs_path) || - strlen(devfs_path) > (PATH_MAX - sizeof (PLATFORM_PATH))) { - syslog(LOG_INFO, PICL_EVENT_DROPPED, ename); - nvlist_free(nvlp); - return; - } - - (void) strlcpy(ptreepath, PLATFORM_PATH, PATH_MAX); - (void) strlcat(ptreepath, devfs_path, PATH_MAX); - (void) strlcpy(dipath, devfs_path, PATH_MAX); - nvlist_free(nvlp); - - if (picldevtree_debug) - syslog(LOG_INFO, "picldevtree: event handler invoked ename:%s " - "ptreepath:%s\n", ename, ptreepath); - - if (strcmp(ename, PICLEVENT_CPU_STATE_CHANGE) == 0) { - goto done; - } - if (strcmp(ename, PICLEVENT_SYSEVENT_DEVICE_ADDED) == 0) { - di_node_t devnode; - char *strp; - picl_nodehdl_t parh; - char nodeclass[PICL_CLASSNAMELEN_MAX]; - char *nodename; - int err; - - /* If the node already exist, then nothing else to do here */ - if (ptree_get_node_by_path(ptreepath, &nodeh) == PICL_SUCCESS) - return; - - /* Skip if unable to find parent PICL node handle */ - parh = plafh; - if (((strp = strrchr(ptreepath, '/')) != NULL) && - (strp != strchr(ptreepath, '/'))) { - *strp = '\0'; - if (ptree_get_node_by_path(ptreepath, &parh) != - PICL_SUCCESS) - return; - } - - /* - * If parent is the root node - */ - if (parh == plafh) { - ph = di_prom_init(); - devnode = di_init(dipath, DINFOCPYALL); - if (devnode == DI_NODE_NIL) { - if (ph != NULL) { - di_prom_fini(ph); - ph = NULL; - } - return; - } - nodename = di_node_name(devnode); - if (nodename == NULL) { - di_fini(devnode); - if (ph != NULL) { - di_prom_fini(ph); - ph = NULL; - } - return; - } - - err = get_node_class(nodeclass, devnode, nodename); - if (err < 0) { - di_fini(devnode); - if (ph != NULL) { - di_prom_fini(ph); - ph = NULL; - } - return; - } - err = construct_devtype_node(plafh, nodename, - nodeclass, devnode, &nodeh); - if (err != PICL_SUCCESS) { - di_fini(devnode); - if (ph != NULL) { - di_prom_fini(ph); - ph = NULL; - } - return; - } - (void) update_subtree(nodeh, devnode); - (void) add_unitaddr_prop_to_subtree(nodeh); - if (ph != NULL) { - di_prom_fini(ph); - ph = NULL; - } - di_fini(devnode); - goto done; - } - - /* kludge ... try without bus-addr first */ - if ((strp = strrchr(dipath, '@')) != NULL) { - char *p; - - p = strrchr(dipath, '/'); - if (p != NULL && strp > p) { - *strp = '\0'; - devnode = di_init(dipath, DINFOCPYALL); - if (devnode != DI_NODE_NIL) - di_fini(devnode); - *strp = '@'; - } - } - /* Get parent devnode */ - if ((strp = strrchr(dipath, '/')) != NULL) - *++strp = '\0'; - devnode = di_init(dipath, DINFOCPYALL); - if (devnode == DI_NODE_NIL) - return; - ph = di_prom_init(); - (void) update_subtree(parh, devnode); - (void) add_unitaddr_prop_to_subtree(parh); - if (ph) { - di_prom_fini(ph); - ph = NULL; - } - di_fini(devnode); - } else if (strcmp(ename, PICLEVENT_SYSEVENT_DEVICE_REMOVED) == 0) { - char delclass[PICL_CLASSNAMELEN_MAX]; - char *strp; - - /* - * if final element of path doesn't have a unit address - * then it is not uniquely identifiable - cannot remove - */ - if (((strp = strrchr(ptreepath, '/')) != NULL) && - strchr(strp, '@') == NULL) - return; - - /* skip if can't find the node */ - if (ptree_get_node_by_path(ptreepath, &nodeh) != PICL_SUCCESS) - return; - - if (ptree_delete_node(nodeh) != PICL_SUCCESS) - return; - - if (picldevtree_debug) - syslog(LOG_INFO, - "picldevtree: deleted node nodeh:%llx\n", nodeh); - if ((ptree_get_propval_by_name(nodeh, - PICL_PROP_CLASSNAME, delclass, PICL_CLASSNAMELEN_MAX) == - PICL_SUCCESS) && IS_MC(delclass)) { - if (post_mc_event(PICLEVENT_MC_REMOVED, nodeh) != - PICL_SUCCESS) - syslog(LOG_WARNING, PICL_EVENT_DROPPED, - PICLEVENT_MC_REMOVED); - } else - (void) ptree_destroy_node(nodeh); - } -done: - (void) setup_cpus(plafh); - (void) add_ffb_config_info(plafh); - set_pci_pciex_deviceid(plafh); - (void) set_sbus_slot(plafh); - if (picldevtree_debug > 1) - syslog(LOG_INFO, "picldevtree: event handler done\n"); -} diff --git a/usr/src/cmd/picl/plugins/common/devtree/picldevtree.h b/usr/src/cmd/picl/plugins/common/devtree/picldevtree.h deleted file mode 100644 index 0c94fe50f3..0000000000 --- a/usr/src/cmd/picl/plugins/common/devtree/picldevtree.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICLDEVTREE_H -#define _PICLDEVTREE_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "picldefs.h" - -#define DEVICE_TYPE_BLOCK "block" -#define DEVICE_TYPE_BYTE "byte" -#define DEVICE_TYPE_DISK "disk" -#define DEVICE_TYPE_SES "ses" -#define DEVICE_TYPE_FP "fp" - -#define HASH_TABLE_SIZE 64 -#define HASH_INDEX(s, x) ((int)((x) & ((s) - 1))) - -#define MAX_NAMEVAL_SIZE 80 -#define CONFFILE_LINELEN_MAX 1024 - -#define KSTAT_STATE_BEGIN "state_begin" -#define KSTAT_CPU_INFO "cpu_info" -#define ASR_DISABLED "disabled" -#define ASR_FAILED "failed" - -#define DEVTREE_CONFFILE_NAME "picldevtree.conf" -#define ASRTREE_CONFFILE_NAME "picl_asr.conf" -#define CONFFILE_COMMENT_CHAR '#' - -/* - * Constants - */ -#define FFB_MANUF_BUFSIZE 256 -#define SUPPORTED_NUM_CELL_SIZE 2 /* #size-cells */ -#define MAX_STATE_SIZE 32 - -/* - * Hash table structure - */ -typedef struct hash_elem { - picl_nodehdl_t hdl; - struct hash_elem *next; -} hash_elem_t; - -typedef struct { - int hash_size; - hash_elem_t **tbl; -} hash_t; - -/* - * name to class map entries in the conf file - */ -typedef struct conf_entries { - char *name; - char *piclclass; - struct conf_entries *next; -} conf_entries_t; - -/* - * name to address to class map for asr2 - */ -typedef struct asr_conf_entries { - char *name; - char *piclclass; - char *status; - char *address; - char *props; - struct asr_conf_entries *next; -} asr_conf_entries_t; - -/* - * type, name, val property triplet for asr2 - */ -typedef struct asr_prop_triplet { - char *proptype; - char *propname; - char *propval; -} asr_prop_triplet_t; - -/* - * built-in name to class mapping table - */ -typedef struct { - char name[MAX_NAMEVAL_SIZE]; - char piclclass[PICL_CLASSNAMELEN_MAX]; -} builtin_map_t; - -/* - * property name to type mapping table - */ -typedef struct { - char pname[PICL_PROPNAMELEN_MAX]; - int type; -} pname_type_map_t; - -/* known values for manufacturer's JED code */ -#define MANF_BROOKTREE 214 -#define MANF_MITSUBISHI 28 -#define FFB_NAME "ffb" -#define FFBIOC ('F' << 8) -#define FFB_SYS_INFO (FFBIOC| 80) - -/* FFB strap reg union */ -typedef union { - struct { - uint32_t unused:24; - uint32_t afb_flag:1; - uint32_t major_rev:2; - uint32_t board_rev:2; - uint32_t board_mem:1; - uint32_t cbuf:1; - uint32_t bbuf:1; - } fld; - uint32_t ffb_strap_bits; -} strap_un_t; - -/* FFB mnufacturer union */ -typedef union { - struct { - uint32_t version:4; /* version of part number */ - uint32_t partno:16; /* part number */ - uint32_t manf:11; /* manufacturer's JED code */ - uint32_t one:1; /* always set to '1' */ - } fld; - uint32_t encoded_id; -} manuf_t; - -typedef struct ffb_sys_info { - strap_un_t ffb_strap_bits; /* ffb_strapping register */ - manuf_t fbc_version; /* revision of FBC chip */ - manuf_t dac_version; /* revision of DAC chip */ - manuf_t fbram_version; /* revision of FBRAMs chip */ - uint32_t flags; /* miscellaneous flags */ - uint32_t afb_nfloats; /* no. of Float asics in AFB */ - uint32_t pad[58]; /* padding for AFB chips & misc. */ -} ffb_sys_info_t; - -typedef struct memspecs { - uint32_t physlo; - uint32_t physhi; - uint64_t size; -} memspecs_t; - -/* - * UnitAddress property related constants and data structures - */ - -#define DEFAULT_ADDRESS_CELLS 2 -#define MAX_UNIT_ADDRESS_LEN 256 - -typedef int unitaddr_func_t(char *, int, uint32_t *, uint_t); - -typedef struct { - char *class; /* class name */ - unitaddr_func_t *func; /* function to encode unit address */ - int addrcellcnt; /* #addrcell expected, if non-zero */ -} unitaddr_map_t; - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLDEVTREE_H */ diff --git a/usr/src/cmd/picl/plugins/common/frutree/Makefile b/usr/src/cmd/picl/plugins/common/frutree/Makefile deleted file mode 100644 index 760a212b7a..0000000000 --- a/usr/src/cmd/picl/plugins/common/frutree/Makefile +++ /dev/null @@ -1,95 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/common/frutree/Makefile -# -LIBRARY= libpiclfrutree.a -VERS= .1 - -OBJECTS= piclfrutree.o - -# include library definitions -include $(SRC)/lib/Makefile.lib - -include $(SRC)/cmd/picl/plugins/Makefile.com - -SRCS= $(OBJECTS:%.o=%.c) - -LIBS = $(DYNLIB) - -ROOTLIBDIR = $(USR_LIB_PLUGINDIR) - -CLOBBERFILES += $(LIBLINKS) - -CPPFLAGS += -I../devtree -CPPFLAGS += -I$(SRC)/cmd/picl/plugins/lib/picld_pluginutil -CFLAGS += $(C_PICFLAGS) -LDLIBS += -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -L$(SRC)/cmd/picl/plugins/lib/picld_pluginutil/$(MACH) -LDLIBS += -L../devtree -LDLIBS += -L../memcfg -LDLIBS += -L$(ROOT)/usr/lib/picl/plugins -LDLIBS += -lc -lpicltree -lpicld_pluginutil -lpicldevtree -LDLIBS += -lpiclmemcfg -$(SPARC_BLD)LDLIBS += -R/usr/platform/lib/picl/plugins \ - -R/usr/platform/sun4u/lib/picl/plugins -LDLIBS += -R/usr/lib/picl/plugins - -.KEEP_STATE: - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -POFILE= piclfrutree.po - -all: $(LIBS) $(LIBLINKS) - -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - -$(MSGDOMAIN): - $(INS.dir) - -$(LIBLINKS): FRC - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -# include library targets -include $(SRC)/cmd/picl/plugins/Makefile.targ -include $(SRC)/lib/Makefile.targ - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/common/frutree/piclfrutree.c b/usr/src/cmd/picl/plugins/common/frutree/piclfrutree.c deleted file mode 100644 index 4ddef5ae8c..0000000000 --- a/usr/src/cmd/picl/plugins/common/frutree/piclfrutree.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 1999-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * This plugin creates the PICL nodes and properties specified in - * configuration file. - * It is used to create the FRU tree for a platform. - * The configuration file for FRU tree is called "piclfrutree.conf". - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "picld_pluginutil.h" - -#define EM_FAIL gettext("SUNW_piclfrutree PICL plugin module failed") - -static void piclfrutree_register(void); -static void piclfrutree_init(void); -static void piclfrutree_fini(void); - -#define FRUTREE_CONFFILE_NAME "piclfrutree.conf" - -#pragma init(piclfrutree_register) - -static picld_plugin_reg_t my_reg_info = { - PICLD_PLUGIN_VERSION_1, - PICLD_PLUGIN_NON_CRITICAL, - "SUNW_piclfrutree", - piclfrutree_init, - piclfrutree_fini -}; - -static void -piclfrutree_register(void) -{ - (void) picld_plugin_register(&my_reg_info); -} - -/* - * Search for the frutree config file from the platform specific - * directory to the common directory. - * - * The size of outfilename must be PATH_MAX - */ -static int -get_config_file(char *outfilename) -{ - char pname[PATH_MAX]; - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_PLAT_PLUGIN_DIR, - FRUTREE_CONFFILE_NAME); - - if (access(pname, R_OK) == 0) { - (void) strlcpy(outfilename, pname, PATH_MAX); - return (0); - } - - (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR, - FRUTREE_CONFFILE_NAME); - - if (access(pname, R_OK) == 0) { - (void) strlcpy(outfilename, pname, PATH_MAX); - return (0); - } - - return (-1); -} - -static void -piclfrutree_init(void) -{ - char fullfilename[PATH_MAX]; - picl_nodehdl_t rooth; - - if (get_config_file(fullfilename) < 0) - return; - - if (ptree_get_root(&rooth) != PICL_SUCCESS) - return; - - if (picld_pluginutil_parse_config_file(rooth, fullfilename) != - PICL_SUCCESS) - syslog(LOG_ERR, EM_FAIL); -} - -static void -piclfrutree_fini(void) -{ -} diff --git a/usr/src/cmd/picl/plugins/common/memcfg/Makefile b/usr/src/cmd/picl/plugins/common/memcfg/Makefile deleted file mode 100644 index 39005c40e4..0000000000 --- a/usr/src/cmd/picl/plugins/common/memcfg/Makefile +++ /dev/null @@ -1,90 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/picl/plugins/common/memcfg/Makefile -# -LIBRARY= libpiclmemcfg.a -VERS= .1 - -OBJECTS= piclmemcfg_comm.o - -# include library definitions -include $(SRC)/lib/Makefile.lib - -include $(SRC)/cmd/picl/plugins/Makefile.com - -SRCS= $(OBJECTS:%.o=%.c) - -LIBS = $(DYNLIB) - -ROOTLIBDIR = $(USR_LIB_PLUGINDIR) - -CPPFLAGS += -I$(SRC)/uts/sun4u/sys -I$(SRC)/cmd/picl/plugins/common/memcfg -CFLAGS += $(C_PICFLAGS) - -LDLIBS += -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -L../devtree -LDLIBS += -L$(ROOT)/usr/lib/picl/plugins -LDLIBS += -lc -lpicltree -lpicldevtree -lnvpair -$(SPARC_BLD)LDLIBS += -R/usr/platform/lib/picl/plugins \ - -R/usr/platform/sun4u/lib/picl/plugins -LDLIBS += -R/usr/lib/picl/plugins - -CLOBBERFILES += $(LIBLINKS) - -.KEEP_STATE: - -SUBDIRS= - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -POFILE= piclmemcfg_comm.po - -all: $(LIBS) $(LIBLINKS) - -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - -$(MSGDOMAIN): - $(INS.dir) - -$(LIBLINKS): FRC - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -# include library targets -include $(SRC)/cmd/picl/plugins/Makefile.targ -include $(SRC)/lib/Makefile.targ - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg.h b/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg.h deleted file mode 100644 index e18bf56199..0000000000 --- a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef _PICLMEMCFG_H -#define _PICLMEMCFG_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "picldefs.h" - -/* - * property names - */ -#define PICL_NAME_MEMORY_SEGMENT PICL_CLASS_MEMORY_SEGMENT -#define PICL_NAME_MEMORY_BANK PICL_CLASS_MEMORY_BANK -#define PICL_NAME_MEMORY_CONTROLLER PICL_CLASS_MEMORY_CONTROLLER -#define PICL_NAME_MEMORY_MODULE PICL_CLASS_MEMORY_MODULE -#define PICL_NAME_MEM_MOD_GROUP PICL_CLASS_MEMORY_MODULE_GROUP - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLMEMCFG_H */ diff --git a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c b/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c deleted file mode 100644 index 3b42116662..0000000000 --- a/usr/src/cmd/picl/plugins/common/memcfg/piclmemcfg_comm.c +++ /dev/null @@ -1,948 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * This plugin creates memory configuration nodes and properties in the - * PICL tree for Cheetah platforms. - * - * Subtree of memory-controller in the physical aspect. - * memory-controller --- memory-module-group --- memory-module - * - * Subtree of memory in the logical aspect. - * memory --- memory-segment --- memory-bank - * Add property _memory-module-group_ at memory-segment referring to the - * memory-module-group if InterleaveFactor is one, or at memory-bank - * if InterleaveFactor is greater than one. - * - * Undo strategy: - * Create all nodes and properties, or none if it fails in physical and - * logical memory tree respectively. It keeps on creating logic - * memory tree although it falis on physical logic tree, but no link to - * memory module group. - * - * NOTE: - * It depends on PICL devtree plugin and currently - * there is no refresh routine for DR. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "piclmemcfg.h" - -/* - * Plugin registration entry points - */ -static void piclmemcfg_register(void); -static void piclmemcfg_init(void); -static void piclmemcfg_fini(void); - -/* - * PICL event handler - */ -static void piclmemcfg_evhandler(const char *ename, const void *earg, - size_t size, void *cookie); - -#pragma init(piclmemcfg_register) - -static picld_plugin_reg_t my_reg_info = { - PICLD_PLUGIN_VERSION_1, - PICLD_PLUGIN_NON_CRITICAL, - "SUNW_piclmemcfg", - piclmemcfg_init, - piclmemcfg_fini -}; - -/* - * Log message texts - */ -#define EM_INIT_FAILED gettext("SUNW_piclmemcfg init failed!\n") -#define EM_PHYSIC_MEM_TREE_FAILED \ - gettext("SUNW_piclmemcfg physical memory tree failed!\n") -#define EM_LOGIC_MEM_TREE_FAILED \ - gettext("SUNW_piclmemcfg logical memory tree failed!\n") - -#define EM_INIT_MC_FAILED \ - gettext("SUNW_piclmemcfg init mc failed!\n") - -/* - * Global variables for Memory Controllers - */ -#define MC_DIR "/dev/mc/" - -static int nsegments; /* The number of memory segments */ -static int nbanks; /* The max. number of banks per segment */ -static int ndevgrps; /* The max. number of device groups per mc */ -static int ndevs; /* The max. number of devices per dev group */ -static int transfersize; - -static picl_nodehdl_t *msegh_info; - -/* - * Memory-module-group node handle list, a singal linking list, where - * memory module group id is the key to match. - * - * It is allocated and added to the head of list, and freed as well. - * The mmgh field is cleared if failure is encountered in the physical - * memory tree. - * - * This list is accessed in the logical memory tree, and allocated memory - * is released at the end of plugin. - */ -typedef struct memmodgrp_info { - int mmgid; - struct memmodgrp_info *next; - picl_nodehdl_t mmgh; - picl_nodehdl_t mch; -} mmodgrp_info_t; - -static mmodgrp_info_t *head2mmodgrp; - -/* - * Release the allocated memory of mmodgrp_info - */ -static void -free_allocated_mem(void) -{ - mmodgrp_info_t *mmghdl, *currmmghdl; - - mmghdl = head2mmodgrp; - - while (mmghdl) { - currmmghdl = mmghdl; - mmghdl = mmghdl->next; - free(currmmghdl); - } - - head2mmodgrp = NULL; -} - -/* - * Delete nodes whose MC is gone at mmodgrp_info - */ -static void -del_plugout_mmodgrp(picl_nodehdl_t mch) -{ - mmodgrp_info_t *mmghdl, *prevmmghdl, *nextmmghdl; - - for (mmghdl = head2mmodgrp, prevmmghdl = NULL; mmghdl != NULL; - mmghdl = nextmmghdl) { - nextmmghdl = mmghdl->next; - if (mmghdl->mch == mch) { - if (prevmmghdl == NULL) - /* we are at the head */ - head2mmodgrp = nextmmghdl; - else - prevmmghdl->next = nextmmghdl; - free(mmghdl); - } else - prevmmghdl = mmghdl; - } -} - -/* - * Search the memory module group node in the mmodgrp_info by global id. - * The matched memory-module-group node handle will be assigned to - * the second parameter. - */ -static int -find_mem_mod_grp_hdl(int id, picl_nodehdl_t *mmodgrph) -{ - mmodgrp_info_t *mmghdl; - int err = PICL_FAILURE; - - mmghdl = head2mmodgrp; - - while (mmghdl) { - if ((mmghdl->mmgh) && (mmghdl->mmgid == id)) { - *mmodgrph = mmghdl->mmgh; - err = PICL_SUCCESS; - break; - } - mmghdl = mmghdl->next; - } - - return (err); -} - -/* - * Delete nodes and properties created in the physical memory tree. - */ -static void -undo_phymem_tree(void) -{ - mmodgrp_info_t *mmghdl; - - mmghdl = head2mmodgrp; - - while (mmghdl) { - /* - * Delete nodes and properties of memory-module-group(s) - */ - if (mmghdl->mmgh == (uintptr_t)NULL) - continue; - - (void) ptree_delete_node(mmghdl->mmgh); - (void) ptree_destroy_node(mmghdl->mmgh); - - /* - * Clear out the saved node handle of memory module group - * so that logic memory tree won't link to it. - */ - mmghdl->mch = mmghdl->mmgh = (uintptr_t)NULL; - mmghdl = mmghdl->next; - } -} - -/* - * Create all memory-banks under the given memory-segment. - */ -static int -add_mem_banks(picl_nodehdl_t msegh, int fd, struct mc_segment *mcseg) -{ - int i; - int err = PICL_SUCCESS; - static picl_nodehdl_t mmodgrph; - picl_prophdl_t bankh; - ptree_propinfo_t propinfo; - struct mc_bank mcbank; - char propname[PICL_CLASSNAMELEN_MAX]; - - /* - * Get all bank information via ioctl - */ - for (i = 0; i < mcseg->nbanks; i++) { - mcbank.id = mcseg->bankids[i].globalid; - if (ioctl(fd, MCIOC_BANK, &mcbank) == -1) - return (PICL_FAILURE); - - /* - * Create memory-bank node under memory-segment node - */ - err = ptree_create_and_add_node(msegh, PICL_NAME_MEMORY_BANK, - PICL_CLASS_MEMORY_BANK, &bankh); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, Size to memory-bank node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcbank.size), - PICL_PROP_SIZE, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(bankh, &propinfo, &mcbank.size, - NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, AddressMask to memory-bank node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcbank.mask), - PICL_PROP_ADDRESSMASK, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(bankh, &propinfo, &mcbank.mask, - NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, AddressMatch to memory-bank node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcbank.match), - PICL_PROP_ADDRESSMATCH, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(bankh, &propinfo, - &mcbank.match, NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add global id of bank to property, ID memory-bank node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, sizeof (mcbank.id), PICL_PROP_ID, - NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(bankh, &propinfo, &mcbank.id, - NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, _memory-module-group_ to memory-bank node - */ - if ((find_mem_mod_grp_hdl(mcbank.devgrpid.globalid, - &mmodgrph)) != PICL_SUCCESS) - continue; - - /* - * The number of memory modules > 1 means there needs - * memory module group, and then refers to it. Otherwise, - * it refers to memory module node handle instead. - */ - (void) strlcpy(propname, (ndevs > 1 ? - PICL_REFPROP_MEMORY_MODULE_GROUP : - PICL_REFPROP_MEMORY_MODULE), PICL_CLASSNAMELEN_MAX); - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_REFERENCE, PICL_READ, sizeof (picl_nodehdl_t), - propname, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(bankh, &propinfo, &mmodgrph, - NULL); - if (err != PICL_SUCCESS) - break; - } - return (PICL_SUCCESS); -} - -static void -undo_logical_tree(int nsegments) -{ - int i; - /* - * Undo in the logical memory tree - */ - for (i = 0; i < nsegments; i++) { - (void) ptree_delete_node(msegh_info[i]); - (void) ptree_destroy_node(msegh_info[i]); - } -} - -/* - * Create logical memory tree - * memory --- memory-segment --- memory-bank - * Get information via ioctl of memory control driver - */ -static int -create_logical_tree(picl_nodehdl_t memh, int fd) -{ - int i; - int err = PICL_SUCCESS; - picl_nodehdl_t msegh; - ptree_propinfo_t propinfo; - struct mc_memory *mcmem; - struct mc_segment *mcseg; - picl_prophdl_t proph; - uint64_t memsize = 0; - - /* - * allocate memory for mc_memory where nsegmentids are various - */ - if ((mcmem = alloca((nsegments - 1) * sizeof (mcmem->segmentids[0]) + - sizeof (*mcmem))) == NULL) - return (PICL_FAILURE); - - mcmem->nsegments = nsegments; - - /* - * Get logical memory information - */ - if (ioctl(fd, MCIOC_MEM, mcmem) == -1) - return (PICL_FAILURE); - - /* - * allocate memory for mc_segment where nbanks are various - */ - if ((mcseg = alloca((nbanks - 1) * sizeof (mcseg->bankids[0]) + - sizeof (*mcseg))) == NULL) - return (PICL_FAILURE); - - /* - * Get all segments to create memory-segment nodes and - * add properties. - */ - for (i = 0; i < nsegments; i++) { - mcseg->id = mcmem->segmentids[i].globalid; - mcseg->nbanks = nbanks; - - if (ioctl(fd, MCIOC_SEG, mcseg) == -1) - break; - - /* - * Create memory-segment node under memory node - */ - err = ptree_create_and_add_node(memh, PICL_NAME_MEMORY_SEGMENT, - PICL_CLASS_MEMORY_SEGMENT, &msegh); - if (err != PICL_SUCCESS) - break; - - msegh_info[i] = msegh; - - /* - * Add property, Size to memory-segment node - */ - if ((ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcseg->size), - PICL_PROP_SIZE, NULL, NULL)) != PICL_SUCCESS) - if (err != PICL_SUCCESS) - break; - - memsize += mcseg->size; - err = ptree_create_and_add_prop(msegh, &propinfo, &mcseg->size, - NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, BaseAddress to memory-segment node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcseg->base), - PICL_PROP_BASEADDRESS, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(msegh, &propinfo, &mcseg->base, - NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcseg->ifactor), - PICL_PROP_INTERLEAVE_FACTOR, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(msegh, &propinfo, - &mcseg->ifactor, NULL); - if (err != PICL_SUCCESS) - break; - - err = add_mem_banks(msegh, fd, mcseg); - if (err != PICL_SUCCESS) - break; - } - - if (err != PICL_SUCCESS) { - undo_logical_tree(nsegments); - return (err); - } - - err = ptree_get_prop_by_name(memh, PICL_PROP_SIZE, &proph); - if (err == PICL_SUCCESS) { /* update the value */ - err = ptree_update_propval(proph, &memsize, sizeof (memsize)); - return (err); - } - - /* - * Add the size property - */ - (void) ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (memsize), - PICL_PROP_SIZE, NULL, NULL); - err = ptree_create_and_add_prop(memh, &propinfo, &memsize, NULL); - - return (err); -} - -/* - * Add memory-module nodes and properties at each enabled memory-module-group. - * The formula of unique id is (id of the given memory module group * - * max number of memory modules per memory module group) + index - * of memory modules in this memory module group - */ -static int -add_mem_modules(picl_nodehdl_t mmodgrph, struct mc_devgrp *mcdevgrp) -{ - uint64_t size; - picl_nodehdl_t dimmh; - ptree_propinfo_t propinfo; - int i; - int err = PICL_SUCCESS; - - size = mcdevgrp->size / mcdevgrp->ndevices; - - /* - * Get all memory-modules of the given memory-module-group - */ - for (i = 0; i < mcdevgrp->ndevices; i++) { - /* - * Create memory-module node under memory-module-group - */ - err = ptree_create_and_add_node(mmodgrph, - PICL_NAME_MEMORY_MODULE, PICL_CLASS_MEMORY_MODULE, &dimmh); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, Size to memory-module-group node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (size), - PICL_PROP_SIZE, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(dimmh, &propinfo, &size, NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, ID to memory-module-group node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, sizeof (i), PICL_PROP_ID, - NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(dimmh, &propinfo, &i, - NULL); - if (err != PICL_SUCCESS) - break; - } - return (err); -} - -/* - * Create the subtree at every enabled Memory Controller where size of - * memory module group is greater than zero. - * Get information via ioctl of memory control driver - */ -static int -create_physical_tree(picl_nodehdl_t mch, void *args) -{ - int i, portid; - int err = PICL_SUCCESS; - mmodgrp_info_t *mmghdl; - picl_nodehdl_t mmodgrph; - ptree_propinfo_t propinfo; - struct mc_control *mccontrol; - struct mc_devgrp mcdevgrp; - int fd; - - fd = (int)args; - /* - * Get portid of memory-controller as the key to get its - * configuration via ioctl. - */ - err = ptree_get_propval_by_name(mch, OBP_PROP_PORTID, &portid, - sizeof (portid)); - if (err != PICL_SUCCESS) - return (err); - - if ((mccontrol = alloca((ndevgrps - 1) * - sizeof (mccontrol->devgrpids[0]) + sizeof (*mccontrol))) == NULL) - return (PICL_FAILURE); - - mccontrol->id = portid; - mccontrol->ndevgrps = ndevgrps; - - if (ioctl(fd, MCIOC_CONTROL, mccontrol) == -1) { - if (errno == EINVAL) - return (PICL_WALK_CONTINUE); - else - return (PICL_FAILURE); - } - - /* - * If returned ndevgrps is zero, Memory Controller is disable, and - * skip it. - */ - if (mccontrol->ndevgrps == 0) - return (PICL_WALK_CONTINUE); - - /* - * Get all memory module groups of the given memory controller. - */ - for (i = 0; i < mccontrol->ndevgrps; i++) { - int mmglocalid = mccontrol->devgrpids[i].localid; - - mcdevgrp.id = mccontrol->devgrpids[i].globalid; - - if (ioctl(fd, MCIOC_DEVGRP, &mcdevgrp) == -1) - return (PICL_FAILURE); - - /* - * Node doesn't need to be created if size is 0, i.e. - * there is no memory dimm at slot. - */ - if (mcdevgrp.size == 0) - continue; - - /* - * Create memory-module-group node under memory-controller - */ - err = ptree_create_and_add_node(mch, PICL_NAME_MEM_MOD_GROUP, - PICL_CLASS_MEMORY_MODULE_GROUP, &mmodgrph); - if (err != PICL_SUCCESS) - break; - - /* - * Allocate space for mmodgrp_info to save the information - * so that it is easier to do the undo and setup of the - * reference property in logical memory tree. - */ - if ((mmghdl = malloc(sizeof (*mmghdl))) == NULL) - return (PICL_FAILURE); - - /* - * Save the information and add it to the beginnong of list. - */ - mmghdl->mmgid = mcdevgrp.id; - mmghdl->mmgh = mmodgrph; - mmghdl->mch = mch; - mmghdl->next = head2mmodgrp; - - head2mmodgrp = mmghdl; - - /* - * Add property, Size to memory-module-group node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (mcdevgrp.size), - PICL_PROP_SIZE, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(mmodgrph, &propinfo, - &mcdevgrp.size, NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Add property, ID to memory-module-group node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_INT, PICL_READ, sizeof (mmglocalid), - PICL_PROP_ID, NULL, NULL); - if (err != PICL_SUCCESS) - break; - - err = ptree_create_and_add_prop(mmodgrph, &propinfo, - &mmglocalid, NULL); - if (err != PICL_SUCCESS) - break; - - /* - * Create all memory-module nodes and properties. - */ - err = add_mem_modules(mmodgrph, &mcdevgrp); - if (err != PICL_SUCCESS) - break; - } - - if (err == PICL_SUCCESS) - return (PICL_WALK_CONTINUE); - return (err); -} - -/* - * Create physical memory tree - * memory-controller --- memory-module-group --- memory-module - * - * It searches all memory-controller nodes in the whole devtree. - * It returns failure if encountering error in physical tree. - */ -static int -find_mc_create_tree(picl_nodehdl_t rooth, int fd) -{ - int err; - - err = ptree_walk_tree_by_class(rooth, PICL_CLASS_MEMORY_CONTROLLER, - (void *)fd, create_physical_tree); - return (err); -} - -static int -init_mc(void) -{ - struct mc_memconf mcmemconf; - int fd; - DIR *dirp; - struct dirent *retp; - char path[PATH_MAX]; - int found = 0; - int valid_entry = 0; - - /* open the directory */ - if ((dirp = opendir(MC_DIR)) == NULL) { - /* - * As not all platforms have mc drivers that create the - * /dev/mc directory, print a message only if there is - * an entry found on which the open failed. - */ - if (errno != ENOENT) - syslog(LOG_ERR, EM_INIT_MC_FAILED); - return (-1); - } - - /* start searching this directory */ - while ((retp = readdir(dirp)) != NULL) { - /* skip . .. etc... */ - if (strcmp(retp->d_name, ".") == 0 || - strcmp(retp->d_name, "..") == 0) - continue; - - (void) strcpy(path, MC_DIR); - (void) strcat(path, retp->d_name); - /* open the memory controller driver */ - if ((fd = open(path, O_RDONLY, 0)) != -1) { - found = 1; - break; - } - if (errno != ENOENT) - valid_entry = 1; - } - (void) closedir(dirp); - - if (!found) { - if (valid_entry) - syslog(LOG_ERR, EM_INIT_MC_FAILED); - return (-1); - } - - /* - * Initialize some global variables via ioctl - */ - if (ioctl(fd, MCIOC_MEMCONF, &mcmemconf) == -1) { - (void) close(fd); - return (-1); - } - - nsegments = mcmemconf.nsegments; - nbanks = mcmemconf.nbanks; - ndevgrps = mcmemconf.ndevgrps; - ndevs = mcmemconf.ndevs; - transfersize = mcmemconf.xfer_size; - - return (fd); -} - -/* - * executed as part of .init when the plugin is dlopen()ed - */ -void -piclmemcfg_register(void) -{ - (void) picld_plugin_register(&my_reg_info); -} - -/* - * init entry point of the plugin - * Creates the PICL nodes and properties in the physical and logical aspects. - */ -void -piclmemcfg_init(void) -{ - picl_nodehdl_t plfh; - picl_nodehdl_t memh; - ptree_propinfo_t propinfo; - int fd, err; - - /* - * Initialize the header pointer of mmodgrp_info list - */ - head2mmodgrp = NULL; - msegh_info = NULL; - - if ((fd = init_mc()) < 0) - return; - - /* - * allocate memory to save memory-segment node handles. Thus, - * it is easier to delete them if it fails. - */ - if ((msegh_info = malloc(nsegments * sizeof (picl_nodehdl_t))) == - NULL) { - syslog(LOG_ERR, EM_INIT_FAILED); - (void) close(fd); - return; - } - - /* - * find platform node - */ - if ((ptree_get_node_by_path(PLATFORM_PATH, &plfh)) != PICL_SUCCESS) { - syslog(LOG_ERR, EM_INIT_FAILED); - (void) close(fd); - return; - } - - /* - * Find the memory node - */ - if ((ptree_get_node_by_path(MEMORY_PATH, &memh)) != PICL_SUCCESS) { - syslog(LOG_ERR, EM_INIT_FAILED); - (void) close(fd); - return; - } - - /* - * Create subtree of memory-controller in the physical aspect. - * memory-controller --- memory-module-group --- memory-module - */ - err = find_mc_create_tree(plfh, fd); - - if (err != PICL_SUCCESS) { - undo_phymem_tree(); - syslog(LOG_ERR, EM_PHYSIC_MEM_TREE_FAILED); - } - - /* - * Add property, TransferSize to memory node - */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_UNSIGNED_INT, PICL_READ, sizeof (transfersize), - PICL_PROP_TRANSFER_SIZE, NULL, NULL); - if (err != PICL_SUCCESS) { - (void) close(fd); - return; - } - - err = ptree_create_and_add_prop(memh, &propinfo, - &transfersize, NULL); - if (err != PICL_SUCCESS) { - (void) close(fd); - return; - } - - /* - * Create subtree of memory in the logical aspect. - * memory --- memory-segment --- memory-bank - */ - if ((create_logical_tree(memh, fd)) != PICL_SUCCESS) { - syslog(LOG_ERR, EM_LOGIC_MEM_TREE_FAILED); - undo_logical_tree(nsegments); - } - - (void) close(fd); - (void) ptree_register_handler(PICLEVENT_MC_ADDED, - piclmemcfg_evhandler, NULL); - (void) ptree_register_handler(PICLEVENT_MC_REMOVED, - piclmemcfg_evhandler, NULL); -} - -/* - * fini entry point of the plugin - */ -void -piclmemcfg_fini(void) -{ - (void) ptree_unregister_handler(PICLEVENT_MC_ADDED, - piclmemcfg_evhandler, NULL); - (void) ptree_unregister_handler(PICLEVENT_MC_REMOVED, - piclmemcfg_evhandler, NULL); - /* - * Release all the allocated memory for global structures - */ - free_allocated_mem(); - free(msegh_info); -} - -/* - * Event handler of this plug-in - */ -/*ARGSUSED*/ -static void -piclmemcfg_evhandler(const char *ename, const void *earg, size_t size, - void *cookie) -{ - int err; - int fd; - picl_nodehdl_t memh; - picl_nodehdl_t nodeh; - int old_nsegs; - nvlist_t *nvlp; - - memh = (uintptr_t)NULL; - if (nvlist_unpack((char *)earg, size, &nvlp, 0)) - return; - - if (nvlist_lookup_uint64(nvlp, PICLEVENTARG_NODEHANDLE, &nodeh)) { - nvlist_free(nvlp); - return; - } - nvlist_free(nvlp); - - /* - * get the memory node - */ - err = ptree_get_node_by_path(MEMORY_PATH, &memh); - if (err != PICL_SUCCESS) - return; - - /* - * nsegments won't be overwritten until init_mc succeeds - */ - old_nsegs = nsegments; - if ((fd = init_mc()) < 0) - return; - - if (strcmp(ename, PICLEVENT_MC_ADDED) == 0) - (void) create_physical_tree(nodeh, (void *)fd); - else if (strcmp(ename, PICLEVENT_MC_REMOVED) == 0) - /* - * Delete the entry at the list only since class at PICL is - * deleted in devtree plugin. - */ - (void) del_plugout_mmodgrp(nodeh); - - (void) undo_logical_tree(old_nsegs); - free(msegh_info); - - /* - * allocate memory to save memory-segment node handles. Thus, - * it is easier to delete them if it fails. - */ - if ((msegh_info = malloc(nsegments * sizeof (picl_nodehdl_t))) == - NULL) { - (void) close(fd); - return; - } - - (void) create_logical_tree(memh, fd); - - (void) close(fd); -} diff --git a/usr/src/cmd/picl/plugins/common/piclevent/Makefile b/usr/src/cmd/picl/plugins/common/piclevent/Makefile deleted file mode 100644 index 286af5cf95..0000000000 --- a/usr/src/cmd/picl/plugins/common/piclevent/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -LIBRARY= libpiclevent.a -VERS= .1 - -OBJECTS= piclevent.o - -# include library definitions -include $(SRC)/lib/Makefile.lib - -include $(SRC)/cmd/picl/plugins/Makefile.com - -MODULES = picl_slm.so -MOD_SRCS = picl_slm.c -MOD_OBJS = picl_slm.o -MOD_LDLIBS = -L$(ROOT)/usr/lib -lsysevent -lnvpair -lc - -# sysevent SLM dirs -SYSEVENT = sysevent -MODDIR = modules -ROOTLIBSYSEVENTDIR = $(ROOTLIB)/$(SYSEVENT) -ROOTLIBSYSEVENTMODDIR = $(ROOTLIBSYSEVENTDIR)/$(MODDIR) -ROOTLIBSYSEVENTMODULES = $(MODULES:%=$(ROOTLIBSYSEVENTMODDIR)/%) -ROOTETCSYSEVENTDIR = $(ROOTETC)/$(SYSEVENT) - -SRCS= $(OBJECTS:%.o=%.c) - -LIBS = $(DYNLIB) - -ROOTLIBDIR = $(USR_LIB_PLUGINDIR) -ROOTETC = $(ROOT)/etc -ROOTLIB = $(ROOT)/usr/lib - -CLOBBERFILES += $(LIBLINKS) -CLOBBERFILES += $(MODULES) - -CPPFLAGS += -I$(SRC)/lib/libsysevent -I$(SRC)/uts/sun - -CFLAGS += $(C_PICFLAGS) -LDLIBS += -L$(SRC)/lib/libsysevent -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -lc -lpicltree -lnvpair - - -.KEEP_STATE: - -SUBDIRS= - -POFILE= piclevent.po - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -all: $(LIBS) $(LIBLINKS) $(MODULES) - -install: $(ROOTLIBDIR) all $(ROOTLIBS) $(ROOTLINKS) \ - $(ROOTETCSYSEVENTDIR) \ - $(ROOTLIBSYSEVENTDIR) \ - $(ROOTLIBSYSEVENTMODDIR) \ - $(ROOTLIBSYSEVENTMODULES) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - - -$(MSGDOMAIN): - $(INS.dir) - -$(LIBLINKS): FRC - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -# include library targets -include $(SRC)/cmd/picl/plugins/Makefile.targ -include $(SRC)/lib/Makefile.targ - -%.so: %.o - $(LINK.c) -o $@ $(GSHARED) -h $@ $< $(MOD_LDLIBS) - -%.o: %.c - $(COMPILE.c) -o $@ $< - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -$(ROOTLIBSYSEVENTDIR): - $(INS.dir) - -$(ROOTETCSYSEVENTDIR): - $(INS.dir) - -$(ROOTLIBSYSEVENTDIR)/%: % - $(INS.file) - -$(ROOTLIBSYSEVENTMODDIR): - $(INS.dir) - -$(ROOTLIBSYSEVENTMODDIR)/%.so: %.so - $(INS.file) - -FRC: diff --git a/usr/src/cmd/picl/plugins/common/piclevent/picl_slm.c b/usr/src/cmd/picl/plugins/common/piclevent/picl_slm.c deleted file mode 100644 index f6bbea770d..0000000000 --- a/usr/src/cmd/picl/plugins/common/piclevent/picl_slm.c +++ /dev/null @@ -1,433 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "piclevent.h" -#include -#include - -#define PICLSLM_DOOR_FAILED gettext("PICL SLM door create failed\n") - -/* - * syseventd event handler - */ -static int piclslm_debug = 0; -static int piclslm_deliver_event(sysevent_t *ev, int flag); -static int door_fd = -1; - -typedef struct nvlist_queue { - char *nvq_item; /* packed nvlist */ - size_t nvq_sz; /* buf size */ - struct nvlist_queue *nvq_next; -} nvlist_queue_t; - -static nvlist_queue_t *nvq_head; -static nvlist_queue_t *nvq_tail; - -static mutex_t nvq_lock; -static cond_t nvq_cv; -static thread_t piclslm_deliver_thr_id; -static int cleanup; - -static struct slm_mod_ops piclslm_mod_ops = { - SE_MAJOR_VERSION, SE_MINOR_VERSION, SE_MAX_RETRY_LIMIT, - piclslm_deliver_event}; - - -static void -init_queue(void) -{ - nvq_head = NULL; - nvq_tail = NULL; -} - -static int -add_to_queue(char *nvl, size_t sz) -{ - nvlist_queue_t *new_nvq; - - new_nvq = malloc(sizeof (*new_nvq)); - if (new_nvq == NULL) - return (-1); - - new_nvq->nvq_item = nvl; - new_nvq->nvq_sz = sz; - new_nvq->nvq_next = NULL; - - if (nvq_head == NULL) - nvq_head = new_nvq; - else - nvq_tail->nvq_next = new_nvq; - nvq_tail = new_nvq; - - return (0); -} - -static nvlist_queue_t * -remove_from_queue(void) -{ - nvlist_queue_t *nvqp; - - if (nvq_head == NULL) - return (NULL); - - nvqp = nvq_head; - nvq_head = nvq_head->nvq_next; - if (nvq_head == NULL) - nvq_tail = NULL; - return (nvqp); -} - -static void -free_nvqueue(nvlist_queue_t *nvqp) -{ - free(nvqp->nvq_item); - free(nvqp); -} - -/* - * deliver the event to the plugin if the door exists - */ -static void -post_piclevent(char *pack_buf, size_t nvl_size) -{ - door_arg_t darg; - - darg.data_ptr = pack_buf; - darg.data_size = nvl_size; - darg.desc_ptr = NULL; - darg.desc_num = 0; - darg.rbuf = NULL; - darg.rsize = 0; - - if (door_fd < 0 || door_call(door_fd, &darg) < 0) { - if (door_fd >= 0) { - if (errno != EBADF) { - return; - } - - /* - * It's not a valid door file descriptor. - * Close and reopen the door and try again - * as "picld" may have restarted. - */ - (void) close(door_fd); - } - - door_fd = open(PICLEVENT_DOOR, O_RDONLY); - if (piclslm_debug) - syslog(LOG_INFO, - "picl_slm: opened door %s door_fd: %d\n", - PICLEVENT_DOOR, door_fd); - if (door_fd < 0 || door_call(door_fd, &darg) < 0) { - return; - } - } - if (piclslm_debug) - syslog(LOG_INFO, - "picl_slm: sent sysevent door:%d pack_buf:%p size:0x%x\n", - door_fd, pack_buf, nvl_size); -} - -/*ARGSUSED*/ -static void * -piclslm_deliver_thr(void *args) -{ - nvlist_queue_t *nvqp; - - for (;;) { - (void) mutex_lock(&nvq_lock); - while (nvq_head == NULL && cleanup == 0) { - (void) cond_wait(&nvq_cv, &nvq_lock); - } - nvqp = remove_from_queue(); - (void) mutex_unlock(&nvq_lock); - while (nvqp) { - post_piclevent(nvqp->nvq_item, nvqp->nvq_sz); - free_nvqueue(nvqp); - (void) mutex_lock(&nvq_lock); - nvqp = remove_from_queue(); - (void) mutex_unlock(&nvq_lock); - } - if (cleanup) - return (NULL); - } - /*NOTREACHED*/ -} - -/* - * returns 0 if arguments successfully added to nvl, EINVAL if arguments missing - * from ev and EAGAIN if nvlist_add_string() fails - */ -static int -piclslm_add_ec_devfs_args(nvlist_t *nvl, sysevent_t *ev) -{ - sysevent_value_t se_val; - - if (sysevent_lookup_attr(ev, DEVFS_PATHNAME, SE_DATA_TYPE_STRING, - &se_val) != 0 || se_val.value.sv_string == NULL) { - return (EINVAL); - } - if (nvlist_add_string(nvl, PICLEVENTARG_DEVFS_PATH, - se_val.value.sv_string)) { - return (EAGAIN); - } - return (0); -} - -/* - * returns 0 if arguments successfully added to nvl, EINVAL if arguments missing - * from ev and EAGAIN if nvlist_add_string() fails - */ -static int -piclslm_add_ec_dr_args(nvlist_t *nvl, sysevent_t *ev) -{ - sysevent_value_t se_val; - - if (sysevent_lookup_attr(ev, DR_AP_ID, SE_DATA_TYPE_STRING, - &se_val) != 0 || se_val.value.sv_string == NULL) { - return (EINVAL); - } - if (nvlist_add_string(nvl, PICLEVENTARG_AP_ID, - se_val.value.sv_string)) { - return (EAGAIN); - } - if (sysevent_lookup_attr(ev, DR_HINT, SE_DATA_TYPE_STRING, - &se_val) != 0 || se_val.value.sv_string == NULL) { - if (nvlist_add_string(nvl, PICLEVENTARG_HINT, "")) - return (EAGAIN); - } else { - if (nvlist_add_string(nvl, PICLEVENTARG_HINT, - se_val.value.sv_string)) - return (EAGAIN); - } - return (0); -} - -/* - * returns 0 if arguments successfully added to nvl, EINVAL if arguments missing - * from ev and EAGAIN if nvlist_add_string() fails - */ -static int -piclslm_add_ec_dr_req_args(nvlist_t *nvl, sysevent_t *ev) -{ - nvlist_t *nvlist = NULL; - char *ap_id = NULL; - char *dr_req = NULL; - - if (sysevent_get_attr_list(ev, &nvlist)) { - return (EAGAIN); - } - - if (nvlist_lookup_string(nvlist, DR_AP_ID, &ap_id) != 0 || - ap_id == NULL) { - nvlist_free(nvlist); - return (EINVAL); - } - - if (nvlist_add_string(nvl, PICLEVENTARG_AP_ID, ap_id)) { - nvlist_free(nvlist); - return (EAGAIN); - } - - dr_req = NULL; - if (nvlist_lookup_string(nvlist, DR_REQ_TYPE, &dr_req) != 0) - dr_req = ""; - - if (nvlist_add_string(nvl, PICLEVENTARG_DR_REQ_TYPE, - dr_req)) { - nvlist_free(nvlist); - return (EAGAIN); - } - - if (piclslm_debug) - syslog(LOG_DEBUG, "piclevent: dr_req_type = %s on %s\n", - (dr_req ? dr_req : "Investigate"), ap_id); - - nvlist_free(nvlist); - return (0); -} - -/* - * piclslm_deliver_event - called by syseventd to deliver an event buffer. - * The event buffer is subsequently delivered to - * picld. If picld, is not responding to the - * delivery attempt, we will ignore it. - */ -/*ARGSUSED*/ -static int -piclslm_deliver_event(sysevent_t *ev, int flag) -{ - sysevent_t *dupev; - nvlist_t *nvl; - char *ec; - char *esc; - char *ename; - int retval; - char *pack_buf; - size_t nvl_size; - int rval; - - /* - * Filter out uninteresting events - */ - ec = sysevent_get_class_name(ev); - esc = sysevent_get_subclass_name(ev); - if (piclslm_debug) - syslog(LOG_INFO, - "picl_slm: got sysevent ev:%p class:%s subclass:%s\n", - ev, (ec) ? ec : "NULL", (esc) ? esc : "NULL"); - if ((ec == NULL) || (esc == NULL)) { - return (0); - } else if (strcmp(ec, EC_DEVFS) == 0) { - if (strcmp(esc, ESC_DEVFS_DEVI_ADD) == 0) - ename = strdup(PICLEVENT_SYSEVENT_DEVICE_ADDED); - else if (strcmp(esc, ESC_DEVFS_DEVI_REMOVE) == 0) - ename = strdup(PICLEVENT_SYSEVENT_DEVICE_REMOVED); - else - return (0); - } else if (strcmp(ec, EC_DR) == 0) { - if (strcmp(esc, ESC_DR_AP_STATE_CHANGE) == 0) - ename = strdup(PICLEVENT_DR_AP_STATE_CHANGE); - else if (strcmp(esc, ESC_DR_REQ) == 0) - ename = strdup(PICLEVENT_DR_REQ); - else - return (0); - } else { - return (0); - } - - if (ename == NULL) - return (EAGAIN); - - /* - * Make a copy to expand attribute list - */ - dupev = sysevent_dup(ev); - if (dupev == NULL) { - free(ename); - return (EAGAIN); - } - - if (nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0)) { - free(ename); - sysevent_free(dupev); - return (EAGAIN); - } - - if (strcmp(ec, EC_DEVFS) == 0) { - rval = piclslm_add_ec_devfs_args(nvl, dupev); - } else if (strcmp(ec, EC_DR) == 0) { - if (strcmp(esc, ESC_DR_REQ) == 0) { - rval = piclslm_add_ec_dr_req_args(nvl, dupev); - } else { - rval = piclslm_add_ec_dr_args(nvl, dupev); - } - } - - if (rval != 0) { - free(ename); - nvlist_free(nvl); - sysevent_free(dupev); - return ((rval == EAGAIN) ? EAGAIN : 0); - } - - pack_buf = NULL; - if (nvlist_add_string(nvl, PICLEVENTARG_EVENT_NAME, ename) || - nvlist_add_string(nvl, PICLEVENTARG_DATA_TYPE, - PICLEVENTARG_PICLEVENT_DATA) || - nvlist_pack(nvl, &pack_buf, &nvl_size, NV_ENCODE_NATIVE, 0)) { - free(ename); - nvlist_free(nvl); - sysevent_free(dupev); - return (EAGAIN); - } - - /* - * Add nvlist_t to queue - */ - (void) mutex_lock(&nvq_lock); - retval = add_to_queue(pack_buf, nvl_size); - (void) cond_signal(&nvq_cv); - (void) mutex_unlock(&nvq_lock); - - nvlist_free(nvl); - sysevent_free(dupev); - free(ename); - return (retval < 0 ? EAGAIN : 0); -} - -struct slm_mod_ops * -slm_init(void) -{ - cleanup = 0; - - init_queue(); - - (void) mutex_init(&nvq_lock, USYNC_THREAD, NULL); - (void) cond_init(&nvq_cv, USYNC_THREAD, NULL); - - if (thr_create(NULL, 0, piclslm_deliver_thr, - NULL, THR_BOUND, &piclslm_deliver_thr_id) != 0) { - (void) mutex_destroy(&nvq_lock); - (void) cond_destroy(&nvq_cv); - return (NULL); - } - return (&piclslm_mod_ops); -} - -void -slm_fini(void) -{ - /* - * Wait for all events to be sent - */ - (void) mutex_lock(&nvq_lock); - cleanup = 1; - (void) cond_signal(&nvq_cv); - (void) mutex_unlock(&nvq_lock); - - /* Wait for delivery thread to exit */ - (void) thr_join(piclslm_deliver_thr_id, NULL, NULL); - - (void) mutex_destroy(&nvq_lock); - (void) cond_destroy(&nvq_cv); - - if (door_fd >= 0) - (void) close(door_fd); - door_fd = -1; -} diff --git a/usr/src/cmd/picl/plugins/common/piclevent/piclevent.c b/usr/src/cmd/picl/plugins/common/piclevent/piclevent.c deleted file mode 100644 index 1185248e6d..0000000000 --- a/usr/src/cmd/picl/plugins/common/piclevent/piclevent.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * PICL plug-in that listens to sysevent and posts picl events - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "piclevent.h" - -/* - * Plugin registration entry points - */ -static void eventplugin_register(void); -static void eventplugin_init(void); -static void eventplugin_fini(void); - -#pragma init(eventplugin_register) - -static picld_plugin_reg_t my_reg_info = { - PICLD_PLUGIN_VERSION_1, - PICLD_PLUGIN_CRITICAL, - "SUNW_piclevent plugin for sysevents", - eventplugin_init, - eventplugin_fini -}; - -/* - * Log message texts - */ -#define EVT_THR_FAILED gettext("Event thread create failed!\n") -#define EVT_OPEN_FAILED gettext("PICL SLM door create failed\n") - -static int door_id = -1; -#define SUNW_PICLEVENT_PLUGIN_DEBUG "SUNW_PICLEVENT_PLUGIN_DEBUG" -static int piclevent_debug = 0; - - -/* - * completion handler for the posted picl event - */ -/*ARGSUSED*/ -static void -piclevent_completion_handler(char *ename, void *earg, size_t size) -{ - free(earg); - free(ename); -} - -/* - * This function posts the incoming piclevent - * It packs the nvlist and posts it to PICL - */ -static void -parse_piclevent(nvlist_t *nvlp) -{ - char *enval; - char *ename; - size_t nvl_size; - char *packed_nvl; - int err; - - if (nvlist_lookup_string(nvlp, PICLEVENTARG_EVENT_NAME, &enval)) - return; - - packed_nvl = NULL; - if (nvlist_pack(nvlp, &packed_nvl, &nvl_size, NV_ENCODE_NATIVE, 0)) - return; - - ename = strdup(enval); - if (ename == NULL) { - free(packed_nvl); - return; - } - - if (piclevent_debug) { - syslog(LOG_INFO, "piclevent: posting ename:%s packed_nvl:%p " - "nvl_size:0x%x\n", ename, packed_nvl, nvl_size); - } - err = ptree_post_event(ename, packed_nvl, nvl_size, - piclevent_completion_handler); - - if (err != PICL_SUCCESS) { - if (piclevent_debug) - syslog(LOG_INFO, - "piclevent: posting ename:%s failed err:%d\n", - ename, err); - free(ename); - free(packed_nvl); - } -} - -/* - * This is the PICL SLM door handler. It parses the event tuple received - * and posts an event to refresh the PICL tree. - */ -/*ARGSUSED*/ -static void -event_handler(void *cookie, char *argp, size_t asize, - door_desc_t *dp, uint_t n_desc) -{ - door_cred_t cred; - nvlist_t *nvlp; - char *dtype; - - if (piclevent_debug) - syslog(LOG_INFO, - "piclevent: got SLM event cookie:%p evarg:%p size:0x%x\n", - cookie, argp, asize); - if ((door_id < 0) || (argp == NULL) || (door_cred(&cred) < 0) || - (cred.dc_euid != 0)) - (void) door_return(argp, 0, NULL, 0); - - if (nvlist_unpack(argp, asize, &nvlp, 0)) - (void) door_return(argp, 0, NULL, 0); - - if (nvlist_lookup_string(nvlp, PICLEVENTARG_DATA_TYPE, &dtype)) { - nvlist_free(nvlp); - (void) door_return(argp, 0, NULL, 0); - } - - if (strcmp(dtype, PICLEVENTARG_PICLEVENT_DATA) == 0) - parse_piclevent(nvlp); - /* - * ignore other event data types - */ - nvlist_free(nvlp); - (void) door_return(argp, 0, NULL, 0); -} - -/* - * Create the slm to picl plugin door - */ -static int -setup_door(void) -{ - struct stat stbuf; - - /* - * Create the door - */ - door_id = door_create(event_handler, PICLEVENT_DOOR_COOKIE, - DOOR_REFUSE_DESC | DOOR_NO_CANCEL); - - if (door_id < 0) - return (-1); - - if (stat(PICLEVENT_DOOR, &stbuf) < 0) { - int newfd; - if ((newfd = creat(PICLEVENT_DOOR, 0444)) < 0) { - (void) door_revoke(door_id); - door_id = -1; - return (-1); - } - (void) close(newfd); - } - - if (fattach(door_id, PICLEVENT_DOOR) < 0) { - if ((errno != EBUSY) || (fdetach(PICLEVENT_DOOR) < 0) || - (fattach(door_id, PICLEVENT_DOOR) < 0)) { - (void) door_revoke(door_id); - door_id = -1; - return (-1); - } - } - - return (0); -} - - -/* - * This function is executed as part of .init when the plugin is - * dlopen()ed - */ -static void -eventplugin_register(void) -{ - if (getenv(SUNW_PICLEVENT_PLUGIN_DEBUG)) - piclevent_debug = 1; - (void) picld_plugin_register(&my_reg_info); -} - -/* - * This function is the init entry point of the plugin. - * It creates the slm to picl plugin door. - */ -static void -eventplugin_init(void) -{ - if (setup_door() < 0) { - syslog(LOG_ERR, EVT_OPEN_FAILED); - } -} - -/* - * This function is the fini entry point of the plugin - */ -static void -eventplugin_fini(void) -{ - if (door_id >= 0) { - (void) door_revoke(door_id); - door_id = -1; - } -} diff --git a/usr/src/cmd/picl/plugins/common/piclevent/piclevent.h b/usr/src/cmd/picl/plugins/common/piclevent/piclevent.h deleted file mode 100644 index a9d1894de5..0000000000 --- a/usr/src/cmd/picl/plugins/common/piclevent/piclevent.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2000-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef _PICLEVENT_H -#define _PICLEVENT_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "picldefs.h" - -#define PICLEVENT_DOOR "/etc/sysevent/piclevent_door" -#define PICLEVENT_DOOR_COOKIE ((void *)0xdabe5555) - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLEVENT_H */ diff --git a/usr/src/cmd/picl/plugins/inc/picldefs.h b/usr/src/cmd/picl/plugins/inc/picldefs.h deleted file mode 100644 index 95efac27f6..0000000000 --- a/usr/src/cmd/picl/plugins/inc/picldefs.h +++ /dev/null @@ -1,366 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICLDEFS_H -#define _PICLDEFS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * PICL Tree paths - */ -#define PLATFORM_PATH "/platform" -#define MEMORY_PATH "/platform/memory" -#define FRUTREE_PATH "/frutree" -#define PICL_FRUTREE_CHASSIS "/frutree/chassis" - -/* - * PICL classes - */ -#define PICL_CLASS_BYTE "byte" -#define PICL_CLASS_BLOCK "block" -#define PICL_CLASS_DISK "disk" -#define PICL_CLASS_CDROM "cdrom" -#define PICL_CLASS_FLOPPY "floppy" -#define PICL_CLASS_TAPE "tape" -#define PICL_CLASS_FABRIC "fabric" -#define PICL_CLASS_SAS "sas" -#define PICL_CLASS_ATTACHMENT_POINT "attachment-point" -#define PICL_CLASS_DISPLAY "display" -#define PICL_CLASS_SERIAL "serial" -#define PICL_CLASS_PARALLEL "parallel" -#define PICL_CLASS_SEEPROM "seeprom" -#define PICL_CLASS_KEYBOARD "keyboard" -#define PICL_CLASS_MOUSE "mouse" -#define PICL_CLASS_MEMORY "memory" -#define PICL_CLASS_I2C "i2c" -#define PICL_CLASS_USB "usb" -#define PICL_CLASS_ISA "isa" -#define PICL_CLASS_DMA "dma" -#define PICL_CLASS_OBP_DEVICE "obp-device" -#define PICL_CLASS_TEMPERATURE_DEVICE "temperature-device" -#define PICL_CLASS_TEMPERATURE_SENSOR "temperature-sensor" -#define PICL_CLASS_TEMPERATURE_INDICATOR "temperature-indicator" -#define PICL_CLASS_VOLTAGE_INDICATOR "voltage-indicator" -#define PICL_CLASS_VOLTAGE_SENSOR "voltage-sensor" -#define PICL_CLASS_CURRENT_INDICATOR "current-indicator" -#define PICL_CLASS_CURRENT_SENSOR "current-sensor" -#define PICL_CLASS_LED "led" -#define PICL_CLASS_FAN "fan" -#define PICL_CLASS_FAN_CONTROL "fan-control" -#define PICL_CLASS_KEYSWITCH "keyswitch" -#define PICL_CLASS_EBUS "ebus" -#define PICL_CLASS_SYSTEM_CONTROLLER "system-controller" -#define PICL_CLASS_SERVICE_PROCESSOR "service-processor" -#define PICL_CLASS_HARDWARE_MONITOR "hardware-monitor" -#define PICL_CLASS_FLASHPROM "flashprom" -#define PICL_CLASS_SEEPROM "seeprom" -#define PICL_CLASS_FIREWIRE "firewire" -#define PICL_CLASS_I86CPUS "cpus" -#define PICL_CLASS_CPU "cpu" -#define PICL_CLASS_UPA "upa" -#define PICL_CLASS_PCI "pci" -#define PICL_CLASS_PCIEX "pciex" -#define PICL_CLASS_PMU "pmu" -#define PICL_CLASS_SOUND "sound" -#define PICL_CLASS_SBUS "sbus" -#define PICL_CLASS_SCSI "scsi" -#define PICL_CLASS_SCSI2 "scsi-2" -#define PICL_CLASS_GPTWO "gptwo" -#define PICL_CLASS_JBUS "jbus" -#define PICL_CLASS_MEMORY "memory" -#define PICL_CLASS_MEMORY_SEGMENT "memory-segment" -#define PICL_CLASS_MEMORY_BANK "memory-bank" -#define PICL_CLASS_MEMORY_CONTROLLER "memory-controller" -#define PICL_CLASS_MEMORY_MODULE_GROUP "memory-module-group" -#define PICL_CLASS_MEMORY_MODULE "memory-module" -#define PICL_CLASS_FRU "fru" -#define PICL_CLASS_LOCATION "location" -#define PICL_CLASS_SECTION "fru-section" -#define PICL_CLASS_SEGMENT "fru-segment" -#define PICL_CLASS_PORT "port" -#define PICL_CLASS_WATCHDOG_CONTROLLER "watchdog-controller" -#define PICL_CLASS_WATCHDOG_TIMER "watchdog-timer" -#define PICL_CLASS_CHASSIS_SERIAL_NUM "chassis-serial-number" -#define PICL_CLASS_MULTIPATH "multipath" - -/* - * Sun4v platforms do not create /frutree; instead they create - * the /physical-platform subtree. The following is the list of - * additional PICL classes that may be present in /physical-platform - */ -#define PICL_CLASS_ALARM "alarm" -#define PICL_CLASS_BACKPLANE "backplane" -#define PICL_CLASS_BATTERY "battery" -#define PICL_CLASS_CHASSIS "chassis" -#define PICL_CLASS_CONTAINER "container" -#define PICL_CLASS_MODULE "module" -#define PICL_CLASS_OTHER "other" -#define PICL_CLASS_POWERSUPPLY "power-supply" -#define PICL_CLASS_RPM_INDICATOR "rpm-indicator" -#define PICL_CLASS_RPM_SENSOR "rpm-sensor" -#define PICL_CLASS_PRESENCE_INDICATOR "presence-indicator" -#define PICL_CLASS_INDICATOR "indicator" -#define PICL_CLASS_SENSOR "sensor" -#define PICL_CLASS_STACK "stack" -#define PICL_CLASS_UNKNOWN "unknown" - -/* - * Solaris driver property names - */ -#define PICL_PROP_INSTANCE "instance" -#define PICL_PROP_BINDING_NAME "binding-name" -#define PICL_PROP_BUS_ADDR "bus-addr" -#define PICL_PROP_DRIVER_NAME "driver-name" -#define PICL_PROP_DEVFS_PATH "devfs-path" -#define PICL_PROP_STATUS "status" - -/* - * PICL property names - */ -#define PICL_PROP_PLATFORM_NAME "PlatformName" -#define PICL_PROP_SYSNAME "OS-Name" -#define PICL_PROP_NODENAME "HostName" -#define PICL_PROP_MACHINE "PlatformGroup" -#define PICL_PROP_RELEASE "OS-Release" -#define PICL_PROP_VERSION "OS-Version" -#define PICL_PROP_SIZE "Size" -#define PICL_PROP_ID "ID" -#define PICL_PROP_STATE "State" -#define PICL_PROP_PROCESSOR_TYPE "ProcessorType" -#define PICL_PROP_FPUTYPE "FPUType" -#define PICL_PROP_STATE_BEGIN "StateBegin" -#define PICL_PROP_FFB_BOARD_REV "FFB-Board-Rev" -#define PICL_PROP_FFB_FBRAM_VER "FFB-FBRAM-Ver" -#define PICL_PROP_FFB_DAC_VER "FFB-DAC-Ver" -#define PICL_PROP_UNIT_ADDRESS "UnitAddress" -#define PICL_PROP_SLOT "Slot" -#define PICL_PROP_DEVICE_ID "DeviceID" -#define PICL_PROP_TRANSFER_SIZE "TransferSize" -#define PICL_PROP_BASEADDRESS "BaseAddress" -#define PICL_PROP_INTERLEAVE_FACTOR "InterleaveFactor" -#define PICL_PROP_ADDRESSMASK "AddressMask" -#define PICL_PROP_ADDRESSMATCH "AddressMatch" -#define PICL_PROP_LABEL "Label" -#define PICL_PROP_CONTAINER "Container" -#define PICL_PROP_OFFSET "Offset" -#define PICL_PROP_LENGTH "Length" -#define PICL_PROP_PROTECTED "Protected" -#define PICL_PROP_NUM_SEGMENTS "#Segments" -#define PICL_PROP_DESCRIPTOR "Descriptor" -#define PICL_PROP_PACKET_TABLE "PacketTable" -#define PICL_PROP_NUM_TAGS "#Packets" -#define PICL_PROP_ADD_SEGMENT "AddSegment" -#define PICL_PROP_DELETE_PACKET "DeletePacket" -#define PICL_PROP_ADD_PACKET "AddPacket" -#define PICL_PROP_DELETE_SEGMENT "DeleteSegment" -#define PICL_PROP_TAG "Tag" -#define PICL_PROP_PAYLOAD "Payload" -#define PICL_PROP_FRUDATA_AVAIL "FRUDataAvailable" -#define PICL_PROP_DEVICEPATH "FRUDevicePath" -#define PICL_PROP_FAN_SPEED "Speed" -#define PICL_PROP_FAN_SPEED_UNIT "SpeedUnit" -#define PICL_PROP_TEMPERATURE "Temperature" -#define PICL_PROP_CPU_AMB_TEMP "AmbientTemperature" -#define PICL_PROP_CPU_DIE_TEMP "Temperature" -#define PICL_PROP_IS_LOCATOR "IsLocator" -#define PICL_PROP_LOCATOR_NAME "LocatorName" -#define PICL_PROP_DEVICES "Devices" -#define PICL_PROP_ENV "Environment" -#define PICL_PROP_COLOR "Color" -#define PICL_PROP_SC_HANDLE "SC_handle" -#define PICL_PROP_FRU_TYPE "FRUType" -#define PICL_PROP_SLOT_TYPE "SlotType" -#define PICL_PROP_OPERATIONAL_STATUS "OperationalStatus" -#define PICL_PROP_VOLTAGE "Voltage" -#define PICL_PROP_CURRENT "Current" -#define PICL_PROP_CLASS "Class" -#define PICL_PROP_CONDITION "Condition" -#define PICL_REFPROP_LOC_PARENT "_location_parent" -#define PICL_REFPROP_FRU_PARENT "_fru_parent" -#define PICL_REFPROP_PORT_PARENT "_port_parent" -#define PICL_REFPROP_MEMORY_MODULE_GROUP "_memory-module-group_" -#define PICL_REFPROP_MEMORY_MODULE "_memory-module_" -#define PICL_REFPROP_SEEPROM_SRC "_seeprom_source" -#define PICL_PROP_DEVICE_TYPE "device_type" -#define PICL_PROP_PROBE_PATH "PdevProbePath" -#define PICL_PROP_WATCHDOG_ACTION "WdAction" -#define PICL_PROP_WATCHDOG_TIMEOUT "WdTimeout" -#define PICL_PROP_WATCHDOG_OPERATION "WdOp" -#define PICL_PROP_STATUS_TIME "StatusTime" -#define PICL_PROP_CONDITION "Condition" -#define PICL_PROP_CONDITION_TIME "ConditionTime" -#define PICL_PROP_CHASSIS_TYPE "ChassisType" -#define PICL_PROP_GEO_ADDR "GeoAddr" -#define PICL_PROP_ADMIN_LOCK "AdminLock" -#define PICL_PROP_PORT_TYPE "PortType" -#define PICL_PROP_SERIAL_NUMBER "SerialNumber" - -#define PICL_UNITADDR_LEN_MAX 256 - -/* - * Additional PICL properties for Sun4v platforms - */ -#define PICL_PROP_BATTERY_STATUS "BatteryStatus" -#define PICL_PROP_EXPECTED "Expected" -#define PICL_PROP_FW_REVISION "FW-version" -#define PICL_PROP_HW_REVISION "HW-version" -#define PICL_PROP_IS_REPLACEABLE "Replaceable" -#define PICL_PROP_IS_HOT_SWAPPABLE "HotSwappable" -#define PICL_PROP_IS_FRU "FRU" -#define PICL_PROP_PHYS_DESCRIPTION "Description" -#define PICL_PROP_SPEED "Speed" -#define PICL_PROP_MFG_NAME "MfgName" -#define PICL_PROP_MODEL_NAME "ModelName" -#define PICL_PROP_SENSOR_VALUE "SensorValue" -#define PICL_PROP_BASE_UNITS "BaseUnits" -#define PICL_PROP_EXPONENT "Exponent" -#define PICL_PROP_RATE_UNITS "RateUnits" - -/* - * Various threshold property names - */ -#define PICL_PROP_LOW_POWER_OFF "LowPowerOffThreshold" -#define PICL_PROP_LOW_SHUTDOWN "LowShutdownThreshold" -#define PICL_PROP_LOW_WARNING "LowWarningThreshold" -#define PICL_PROP_TARGET_TEMPERATURE "TargetTemperature" -#define PICL_PROP_HIGH_POWER_OFF "HighPowerOffThreshold" -#define PICL_PROP_HIGH_SHUTDOWN "HighShutdownThreshold" -#define PICL_PROP_HIGH_WARNING "HighWarningThreshold" - -/* - * OBP property names - */ -#define OBP_PROP_UPA_PORTID "upa-portid" -#define OBP_PROP_PORTID "portid" -#define OBP_PROP_CPUID "cpuid" -#define OBP_PROP_SIZE_CELLS "#size-cells" -#define OBP_PROP_ADDRESS_CELLS "#address-cells" - -/* - * PICL Event names - */ -#define PICLEVENT_SYSEVENT_DEVICE_ADDED "sysevent-device-added" -#define PICLEVENT_SYSEVENT_DEVICE_REMOVED "sysevent-device-removed" -#define PICLEVENT_DR_AP_STATE_CHANGE "dr-ap-state-change" -#define PICLEVENT_MC_ADDED "picl-memory-controller-added" -#define PICLEVENT_MC_REMOVED "picl-memory-controller-removed" -#define PICLEVENT_STATE_CHANGE "picl-state-change" -#define PICLEVENT_CONDITION_CHANGE "picl-condition-change" -#define PICLEVENT_CPU_STATE_CHANGE "picl-cpu-node-state-change" -#define PICLEVENT_DR_REQ "dr-req" - -/* - * Contract Private - */ -#define PICL_FRU_ADDED "picl-fru-added" /* PSARC/2000/546 */ -#define PICL_FRU_REMOVED "picl-fru-removed" /* PSARC/2000/546 */ - -/* - * PICL Event Argument Names - */ -#define PICLEVENTARG_DEVFS_PATH "devfs-path" -#define PICLEVENTARG_AP_ID "ap-id" -#define PICLEVENTARG_HINT "hint" -#define PICLEVENTARG_NODEHANDLE "picl-nodehandle" -#define PICLEVENTARG_DR_REQ_TYPE "req-type" -#define PICLEVENTARG_CPU_EV_TYPE "cpu-ev-type" -#define PICLEVENTARG_STATE "State" -#define PICLEVENTARG_LAST_STATE "LastState" -#define PICLEVENTARG_CONDITION "Condition" - -/* - * PICL Label Names - */ -#define PICL_PROPVAL_LABEL_DIE "Die" -#define PICL_PROPVAL_LABEL_AMBIENT "Ambient" - -/* - * Contract Private - */ -#define PICLEVENTARG_FRUHANDLE "picl-fru-handle" /* PSARC/2000/546 */ -#define PICLEVENTARG_PARENTHANDLE "picl-parent-handle" /* 2000/546 */ - -/* - * The following are PICL PRIVATE event argument names - */ -#define PICLEVENTARG_EVENT_NAME "piclevent-name" -#define PICLEVENTARG_DATA_TYPE "piclevent-data-type" - -/* - * The following are values of piclevent-data-type (PRIVATE) - */ -#define PICLEVENTARG_PICLEVENT_DATA "piclevent-data" - -/* These values are used for PICLEVENT_CPU_STATE_CHANGE event */ -#define PICLEVENTARGVAL_ONLINE "Online" -#define PICLEVENTARGVAL_OFFLINE "Offline" - -/* - * These values are used for PICLEVENT_STATE_CHANGE, - * PICLEVENT_CONDITION_CHANGE event - */ -#define PICLEVENTARGVAL_UNKNOWN "unknown" -#define PICLEVENTARGVAL_OK "ok" -#define PICLEVENTARGVAL_FAILING "failing" -#define PICLEVENTARGVAL_FAILED "failed" -#define PICLEVENTARGVAL_TESTING "testing" -#define PICLEVENTARGVAL_UNUSABLE "unusable" -#define PICLEVENTARGVAL_CONNECTING "connecting" -#define PICLEVENTARGVAL_DISCONNECTING "disconnecting" -#define PICLEVENTARGVAL_CONNECTED "connected" -#define PICLEVENTARGVAL_DISCONNECTED "disconnected" -#define PICLEVENTARGVAL_EMPTY "empty" -#define PICLEVENTARGVAL_CONFIGURED "configured" -#define PICLEVENTARGVAL_UNCONFIGURED "unconfigured" -#define PICLEVENTARGVAL_CONFIGURING "configuring" -#define PICLEVENTARGVAL_UNCONFIGURING "unconfiguring" -#define PICLEVENTARGVAL_UP "up" -#define PICLEVENTARGVAL_DOWN "down" - -/* PSARC 2003/163 */ -#define PICLEVENTARGVAL_SENSOR_COND_WARNING "warning" -#define PICLEVENTARGVAL_SENSOR_COND_SHUTDOWN "shutdown" - -/* PSARC 2003/231 */ -/* watchdog property values */ -#define PICL_PROPVAL_WD_OP_ARM "arm" -#define PICL_PROPVAL_WD_OP_DISARM "disarm" -#define PICL_PROPVAL_WD_ACTION_NONE "none" -#define PICL_PROPVAL_WD_ACTION_REBOOT "reboot" -#define PICL_PROPVAL_WD_ACTION_ALARM "alarm" -#define PICL_PROPVAL_WD_ACTION_RESET "reset" -#define PICL_PROPVAL_WD_STATE_ARMED "armed" -#define PICL_PROPVAL_WD_STATE_DISARMED "disarmed" -#define PICL_PROPVAL_WD_STATE_EXPIRED "expired" - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLDEFS_H */ diff --git a/usr/src/cmd/picl/plugins/lib/Makefile b/usr/src/cmd/picl/plugins/lib/Makefile deleted file mode 100644 index dd3651618e..0000000000 --- a/usr/src/cmd/picl/plugins/lib/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1999-2000 by Sun Microsystems, Inc. -# All rights reserved. -# -# cmd/picl/plugins/lib/Makefile -# -SUBDIRS= picld_pluginutil - -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -.KEEP_STATE: - -all clean clobber _msg : $(SUBDIRS) - -install: $(SUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile deleted file mode 100644 index 6a037e1d4c..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include $(SRC)/lib/Makefile.lib - -SUBDIRS = $(MACH) - -# conditional assignments -all := TARGET= all -clean := TARGET= clean -clobber := TARGET= clobber -install := TARGET= install -_msg := TARGET= _msg - -.KEEP_STATE: - -all clean clobber install _msg: $(SUBDIRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: - diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile.com b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile.com deleted file mode 100644 index 915b1d13a3..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/Makefile.com +++ /dev/null @@ -1,69 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -LIBRARY= libpicld_pluginutil.a -VERS= .1 - -OBJECTS= picld_pluginutil.o - -# include library definitions -include $(SRC)/lib/Makefile.lib - -SRCS= $(OBJECTS:%.o=../%.c) - -CLOBBERFILES += $(LIBLINKS) - -LIBS = $(DYNLIB) - -XGETFLAGS += -a -POFILE= picld_pluginutil.po - -CPPFLAGS += -I.. -I$(SRC)/lib/libpicl -I$(SRC)/lib/libpicltree -CERRWARN += -Wno-uninitialized -DYNFLAGS += $(ZNOLAZYLOAD) -LDLIBS += -L$(SRC)/lib/libpicltree/$(MACH) -LDLIBS += -lc -lpicltree - -.KEEP_STATE: - -all : $(LIBS) - -%.po: ../%.c - $(CP) $< $<.i - $(BUILD.po) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - -$(MSGDOMAIN): - $(INS.dir) - -# include library targets -include $(SRC)/lib/Makefile.targ - -pics/%.o: ../%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/i386/Makefile b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/i386/Makefile deleted file mode 100644 index 62d7e08451..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/i386/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com - -.KEEP_STATE: - -all: $(ROOTLIBDIR) $(LIBS) $(LIBLINKS) - -$(LIBLINKS): - $(RM) $@; $(SYMLINK) $(DYNLIB) $@ - -$(ROOTLIBDIR): - $(INS.dir) - -install: all $(ROOTLIBS) $(ROOTLINKS) diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/mapfile-vers b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/mapfile-vers deleted file mode 100644 index 38fed34ab8..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/mapfile-vers +++ /dev/null @@ -1,46 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. -# - -# -# MAPFILE HEADER START -# -# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. -# Object versioning must comply with the rules detailed in -# -# usr/src/lib/README.mapfiles -# -# You should not be making modifications here until you've read the most current -# copy of that file. If you need help, contact a gatekeeper for guidance. -# -# MAPFILE HEADER END -# - -$mapfile_version 2 - -SYMBOL_VERSION SUNWprivate_1.1 { - global: - picld_pluginutil_parse_config_file; - local: - *; -}; diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.c b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.c deleted file mode 100644 index c8e74051b5..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.c +++ /dev/null @@ -1,1698 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * This module implements the routine to parse the configuration file. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "picld_pluginutil.h" -#include "picld_pluginutil_impl.h" - -/* error codes returned from syntax checking */ -#define EC_SYNTAX_OK 0 -#define EC_INSUFFICIENT_TOKEN 1 -#define EC_SYNTAX_ERR 2 -#define EC_UNSUPPORTED 3 -#define EC_PATH_ERR 4 -#define EC_NODE_MISMATCH 5 -#define EC_FAILURE 6 -#define EC_PICL_ERR 7 -#define EC_TABLE_MISMATCH 8 -#define EC_ROW_MISMATCH 9 -#define EC_ROW_EMPTY 10 - -/* - * Error message texts - */ -static char *err_msg[] = { - "%s: Syntax OK", /* 0 */ - "%s::%s[line %d]: Insufficient token\n", /* 1 */ - "%s::%s[line %d]: Syntax error\n", /* 2 */ - "%s::%s[line %d]: Unsupported or missing version\n", /* 3 */ - "%s::%s[line %d]: Illegal use of nodepath or namepath\n", /* 4 */ - "%s::%s[line %d]: Node and endnode mismatch\n", /* 5 */ - "%s::%s[line %d]: General system failure\n", /* 6 */ - "%s: PICL error code %d\n", /* 7 */ - "%s::%s[line %d]: Table and endtable mismatch\n", /* 8 */ - "%s::%s[line %d]: Row and endrow mismatch\n", /* 9 */ - "%s::%s[line %d]: Row has no entries \n" /* 10 */ -}; - -/* token per directive */ -#define TOK_CLASSPATH 0 -#define TOK_NAMEPATH 1 -#define TOK_NODE 2 -#define TOK_ENDNODE 3 -#define TOK_PROP 4 -#define TOK_REFPROP 5 -#define TOK_VERSION 6 -#define TOK_REFNODE 7 -#define TOK_VERBOSE 8 -#define TOK_TABLE 9 -#define TOK_ENDTABLE 10 -#define TOK_ROW 11 -#define TOK_ENDROW 12 - -static const char *tokens[] = { - "_class", /* _CLASS: */ - "name", /* NAME: */ - "node", /* NODE */ - "endnode", /* ENDNODE */ - "prop", /* PROP */ - "refprop", /* REFPROP */ - "version", /* VERSION */ - "refnode", /* REFNODE WITH */ - "verbose", /* VERBOSE */ - "table", /* TABLE */ - "endtable", /* ENDTABLE */ - "row", /* ROW */ - "endrow" /* ENDROW */ -}; - -#define BUF_SIZE_MAX 1024 - -/* - * print error message - */ -/*VARARGS2*/ -static void -verbose_log(int pri, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog(pri, fmt, ap); - va_end(ap); -} - -/* - * Undo the commands which have created valid node/prop handle - * The undo order is from last command to the first command. - */ -static void -undo_commands(cmdbuf_t *cmds, int last_cmd_index) -{ - int i; - command_t *com = cmds->commands; - - for (i = last_cmd_index; i >= 0; i--) { - switch (com[i].type) { - case TOK_NODE: - if (com[i].nodecmd_nodeh == 0) - break; - - (void) ptree_delete_node(com[i].nodecmd_nodeh); - (void) ptree_destroy_node(com[i].nodecmd_nodeh); - break; - case TOK_REFNODE: - if (com[i].refnodecmd_nodeh == 0) - break; - (void) ptree_delete_node(com[i].refnodecmd_nodeh); - (void) ptree_destroy_node(com[i].refnodecmd_nodeh); - break; - case TOK_PROP: - if (com[i].propcmd_proph == 0) - break; - (void) ptree_delete_prop(com[i].propcmd_proph); - (void) ptree_destroy_prop(com[i].propcmd_proph); - break; - case TOK_REFPROP: - if (com[i].refpropcmd_proph == 0) - break; - (void) ptree_delete_prop(com[i].refpropcmd_proph); - (void) ptree_destroy_prop(com[i].refpropcmd_proph); - break; - case TOK_TABLE: - if ((com[i].tablecmd_tblh == 0) || - (com[i].tablecmd_newtbl == 0)) - break; - (void) ptree_delete_prop(com[i].tablecmd_tblh); - (void) ptree_destroy_prop(com[i].tablecmd_tblh); - break; - case TOK_ENDTABLE: - /*FALLTHROUGH*/ - case TOK_ROW: - /*FALLTHROUGH*/ - case TOK_ENDROW: - /*FALLTHROUGH*/ - case TOK_NAMEPATH: - /*FALLTHROUGH*/ - case TOK_CLASSPATH: - /*FALLTHROUGH*/ - case TOK_ENDNODE: - /*FALLTHROUGH*/ - case TOK_VERBOSE: - /*FALLTHROUGH*/ - default: - break; - } - } -} - -/* - * Get the token index from the tokens table - */ -static int -get_token_id(char *t) -{ - int i; - - for (i = 0; i < sizeof (tokens)/ sizeof (char *); ++i) - if (strcasecmp(tokens[i], t) == 0) - return (i); - - return (-1); -} - -/* - * Check the version syntax and set the version_no - * - * VERSION -- specify the configuration version - */ -static int -parse_version(cmdbuf_t *cmds, char *line) -{ - char *tok; - char *vertok; - char *last; - char *endptr; - - /* get the VERSION directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the version number */ - vertok = strtok_r(last, WHITESPACE, &last); - if (vertok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - cmds->version_no = (float)strtod(vertok, &endptr); - if (endptr != (vertok + strlen(vertok))) - return (EC_UNSUPPORTED); - - if (cmds->version_no > (float)SUPPORTED_VERSION_NUM) - return (EC_UNSUPPORTED); - - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - - return (EC_SYNTAX_OK); -} - -/* - * free path_cmd_t - */ -static void -free_path(command_t *command) -{ - free(command->pathcmd_name); -} - -/* - * Check the path syntax - * NAMEPATH: -- gives the anchor node - * or - * CLASSPATH: -- gives the anchor node - */ -static int -parse_path(char *line, command_t *command) -{ - char *tok; - char *pathtok; - char *last; - - pathtok = strtok_r(line, WHITESPACE, &last); - if (pathtok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - - command->pathcmd_name = strdup(pathtok); - if (command->pathcmd_name == NULL) - return (EC_FAILURE); - - return (EC_SYNTAX_OK); -} - -/* - * Process the path command and return PICL node handle - */ -static int -process_path(command_t *command, picl_nodehdl_t *nodeh) -{ - int err; - - err = ptree_get_node_by_path(command->pathcmd_name, nodeh); - return (err); -} - -/* - * free node_cmd_t - */ -static void -free_node(command_t *command) -{ - free(command->nodecmd_nodename); - free(command->nodecmd_classname); -} - -/* - * Check the NODE syntax - * NODE - */ -static int -parse_node(char *line, command_t *command) -{ - char *tok; - char *nametok; - char *classtok; - char *last; - - /* get the NODE directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get name */ - nametok = strtok_r(last, WHITESPACE, &last); - if (nametok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - classtok = strtok_r(last, WHITESPACE, &last); - if (classtok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - - command->nodecmd_nodename = strdup(nametok); - command->nodecmd_classname = strdup(classtok); - command->nodecmd_nodeh = 0; - if ((command->nodecmd_nodename == NULL) || - (command->nodecmd_classname == NULL)) - return (EC_FAILURE); - - return (EC_SYNTAX_OK); -} - -/* - * Process the NODE command and return PICL node handle - */ -static int -process_node(command_t *command, picl_nodehdl_t parh, picl_nodehdl_t *nodeh) -{ - int err; - - err = ptree_create_and_add_node(parh, command->nodecmd_nodename, - command->nodecmd_classname, nodeh); - - if (err == PICL_SUCCESS) - command->nodecmd_nodeh = *nodeh; - - return (err); -} - -/* - * get the PICL property type - */ -static int -getpicltype(char *type) -{ - if (strcasecmp(type, KEYWORD_INT_TYPE) == 0) - return (PICL_PTYPE_INT); - else if (strcasecmp(type, KEYWORD_UINT_TYPE) == 0) - return (PICL_PTYPE_UNSIGNED_INT); - else if (strcasecmp(type, KEYWORD_FLOAT_TYPE) == 0) - return (PICL_PTYPE_FLOAT); - else if (strcasecmp(type, KEYWORD_STRING_TYPE) == 0) - return (PICL_PTYPE_CHARSTRING); - else if (strcasecmp(type, KEYWORD_VOID_TYPE) == 0) - return (PICL_PTYPE_VOID); - else - return (-1); -} - -/* - * get the PICL accessmode mode - */ -static int -getpiclmode(char *mode) -{ - if (strcasecmp(mode, KEYWORD_READ_MODE) == 0) - return (PICL_READ); - else if (strcasecmp(mode, KEYWORD_WRITE_MODE) == 0) - return (PICL_WRITE); - else if (strcasecmp(mode, KEYWORD_READWRITE_MODE) == 0) - return (PICL_READ|PICL_WRITE); - else - return (-1); -} - -/* - * check if the size and value are valid given by the prop type - */ -static int -validate_size_and_cvt_val(void *outbuf, size_t size, int type, char *val) -{ - int64_t llval; - int32_t intval; - int16_t sval; - int8_t cval; - uint64_t ullval; - uint32_t uintval; - uint16_t usval; - uint8_t ucval; - float fval; - double dval; - char *endptr; - - switch (type) { - case PICL_PTYPE_CHARSTRING: - break; - case PICL_PTYPE_INT: - switch (size) { - case sizeof (int64_t): - llval = strtoll(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &llval, size); - break; - case sizeof (int32_t): - intval = strtol(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &intval, size); - break; - case sizeof (int16_t): - sval = (int16_t)strtol(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &sval, size); - break; - case sizeof (int8_t): - cval = (int8_t)strtol(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &cval, size); - break; - default: /* invalid size */ - return (EC_SYNTAX_ERR); - } - break; - case PICL_PTYPE_UNSIGNED_INT: - switch (size) { - case sizeof (uint64_t): - ullval = strtoull(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &ullval, size); - break; - case sizeof (uint32_t): - uintval = strtoul(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &uintval, size); - break; - case sizeof (uint16_t): - usval = (uint16_t)strtoul(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &usval, size); - break; - case sizeof (uint8_t): - ucval = (uint8_t)strtoul(val, &endptr, 0); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &ucval, size); - break; - default: /* invalid size */ - return (EC_SYNTAX_ERR); - } - break; - case PICL_PTYPE_FLOAT: - switch (size) { - case sizeof (double): - dval = strtod(val, &endptr); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &dval, size); - break; - case sizeof (float): - fval = (float)strtod(val, &endptr); - if (endptr != (val + strlen(val))) - return (EC_SYNTAX_ERR); - (void) memcpy(outbuf, &fval, size); - break; - default: /* invalid size */ - return (EC_SYNTAX_ERR); - } - break; - default: /* not supported type */ - return (EC_SYNTAX_ERR); - } - - return (EC_SYNTAX_OK); -} - -/* - * free prop_cmd_t - */ -static void -free_prop(command_t *command) -{ - free(command->propcmd_pname); - if (command->propcmd_type != PICL_PTYPE_VOID) - free(command->propcmd_valbuf); -} - -/* - * return the string token in two double quotes - * The current version won't support multiple-line string - */ -static int -get_string_token(char *line, char **valtok) -{ - char *optr; /* ptr to the open quote */ - char *cptr; /* ptr to the close quote */ - char *ptr; - char *tmpbuf; - - if (line == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* skipping leading white spaces */ - optr = line; - while ((*optr == ' ') || (*optr == '\t') || (*optr == '\n')) - optr++; - - /* reach end of string */ - if (*optr == '\0') - return (EC_INSUFFICIENT_TOKEN); - - /* it's not an open double quote */ - if (*optr != '"') - return (EC_SYNTAX_ERR); - - /* skipping ending white spaces */ - cptr = line + strlen(line) - 1; - while ((*cptr == ' ') || (*cptr == '\t') || (*cptr == '\n')) - cptr--; - - /* it's not an close double quote */ - if (*cptr != '"') - return (EC_SYNTAX_ERR); - - /* close double quote is missing */ - if (cptr == optr) - return (EC_SYNTAX_ERR); - - /* replace close qoute by null to make a string */ - *cptr = '\0'; - /* move the begin pointer to the first char of string */ - optr++; - - tmpbuf = malloc(strlen(optr) + 1); - if (tmpbuf == NULL) - return (EC_FAILURE); - - for (ptr = tmpbuf; *optr != '\0'; ptr++, optr++) { - /* if escape character, go to next character */ - if (*optr == '\\') { - optr++; - if (*optr == '\0') { /* for exampe, "xxx\" */ - free(tmpbuf); - return (EC_SYNTAX_ERR); - } - } - *ptr = *optr; - } - - *ptr = '\0'; - *valtok = tmpbuf; - return (EC_SYNTAX_OK); -} - -/* - * Check the PROP syntax - * PROP [ ] - * supported prop types: void, int, uint, float, string - * supported prop access_modes: r, w, rw - * For void prop, and are not needed - * For string prop, will be set the actual string size if - * is 0 - */ -static int -parse_prop(char *line, command_t *command) -{ - char *tok; - char *pnametok; - int typetok; - size_t sizetok; - int modetok; - char *valtok; - char *last; - char *endptr; - int err; - - /* get the PROP directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the property name */ - pnametok = strtok_r(last, WHITESPACE, &last); - if (pnametok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the type */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - if ((typetok = getpicltype(tok)) < 0) - return (EC_SYNTAX_ERR); - - /* get mode */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - if ((modetok = getpiclmode(tok)) < 0) - return (EC_SYNTAX_ERR); - - if (typetok == PICL_PTYPE_VOID) { - /* ignore the rest of arguments */ - command->propcmd_valbuf = NULL; - command->propcmd_pname = strdup(pnametok); - if (command->propcmd_pname == NULL) - return (EC_FAILURE); - command->propcmd_type = typetok; - command->propcmd_accessmode = modetok; - command->propcmd_size = 0; - command->propcmd_proph = 0; - return (EC_SYNTAX_OK); - } - - /* get size */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - sizetok = (size_t)strtol(tok, &endptr, 0); - if (endptr != (tok + strlen(tok))) - return (EC_SYNTAX_ERR); - - /* get val */ - if (typetok == PICL_PTYPE_CHARSTRING) { - err = get_string_token(last, &valtok); - if (err != EC_SYNTAX_OK) - return (err); - if (sizetok == 0) - sizetok = strlen(valtok) + 1; - command->propcmd_valbuf = valtok; - } else { - valtok = strtok_r(last, WHITESPACE, &last); - if (valtok == NULL) - return (EC_INSUFFICIENT_TOKEN); - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - command->propcmd_valbuf = malloc(sizetok); - if (command->propcmd_valbuf == NULL) - return (EC_FAILURE); - err = validate_size_and_cvt_val(command->propcmd_valbuf, - sizetok, typetok, valtok); - if (err != EC_SYNTAX_OK) { - free(command->propcmd_valbuf); - return (err); - } - } - - command->propcmd_pname = strdup(pnametok); - if (command->propcmd_pname == NULL) - return (EC_FAILURE); - command->propcmd_type = typetok; - command->propcmd_accessmode = modetok; - command->propcmd_size = sizetok; - command->propcmd_proph = 0; - return (EC_SYNTAX_OK); -} - -/* - * Add a property to the row, the row gets added to the node at endrow - */ -static int -add_proph_to_row(command_t *command, picl_prophdl_t proph) -{ - if (command->rowcmd_index >= command->rowcmd_nproph) - return (PICL_FAILURE); - command->rowcmd_prophs[command->rowcmd_index] = proph; - command->rowcmd_index++; - return (PICL_SUCCESS); -} - -/* - * Process the PROP command and add the specified property under the given - * node handle - */ -static int -process_prop(cmdbuf_t *cmds, command_t *command, picl_nodehdl_t nodeh) -{ - ptree_propinfo_t propinfo; - picl_prophdl_t proph; - int err; - - /* prop in discarded row */ - if (cmds->inside_row_block && - cmds->commands[cmds->current_row].rowcmd_nproph == 0) - return (PICL_SUCCESS); - - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - command->propcmd_type, command->propcmd_accessmode, - command->propcmd_size, command->propcmd_pname, NULL, - NULL); - - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_prop(&propinfo, command->propcmd_valbuf, &proph); - - if (err != PICL_SUCCESS) - return (err); - - command->propcmd_proph = proph; - - if (cmds->inside_row_block) { - err = add_proph_to_row(&cmds->commands[cmds->current_row], - proph); - } else { - err = ptree_add_prop(nodeh, proph); - } - - return (err); -} - -/* - * free refnode_cmd_t - */ -static void -free_refnode(command_t *command) -{ - free(command->refnodecmd_name); - free(command->refnodecmd_class); - free(command->refnodecmd_dstnode); -} - -/* - * Check the REFNODE syntax - * - * REFNODE with -- if exists, - * create node with nodename and piclclass - */ -static int -parse_refnode(char *line, command_t *command) -{ - char *tok; - char *dsttok; - char *classnm; - char *nodenm; - char *last; - - /* get the directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the nodename */ - nodenm = strtok_r(last, WHITESPACE, &last); - if (nodenm == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the class */ - classnm = strtok_r(last, WHITESPACE, &last); - if (classnm == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the WITH keyword */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - if (strcasecmp(tok, KEYWORD_WITH_STR) != 0) - return (EC_SYNTAX_ERR); - - /* get the dst node */ - dsttok = strtok_r(last, WHITESPACE, &last); - if (dsttok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - - command->refnodecmd_name = strdup(nodenm); - command->refnodecmd_class = strdup(classnm); - command->refnodecmd_dstnode = strdup(dsttok); - command->refnodecmd_nodeh = 0; - if ((command->refnodecmd_name == NULL) || - (command->refnodecmd_class == NULL) || - (command->refnodecmd_dstnode == NULL)) - return (EC_FAILURE); - - return (EC_SYNTAX_OK); -} - -/* - * Process the REFNODE command - */ -static int -process_refnode(command_t *command, picl_nodehdl_t parh) -{ - picl_nodehdl_t dsth; - picl_nodehdl_t nodeh; - int err; - - if ((ptree_get_node_by_path(command->refnodecmd_dstnode, - &dsth) == PICL_SUCCESS)) { - err = ptree_create_and_add_node(parh, command->refnodecmd_name, - command->refnodecmd_class, &nodeh); - if (err == PICL_SUCCESS) - command->refnodecmd_nodeh = nodeh; - - return (err); - } - - return (PICL_SUCCESS); -} - -/* - * free refprop_cmd_t - */ -static void -free_refprop(command_t *command) -{ - free(command->refpropcmd_pname); - free(command->refpropcmd_dstnode); -} - -/* - * Check the REFPROP syntax - * - * REFPROP -- creates a reference property to - */ -static int -parse_refprop(char *line, command_t *command) -{ - char *tok; - char *pnametok; - char *dsttok; - char *last; - - /* get the REFPROP directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the propname */ - pnametok = strtok_r(last, WHITESPACE, &last); - if (pnametok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - dsttok = strtok_r(last, WHITESPACE, &last); - if (dsttok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - - command->refpropcmd_pname = strdup(pnametok); - command->refpropcmd_dstnode = strdup(dsttok); - command->refpropcmd_proph = 0; - if ((command->refpropcmd_pname == NULL) || - (command->refpropcmd_dstnode == NULL)) - return (EC_FAILURE); - - return (EC_SYNTAX_OK); -} - -/* - * Process the REFPROP command - */ -static int -process_refprop(cmdbuf_t *cmds, command_t *command, picl_nodehdl_t nodeh) -{ - int err; - picl_nodehdl_t dsth; - picl_prophdl_t proph; - ptree_propinfo_t propinfo; - - /* refprop in discarded row */ - if (cmds->inside_row_block && - cmds->commands[cmds->current_row].rowcmd_nproph == 0) - return (PICL_SUCCESS); - - /* try finding the refprop's dstnode */ - err = ptree_get_node_by_path(command->refpropcmd_dstnode, &dsth); - - /* dstnode doesn't exist, return */ - if (err != PICL_SUCCESS) - return (err); - - /* dstnode exists, try adding the refprop to nodeh */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_REFERENCE, PICL_READ, sizeof (picl_nodehdl_t), - command->refpropcmd_pname, NULL, NULL); - - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_prop(&propinfo, &dsth, &proph); - - if (err != PICL_SUCCESS) - return (err); - - command->refpropcmd_proph = proph; - - if (cmds->inside_row_block) { - err = add_proph_to_row(&cmds->commands[cmds->current_row], - proph); - } else { - err = ptree_add_prop(nodeh, proph); - } - - return (err); -} - -/* - * free table_cmd_t - */ -static void -free_table(command_t *command) -{ - free(command->tablecmd_tname); -} - -/* - * Check the TABLE syntax - * TABLE - * - */ -static int -parse_table(char *line, command_t *command) -{ - char *tok = NULL; - char *tnametok = NULL; - char *last = NULL; - - /* get the TABLE directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get the property name */ - tnametok = strtok_r(last, WHITESPACE, &last); - if (tnametok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - command->tablecmd_tname = strdup(tnametok); - if (command->tablecmd_tname == NULL) - return (EC_FAILURE); - - command->tablecmd_newtbl = 0; - command->tablecmd_tblh = 0; - - return (EC_SYNTAX_OK); -} - -/* - * Process the TABLE command and add the specified property under the given - * node handle - */ -static int -process_table(command_t *command, picl_nodehdl_t nodeh) -{ - int err; - picl_prophdl_t tblh; - picl_prophdl_t proph; - ptree_propinfo_t propinfo; - - /* find if table already exists */ - err = ptree_get_prop_by_name(nodeh, command->tablecmd_tname, &tblh); - if (err == PICL_SUCCESS) { - err = ptree_get_propinfo(tblh, &propinfo); - if (err != PICL_SUCCESS) - return (err); - /* prop with the same name as table? */ - if (propinfo.piclinfo.type != PICL_PTYPE_TABLE) - return (EC_SYNTAX_ERR); - command->tablecmd_newtbl = 0; - command->tablecmd_tblh = tblh; - return (PICL_SUCCESS); - } - - /* init and create a new table */ - err = ptree_init_propinfo(&propinfo, PTREE_PROPINFO_VERSION, - PICL_PTYPE_TABLE, PICL_READ|PICL_WRITE, - sizeof (picl_prophdl_t), command->tablecmd_tname, NULL, NULL); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_create_table(&tblh); - if (err != PICL_SUCCESS) - return (err); - - command->tablecmd_newtbl = 1; - command->tablecmd_tblh = tblh; - - err = ptree_create_prop(&propinfo, &tblh, &proph); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_add_prop(nodeh, proph); - - return (err); -} - -/* - * Process the ROW command by alloc'ing space to store the prop handles for - * the whole row. The number of props in the row gets known while parsing. - */ -static int -process_row(command_t *command) -{ - command->rowcmd_index = 0; - command->rowcmd_prophs = - malloc(command->rowcmd_nproph * sizeof (picl_prophdl_t)); - - if (command->rowcmd_prophs == NULL) - return (PICL_FAILURE); - - return (PICL_SUCCESS); -} - -/* - * Process the ENDROW command. If a valid row, add the row to the ptree. - */ -static int -process_endrow(cmdbuf_t *cmds) -{ - int err; - int i; - command_t *curr_row; - - curr_row = &cmds->commands[cmds->current_row]; - - /* if nproph == 0, some row prop had problems, don't add */ - if (curr_row->rowcmd_nproph == 0) { - for (i = 0; i < curr_row->rowcmd_index; i++) { - (void) ptree_delete_prop(curr_row->rowcmd_prophs[i]); - (void) ptree_destroy_prop(curr_row->rowcmd_prophs[i]); - } - err = PICL_SUCCESS; - } else - err = ptree_add_row_to_table( - cmds->commands[cmds->current_tbl].tablecmd_tblh, - curr_row->rowcmd_nproph, - curr_row->rowcmd_prophs); - - /* let go the space alloc'd in process_row */ - free(curr_row->rowcmd_prophs); - curr_row->rowcmd_prophs = NULL; - - return (err); -} - -/* - * Check the VERBOSE syntax - * VERBOSE - */ -static int -parse_verbose(cmdbuf_t *cmds, char *line, command_t *command) -{ - char *tok; - char *level; - char *last; - char *endptr; - int verbose_level; - - /* get the VERBOSE directive */ - tok = strtok_r(line, WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - /* get verbose level */ - level = strtok_r(last, WHITESPACE, &last); - if (level == NULL) - return (EC_INSUFFICIENT_TOKEN); - verbose_level = strtol(level, &endptr, 0); - if (endptr != (level + strlen(level))) - return (EC_SYNTAX_ERR); - - /* check if more tokens */ - tok = strtok_r(last, WHITESPACE, &last); - if (tok != NULL) - return (EC_SYNTAX_ERR); - - cmds->verbose = verbose_level; - command->verbosecmd_level = verbose_level; - - return (EC_SYNTAX_OK); -} - -/* - * Process the VERBOSE command to set the verbose level - */ -static int -process_verbose(cmdbuf_t *cmds, command_t *command) -{ - cmds->verbose = command->verbosecmd_level; - return (PICL_SUCCESS); -} - -/* - * parse and tokenize the line - */ -static int -parse_and_tokenize_line(cmdbuf_t *cmds, char *buf, command_t *command) -{ - char rec[RECORD_SIZE_MAX]; - char *tok; - int err; - char *last; - int id; - - (void) strcpy(rec, buf); - tok = strtok_r(rec, RECORD_WHITESPACE, &last); - if (tok == NULL) - return (EC_INSUFFICIENT_TOKEN); - - id = get_token_id(tok); - - (void) strcpy(rec, buf); - - switch (id) { - case TOK_VERSION: - err = parse_version(cmds, rec); - break; - case TOK_CLASSPATH: - case TOK_NAMEPATH: - if (cmds->inside_node_block != 0) - return (EC_PATH_ERR); - - err = parse_path(rec, command); - if (err != EC_SYNTAX_OK) - return (err); - break; - case TOK_NODE: - /* Check for NODE outside of TABLE, ROW */ - if ((cmds->inside_table_block != 0) || - (cmds->inside_row_block != 0)) - return (EC_SYNTAX_ERR); - err = parse_node(rec, command); - if (err != EC_SYNTAX_OK) - return (err); - cmds->inside_node_block++; - break; - case TOK_ENDNODE: - /* Check for ENDNODE outside of TABLE, ROW */ - if ((cmds->inside_table_block != 0) || - (cmds->inside_row_block != 0)) - return (EC_SYNTAX_ERR); - cmds->inside_node_block--; - err = EC_SYNTAX_OK; - break; - case TOK_PROP: - /* Check if inside TABLE, but not in ROW */ - if ((cmds->inside_table_block != 0) && - (cmds->inside_row_block == 0)) - return (EC_SYNTAX_ERR); - err = parse_prop(rec, command); - if (err != EC_SYNTAX_OK) - return (err); - if (cmds->inside_row_block) { - cmds->commands[cmds->current_row].rowcmd_nproph++; - } - break; - case TOK_REFNODE: - err = parse_refnode(rec, command); - if (err != EC_SYNTAX_OK) - return (err); - break; - case TOK_REFPROP: - /* Check if inside TABLE, but not in ROW */ - if ((cmds->inside_table_block != 0) && - (cmds->inside_row_block == 0)) - return (EC_SYNTAX_ERR); - err = parse_refprop(rec, command); - if (err != EC_SYNTAX_OK) - return (err); - if (cmds->inside_row_block) { - cmds->commands[cmds->current_row].rowcmd_nproph++; - } - break; - case TOK_TABLE: - /* Table/Row supported in version 1.1 and above */ - if (cmds->version_no < (float)SUPPORTED_VERSION_NUM) - return (EC_UNSUPPORTED); - if (cmds->inside_table_block != 0) - return (EC_SYNTAX_ERR); - err = parse_table(rec, command); - if (err != EC_SYNTAX_OK) - return (err); - cmds->inside_table_block = 1; - break; - case TOK_ENDTABLE: - /* Check for ENDTABLE before TABLE */ - if (cmds->inside_table_block == 0) - return (EC_SYNTAX_ERR); - - cmds->inside_table_block = 0; - - break; - case TOK_ROW: - /* Check for ROW outside of TABLE, ROW inside ROW */ - if ((cmds->inside_table_block == 0) || - (cmds->inside_row_block != 0)) - return (EC_SYNTAX_ERR); - cmds->inside_row_block = 1; - break; - case TOK_ENDROW: - /* Check for ENDROW outside of TABLE, ENDROW before ROW */ - if ((cmds->inside_table_block == 0) || - (cmds->inside_row_block == 0)) - return (EC_SYNTAX_ERR); - else - err = EC_SYNTAX_OK; - - cmds->inside_row_block = 0; - - /* error if row is empty */ - if (cmds->commands[cmds->current_row].rowcmd_nproph <= 0) - return (EC_ROW_EMPTY); - break; - case TOK_VERBOSE: - err = parse_verbose(cmds, rec, command); - if (err != EC_SYNTAX_OK) - return (err); - break; - default: /* unsupported command */ - return (EC_SYNTAX_ERR); - } - - command->type = id; - return (EC_SYNTAX_OK); -} - -/* - * Check the syntax and save the tokens in the commands buffer - */ -static int -check_line_syntax(cmdbuf_t *cmds, char *buf) -{ - int err; - command_t command; - - (void) memset(&command, 0, sizeof (command_t)); - err = parse_and_tokenize_line(cmds, buf, &command); - if (err != EC_SYNTAX_OK) - return (err); - - /* - * don't add and count version command in the command buffer - */ - if (command.type == TOK_VERSION) - return (EC_SYNTAX_OK); - - /* - * check if the commands buffer has been filled - * If it is full, reallocate the buffer. - */ - if (cmds->count == cmds->allocated) { - cmds->commands = reallocarray(cmds->commands, - cmds->allocated + PER_ALLOC_COUNT, sizeof (command_t)); - if (cmds->commands == NULL) - return (EC_FAILURE); - cmds->allocated += PER_ALLOC_COUNT; - } - - cmds->commands[cmds->count] = command; /* copy */ - - /* - * make a note of the row/endrow command, to keep track of # of props - */ - if (command.type == TOK_ROW) - cmds->current_row = cmds->count; - - if (command.type == TOK_ENDROW) - cmds->current_row = 0; - - cmds->count++; - - return (EC_SYNTAX_OK); -} - -/* - * get the line control information - * return 1 if it's the line control information, else return 0 - */ -static int -get_line_control_info(char *buf, uint32_t *linenum, char *filename) -{ - char *ptr; - char *last; - uint32_t num; - char *fname; - char *endptr; - - /* skip # and get next string */ - ptr = strtok_r(buf + 1, WHITESPACE, &last); - if (ptr == NULL) { - return (0); - } - - num = strtoul(ptr, &endptr, 0); - - /* - * It's not the line control information - */ - if (endptr != (ptr + strlen(ptr))) { - return (0); - } - - /* - * get the filename - */ - - /* get the beginning double quote */ - last = strchr(last, '"'); - if (last == NULL) - return (0); - - last++; - - /* get the ending double quote */ - fname = strtok_r(last, DOUBLE_QUOTE, &last); - if (fname == NULL) - return (0); - - *linenum = num; - (void) strlcpy(filename, fname, PATH_MAX); - return (1); -} - -/* - * check the syntax of the configuration file - */ -static int -check_conffile_syntax(cmdbuf_t *cmds, FILE *fp) -{ - char lbuf[RECORD_SIZE_MAX]; - char buf[RECORD_SIZE_MAX]; - uint32_t linenum; - char cppfile[PATH_MAX] = ""; - int err = EC_SYNTAX_OK; - - linenum = 0; - while (fgets(buf, sizeof (buf), fp) != NULL) { - /* - * get cpp line control information, if any - */ - if (buf[0] == '#') { - if (!get_line_control_info(buf, &linenum, cppfile)) - ++linenum; - continue; - } - - ++linenum; - /* - * skip line whose first char is a newline char - */ - if (buf[0] == '\n') { - continue; - } - - if (err == EC_SYNTAX_OK) - (void) strlcpy(lbuf, buf, RECORD_SIZE_MAX); - else if (strlcat(lbuf, buf, RECORD_SIZE_MAX) >= - RECORD_SIZE_MAX) { /* buffer overflow */ - err = EC_FAILURE; - break; - } - - err = check_line_syntax(cmds, lbuf); - if ((err != EC_INSUFFICIENT_TOKEN) && (err != EC_SYNTAX_OK)) - break; - } - - if (err != EC_SYNTAX_OK) { - if (cmds->verbose) { - verbose_log(LOG_ERR, err_msg[err], - cmds->fname, cppfile, linenum); - } - return (err); - } - - /* - * check if the version has been set - */ - if (cmds->version_no > (float)SUPPORTED_VERSION_NUM) { - if (cmds->verbose) { - verbose_log(LOG_ERR, err_msg[EC_UNSUPPORTED], - cmds->fname, cppfile, linenum); - } - return (EC_UNSUPPORTED); - } - - /* - * check if node and endnode command mismatch - */ - if (cmds->inside_node_block != 0) { - if (cmds->verbose) { - verbose_log(LOG_ERR, err_msg[EC_NODE_MISMATCH], - cmds->fname, cppfile, linenum); - } - return (EC_NODE_MISMATCH); - } - - /* - * check if row and endrow command mismatch - */ - if (cmds->inside_row_block != 0) { - if (cmds->verbose) { - verbose_log(LOG_ERR, err_msg[EC_ROW_MISMATCH], - cmds->fname, cppfile, linenum); - } - return (EC_ROW_MISMATCH); - } - - /* - * check if table and endtable command mismatch - */ - if (cmds->inside_table_block != 0) { - if (cmds->verbose) { - verbose_log(LOG_ERR, err_msg[EC_TABLE_MISMATCH], - cmds->fname, cppfile, linenum); - } - return (EC_TABLE_MISMATCH); - } - - return (EC_SYNTAX_OK); -} - -/* - * If classpath/namepath given is not found in the picl tree, - * skip the whole blocks until next valid classpath or namepath - */ -static void -skip_to_next_valid_path(cmdbuf_t *cmds, int starting_index, - picl_nodehdl_t *parent, int *last_processed_index) -{ - int err; - int index; - - for (index = starting_index; index < cmds->count; ++index) { - switch (cmds->commands[index].type) { - case TOK_CLASSPATH: - case TOK_NAMEPATH: - err = process_path(&cmds->commands[index], parent); - if (err == PICL_SUCCESS) { - *last_processed_index = index; - return; - } - default: - /* skipped this line */ - break; - } - } - - /* reach last command */ - *last_processed_index = cmds->count - 1; -} - -/* - * Process the command buffer and return last command index and the new head of - * the handle list - */ -static int -process_commands(cmdbuf_t *cmds, int starting_index, picl_nodehdl_t parent, - int *last_processed_index) -{ - int err; - int index; - picl_nodehdl_t rooth; - picl_nodehdl_t nodeh; - command_t *commands = cmds->commands; - - for (index = starting_index; index < cmds->count; ++index) { - switch (commands[index].type) { - case TOK_CLASSPATH: - case TOK_NAMEPATH: - err = process_path(&commands[index], &rooth); - if (err != PICL_SUCCESS) { - index++; - (void) skip_to_next_valid_path(cmds, index, - &rooth, &index); - } - parent = rooth; - continue; - case TOK_NODE: - err = process_node(&commands[index], parent, &nodeh); - if (err == PICL_SUCCESS) { - index++; - err = process_commands(cmds, index, nodeh, - &index); - } - break; - case TOK_ENDNODE: - *last_processed_index = index; - return (PICL_SUCCESS); - case TOK_PROP: - err = process_prop(cmds, &commands[index], parent); - break; - case TOK_REFPROP: - err = process_refprop(cmds, &commands[index], parent); - /* no reference node */ - if (err == PICL_NOTNODE) { - err = PICL_SUCCESS; /* discard prop */ - /* discard row by setting nproph = 0 */ - if (cmds->inside_row_block) - cmds->commands[cmds->current_row] - .rowcmd_nproph = 0; - } - break; - case TOK_REFNODE: - err = process_refnode(&commands[index], parent); - break; - case TOK_TABLE: - cmds->inside_table_block = 1; - err = process_table(&commands[index], parent); - cmds->current_tbl = index; - break; - case TOK_ENDTABLE: - cmds->inside_table_block = 0; - cmds->current_tbl = 0; - break; - case TOK_ROW: - cmds->inside_row_block = 1; - err = process_row(&commands[index]); - cmds->current_row = index; - break; - case TOK_ENDROW: - err = process_endrow(cmds); - cmds->inside_row_block = 0; - cmds->current_row = 0; - break; - case TOK_VERBOSE: - err = process_verbose(cmds, &commands[index]); - break; - default: /* won't reach here */ - err = PICL_FAILURE; - break; - } - - if ((err != PICL_SUCCESS) && (err != PICL_PROPEXISTS)) { - *last_processed_index = index; - return (err); - } - } - - /* reach last command */ - *last_processed_index = cmds->count - 1; - return (PICL_SUCCESS); -} - -/* - * clean up the commands buffer - */ -static void -clean_up(cmdbuf_t *cmds) -{ - int cmd_index; - - for (cmd_index = 0; cmd_index < cmds->count; cmd_index++) { - switch (cmds->commands[cmd_index].type) { - case TOK_CLASSPATH: - case TOK_NAMEPATH: - free_path(&cmds->commands[cmd_index]); - break; - case TOK_NODE: - free_node(&cmds->commands[cmd_index]); - break; - case TOK_PROP: - free_prop(&cmds->commands[cmd_index]); - break; - case TOK_REFPROP: - free_refprop(&cmds->commands[cmd_index]); - break; - case TOK_REFNODE: - free_refnode(&cmds->commands[cmd_index]); - break; - case TOK_TABLE: - free_table(&cmds->commands[cmd_index]); - break; - case TOK_ENDTABLE: - case TOK_ROW: - case TOK_ENDROW: - case TOK_ENDNODE: - case TOK_VERBOSE: - default: - break; - } - } - free(cmds->commands); -} - -/* - * Parse the configuration file and create nodes/properties under nh - * - * It checks the syntax first. If there is any syntax error, - * it returns 1 and won't continue processing the file to add nodes or props. - * - * If any error happens during command processing, all nodes - * and properties just created will be deleted, i.e. undo - * commands which have been processed. It returns 1. - * - * If success, return 0. - */ -int -picld_pluginutil_parse_config_file(picl_nodehdl_t nh, const char *filename) -{ - FILE *ifp; - int last_processed_index; - int err; - cmdbuf_t *cmds; - - /* set correct locale for use inside pluginutil */ - setlocale(LC_ALL, "C"); - - /* - * Initialize the command buffer - */ - - cmds = malloc(sizeof (*cmds)); - if (cmds == NULL) { - setlocale(LC_ALL, ""); - return (1); - } - - memset(cmds, 0, sizeof (cmdbuf_t)); - - cmds->fname = filename; - - ifp = fopen(filename, "r"); - if (ifp == NULL) { - setlocale(LC_ALL, ""); - free(cmds); - return (1); - } - - /* - * check the syntax of the configuration file - */ - err = check_conffile_syntax(cmds, ifp); - - (void) fclose(ifp); - - if (err != EC_SYNTAX_OK) { - clean_up(cmds); - free(cmds); - setlocale(LC_ALL, ""); - return (1); - } - - /* - * Process the commands - */ - err = process_commands(cmds, STARTING_INDEX, nh, &last_processed_index); - - /* - * If any PICL error, remove the newly created node/prop - * handles from the PICL tree. - */ - if (err != PICL_SUCCESS) { - undo_commands(cmds, last_processed_index); - if (cmds->verbose) - verbose_log(LOG_ERR, err_msg[EC_PICL_ERR], filename, - err); - } - - clean_up(cmds); - free(cmds); - - /* reset the locale */ - setlocale(LC_ALL, ""); - - return ((err == PICL_SUCCESS) ? 0 : 1); -} diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.h b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.h deleted file mode 100644 index 6c7f9ee246..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 1999-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef _PICLD_PLUGINUTIL_H -#define _PICLD_PLUGINUTIL_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -extern int picld_pluginutil_parse_config_file(picl_nodehdl_t nh, - const char *filename); - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLD_PLUGINUTIL_H */ diff --git a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil_impl.h b/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil_impl.h deleted file mode 100644 index 8bd476f1d1..0000000000 --- a/usr/src/cmd/picl/plugins/lib/picld_pluginutil/picld_pluginutil_impl.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICLD_PLUGINUTIL_IMPL_H -#define _PICLD_PLUGINUTIL_IMPL_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PER_ALLOC_COUNT 256 -#define RECORD_SIZE_MAX 1024 -#define STARTING_INDEX 0 -#define SUPPORTED_VERSION_NUM 1.1 - -/* reserved keyword (case insensitive) */ -#define KEYWORD_INT_TYPE "int" -#define KEYWORD_UINT_TYPE "uint" -#define KEYWORD_FLOAT_TYPE "float" -#define KEYWORD_STRING_TYPE "string" -#define KEYWORD_VOID_TYPE "void" -#define KEYWORD_READ_MODE "r" -#define KEYWORD_WRITE_MODE "w" -#define KEYWORD_READWRITE_MODE "rw" -#define KEYWORD_WITH_STR "with" - -#define WHITESPACE " \t\n" -#define RECORD_WHITESPACE ": \t\n" -#define DOUBLE_QUOTE "\"" - -typedef struct { - char *path; -} path_cmd_t; - -typedef struct { - picl_nodehdl_t nodeh; - char *nodename; - char *classname; -} node_cmd_t; - -typedef struct { - picl_prophdl_t proph; - size_t size; - int type; - int accessmode; - char *pname; - void *valbuf; -} prop_cmd_t; - -typedef struct { - picl_prophdl_t proph; - char *pname; - char *dstnode; -} refprop_cmd_t; - -typedef struct { - picl_nodehdl_t nodeh; - char *newnodename; - char *newnodeclass; - char *dstnode; -} refnode_cmd_t; - -typedef struct { - picl_prophdl_t tblh; - int newtbl; - char *tname; -} table_cmd_t; - -typedef struct { - int index; - int nproph; - picl_prophdl_t *prophs; -} row_cmd_t; - -typedef struct { - int32_t level; -} verbose_cmd_t; - -typedef struct { - int type; - union { - path_cmd_t path; - node_cmd_t node; - prop_cmd_t prop; - refprop_cmd_t refprop; - refnode_cmd_t refnode; - table_cmd_t table; - row_cmd_t row; - verbose_cmd_t verbose; - } u; -} command_t; - -typedef struct { - int count; - int allocated; - float version_no; - int inside_node_block; - int verbose; - const char *fname; - int inside_table_block; - int current_tbl; - int inside_row_block; - int current_row; - command_t *commands; -} cmdbuf_t; - -#define pathcmd_name u.path.path -#define nodecmd_nodeh u.node.nodeh -#define nodecmd_nodename u.node.nodename -#define nodecmd_classname u.node.classname -#define nodecmd_classname u.node.classname -#define propcmd_proph u.prop.proph -#define propcmd_pname u.prop.pname -#define propcmd_type u.prop.type -#define propcmd_accessmode u.prop.accessmode -#define propcmd_size u.prop.size -#define propcmd_valbuf u.prop.valbuf -#define refpropcmd_proph u.refprop.proph -#define refpropcmd_pname u.refprop.pname -#define refpropcmd_dstnode u.refprop.dstnode -#define refnodecmd_nodeh u.refnode.nodeh -#define refnodecmd_name u.refnode.newnodename -#define refnodecmd_class u.refnode.newnodeclass -#define refnodecmd_dstnode u.refnode.dstnode -#define tablecmd_tblh u.table.tblh -#define tablecmd_newtbl u.table.newtbl -#define tablecmd_tname u.table.tname -#define rowcmd_index u.row.index -#define rowcmd_nproph u.row.nproph -#define rowcmd_prophs u.row.prophs -#define verbosecmd_level u.verbose.level - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLD_PLUGINUTIL_IMPL_H */ diff --git a/usr/src/cmd/picl/prtpicl/Makefile b/usr/src/cmd/picl/prtpicl/Makefile deleted file mode 100644 index 05ff9bdb69..0000000000 --- a/usr/src/cmd/picl/prtpicl/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= prtpicl - -OBJS = prtpicl.o - -include $(SRC)/cmd/Makefile.cmd - -CPPFLAGS += -I$(SRC)/lib/libpicl -LDLIBS += -L$(SRC)/lib/libpicl/$(MACH) -lpicl - -FILEMODE= 755 - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTUSRSBINPROG) - -clean: - $(RM) $(OBJS) - - -include $(SRC)/cmd/Makefile.targ - diff --git a/usr/src/cmd/picl/prtpicl/prtpicl.c b/usr/src/cmd/picl/prtpicl/prtpicl.c deleted file mode 100644 index 6d5f3a50d1..0000000000 --- a/usr/src/cmd/picl/prtpicl/prtpicl.c +++ /dev/null @@ -1,574 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2010 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Constant definitions and macros - */ -#define COL_DELIM "|" -#define ROOT_LEVEL 0 -#define LEVEL_INDENT 4 -#define PROP_INDENT 2 -#define NCOLS 80 -#define NODEINFO_LEFT_MARGIN(x) (x * LEVEL_INDENT) -#define PROPINFO_LEFT_MARGIN(x) (x * LEVEL_INDENT + PROP_INDENT) - -#define PRIxPICLTBL PRIx64 -#define PRIxPICLHDL PRIx64 - -/* - * Program variables - */ -static char *prog; -static int verbose_mode = 0; - -/* - * Error codes - */ -#define EM_USAGE 0 -#define EM_INIT 1 -#define EM_GETROOT 2 -#define EM_GETPVAL 3 -#define EM_GETNXTBYCOL 4 -#define EM_GETNXTBYROW 5 -#define EM_GETPINFO 6 -#define EM_GETPVALBYNAME 7 -#define EM_GETPROPBYNAME 8 -#define EM_INT_INVSIZE 9 -#define EM_UINT_INVSIZE 10 -#define EM_FLOAT_INVSIZE 11 -#define EM_TS_INVALID 12 -#define EM_TABLE_INVSIZE 13 -#define EM_REF_INVSIZE 14 -#define EM_TYPE_UNKNOWN 15 -#define EM_TS_OVERFLOW 16 -#define EM_TS_INVSIZE 17 - -/* - * Error mesage texts - */ -static char *err_msg[] = { - /* program usage */ - "Usage: %s [-v] [-c ]\n", /* 0 */ - /* picl call failed messages */ - "picl_initialize failed: %s\n", /* 1 */ - "picl_get_root failed: %s\n", /* 2 */ - "picl_get_propval failed: %s\n", /* 3 */ - "picl_get_next_by_col failed: %s\n", /* 4 */ - "picl_get_next_by_row failed: %s\n", /* 5 */ - "picl_get_propinfo failed: %s\n", /* 6 */ - "picl_get_propval_by_name failed: %s\n", /* 7 */ - "picl_get_prop_by_name failed: %s\n", /* 8 */ - /* invalid data error messages */ - "picl_get_propval: invalid int size %d\n", /* 9 */ - "picl_get_propval: invalid unsigned int size %d\n", /* 10 */ - "picl_get_propval: invalid float size %d\n", /* 11 */ - "picl_get_propval: invalid timestamp\n", /* 12 */ - "picl_get_propval: invalid table handle size %d\n", /* 13 */ - "picl_get_propval: invalid reference size %d\n", /* 14 */ - "picl_get_propval: unknown type\n", /* 15 */ - "picl_get_propval: timestamp value too large\n", /* 16 */ - "picl_get_propval: invalid timestamp size\n" /* 17 */ -}; - -/*PRINTFLIKE1*/ -static void -print_errmsg(char *message, ...) -{ - va_list ap; - - va_start(ap, message); - (void) fprintf(stderr, "%s: ", prog); - (void) vfprintf(stderr, message, ap); - va_end(ap); -} - -/* - * Print prtpicl usage - */ -static void -usage(void) -{ - print_errmsg(gettext(err_msg[EM_USAGE]), prog); - exit(1); -} - -/* - * print a bytearray value and format it to fit in 80 columns - */ -static void -print_bytearray(int lvl, uint8_t *vbuf, size_t nbytes) -{ - int cnum; - int columns; - char *s; - struct winsize winsize; - size_t i; - - /* - * The COLUMNS_PER_BYTE is set to 4 to match the printf - * format used below, i.e. " %02x ", to print a byte - */ -#define COLUMNS_PER_BYTE 4 - - /* - * Kind of a hack to determine the width of the output... - */ - columns = NCOLS; - if ((s = getenv("COLUMNS")) != NULL && (cnum = atoi(s)) > 0) - columns = cnum; - else if (isatty(fileno(stdout)) && - ioctl(fileno(stdout), TIOCGWINSZ, &winsize) == 0 && - winsize.ws_col != 0) - columns = winsize.ws_col; - - - cnum = PROPINFO_LEFT_MARGIN(lvl); - if ((nbytes * COLUMNS_PER_BYTE + cnum) > columns) { - (void) printf("\n"); - cnum = 0; - } - for (i = 0; i < nbytes; ++i) { - if (cnum > columns - COLUMNS_PER_BYTE) { - (void) printf("\n"); - cnum = 0; - } - (void) printf(" %02x ", vbuf[i]); - cnum += COLUMNS_PER_BYTE; - } -} - -/* - * Print a property's value - * If the property is read protected, return success. - * If an invalid/stale handle error is encountered, return the error. For - * other errors, print a message and return success. - */ -static int -print_propval(int lvl, picl_prophdl_t proph, const picl_propinfo_t *propinfo) -{ - int err; - void *vbuf; - char *str; - uint64_t val64; - time_t tmp; - - /* - * If property is read protected, print a message and continue - */ - if (!(propinfo->accessmode & PICL_READ)) { - (void) printf("<%s>", gettext("WRITE-ONLY")); - return (PICL_SUCCESS); - } - - vbuf = alloca(propinfo->size); - if (propinfo->type == PICL_PTYPE_VOID) - return (PICL_SUCCESS); - - err = picl_get_propval(proph, vbuf, propinfo->size); - /* - * If the error is not a stale/invalid handle or noresponse, continue - * by ignoring the error/skipping the property. - */ - if ((err == PICL_INVALIDHANDLE) || (err == PICL_STALEHANDLE) || - (err == PICL_NORESPONSE)) - return (err); - else if (err != PICL_SUCCESS) { - (void) printf("<%s: %s>", gettext("ERROR"), picl_strerror(err)); - return (PICL_SUCCESS); - } - - switch (propinfo->type) { - case PICL_PTYPE_CHARSTRING: - if (propinfo->size > 0) - (void) printf(" %s ", (char *)vbuf); - break; - case PICL_PTYPE_INT: - switch (propinfo->size) { - case sizeof (int8_t): - /* avoid using PRId8 until lint recognizes hh */ - (void) printf(" %d ", *(int8_t *)vbuf); - break; - case sizeof (int16_t): - (void) printf(" %" PRId16 " ", *(int16_t *)vbuf); - break; - case sizeof (int32_t): - (void) printf(" %" PRId32 " ", *(int32_t *)vbuf); - break; - case sizeof (int64_t): - (void) printf(" %" PRId64 " ", *(int64_t *)vbuf); - break; - default: - print_errmsg(gettext(err_msg[EM_INT_INVSIZE]), - propinfo->size); - return (PICL_FAILURE); - } - break; - case PICL_PTYPE_UNSIGNED_INT: - switch (propinfo->size) { - case sizeof (uint8_t): - /* avoid using PRIx8 until lint recognizes hh */ - (void) printf(" %#x ", *(uint8_t *)vbuf); - break; - case sizeof (uint16_t): - (void) printf(" %#" PRIx16 " ", *(uint16_t *)vbuf); - break; - case sizeof (uint32_t): - (void) printf(" %#" PRIx32 " ", *(uint32_t *)vbuf); - break; - case sizeof (uint64_t): - (void) printf(" %#" PRIx64 " ", *(uint64_t *)vbuf); - break; - default: - print_errmsg(gettext(err_msg[EM_UINT_INVSIZE]), - propinfo->size); - return (PICL_FAILURE); - } - break; - case PICL_PTYPE_FLOAT: - switch (propinfo->size) { - case sizeof (float): - (void) printf(" %f ", *(float *)vbuf); - break; - case sizeof (double): - (void) printf(" %f ", *(double *)vbuf); - break; - default: - print_errmsg(gettext(err_msg[EM_FLOAT_INVSIZE]), - propinfo->size); - return (PICL_FAILURE); - } - break; - case PICL_PTYPE_TIMESTAMP: - if (propinfo->size != sizeof (val64)) { - print_errmsg(gettext(err_msg[EM_TS_INVSIZE])); - return (PICL_FAILURE); - } - val64 = *(uint64_t *)vbuf; - tmp = (time_t)val64; - if ((uint64_t)tmp != val64) { - print_errmsg(gettext(err_msg[EM_TS_OVERFLOW])); - return (PICL_FAILURE); - } - str = ctime(&tmp); - if (str == NULL) { - print_errmsg(gettext(err_msg[EM_TS_INVALID])); - return (PICL_FAILURE); - } - str[strlen(str) - 1] = '\0'; - (void) printf(" %s ", str); - break; - case PICL_PTYPE_TABLE: - if (propinfo->size != sizeof (picl_prophdl_t)) { - print_errmsg(gettext(err_msg[EM_TABLE_INVSIZE]), - propinfo->size); - return (PICL_FAILURE); - } - (void) printf("(%" PRIxPICLTBL "TBL) ", - *(picl_prophdl_t *)vbuf); - break; - case PICL_PTYPE_REFERENCE: - if (propinfo->size != sizeof (picl_nodehdl_t)) { - print_errmsg(gettext(err_msg[EM_REF_INVSIZE]), - propinfo->size); - return (PICL_FAILURE); - } - (void) printf(" (%" PRIxPICLHDL "H) ", *(picl_nodehdl_t *)vbuf); - break; - case PICL_PTYPE_BYTEARRAY: - if (propinfo->size > 0) - print_bytearray(lvl, vbuf, propinfo->size); - break; - default: - print_errmsg(gettext(err_msg[EM_TYPE_UNKNOWN])); - return (PICL_FAILURE); - } - return (PICL_SUCCESS); -} - -/* - * print table property value - */ -static int -print_table_prop(int lvl, picl_prophdl_t tblh) -{ - picl_prophdl_t rowproph; - picl_prophdl_t colproph; - int err; - picl_propinfo_t propinfo; - - for (err = picl_get_next_by_col(tblh, &rowproph); err != PICL_ENDOFLIST; - err = picl_get_next_by_col(rowproph, &rowproph)) { - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETNXTBYCOL]), - picl_strerror(err)); - return (err); - } - - (void) printf("%*s %s", PROPINFO_LEFT_MARGIN(lvl), " ", - COL_DELIM); - - for (colproph = rowproph; err != PICL_ENDOFLIST; - err = picl_get_next_by_row(colproph, &colproph)) { - - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETNXTBYROW]), - picl_strerror(err)); - return (err); - } - - err = picl_get_propinfo(colproph, &propinfo); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPINFO]), - picl_strerror(err)); - return (err); - } - - err = print_propval(lvl, colproph, &propinfo); - if (err != PICL_SUCCESS) - return (err); - (void) printf(COL_DELIM); - } - (void) printf("\n"); - } - return (PICL_SUCCESS); -} - -/* - * Print the properties (name = value) of a node. If an error occurs - * when printing the property value, stop. print_propval() suppresses - * errors during getting property value except for stale/invalid handle - * and no response errors. - */ -static int -print_proplist(int lvl, picl_nodehdl_t nodeh) -{ - int err; - picl_prophdl_t proph; - picl_propinfo_t propinfo; - picl_prophdl_t tblh; - - for (err = picl_get_first_prop(nodeh, &proph); err == PICL_SUCCESS; - err = picl_get_next_prop(proph, &proph)) { - - err = picl_get_propinfo(proph, &propinfo); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPINFO]), - picl_strerror(err)); - return (err); - } - - if (propinfo.type == PICL_PTYPE_VOID) - (void) printf("%*s:%s\n", PROPINFO_LEFT_MARGIN(lvl), - " ", propinfo.name); - else { - (void) printf("%*s:%s\t", PROPINFO_LEFT_MARGIN(lvl), - " ", propinfo.name); - err = print_propval(lvl, proph, &propinfo); - (void) printf("\n"); - if (err != PICL_SUCCESS) - return (err); - } - - /* - * Expand the table property - */ - if (propinfo.type == PICL_PTYPE_TABLE) { - err = picl_get_propval(proph, &tblh, propinfo.size); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPVAL]), - picl_strerror(err)); - return (err); - } - err = print_table_prop(lvl, tblh); - if (err != PICL_SUCCESS) - return (err); - } - } - return (PICL_SUCCESS); -} - -/* - * Recursively print the PICL tree - * When piclclass is specified, print only the nodes of that class. - */ -static int -print_tree_by_class(int lvl, picl_nodehdl_t nodeh, char *piclclass) -{ - picl_nodehdl_t chdh; - char *nameval; - char classval[PICL_PROPNAMELEN_MAX]; - int err; - picl_prophdl_t proph; - picl_propinfo_t pinfo; - - /* - * First get the class name of the node to compare with piclclass - */ - err = picl_get_propval_by_name(nodeh, PICL_PROP_CLASSNAME, classval, - sizeof (classval)); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPVALBYNAME]), - picl_strerror(err)); - return (err); - } - -#define MATCHING_CLASSVAL(x, y) ((x == NULL) || (strcasecmp(x, y) == 0)) - - if (MATCHING_CLASSVAL(piclclass, classval)) { - err = picl_get_prop_by_name(nodeh, PICL_PROP_NAME, &proph); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPROPBYNAME]), - picl_strerror(err)); - return (err); - } - - err = picl_get_propinfo(proph, &pinfo); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPINFO]), - picl_strerror(err)); - return (err); - } - - nameval = alloca(pinfo.size); - err = picl_get_propval(proph, nameval, pinfo.size); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPVAL]), - picl_strerror(err)); - return (err); - } - - (void) printf("%*s %s (%s, %" PRIxPICLHDL ")\n", - NODEINFO_LEFT_MARGIN(lvl), " ", nameval, classval, nodeh); - - if (verbose_mode) { - err = print_proplist(lvl, nodeh); - if (err != PICL_SUCCESS) - return (err); - } - ++lvl; - } - - for (err = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &chdh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = picl_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (picl_nodehdl_t))) { - - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETPVALBYNAME]), - picl_strerror(err)); - return (err); - } - - err = print_tree_by_class(lvl, chdh, piclclass); - if (err != PICL_SUCCESS) - return (err); - } - return (PICL_SUCCESS); -} - - -/* - * This program prints the PICL tree. - * If an invalid handle or stale handle is encountered while printing - * the tree, it starts over from the root node. - */ -int -main(int argc, char **argv) -{ - int err; - picl_nodehdl_t rooth; - int c; - int done; - char piclclass[PICL_CLASSNAMELEN_MAX]; - int cflg; - - (void) setlocale(LC_ALL, ""); - (void) textdomain(TEXT_DOMAIN); - - if ((prog = strrchr(argv[0], '/')) == NULL) - prog = argv[0]; - else - prog++; - - cflg = 0; - while ((c = getopt(argc, argv, "vc:")) != EOF) { - switch (c) { - case 'v': - verbose_mode = 1; - break; - case 'c': - cflg = 1; - (void) strlcpy(piclclass, optarg, - PICL_CLASSNAMELEN_MAX); - break; - case '?': - /*FALLTHROUGH*/ - default: - usage(); - /*NOTREACHED*/ - } - } - if (optind != argc) - usage(); - - err = picl_initialize(); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_INIT]), picl_strerror(err)); - exit(1); - } - - - do { - done = 1; - err = picl_get_root(&rooth); - if (err != PICL_SUCCESS) { - print_errmsg(gettext(err_msg[EM_GETROOT]), - picl_strerror(err)); - exit(1); - } - - err = print_tree_by_class(ROOT_LEVEL, rooth, - (cflg ? piclclass : NULL)); - if ((err == PICL_STALEHANDLE) || (err == PICL_INVALIDHANDLE)) - done = 0; - } while (!done); - - (void) picl_shutdown(); - - return (0); -} diff --git a/usr/src/cmd/svc/profile/generic_limited_net.xml b/usr/src/cmd/svc/profile/generic_limited_net.xml index dd61a6a2c0..66679fe1ca 100644 --- a/usr/src/cmd/svc/profile/generic_limited_net.xml +++ b/usr/src/cmd/svc/profile/generic_limited_net.xml @@ -76,9 +76,6 @@ - - - diff --git a/usr/src/cmd/svc/profile/generic_open.xml b/usr/src/cmd/svc/profile/generic_open.xml index 47b00fb4de..124632f528 100644 --- a/usr/src/cmd/svc/profile/generic_open.xml +++ b/usr/src/cmd/svc/profile/generic_open.xml @@ -73,9 +73,6 @@ - - - diff --git a/usr/src/lib/Makefile b/usr/src/lib/Makefile index d9d1aaffac..0fbcb36fee 100644 --- a/usr/src/lib/Makefile +++ b/usr/src/lib/Makefile @@ -162,8 +162,6 @@ SUBDIRS += \ libpam \ libpcidb \ libpctx \ - libpicl \ - libpicltree \ libpool \ libpp \ libproc \ @@ -277,7 +275,6 @@ MSGSUBDIRS= \ libnwam \ libofmt \ libpam \ - libpicl \ libpool \ libpp \ libreparse \ @@ -365,8 +362,6 @@ HDRSUBDIRS= \ libpam \ libpcidb \ libpctx \ - libpicl \ - libpicltree \ libpool \ libpp \ libproc \ diff --git a/usr/src/lib/libpicl/Makefile b/usr/src/lib/libpicl/Makefile deleted file mode 100644 index a27bcf947c..0000000000 --- a/usr/src/lib/libpicl/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include $(SRC)/lib/Makefile.lib - -SUBDIRS = $(MACH) -$(BUILD64)SUBDIRS += $(MACH64) - -# conditional assignments -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -_msg := TARGET= _msg - -# definitions for install_h target -HDRS= picl.h -ROOTHDRDIR= $(ROOT)/usr/include -ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) -CHECKHDRS= $(HDRS:%.h=%.check) - -.KEEP_STATE: - -all install clean clobber _msg: $(SUBDIRS) - -# install rule for install_h target - -$(ROOTHDRDIR)/%: % - $(INS.file) - -install_h: $(ROOTHDRDIR) $(ROOTHDRS) - -$(ROOTHDRDIR): - $(INS.dir) - -check: $(CHECKHDRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: - diff --git a/usr/src/lib/libpicl/Makefile.com b/usr/src/lib/libpicl/Makefile.com deleted file mode 100644 index 23417a6ef1..0000000000 --- a/usr/src/lib/libpicl/Makefile.com +++ /dev/null @@ -1,53 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -LIBRARY= libpicl.a -VERS= .1 -OBJECTS= picl.o - -include $(SRC)/lib/Makefile.lib - -LIBS = $(DYNLIB) -LDLIBS += -lc - -CPPFLAGS += -I.. - -XGETFLAGS += -a -POFILE = picl.po - -.KEEP_STATE: - -all: $(LIBS) - -%.po: ../%.c - $(CP) $< $<.i - $(BUILD.po) - -_msg: $(MSGDOMAINPOFILE) - -include $(SRC)/lib/Makefile.targ -include $(SRC)/Makefile.msg.targ diff --git a/usr/src/lib/libpicl/amd64/Makefile b/usr/src/lib/libpicl/amd64/Makefile deleted file mode 100644 index cb39a2beff..0000000000 --- a/usr/src/lib/libpicl/amd64/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com -include ../../Makefile.lib.64 - -install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/libpicl/i386/Makefile b/usr/src/lib/libpicl/i386/Makefile deleted file mode 100644 index 21e82ec04a..0000000000 --- a/usr/src/lib/libpicl/i386/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com - -install: all $(ROOTLIBS) $(ROOTLINKS) diff --git a/usr/src/lib/libpicl/mapfile-vers b/usr/src/lib/libpicl/mapfile-vers deleted file mode 100644 index 407ea3ef9e..0000000000 --- a/usr/src/lib/libpicl/mapfile-vers +++ /dev/null @@ -1,73 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. -# - -# -# MAPFILE HEADER START -# -# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. -# Object versioning must comply with the rules detailed in -# -# usr/src/lib/README.mapfiles -# -# You should not be making modifications here until you've read the most current -# copy of that file. If you need help, contact a gatekeeper for guidance. -# -# MAPFILE HEADER END -# - -$mapfile_version 2 - -SYMBOL_VERSION SUNW_1.3 { - global: - picl_find_node; - picl_get_frutree_parent; - picl_get_node_by_path; -} SUNW_1.2; - -SYMBOL_VERSION SUNW_1.2 { - global: - picl_get_propinfo_by_name; - picl_walk_tree_by_class; -} SUNW_1.1; - -SYMBOL_VERSION SUNW_1.1 { - global: - picl_get_first_prop; - picl_get_next_by_col; - picl_get_next_by_row; - picl_get_next_prop; - picl_get_prop_by_name; - picl_get_propinfo; - picl_get_propval; - picl_get_propval_by_name; - picl_get_root; - picl_initialize; - picl_set_propval; - picl_set_propval_by_name; - picl_shutdown; - picl_strerror; - picl_wait; - local: - *; -}; diff --git a/usr/src/lib/libpicl/picl.c b/usr/src/lib/libpicl/picl.c deleted file mode 100644 index 449aacb4c0..0000000000 --- a/usr/src/lib/libpicl/picl.c +++ /dev/null @@ -1,869 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * This module implements the PICL Interface used by PICL clients - * to access services of the PICL daemon - * - * Locking Strategy - * A single reader/writer lock (icl_lock) protects the access to the interface - * to the picl daemon, and the reference count, refcnt, variable. - * A reader lock is obtained to send a request to the daemon. - * A writer lock is obtained to initialize, reinitialize, or shutdown - * the interface. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "picl2door.h" - -/* - * Module variables - */ -static int door_handle = -1; -static uint32_t refcnt = 0; -static rwlock_t picl_lock = DEFAULTRWLOCK; - -static char *picl_errmsg[] = { - "No error", - "General system failure", - "Daemon not responding", - "Unknown PICL service", - "Session not initialized", - "Invalid arguments", - "Argument too big", - "Property not found", - "Not a table property handle", - "Not a node handle", - "Not a property handle", - "End of property list", - "Property already exists", - "Property not writable", - "Insufficient permissions", - "Invalid handle", - "Stale handle", - "Unsupported version", - "Wait timed out", - "Attempting to destroy before delete", - "PICL Tree is busy", - "Already has a parent", - "Property name is reserved", - "Invalid reference value", - "Continue tree walk", - "Terminate tree walk", - "Node not found", - "Not enough space available", - "Property not readable", - "Property value unavailable" -}; - -#define N_ERRORS (sizeof (picl_errmsg)/sizeof (picl_errmsg[0])) -#define SEND_REQ_TRYCOUNT 1 - -/* - * This function sends the client request to the daemon using a door call. - * If door_handle is -1, it returns PICL_NOTINITIALIZED. - * If the door_call fails, it returns PICL_NORESPONSE. Otherwise, it - * checks the response from the daemon for error. If an error is returned - * this function returns the error code returned and unmaps any - * memory mapped by the door call. For successful results, the caller is - * responsible to unmap the mapped memory after retrieving the results. - * - * This function does not attempt to reinitialize the interface if the - * initial door_call fails. It is called from handshake() , shutdown() - * and trysend_req() routines. - */ -static int -post_req(door_arg_t *dargp, void *data_ptr, size_t data_size, - door_desc_t *desc_ptr, uint_t desc_num, void *rbuf, size_t rsize) -{ - int err; - picl_service_t *ret; - int req_cnum; - - req_cnum = ((picl_service_t *)data_ptr)->in.cnum; - dargp->data_ptr = data_ptr; - dargp->data_size = data_size; - dargp->desc_ptr = desc_ptr; - dargp->desc_num = desc_num; - dargp->rbuf = rbuf; - dargp->rsize = rsize; - - if (door_call(door_handle, dargp) < 0) - return (PICL_NORESPONSE); - - /*LINTED*/ - ret = (picl_service_t *)dargp->rbuf; - if (ret->in.cnum == req_cnum) - return (PICL_SUCCESS); - else if ((ret->in.cnum == PICL_CNUM_ERROR) && - (ret->ret_error.in_cnum == req_cnum)) - err = ret->ret_error.errnum; - else - err = PICL_UNKNOWNSERVICE; - if (dargp->rbuf != rbuf) - (void) munmap(dargp->rbuf, dargp->rsize); - return (err); -} - -/* - * This function posts an INIT message to the daemon to - * verify communication channel. - */ -static int -handshake(void) -{ - int err; - door_arg_t darg; - picl_reqinit_t req; - picl_retinit_t outargs; - - req.cnum = PICL_CNUM_INIT; - req.clrev = PICL_VERSION_1; - - if ((err = post_req(&darg, &req, sizeof (picl_reqinit_t), NULL, - 0, &outargs, sizeof (picl_retinit_t))) != PICL_SUCCESS) - return (err); - - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function calls post_req() to make door_call and reinitializes - * the interface is post_req() fails. - */ -static int -trysend_req(door_arg_t *dargp, void *data_ptr, size_t data_size, - door_desc_t *desc_ptr, uint_t desc_num, void *rbuf, size_t rsize, - unsigned int trycount) -{ - int err; - int write_locked; - - write_locked = 0; - (void) rw_rdlock(&picl_lock); - if (refcnt == 0) { - (void) rw_unlock(&picl_lock); /* read unlock */ - return (PICL_NOTINITIALIZED); - } - - while ((err = post_req(dargp, data_ptr, data_size, desc_ptr, desc_num, - rbuf, rsize)) == PICL_NORESPONSE) { - if (trycount == 0) /* no more retry */ - break; - - if (write_locked == 1) { /* close and open door */ - (void) close(door_handle); - if ((door_handle = open(PICLD_DOOR, O_RDONLY)) < 0) { - err = PICL_NORESPONSE; - break; - } - --trycount; - continue; - } - /* - * Upgrade read to a write lock - */ - (void) rw_unlock(&picl_lock); - (void) rw_wrlock(&picl_lock); - - /* - * if picl_shutdown happens during lock upgrade - */ - if (refcnt == 0) { - err = PICL_NOTINITIALIZED; - break; - } - write_locked = 1; - continue; - } - (void) rw_unlock(&picl_lock); /* read or write unlock */ - return (err); -} - -/* - * Initialize the PICL interface - * Increment the reference count. - */ -int -picl_initialize(void) -{ - int err; - - (void) rw_wrlock(&picl_lock); - if (refcnt > 0) { /* previously initialized */ - err = handshake(); - if (err == PICL_SUCCESS) { - ++refcnt; - (void) rw_unlock(&picl_lock); /* write unlock */ - return (err); - } - if (err != PICL_NORESPONSE) { - (void) rw_unlock(&picl_lock); /* write unlock */ - return (err); - } - (void) close(door_handle); /* close bad door */ - } - - /* - * Open picld door and initialize door_handle - */ - if ((door_handle = open(PICLD_DOOR, O_RDONLY)) < 0) { - (void) rw_unlock(&picl_lock); /* write unlock */ - return (PICL_NORESPONSE); - } - - err = handshake(); - if (err != PICL_SUCCESS) - (void) close(door_handle); - else - ++refcnt; - (void) rw_unlock(&picl_lock); /* write unlock */ - return (err); -} - -/* - * Shutdown the PICL interface - * Decrement the reference count and close the door_handle if refcnt is zero - */ -int -picl_shutdown(void) -{ - int err; - door_arg_t darg; - picl_reqfini_t req_fini; - picl_retfini_t outargs; - - (void) rw_wrlock(&picl_lock); /* write lock */ - if (refcnt == 0) { - (void) rw_unlock(&picl_lock); /* write unlock */ - return (PICL_NOTINITIALIZED); - } - req_fini.cnum = PICL_CNUM_FINI; - err = post_req(&darg, &req_fini, sizeof (picl_reqfini_t), - NULL, 0, &outargs, sizeof (picl_retfini_t)); - --refcnt; - if (refcnt == 0) - (void) close(door_handle); - (void) rw_unlock(&picl_lock); /* write unlock */ - if (err != PICL_SUCCESS) - return (err); - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function waits for the specified number of seconds for a PICL - * tree refresh. - */ -int -picl_wait(unsigned int secs) -{ - door_arg_t darg; - picl_reqwait_t req_wait; - picl_retwait_t outargs; - picl_service_t *ret; - int err; - - req_wait.cnum = PICL_CNUM_WAIT; - req_wait.secs = secs; - err = trysend_req(&darg, &req_wait, sizeof (picl_reqwait_t), - NULL, 0, &outargs, sizeof (picl_retwait_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - err = ret->ret_wait.retcode; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (err); -} - -/* - * This function copies the handle of the root node of the PICL tree into - * the buffer - */ -int -picl_get_root(picl_nodehdl_t *rooth) -{ - door_arg_t darg; - picl_reqroot_t req_root; - picl_retroot_t outargs; - picl_service_t *ret; - int err; - - req_root.cnum = PICL_CNUM_GETROOT; - err = trysend_req(&darg, &req_root, sizeof (picl_reqroot_t), NULL, - 0, &outargs, sizeof (picl_retroot_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *rooth = ret->ret_root.rnode; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the value of the property specified by its handle - * into the buffer . - */ -int -picl_get_propval(picl_prophdl_t proph, void *valbuf, size_t nbytes) -{ - door_arg_t darg; - picl_reqattrval_t req_attrval; - picl_service_t *ret; - picl_retattrval_t *outargs; - int err; - - req_attrval.cnum = PICL_CNUM_GETATTRVAL; - req_attrval.attr = proph; - req_attrval.bufsize = (uint32_t)nbytes; - if ((size_t)req_attrval.bufsize != nbytes) - return (PICL_VALUETOOBIG); - outargs = alloca(sizeof (picl_retattrval_t) + nbytes); - - err = trysend_req(&darg, &req_attrval, sizeof (picl_reqattrval_t), - NULL, 0, outargs, sizeof (picl_retattrval_t) + nbytes, - SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - if (ret->ret_attrval.nbytes > (uint32_t)nbytes) - err = PICL_VALUETOOBIG; - else - (void) memcpy(valbuf, ret->ret_attrval.ret_buf, - (size_t)ret->ret_attrval.nbytes); - if (darg.rbuf != (char *)outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (err); -} - -/* - * This function copies the value of the property specified by its - * name into the buffer - */ -int -picl_get_propval_by_name(picl_nodehdl_t nodeh, const char *propname, - void *valbuf, size_t nbytes) -{ - door_arg_t darg; - picl_reqattrvalbyname_t req_attrvalbyname; - picl_service_t *ret; - picl_retattrvalbyname_t *outargs; - int err; - - req_attrvalbyname.cnum = PICL_CNUM_GETATTRVALBYNAME; - req_attrvalbyname.nodeh = nodeh; - (void) strcpy(req_attrvalbyname.propname, propname); - req_attrvalbyname.bufsize = (uint32_t)nbytes; - if ((size_t)req_attrvalbyname.bufsize != nbytes) - return (PICL_VALUETOOBIG); - outargs = alloca(sizeof (picl_retattrvalbyname_t) + nbytes); - - err = trysend_req(&darg, &req_attrvalbyname, - sizeof (picl_reqattrvalbyname_t), NULL, 0, outargs, - sizeof (picl_retattrvalbyname_t) + nbytes, SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - if (ret->ret_attrvalbyname.nbytes > (uint32_t)nbytes) - err = PICL_VALUETOOBIG; - else - (void) memcpy(valbuf, ret->ret_attrvalbyname.ret_buf, - (size_t)ret->ret_attrvalbyname.nbytes); - if (darg.rbuf != (char *)outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (err); -} - -/* - * This function sets the value of the property specified by its - * handle with the value specified in . - */ -int -picl_set_propval(picl_prophdl_t proph, void *valbuf, size_t nbytes) -{ - door_arg_t darg; - picl_reqsetattrval_t ret_setattrval; - picl_reqsetattrval_t *inargs; - int err; - - if (nbytes >= (size_t)PICL_PROPSIZE_MAX) - return (PICL_VALUETOOBIG); - - inargs = alloca(sizeof (picl_reqsetattrval_t) + nbytes); - inargs->cnum = PICL_CNUM_SETATTRVAL; - inargs->attr = proph; - inargs->bufsize = (uint32_t)nbytes; - if ((size_t)inargs->bufsize != nbytes) - return (PICL_VALUETOOBIG); - (void) memcpy(inargs->valbuf, valbuf, nbytes); - - err = trysend_req(&darg, inargs, sizeof (picl_reqsetattrval_t) + - nbytes, NULL, 0, &ret_setattrval, - sizeof (picl_retsetattrval_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - if (darg.rbuf != (char *)&ret_setattrval) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function sets the value of the property specified by its - * name with the value given in - */ -int -picl_set_propval_by_name(picl_nodehdl_t nodeh, const char *propname, - void *valbuf, size_t nbytes) -{ - door_arg_t darg; - picl_retsetattrvalbyname_t ret_setattrvalbyname; - picl_reqsetattrvalbyname_t *inargs; - int err; - - if (nbytes >= (size_t)PICL_PROPSIZE_MAX) - return (PICL_VALUETOOBIG); - - inargs = alloca(sizeof (picl_reqsetattrvalbyname_t) + nbytes); - inargs->cnum = PICL_CNUM_SETATTRVALBYNAME; - inargs->nodeh = nodeh; - (void) strcpy(inargs->propname, propname); - inargs->bufsize = (uint32_t)nbytes; - if ((size_t)inargs->bufsize != nbytes) - return (PICL_VALUETOOBIG); - (void) memcpy(inargs->valbuf, valbuf, nbytes); - - err = trysend_req(&darg, inargs, - sizeof (picl_reqsetattrvalbyname_t) + nbytes, NULL, 0, - &ret_setattrvalbyname, sizeof (picl_retsetattrvalbyname_t), - SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - if (darg.rbuf != (char *)&ret_setattrvalbyname) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the information of the specified property - * into - */ -int -picl_get_propinfo(picl_prophdl_t proph, picl_propinfo_t *pinfo) -{ - door_arg_t darg; - picl_reqattrinfo_t req_attrinfo; - picl_service_t *ret; - picl_retattrinfo_t outargs; - int err; - - req_attrinfo.cnum = PICL_CNUM_GETATTRINFO; - req_attrinfo.attr = proph; - - err = trysend_req(&darg, &req_attrinfo, - sizeof (picl_reqattrinfo_t), NULL, 0, &outargs, - sizeof (picl_retattrinfo_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - pinfo->type = ret->ret_attrinfo.type; - pinfo->accessmode = ret->ret_attrinfo.accessmode; - pinfo->size = (size_t)ret->ret_attrinfo.size; - (void) strcpy(pinfo->name, ret->ret_attrinfo.name); - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the handle of the first property of a node into - * - */ -int -picl_get_first_prop(picl_nodehdl_t nodeh, picl_prophdl_t *proph) -{ - door_arg_t darg; - picl_reqfirstattr_t req_firstattr; - picl_service_t *ret; - picl_retfirstattr_t outargs; - int err; - - req_firstattr.cnum = PICL_CNUM_GETFIRSTATTR; - req_firstattr.nodeh = nodeh; - - err = trysend_req(&darg, &req_firstattr, - sizeof (picl_reqfirstattr_t), NULL, 0, &outargs, - sizeof (picl_retfirstattr_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *proph = ret->ret_firstattr.attr; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the handle of the next property in list - * into . - */ -int -picl_get_next_prop(picl_prophdl_t proph, picl_prophdl_t *nextprop) -{ - door_arg_t darg; - picl_reqnextattr_t req_nextattr; - picl_service_t *ret; - picl_retnextattr_t outargs; - int err; - - - req_nextattr.cnum = PICL_CNUM_GETNEXTATTR; - req_nextattr.attr = proph; - - err = trysend_req(&darg, &req_nextattr, - sizeof (picl_reqnextattr_t), NULL, 0, &outargs, - sizeof (picl_retnextattr_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *nextprop = ret->ret_nextattr.nextattr; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the handle of the property specified by its - * name into . - */ -int -picl_get_prop_by_name(picl_nodehdl_t nodeh, const char *name, - picl_prophdl_t *proph) -{ - door_arg_t darg; - picl_reqattrbyname_t req_attrbyname; - picl_service_t *ret; - picl_retattrbyname_t outargs; - int err; - - req_attrbyname.cnum = PICL_CNUM_GETATTRBYNAME; - req_attrbyname.nodeh = nodeh; - (void) strcpy(req_attrbyname.propname, name); - - err = trysend_req(&darg, &req_attrbyname, - sizeof (picl_reqattrbyname_t), NULL, 0, &outargs, - sizeof (picl_retattrbyname_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *proph = ret->ret_attrbyname.attr; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the handle of the next property on the same - * row of the table into . - * When proph is the table handle, the handle of the property that is - * in first row and first column is copied. - */ -int -picl_get_next_by_row(picl_prophdl_t proph, picl_prophdl_t *rowproph) -{ - door_arg_t darg; - picl_reqattrbyrow_t req_attrbyrow; - picl_service_t *ret; - picl_retattrbyrow_t outargs; - int err; - - req_attrbyrow.cnum = PICL_CNUM_GETATTRBYROW; - req_attrbyrow.attr = proph; - - err = trysend_req(&darg, &req_attrbyrow, - sizeof (picl_reqattrbyrow_t), NULL, 0, &outargs, - sizeof (picl_retattrbyrow_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *rowproph = ret->ret_attrbyrow.rowattr; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function copies the handle of the next property on the same - * column of the table into . - * When proph is the table handle, the handle of the property that is - * in the first row and first column is copied. - */ -int -picl_get_next_by_col(picl_prophdl_t proph, picl_prophdl_t *colproph) -{ - door_arg_t darg; - picl_reqattrbycol_t req_attrbycol; - picl_service_t *ret; - picl_retattrbycol_t outargs; - int err; - - req_attrbycol.cnum = PICL_CNUM_GETATTRBYCOL; - req_attrbycol.attr = proph; - - err = trysend_req(&darg, (char *)&req_attrbycol, - sizeof (picl_reqattrbycol_t), NULL, 0, (char *)&outargs, - sizeof (picl_retattrbycol_t), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *colproph = ret->ret_attrbycol.colattr; - if (darg.rbuf != (char *)&outargs) - (void) munmap(darg.rbuf, darg.rsize); - return (PICL_SUCCESS); -} - -/* - * This function returns the picl error messages corresponding to the - * error number. - */ -char * -picl_strerror(int err) -{ - if ((err < N_ERRORS) && (err >= 0)) { - return (gettext(picl_errmsg[err])); - } - return (NULL); -} - -/* - * recursively visit all nodes - */ -static int -do_walk(picl_nodehdl_t rooth, const char *classname, - void *c_args, int (*callback_fn)(picl_nodehdl_t hdl, void *args)) -{ - int err; - picl_nodehdl_t chdh; - char classval[PICL_CLASSNAMELEN_MAX]; - - err = picl_get_propval_by_name(rooth, PICL_PROP_CHILD, &chdh, - sizeof (chdh)); - while (err == PICL_SUCCESS) { - err = picl_get_propval_by_name(chdh, PICL_PROP_CLASSNAME, - classval, sizeof (classval)); - if (err != PICL_SUCCESS) - return (err); - - if ((classname == NULL) || (strcmp(classname, classval) == 0)) { - err = callback_fn(chdh, c_args); - if (err != PICL_WALK_CONTINUE) - return (err); - } - - if ((err = do_walk(chdh, classname, c_args, callback_fn)) != - PICL_WALK_CONTINUE) - return (err); - - err = picl_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (chdh)); - } - if (err == PICL_PROPNOTFOUND) /* end of a branch */ - return (PICL_WALK_CONTINUE); - return (err); - -} - -/* - * This function walks the tree by class and invokes the callback - * function on class name matches. - */ -int -picl_walk_tree_by_class(picl_nodehdl_t rooth, const char *classname, - void *c_args, int (*callback_fn)(picl_nodehdl_t hdl, void *args)) -{ - int err; - - if (callback_fn == NULL) - return (PICL_INVALIDARG); - err = do_walk(rooth, classname, c_args, callback_fn); - if ((err == PICL_WALK_CONTINUE) || (err == PICL_WALK_TERMINATE)) - return (PICL_SUCCESS); - return (err); -} - -/* - * This function gets propinfo and prop handle of the named property - */ -int -picl_get_propinfo_by_name(picl_nodehdl_t nodeh, const char *prop_name, - picl_propinfo_t *pinfo, picl_prophdl_t *proph) -{ - int err; - picl_prophdl_t tmpproph; - picl_propinfo_t tmppinfo; - - err = picl_get_prop_by_name(nodeh, prop_name, &tmpproph); - if (err != PICL_SUCCESS) - return (err); - - err = picl_get_propinfo(tmpproph, &tmppinfo); - if (err != PICL_SUCCESS) - return (err); - - *proph = tmpproph; - *pinfo = tmppinfo; - return (PICL_SUCCESS); -} - -int -picl_get_node_by_path(const char *piclpath, picl_nodehdl_t *nodeh) -{ - door_arg_t darg; - picl_reqnodebypath_t req; - picl_retnodebypath_t out; - picl_service_t *ret; - int err; - - req.cnum = PICL_CNUM_NODEBYPATH; - req.psize = PATH_MAX; - if (strlen(piclpath) >= PATH_MAX) - return (PICL_VALUETOOBIG); - (void) strncpy(req.pathbuf, piclpath, PATH_MAX); - - err = trysend_req(&darg, &req, sizeof (req), NULL, 0, &out, - sizeof (out), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *nodeh = ret->ret_nodebypath.nodeh; - if (darg.rbuf != (char *)&out) - (void) munmap(darg.rbuf, darg.rsize); - return (err); -} - -int -picl_find_node(picl_nodehdl_t rooth, char *pname, picl_prop_type_t ptype, - void *pval, size_t valsize, picl_nodehdl_t *retnodeh) -{ - door_arg_t darg; - picl_reqfindnode_t *req; - picl_service_t *ret; - picl_retfindnode_t out; - int err; - - req = alloca(sizeof (picl_reqfindnode_t) + valsize); - req->cnum = PICL_CNUM_FINDNODE; - req->nodeh = rooth; - if (strlen(pname) >= PICL_PROPNAMELEN_MAX) - return (PICL_VALUETOOBIG); - (void) strncpy(req->propname, pname, PICL_PROPNAMELEN_MAX); - req->ptype = ptype; - req->valsize = (uint32_t)valsize; - if ((size_t)req->valsize != valsize) - return (PICL_VALUETOOBIG); - (void) memcpy(req->valbuf, pval, valsize); - - err = trysend_req(&darg, req, sizeof (picl_reqfindnode_t) + valsize, - NULL, 0, &out, sizeof (out), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *retnodeh = ret->ret_findnode.rnodeh; - if (darg.rbuf != (char *)&out) - (void) munmap(darg.rbuf, darg.rsize); - return (err); -} - -int -picl_get_frutree_parent(picl_nodehdl_t devh, picl_nodehdl_t *fruh) -{ - door_arg_t darg; - picl_reqfruparent_t req; - picl_retfruparent_t out; - picl_service_t *ret; - int err; - - req.cnum = PICL_CNUM_FRUTREEPARENT; - req.devh = devh; - - err = trysend_req(&darg, &req, sizeof (req), NULL, 0, &out, - sizeof (out), SEND_REQ_TRYCOUNT); - if (err != PICL_SUCCESS) - return (err); - - /*LINTED*/ - ret = (picl_service_t *)darg.rbuf; - *fruh = ret->ret_fruparent.fruh; - if (darg.rbuf != (char *)&out) - (void) munmap(darg.rbuf, darg.rsize); - return (err); -} diff --git a/usr/src/lib/libpicl/picl.h b/usr/src/lib/libpicl/picl.h deleted file mode 100644 index 02ca5bbb10..0000000000 --- a/usr/src/lib/libpicl/picl.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICL_H -#define _PICL_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * PICL Interface - */ - -#include - -#define PICL_VERSION_1 0x1 - -/* - * A PICL handle - */ -typedef uint64_t picl_nodehdl_t; -typedef uint64_t picl_prophdl_t; - -/* - * Maximum length of a property name - */ -#define PICL_PROPNAMELEN_MAX 256 -#define PICL_CLASSNAMELEN_MAX (PICL_PROPNAMELEN_MAX - sizeof ("__")) - -/* - * Maximum size of a property value - */ -#define PICL_PROPSIZE_MAX (512 * 1024) - -/* - * PICL property access modes - */ -#define PICL_READ 0x1 -#define PICL_WRITE 0x2 -/* Not seen by clients */ -#define PICL_VOLATILE 0x4 - -/* - * PICL error numbers - */ -typedef enum { - PICL_SUCCESS = 0x0, - PICL_FAILURE, /* general failure */ - PICL_NORESPONSE, /* No response */ - PICL_UNKNOWNSERVICE, /* unknown PICL service */ - PICL_NOTINITIALIZED, /* interface not initialized */ - PICL_INVALIDARG, /* invalid arguments passed */ - PICL_VALUETOOBIG, /* value too big for buffer */ - PICL_PROPNOTFOUND, /* property not found */ - PICL_NOTTABLE, /* not a table */ - PICL_NOTNODE, /* not a node */ - PICL_NOTPROP, /* not a prop */ - PICL_ENDOFLIST, /* end of list */ - PICL_PROPEXISTS, /* prop already exists */ - PICL_NOTWRITABLE, /* not writable */ - PICL_PERMDENIED, /* permission denied */ - PICL_INVALIDHANDLE, /* invalid handle */ - PICL_STALEHANDLE, /* stale handle */ - PICL_NOTSUPPORTED, /* version not supported */ - PICL_TIMEDOUT, /* timed out */ - PICL_CANTDESTROY, /* cannot destroy */ - PICL_TREEBUSY, /* too busy to lock tree */ - PICL_CANTPARENT, /* already has a parent */ - PICL_RESERVEDNAME, /* property name is reserved */ - PICL_INVREFERENCE, /* Invalid reference value */ - PICL_WALK_CONTINUE, /* continue walking tree */ - PICL_WALK_TERMINATE, /* stop walking tree */ - PICL_NODENOTFOUND, /* node not found */ - PICL_NOSPACE, /* not enough space available */ - PICL_NOTREADABLE, /* property not readable */ - PICL_PROPVALUNAVAILABLE /* property value unavailable */ -} picl_errno_t; - -/* - * PICL property types - */ -typedef enum { - PICL_PTYPE_UNKNOWN = 0x0, - PICL_PTYPE_VOID, /* exists or not */ - PICL_PTYPE_INT, /* scalar */ - PICL_PTYPE_UNSIGNED_INT, /* scalar */ - PICL_PTYPE_FLOAT, /* scalar */ - PICL_PTYPE_REFERENCE, /* reference handle */ - PICL_PTYPE_TABLE, /* table handle */ - PICL_PTYPE_TIMESTAMP, /* time stamp */ - PICL_PTYPE_BYTEARRAY, /* array of bytes */ - PICL_PTYPE_CHARSTRING /* nul terminated array of chars */ -} picl_prop_type_t; - -typedef struct { - picl_prop_type_t type; - unsigned int accessmode; /* always == PICL_READ */ - size_t size; /* item size or string size */ - char name[PICL_PROPNAMELEN_MAX]; -} picl_propinfo_t; - -/* - * ------------------------------------- - * Function prototypes of PICL Interface - * ------------------------------------- - */ - -extern int picl_initialize(void); -extern int picl_shutdown(void); -extern int picl_get_root(picl_nodehdl_t *nodehandle); -extern int picl_get_propval(picl_prophdl_t proph, void *valbuf, - size_t sz); -extern int picl_get_propval_by_name(picl_nodehdl_t nodeh, - const char *propname, void *valbuf, size_t sz); -extern int picl_set_propval(picl_prophdl_t proph, void *valbuf, - size_t sz); -extern int picl_set_propval_by_name(picl_nodehdl_t nodeh, - const char *propname, void *valbuf, size_t sz); -extern int picl_get_propinfo(picl_prophdl_t proph, picl_propinfo_t *pi); -extern int picl_get_first_prop(picl_nodehdl_t nodeh, picl_prophdl_t *proph); -extern int picl_get_next_prop(picl_prophdl_t proph, picl_prophdl_t *nexth); -extern int picl_get_prop_by_name(picl_nodehdl_t nodeh, const char *nm, - picl_prophdl_t *ph); -extern int picl_get_next_by_row(picl_prophdl_t thish, picl_prophdl_t *proph); -extern int picl_get_next_by_col(picl_prophdl_t thish, picl_prophdl_t *proph); -extern int picl_wait(unsigned int secs); -extern char *picl_strerror(int err); -extern int picl_walk_tree_by_class(picl_nodehdl_t rooth, - const char *classname, void *c_args, - int (*callback_fn)(picl_nodehdl_t hdl, void *args)); -extern int picl_get_propinfo_by_name(picl_nodehdl_t nodeh, const char *pname, - picl_propinfo_t *pinfo, picl_prophdl_t *proph); - -extern int picl_find_node(picl_nodehdl_t rooth, char *pname, - picl_prop_type_t ptype, void *pval, size_t valsize, - picl_nodehdl_t *retnodeh); - -extern int picl_get_node_by_path(const char *piclpath, picl_nodehdl_t *nodeh); - -extern int picl_get_frutree_parent(picl_nodehdl_t devh, picl_nodehdl_t *fruh); - -/* - * Standard PICL names: properties and nodes - */ -#define PICL_NODE_ROOT "/" -#define PICL_NODE_PLATFORM "platform" -#define PICL_NODE_OBP "obp" -#define PICL_NODE_FRUTREE "frutree" - -#define PICL_PROP_NAME "name" -#define PICL_PROP_CLASSNAME "_class" -#define PICL_PROP_PARENT "_parent" -#define PICL_PROP_CHILD "_child" -#define PICL_PROP_PEER "_peer" - -#define PICL_CLASS_PICL "picl" - -#ifdef __cplusplus -} -#endif - -#endif /* _PICL_H */ diff --git a/usr/src/lib/libpicl/picl2door.h b/usr/src/lib/libpicl/picl2door.h deleted file mode 100644 index 7399d0ed9e..0000000000 --- a/usr/src/lib/libpicl/picl2door.h +++ /dev/null @@ -1,436 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICL2DOOR_H -#define _PICL2DOOR_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PICLD_DOOR_VERSION 1 -#define PICLD_DOOR "/var/run/picld_door" -#define PICLD_DOOR_COOKIE ((void *)(0xdeaffeed ^ PICLD_DOOR_VERSION)) - -/* - * PICL service calls - */ -typedef enum { - PICL_CNUM_INIT = 0x1, /* initialize */ - PICL_CNUM_FINI, /* fini */ - PICL_CNUM_GETROOT, /* get root node */ - PICL_CNUM_GETATTRVAL, /* get attr val */ - PICL_CNUM_GETATTRVALBYNAME, /* get attr val by name */ - PICL_CNUM_GETATTRINFO, /* get attribute information */ - PICL_CNUM_GETFIRSTATTR, /* get first attribute */ - PICL_CNUM_GETNEXTATTR, /* get next attribute */ - PICL_CNUM_GETATTRBYNAME, /* get attr by name */ - PICL_CNUM_GETATTRBYROW, /* get attr by row */ - PICL_CNUM_GETATTRBYCOL, /* get attr by column */ - PICL_CNUM_SETATTRVAL, /* set attribute's value */ - PICL_CNUM_SETATTRVALBYNAME, /* set attr val by name */ - PICL_CNUM_PING, /* ping daemon */ - PICL_CNUM_WAIT, /* wait n seconds for refresh */ - PICL_CNUM_ERROR, /* error response */ - PICL_CNUM_FINDNODE, /* find node */ - PICL_CNUM_NODEBYPATH, /* get node by path */ - PICL_CNUM_FRUTREEPARENT /* get frutree parent */ -} picl_callnumber_t; - -typedef union { - picl_nodehdl_t nodeh; - picl_prophdl_t proph; - char str[1]; -} propval_t; -#define ret_buf u.str -#define ret_nodeh u.nodeh -#define ret_proph u.proph - -/* - * Generic picl service request argument - */ -typedef struct { - picl_callnumber_t cnum; /* service call number */ - char buf[4]; /* buffer containing input arguments */ -} picl_req_t; - -typedef struct { - picl_callnumber_t cnum; /* service call number */ - char buf[4]; /* buffer containing the results */ -} picl_ret_t; - - /* - * PICL initialize - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_INIT */ - unsigned int clrev; /* client's ID and revision number */ -} picl_reqinit_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_INIT */ - int rev; /* PICL daemon's revision number */ -} picl_retinit_t; - - - /* - * PICL shutdown - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_FINI */ -} picl_reqfini_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_FINI */ -} picl_retfini_t; - - /* - * PICL get root - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETROOT */ -} picl_reqroot_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETROOT */ - picl_nodehdl_t rnode; /* root handle */ -} picl_retroot_t; - - /* - * PICL get attr val - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRVAL */ - picl_prophdl_t attr; /* attribute handle */ - uint32_t bufsize; /* value buffer size */ -} picl_reqattrval_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRVAL */ - picl_prophdl_t attr; /* attribute handle */ - uint32_t nbytes; /* return value size */ - propval_t u; -} picl_retattrval_t; - - /* - * PICL get attr val by name - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRVALBYNAME */ - picl_nodehdl_t nodeh; /* node handle */ - /* attribute name */ - char propname[PICL_PROPNAMELEN_MAX]; - uint32_t bufsize; /* buffer size */ -} picl_reqattrvalbyname_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRVALBYNAME */ - picl_nodehdl_t nodeh; /* node handle */ - /* attribute name */ - char propname[PICL_PROPNAMELEN_MAX]; - uint32_t nbytes; /* return value size */ - propval_t u; /* return value */ -} picl_retattrvalbyname_t; - - /* - * PICL get attr info - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRINFO */ - picl_prophdl_t attr; /* attribute handle */ -} picl_reqattrinfo_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRINFO */ - picl_prophdl_t attr; /* attribute handle */ - picl_prop_type_t type; /* attribute type */ - unsigned int accessmode; /* access mode */ - uint32_t size; /* value size */ - /* attr name */ - char name[PICL_PROPNAMELEN_MAX]; -} picl_retattrinfo_t; - - /* - * PICL get first attr - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETFIRSTATTR */ - picl_nodehdl_t nodeh; /* node handle */ -} picl_reqfirstattr_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETFIRSTATTR */ - picl_nodehdl_t nodeh; /* node handle */ - picl_prophdl_t attr; /* first attribute handle */ -} picl_retfirstattr_t; - - /* - * PICL get next attr - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETNEXTATTR */ - picl_prophdl_t attr; /* attribute handle */ -} picl_reqnextattr_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETNEXTATTR */ - picl_prophdl_t attr; /* attribute handle */ - picl_prophdl_t nextattr; /* next attribute handle */ -} picl_retnextattr_t; - - /* - * PICL get attr by name - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRBYNAME */ - picl_nodehdl_t nodeh; /* node handle */ - /* attr name */ - char propname[PICL_PROPNAMELEN_MAX]; -} picl_reqattrbyname_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRBYNAME */ - picl_nodehdl_t nodeh; /* node handle */ - /* attr name */ - char propname[PICL_PROPNAMELEN_MAX]; - picl_prophdl_t attr; /* attr handle */ -} picl_retattrbyname_t; - - /* - * PICL get attr by row - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRBYROW */ - picl_prophdl_t attr; /* attr handle */ -} picl_reqattrbyrow_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRBYROW */ - picl_prophdl_t attr; /* attr handle */ - picl_prophdl_t rowattr; /* attr by row handle */ -} picl_retattrbyrow_t; - - /* - * PICL get attr by column - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRBYCOL */ - picl_prophdl_t attr; /* attr handle */ -} picl_reqattrbycol_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_GETATTRBYCOL */ - picl_prophdl_t attr; /* attr handle */ - picl_prophdl_t colattr; /* attr by col handle */ -} picl_retattrbycol_t; - - /* - * PICL set attr val - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_SETATTRVAL */ - picl_prophdl_t attr; /* attribute handle */ - uint32_t bufsize; /* value buffer size */ - char valbuf[1]; -} picl_reqsetattrval_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_SETATTRVAL */ - picl_prophdl_t attr; /* attribute handle */ -} picl_retsetattrval_t; - - /* - * PICL set attr val by name - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_SETATTRVALBYNAME */ - picl_nodehdl_t nodeh; /* node handle */ - /* attr name */ - char propname[PICL_PROPNAMELEN_MAX]; - uint32_t bufsize; /* buffer size */ - char valbuf[1]; -} picl_reqsetattrvalbyname_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_SETATTRVALBYNAME */ - picl_nodehdl_t nodeh; /* node handle */ - /* attr name */ - char propname[PICL_PROPNAMELEN_MAX]; -} picl_retsetattrvalbyname_t; - - /* - * PICL ping - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_PING */ -} picl_reqping_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_PING */ -} picl_retping_t; - - /* - * PICL wait - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_WAIT */ - unsigned int secs; /* number of seconds */ -} picl_reqwait_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_WAIT service */ - unsigned int secs; /* input seconds */ - int retcode; /* return code */ -} picl_retwait_t; - - /* - * PICL find node - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_FINDNODE */ - picl_nodehdl_t nodeh; /* top node handle */ - /* property name */ - char propname[PICL_PROPNAMELEN_MAX]; - picl_prop_type_t ptype; /* property type */ - uint32_t valsize; /* size of prop value */ - char valbuf[1]; /* prop value */ -} picl_reqfindnode_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_FINDNODE */ - picl_nodehdl_t rnodeh; /* matched node */ -} picl_retfindnode_t; - - /* - * PICL get node by path - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_NODEBYPATH */ - uint32_t psize; /* size of path */ - char pathbuf[PATH_MAX]; /* picl path */ -} picl_reqnodebypath_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_NODEBYPATH */ - picl_nodehdl_t nodeh; /* node handle */ -} picl_retnodebypath_t; - - /* - * PICL get frutree parent - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_FRUTREEPARENT */ - picl_nodehdl_t devh; /* dev node handle */ -} picl_reqfruparent_t; - -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_FRUTREEPARENT */ - picl_nodehdl_t fruh; /* fru parent handle */ -} picl_retfruparent_t; - - /* - * PICL error return - */ -typedef struct { - picl_callnumber_t cnum; /* PICL_CNUM_ERROR */ - picl_callnumber_t in_cnum; /* requested service number */ - picl_errno_t errnum; /* return error code */ -} picl_reterror_t; - -typedef union { - picl_req_t in; /* req arguments */ - picl_ret_t out; /* out results */ - - picl_reqinit_t req_init; /* req initialize */ - picl_retinit_t ret_init; /* ret initialize */ - - picl_reqfini_t req_fini; /* req fini */ - picl_retfini_t ret_fini; /* ret fini */ - - picl_reqroot_t req_root; /* req root node */ - picl_retroot_t ret_root; /* ret root node */ - - picl_reqattrval_t req_attrval; /* req attr value */ - picl_retattrval_t ret_attrval; /* ret attr value */ - - /* req attr val by name */ - picl_reqattrvalbyname_t req_attrvalbyname; - /* ret attr val by name */ - picl_retattrvalbyname_t ret_attrvalbyname; - - picl_reqattrinfo_t req_attrinfo; /* req attr info */ - picl_retattrinfo_t ret_attrinfo; /* ret attr info */ - - picl_reqfirstattr_t req_firstattr; /* req first attr */ - picl_retfirstattr_t ret_firstattr; /* ret first attr */ - - picl_reqnextattr_t req_nextattr; /* req next attr */ - picl_retnextattr_t ret_nextattr; /* ret next attr */ - - picl_reqattrbyname_t req_attrbyname; /* req attr by name */ - picl_retattrbyname_t ret_attrbyname; /* ret attr by name */ - - picl_reqattrbyrow_t req_attrbyrow; /* req attr by row */ - picl_retattrbyrow_t ret_attrbyrow; /* ret attr by row */ - - picl_reqattrbycol_t req_attrbycol; /* req attr by col */ - picl_retattrbycol_t ret_attrbycol; /* ret attr by col */ - - /* set attribute value */ - picl_reqsetattrval_t req_setattrval; - /* ret set attribute value */ - picl_retsetattrval_t ret_setattrval; - - /* set attr val by name */ - picl_reqsetattrvalbyname_t req_setattrvalbyname; - /* set attr val by name */ - picl_retsetattrvalbyname_t ret_setattrvalbyname; - - picl_reqping_t req_ping; /* req ping */ - picl_retping_t ret_ping; /* ret ping */ - - picl_reqwait_t req_wait; /* req wait */ - picl_retwait_t ret_wait; /* ret wait */ - - picl_reqfindnode_t req_findnode; /* req find node */ - picl_retfindnode_t ret_findnode; /* ret find node */ - - picl_reqnodebypath_t req_nodebypath; /* get node by path */ - picl_retnodebypath_t ret_nodebypath; /* ret node by path */ - - picl_reqfruparent_t req_fruparent; /* get frutree parent */ - picl_retfruparent_t ret_fruparent; /* ret frutree parent */ - - picl_reterror_t ret_error; /* return error */ -} picl_service_t; - -#ifdef __cplusplus -} -#endif - -#endif /* _PICL2DOOR_H */ diff --git a/usr/src/lib/libpicltree/Makefile b/usr/src/lib/libpicltree/Makefile deleted file mode 100644 index 311738ae47..0000000000 --- a/usr/src/lib/libpicltree/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include $(SRC)/lib/Makefile.lib - -SUBDIRS = $(MACH) - -# conditional assignments -all := TARGET= all -install := TARGET= install -clean := TARGET= clean -clobber := TARGET= clobber -test := TARGET= test - -# definitions for install_h target -HDRS= picltree.h -ROOTHDRDIR= $(ROOT)/usr/include -ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) -CHECKHDRS= $(HDRS:%.h=%.check) - -.KEEP_STATE: - -all install clean clobber: $(SUBDIRS) - -# install rule for install_h target - -$(ROOTHDRDIR)/%: % - $(INS.file) - -install_h: $(ROOTHDRDIR) $(ROOTHDRS) - -$(ROOTHDRDIR): - $(INS.dir) - -check: $(CHECKHDRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC: - diff --git a/usr/src/lib/libpicltree/Makefile.com b/usr/src/lib/libpicltree/Makefile.com deleted file mode 100644 index b9fa415fac..0000000000 --- a/usr/src/lib/libpicltree/Makefile.com +++ /dev/null @@ -1,43 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -LIBRARY= libpicltree.a -VERS= .1 -OBJECTS= picltree.o - -include $(SRC)/lib/Makefile.lib - -LIBS = $(DYNLIB) -LDLIBS += -lc - -CPPFLAGS += -I.. -I../../libpicl -I$(SRC)/cmd/picl/plugins/inc - -CERRWARN += -Wno-uninitialized - -.KEEP_STATE: - -all : $(LIBS) - -include $(SRC)/lib/Makefile.targ diff --git a/usr/src/lib/libpicltree/i386/Makefile b/usr/src/lib/libpicltree/i386/Makefile deleted file mode 100644 index 21e82ec04a..0000000000 --- a/usr/src/lib/libpicltree/i386/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com - -install: all $(ROOTLIBS) $(ROOTLINKS) diff --git a/usr/src/lib/libpicltree/mapfile-vers b/usr/src/lib/libpicltree/mapfile-vers deleted file mode 100644 index 6a3c7fa4cc..0000000000 --- a/usr/src/lib/libpicltree/mapfile-vers +++ /dev/null @@ -1,110 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. -# - -# -# MAPFILE HEADER START -# -# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. -# Object versioning must comply with the rules detailed in -# -# usr/src/lib/README.mapfiles -# -# You should not be making modifications here until you've read the most current -# copy of that file. If you need help, contact a gatekeeper for guidance. -# -# MAPFILE HEADER END -# - -$mapfile_version 2 - -SYMBOL_VERSION SUNW_1.3 { - global: - ptree_get_frutree_parent; -} SUNW_1.2; - -SYMBOL_VERSION SUNW_1.2 { - global: - ptree_create_and_add_node; - ptree_create_and_add_prop; - ptree_find_node; - ptree_get_node_by_path; - ptree_init_propinfo; - ptree_post_event; - ptree_register_handler; - ptree_unregister_handler; - ptree_walk_tree_by_class; -} SUNW_1.1; - -SYMBOL_VERSION SUNW_1.1 { - global: - picld_plugin_register; - ptree_add_node; - ptree_add_prop; - ptree_add_row_to_table; - ptree_create_node; - ptree_create_prop; - ptree_create_table; - ptree_delete_node; - ptree_delete_prop; - ptree_destroy_node; - ptree_destroy_prop; - ptree_get_first_prop; - ptree_get_next_by_col; - ptree_get_next_by_row; - ptree_get_next_prop; - ptree_get_prop_by_name; - ptree_get_propinfo; - ptree_get_propval; - ptree_get_propval_by_name; - ptree_get_root; - ptree_update_propval; - ptree_update_propval_by_name; -}; - -# There really should be only one SUNWprivate version. -# Don't add any more. Add new private symbols to SUNWprivate_1.2 - -SYMBOL_VERSION SUNWprivate_1.2 { - global: - dbg_exec; - dbg_print; - verbose_level; -} SUNWprivate_1.1; - -SYMBOL_VERSION SUNWprivate_1.1 { - global: - cvt_picl2ptree; - cvt_ptree2picl; - xptree_destroy; - xptree_get_propinfo_by_name; - xptree_get_propval_by_name_with_cred; - xptree_get_propval_with_cred; - xptree_initialize; - xptree_refresh_notify; - xptree_reinitialize; - xptree_update_propval_by_name_with_cred; - xptree_update_propval_with_cred; - local: - *; -}; diff --git a/usr/src/lib/libpicltree/picltree.c b/usr/src/lib/libpicltree/picltree.c deleted file mode 100644 index 77804b985c..0000000000 --- a/usr/src/lib/libpicltree/picltree.c +++ /dev/null @@ -1,3658 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. - */ - -/* - * This module implements the PTree interface and the PICL to PTree calls - */ - -/* - * Note: - * PICL Node and Property Handles Table: - * A node or property in PICL tree has two handles: a ptree handle, which is - * used by plug-ins and the libpicltree interface, and a picl handle - * which is used by clients and the libpicl interface. - * The mapping of ptree handles to the internal PICL object (picl_obj_t) is - * kept in a ptree hash table (ptreetbl), and the mapping of a picl handle - * to its ptree handle is kept in the picl hash table (picltbl). - * The reader/writer lock, ptree_rwlock, is held when reading or modifying ptree - * hash table (ptreetbl) and/or the PICL tree structure (nodes and linkages - * between them). The reader/writer lock, picltbl_rwlock, is held when reading - * or modifying picl hash table (picltbl). - * - * The mutex, ptreehdl_lock, is used to control allocation of ptree handles. - * The mutex, piclhdl_lock, is used to control allocation of picl handles. - * - * The mutex, ptree_refresh_mutex, and the condition, ptree_refresh_cond, - * are used to synchronize PICL refreshes (ptree_refresh) and to wait/signal - * change in PICL tree structure. - * - * The counter, picl_hdl_hi, is the hi water mark for allocated picl handles. - * The counter, ptree_hdl_hi, is the hi water mark for allocated ptree handles. - * A stale handle error is returned for handle values below the hi water - * mark, and invalid handles are returned for handle values above the hi water - * mark or when the process id field of the handle does not match. - * - * Locking Scheme: - * The structure of the PICL tree is controlled by the ptree_rwlock. The - * properties of a node are controlled by individual node locks. The - * piclize-ing or unpiclize-ing of a node is controlled by picltbl_rwlock. - * - * Two-Phase Locking scheme: lock acquire phase and lock release phase. - * - * Lock Ordering: - * The ptree_rwlock and node locks are always acquired in the following order: - * lock ptree_rwlock - * lock node - * - * Lock Strategy: - * There are three locks: - * ptree_rwlock: a reader lock is obtained to do ptree hash table - * lookups and traverse tree. A writer lock is obtained - * when creating or destroying nodes from the ptree, - * or when modifying node linkages: parent, peer, child. - * picltbl_rwlock: a reader lock is obtained for picl hash table lookups. - * A writer lock is obtained when piclize-ing or - * unpiclize-ing nodes or properties. - * node_lock: This is a reader/writer lock for properties of a node. - * A reader lock is obtained before reading property - * values. A writer lock is obtained when adding or - * removing properties and when modifying a property value. - * - * Never hold more than one node lock at a time. - * - * Event Locking: - * There are two locks: - * evtq_lock: this lock protects the event queue. It is obtained - * to queue events that are posted and to unqueue - * events to be dispatched. - * evtq_cv: condition variable is protected by evtq_lock. It is - * used by the ptree event thread to wait for events - * until eventqp is not NULL. - * evtq_empty: condition variable protected by evtq_lock. It is - * used to signal when the eventq becomes empty. The - * reinitialization process waits on this condition. - * evthandler_lock: this protects the event handler list. It is obtained - * to add event handlers on registration and to remove - * event handlers on unregistration. - * (handler)->cv: condition variable per handler protected by - * evthandler_lock. It is used to wait until the - * event handler completes execution (execflg == 0) - * before unregistering the handler. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "picldefs.h" -#include "ptree_impl.h" - -#define SO_VERS ".so.1" - -static hash_t picltbl; /* client handles to picl obj */ -static hash_t ptreetbl; /* ptree handles to picl obj */ -static pthread_mutex_t ptreehdl_lock; -static pthread_mutex_t piclhdl_lock; -static pthread_mutex_t ptree_refresh_mutex; -static rwlock_t picltbl_rwlock; /* PICL handle table lock */ -static rwlock_t ptree_rwlock; /* PICL tree lock */ -static pthread_cond_t ptree_refresh_cond = PTHREAD_COND_INITIALIZER; -static uint32_t ptree_hdl_hi = 1; -static uint32_t picl_hdl_hi = 1; -static picl_obj_t *picl_root_obj = NULL; -static picl_nodehdl_t ptree_root_hdl = PICL_INVALID_PICLHDL; -static int ptree_generation = 0; -static pid_t picld_pid; -static door_cred_t picld_cred; -static int qempty_wait; /* evtq_empty condition waiter flag */ - -static picld_plugin_reg_list_t *plugin_reg_list = NULL; -static picld_plugin_desc_t *plugin_desc; - -static eventq_t *eventqp; /* PICL events queue */ -static pthread_mutex_t evtq_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t evtq_cv = PTHREAD_COND_INITIALIZER; -static pthread_cond_t evtq_empty = PTHREAD_COND_INITIALIZER; -static evt_handler_t *evt_handlers; /* Event handler list */ -static pthread_mutex_t evthandler_lock = PTHREAD_MUTEX_INITIALIZER; - -/* - * PICL daemon verbose level - */ -int verbose_level; - - -/* - * Event handler free functions - */ -static void -free_handler(evt_handler_t *evhp) -{ - free(evhp->ename); - (void) pthread_cond_broadcast(&evhp->cv); - (void) pthread_cond_destroy(&evhp->cv); - free(evhp); -} - - -/* - * queue_event to events queue - */ -static void -queue_event(eventq_t *evt) -{ - eventq_t *tmpp; - - evt->next = NULL; - if (eventqp == NULL) - eventqp = evt; - else { - tmpp = eventqp; - while (tmpp->next != NULL) - tmpp = tmpp->next; - tmpp->next = evt; - } -} - -/* - * unqueue_event from the specified eventq - */ -static eventq_t * -unqueue_event(eventq_t **qp) -{ - eventq_t *evtp; - - evtp = *qp; - if (evtp != NULL) - *qp = evtp->next; - return (evtp); -} - -/* - * register an event handler by adding it to the list - */ -int -ptree_register_handler(const char *ename, - void (*evt_handler)(const char *ename, const void *earg, size_t size, - void *cookie), void *cookie) -{ - evt_handler_t *ent; - evt_handler_t *iter; - - if (ename == NULL) - return (PICL_INVALIDARG); - - /* - * Initialize event handler entry - */ - ent = malloc(sizeof (*ent)); - if (ent == NULL) - return (PICL_FAILURE); - ent->ename = strdup(ename); - if (ent->ename == NULL) { - free(ent); - return (PICL_FAILURE); - } - ent->cookie = cookie; - ent->evt_handler = evt_handler; - ent->execflg = 0; - ent->wakeupflg = 0; - (void) pthread_cond_init(&ent->cv, NULL); - ent->next = NULL; - - /* - * add handler to the handler list - */ - (void) pthread_mutex_lock(&evthandler_lock); - if (evt_handlers == NULL) { - evt_handlers = ent; - (void) pthread_mutex_unlock(&evthandler_lock); - return (PICL_SUCCESS); - } - iter = evt_handlers; - while (iter->next != NULL) - iter = iter->next; - iter->next = ent; - (void) pthread_mutex_unlock(&evthandler_lock); - - return (PICL_SUCCESS); -} - -/* - * unregister handler - */ -void -ptree_unregister_handler(const char *ename, - void (*evt_handler)(const char *ename, const void *earg, size_t size, - void *cookie), void *cookie) -{ - evt_handler_t *evhdlrp, **evhdlrpp; - - if (ename == NULL) - return; - - /* - * unlink handler from handler list - */ - (void) pthread_mutex_lock(&evthandler_lock); - -retry: - for (evhdlrpp = &evt_handlers; (evhdlrp = *evhdlrpp) != NULL; - evhdlrpp = &evhdlrp->next) { - if ((evhdlrp->cookie != cookie) || - (strcmp(evhdlrp->ename, ename) != 0) || - (evhdlrp->evt_handler != evt_handler)) - continue; - - /* - * If the handler is in execution, release the lock - * and wait for it to complete and retry. - */ - if (evhdlrp->execflg) { - evhdlrp->wakeupflg = 1; - (void) pthread_cond_wait(&evhdlrp->cv, - &evthandler_lock); - goto retry; - } - - /* - * Unlink this handler from the linked list - */ - *evhdlrpp = evhdlrp->next; - free_handler(evhdlrp); - break; - } - - (void) pthread_mutex_unlock(&evthandler_lock); -} - -/* - * Call all registered handlers for the event - */ -static void -call_event_handlers(eventq_t *ev) -{ - evt_handler_t *iter; - void (*evhandler)(const char *, const void *, size_t, void *); - void (*completion_handler)(char *ename, void *earg, size_t size); - - (void) pthread_mutex_lock(&evthandler_lock); - iter = evt_handlers; - while (iter != NULL) { - if (strcmp(iter->ename, ev->ename) == 0) { - evhandler = iter->evt_handler; - iter->execflg = 1; - (void) pthread_mutex_unlock(&evthandler_lock); - if (evhandler) { - dbg_print(2, "ptree_evthr: Invoking evthdlr:%p" - " ename:%s\n", evhandler, ev->ename); - (*evhandler)(ev->ename, ev->earg, ev->size, - iter->cookie); - dbg_print(2, "ptree_evthr: done evthdlr:%p " - "ename:%s\n", evhandler, ev->ename); - } - (void) pthread_mutex_lock(&evthandler_lock); - iter->execflg = 0; - if (iter->wakeupflg) { - iter->wakeupflg = 0; - (void) pthread_cond_broadcast(&iter->cv); - } - } - iter = iter->next; - } - (void) pthread_mutex_unlock(&evthandler_lock); - if ((completion_handler = ev->completion_handler) != NULL) { - dbg_print(2, - "ptree_evthr: Invoking completion hdlr:%p ename:%s\n", - completion_handler, ev->ename); - (*completion_handler)((char *)ev->ename, (void *)ev->earg, - ev->size); - dbg_print(2, "ptree_evthr: done completion hdlr:%p ename:%s\n", - completion_handler, ev->ename); - } - (void) pthread_mutex_lock(&ptree_refresh_mutex); - ++ptree_generation; - (void) pthread_cond_broadcast(&ptree_refresh_cond); - (void) pthread_mutex_unlock(&ptree_refresh_mutex); -} - -/* - * This function is called by a plug-in to post an event - */ -int -ptree_post_event(const char *ename, const void *earg, size_t size, - void (*completion_handler)(char *ename, void *earg, size_t size)) -{ - eventq_t *evt; - - if (ename == NULL) - return (PICL_INVALIDARG); - - evt = malloc(sizeof (*evt)); - if (evt == NULL) - return (PICL_FAILURE); - evt->ename = ename; - evt->earg = earg; - evt->size = size; - evt->completion_handler = completion_handler; - - (void) pthread_mutex_lock(&evtq_lock); - queue_event(evt); - (void) pthread_cond_broadcast(&evtq_cv); - (void) pthread_mutex_unlock(&evtq_lock); - return (PICL_SUCCESS); -} - -/* - * PICLTREE event thread - */ -/*ARGSUSED*/ -static void * -ptree_event_thread(void *argp) -{ - eventq_t *evt; - - for (;;) { - (void) pthread_mutex_lock(&evtq_lock); - while (eventqp == NULL) { - /* - * Signal empty queue - */ - if (qempty_wait) - (void) pthread_cond_broadcast(&evtq_empty); - (void) pthread_cond_wait(&evtq_cv, &evtq_lock); - } - if ((evt = unqueue_event(&eventqp)) != NULL) { - (void) pthread_mutex_unlock(&evtq_lock); - call_event_handlers(evt); - free(evt); - } else - (void) pthread_mutex_unlock(&evtq_lock); - } - /*NOTREACHED*/ - return (NULL); -} - - -/* - * Create a new element - */ -static hash_elem_t * -hash_newobj(uint32_t hdl_val, void *obj_val) -{ - hash_elem_t *n; - - n = malloc(sizeof (*n)); - if (n == NULL) - return (NULL); - n->hdl = hdl_val; - n->hash_obj = obj_val; - n->next = NULL; - return (n); -} - -static hash_elem_t * -hash_newhdl(uint32_t picl_hdl, uint32_t ptreeh) -{ - hash_elem_t *n; - - n = malloc(sizeof (*n)); - if (n == NULL) - return (NULL); - n->hdl = picl_hdl; - n->hash_hdl = ptreeh; - n->next = NULL; - return (n); -} - -/* - * Initialize a hash table by setting all entries to NULL - */ -static int -hash_init(hash_t *htbl) -{ - int i; - - htbl->hash_size = HASH_TBL_SIZE; - htbl->tbl = malloc(sizeof (hash_elem_t *) * HASH_TBL_SIZE); - if (htbl->tbl == NULL) - return (-1); - for (i = 0; i < htbl->hash_size; ++i) - htbl->tbl[i] = NULL; - return (0); -} - -/* - * Lock free function to add an entry in the hash table - */ -static int -hash_add_newobj(hash_t *htbl, picl_hdl_t hdl, void *pobj) -{ - int indx; - hash_elem_t *n; - uint32_t hash_val = HASH_VAL(hdl); - - n = hash_newobj(hash_val, pobj); - if (n == NULL) - return (-1); - indx = HASH_INDEX(htbl->hash_size, hash_val); - n->next = htbl->tbl[indx]; - htbl->tbl[indx] = n; - return (0); -} - -static int -hash_add_newhdl(hash_t *htbl, picl_hdl_t piclh, picl_hdl_t ptreeh) -{ - int indx; - hash_elem_t *n; - uint32_t picl_val = HASH_VAL(piclh); - uint32_t ptree_val = HASH_VAL(ptreeh); - - n = hash_newhdl(picl_val, ptree_val); - if (n == NULL) - return (-1); - - indx = HASH_INDEX(htbl->hash_size, picl_val); - n->next = htbl->tbl[indx]; - htbl->tbl[indx] = n; - return (0); -} - -/* - * Lock free function to remove the handle from the hash table - * Returns -1 if element not found, 0 if successful - */ -static int -hash_remove(hash_t *htbl, picl_hdl_t hdl) -{ - hash_elem_t *nxt; - hash_elem_t *cur; - int i; - uint32_t hash_val = HASH_VAL(hdl); - - i = HASH_INDEX(htbl->hash_size, hash_val); - if (htbl->tbl[i] == NULL) - return (-1); - - cur = htbl->tbl[i]; - if (cur->hdl == hash_val) { - htbl->tbl[i] = cur->next; - free(cur); - return (0); - } - nxt = cur->next; - while (nxt != NULL) { - if (nxt->hdl == hash_val) { - cur->next = nxt->next; - free(nxt); - return (0); - } - cur = nxt; - nxt = nxt->next; - } - return (-1); -} - -/* - * Lock free function to lookup the hash table for a given handle - * Returns NULL if not found - */ -static void * -hash_lookup_obj(hash_t *htbl, picl_hdl_t hdl) -{ - hash_elem_t *tmp; - int i; - uint32_t hash_val; - - hash_val = HASH_VAL(hdl); - i = HASH_INDEX(htbl->hash_size, hash_val); - tmp = htbl->tbl[i]; - while (tmp != NULL) { - if (tmp->hdl == hash_val) - return (tmp->hash_obj); - tmp = tmp->next; - } - return (NULL); -} - -static picl_hdl_t -hash_lookup_hdl(hash_t *htbl, picl_hdl_t hdl) -{ - hash_elem_t *tmp; - int i; - uint32_t hash_val; - - hash_val = HASH_VAL(hdl); - i = HASH_INDEX(htbl->hash_size, hash_val); - tmp = htbl->tbl[i]; - while (tmp != NULL) { - if (tmp->hdl == hash_val) - return (MAKE_HANDLE(picld_pid, tmp->hash_hdl)); - tmp = tmp->next; - } - return (PICL_INVALID_PICLHDL); -} - -/* - * Is the PICL handle stale or invalid handle? - */ -static int -picl_hdl_error(picl_hdl_t hdl) -{ - uint32_t hash_val = HASH_VAL(hdl); - pid_t pid = GET_PID(hdl); - int err; - - (void) pthread_mutex_lock(&piclhdl_lock); - err = PICL_STALEHANDLE; - if ((pid != picld_pid) || (hash_val >= picl_hdl_hi) || - (hash_val == 0)) - err = PICL_INVALIDHANDLE; - (void) pthread_mutex_unlock(&piclhdl_lock); - return (err); -} - -/* - * Is the Ptree handle stale or invalid handle? - */ -static int -ptree_hdl_error(picl_hdl_t hdl) -{ - uint32_t hash_val = HASH_VAL(hdl); - pid_t pid = GET_PID(hdl); - int err; - - (void) pthread_mutex_lock(&ptreehdl_lock); - err = PICL_STALEHANDLE; - if ((pid != picld_pid) || (hash_val >= ptree_hdl_hi) || - (hash_val == 0)) - err = PICL_INVALIDHANDLE; - (void) pthread_mutex_unlock(&ptreehdl_lock); - return (err); -} - -/* - * For a PICL handle, return the PTree handle and the PICL object - * Locks and releases the PICL table. - */ -int -cvt_picl2ptree(picl_hdl_t hdl, picl_hdl_t *ptree_hdl) -{ - picl_hdl_t tmph; - int err; - - (void) rw_rdlock(&picltbl_rwlock); /* lock picl */ - tmph = hash_lookup_hdl(&picltbl, hdl); - if (tmph == PICL_INVALID_PICLHDL) { - err = picl_hdl_error(hdl); - (void) rw_unlock(&picltbl_rwlock); /* unlock picl */ - return (err); - } - *ptree_hdl = tmph; - (void) rw_unlock(&picltbl_rwlock); /* unlock picl */ - return (PICL_SUCCESS); -} - -/* - * Allocate a ptree handle - */ -static picl_hdl_t -alloc_ptreehdl(void) -{ - picl_hdl_t hdl; - - (void) pthread_mutex_lock(&ptreehdl_lock); /* lock ptreehdl */ - hdl = MAKE_HANDLE(picld_pid, ptree_hdl_hi); - ++ptree_hdl_hi; - (void) pthread_mutex_unlock(&ptreehdl_lock); /* unlock ptreehdl */ - return (hdl); -} - -/* - * Allocate a picl handle - * A PICL handle is ptree_hdl value with 1 in MSB of handle value. - * If a ptree handle already has 1 in MSB, then it cannot be piclized - * and the daemon must be restarted. - */ -static picl_hdl_t -alloc_piclhdl(void) -{ - picl_hdl_t hdl; - - (void) pthread_mutex_lock(&piclhdl_lock); /* lock piclhdl */ - hdl = MAKE_HANDLE(picld_pid, picl_hdl_hi); - ++picl_hdl_hi; - (void) pthread_mutex_unlock(&piclhdl_lock); /* unlock piclhdl */ - return (hdl); -} - -/* - * Allocate and add handle to PTree hash table - */ -static void -alloc_and_add_to_ptree(picl_obj_t *pobj) -{ - pobj->ptree_hdl = alloc_ptreehdl(); - (void) rw_wrlock(&ptree_rwlock); - (void) hash_add_newobj(&ptreetbl, pobj->ptree_hdl, pobj); - (void) rw_unlock(&ptree_rwlock); -} - -/* - * Lock a picl node object - */ -static int -lock_obj(int rw, picl_obj_t *nodep) -{ - if (rw == RDLOCK_NODE) - (void) rw_rdlock(&nodep->node_lock); - else if (rw == WRLOCK_NODE) - (void) rw_wrlock(&nodep->node_lock); - else - return (-1); - return (0); -} - -/* - * Release the picl node object. - * This function may be called with a NULL object pointer. - */ -static void -unlock_node(picl_obj_t *nodep) -{ - if (nodep == NULL) - return; - (void) rw_unlock(&nodep->node_lock); -} - -/* - * This function locks the node of a property and returns the node object - * and the property object. - */ -static int -lookup_and_lock_propnode(int rw, picl_prophdl_t proph, picl_obj_t **nodep, - picl_obj_t **propp) -{ - picl_obj_t *pobj; - picl_obj_t *nobj; - - pobj = hash_lookup_obj(&ptreetbl, proph); - if (pobj == NULL) - return (ptree_hdl_error(proph)); - - /* - * Get the property's or table entry's node object - */ - nobj = NULL; - if (pobj->obj_type == PICL_OBJ_PROP) - nobj = pobj->prop_node; - else if (pobj->obj_type == (PICL_OBJ_PROP|PICL_OBJ_TABLEENTRY)) - nobj = pobj->prop_table->prop_node; - else { - *propp = pobj; /* return the prop */ - return (PICL_NOTPROP); - } - - if (nobj && (lock_obj(rw, nobj) < 0)) /* Lock node */ - return (PICL_FAILURE); - - *nodep = nobj; - *propp = pobj; - - return (PICL_SUCCESS); -} - -/* - * This function locks the node of a table and returns the node object - * and the table object. - */ -static int -lookup_and_lock_tablenode(int rw, picl_prophdl_t tblh, picl_obj_t **nodep, - picl_obj_t **tblobj) -{ - picl_obj_t *pobj; - picl_obj_t *nobj; - - pobj = hash_lookup_obj(&ptreetbl, tblh); - if (pobj == NULL) - return (ptree_hdl_error(tblh)); - - /* - * Get the property's or table entry's node object - */ - nobj = NULL; - if (pobj->obj_type != PICL_OBJ_TABLE) - return (PICL_NOTTABLE); - nobj = pobj->prop_node; - - if (nobj && (lock_obj(rw, nobj) < 0)) /* Lock node */ - return (PICL_FAILURE); - - *nodep = nobj; - *tblobj = pobj; - - return (PICL_SUCCESS); -} - -/* - * This locks the node of a table or a table entry and returns the - * node object and the table or table entry object - */ -static int -lookup_and_lock_tableprop_node(int rw, picl_prophdl_t tblproph, - picl_obj_t **nodep, picl_obj_t **tblpropp) -{ - picl_obj_t *pobj; - picl_obj_t *nobj; - - pobj = hash_lookup_obj(&ptreetbl, tblproph); - if (pobj == NULL) - return (ptree_hdl_error(tblproph)); - - /* - * Get the property's or table entry's node object - */ - nobj = NULL; - if ((pobj->obj_type != PICL_OBJ_TABLE) && /* not a table */ - !(pobj->obj_type & PICL_OBJ_TABLEENTRY)) /* or an entry */ - return (PICL_NOTTABLE); - if (pobj->obj_type == PICL_OBJ_TABLE) - nobj = pobj->prop_node; - else - nobj = pobj->prop_table->prop_node; - - if (nobj && (lock_obj(rw, nobj) < 0)) /* Lock node */ - return (PICL_FAILURE); - - *tblpropp = pobj; - *nodep = nobj; - - return (PICL_SUCCESS); -} - -/* - * Lock the node corresponding to the given handle and return its object - */ -static int -lookup_and_lock_node(int rw, picl_nodehdl_t nodeh, picl_obj_t **nodep) -{ - picl_obj_t *nobj; - - nobj = hash_lookup_obj(&ptreetbl, nodeh); - if (nobj == NULL) - return (ptree_hdl_error(nodeh)); - else if (nobj->obj_type != PICL_OBJ_NODE) - return (PICL_NOTNODE); - if (lock_obj(rw, nobj) < 0) /* Lock node */ - return (PICL_FAILURE); - *nodep = nobj; - return (PICL_SUCCESS); -} - -/* - * Is the property name a restricted property name? - */ -static int -picl_restricted(const char *name) -{ - if (strcmp(name, PICL_PROP_CLASSNAME) == 0) - return (0); /* not restricted */ - - if ((name[0] == '_') && (strchr(&name[1], '_') == NULL)) - return (1); - return (0); -} - -/* - * Check the value size with the property size - * Return PICL_INVALIDARG if the size does not match exactly for strongly - * typed properties. - * For charstring reads allow sizes that match the value size - * For bytearray return PICL_VALUETOOBIG - * if the size is greater than the buffer size. - */ -static int -check_propsize(int op, picl_obj_t *propp, size_t sz) -{ - if (propp->prop_mode & PICL_VOLATILE) { - if (sz != propp->prop_size) - return (PICL_INVALIDARG); - else - return (PICL_SUCCESS); - } - - /* - * check size for non-volatile properties - */ - switch (propp->prop_type) { - case PICL_PTYPE_CHARSTRING: - if ((op == PROP_READ) && - (strlen(propp->prop_val) >= sz)) - return (PICL_VALUETOOBIG); - if ((op == PROP_WRITE) && (sz > propp->prop_size)) - return (PICL_VALUETOOBIG); - break; - case PICL_PTYPE_BYTEARRAY: - if (op == PROP_WRITE) { - if (sz > propp->prop_size) - return (PICL_VALUETOOBIG); - return (PICL_SUCCESS); /* allow small writes */ - } - /* FALLTHROUGH */ - default: - if (propp->prop_size != sz) - return (PICL_INVALIDARG); - break; - } - return (PICL_SUCCESS); -} - -void -cvt_ptree2picl(picl_hdl_t *handlep) -{ - picl_obj_t *pobj; - - (void) rw_rdlock(&ptree_rwlock); - pobj = hash_lookup_obj(&ptreetbl, *handlep); - if (pobj == NULL) - *handlep = PICL_INVALID_PICLHDL; - else - (void) memcpy(handlep, &pobj->picl_hdl, sizeof (*handlep)); - (void) rw_unlock(&ptree_rwlock); -} - -/* - * The caller of the piclize() set of functions is assumed to hold - * the ptree_rwlock(). - */ -static void -piclize_obj(picl_obj_t *pobj) -{ - (void) rw_wrlock(&picltbl_rwlock); - pobj->picl_hdl = alloc_piclhdl(); - (void) hash_add_newhdl(&picltbl, pobj->picl_hdl, pobj->ptree_hdl); - (void) rw_unlock(&picltbl_rwlock); -} - -static void -piclize_table(picl_obj_t *tbl_obj) -{ - picl_obj_t *rowp; - picl_obj_t *colp; - - for (rowp = tbl_obj->next_row; rowp != NULL; rowp = rowp->next_col) - for (colp = rowp; colp != NULL; colp = colp->next_row) - piclize_obj(colp); -} - -static void -piclize_prop(picl_obj_t *propp) -{ - picl_obj_t *tbl_obj; - picl_prophdl_t tblh; - - piclize_obj(propp); - if (!(propp->prop_mode & PICL_VOLATILE) && - (propp->prop_type == PICL_PTYPE_TABLE)) { - tblh = *(picl_prophdl_t *)propp->prop_val; - tbl_obj = hash_lookup_obj(&ptreetbl, tblh); - if (tbl_obj == NULL) - return; - piclize_obj(tbl_obj); - piclize_table(tbl_obj); - } -} - -/* - * Function to create PICL handles for a subtree and add them to - * the table - */ -static void -piclize_node(picl_obj_t *nodep) -{ - picl_obj_t *propp; - picl_obj_t *chdp; - - piclize_obj(nodep); - propp = nodep->first_prop; - while (propp != NULL) { - piclize_prop(propp); - propp = propp->next_prop; - } - - /* go through the children */ - for (chdp = nodep->child_node; chdp != NULL; chdp = chdp->sibling_node) - piclize_node(chdp); -} - -/* - * Function to remove PICL handles - */ -static void -unpiclize_obj(picl_obj_t *pobj) -{ - (void) rw_wrlock(&picltbl_rwlock); - (void) hash_remove(&picltbl, pobj->picl_hdl); - pobj->picl_hdl = PICL_INVALID_PICLHDL; - (void) rw_unlock(&picltbl_rwlock); -} - -static void -unpiclize_table(picl_obj_t *tbl_obj) -{ - picl_obj_t *rowp; - picl_obj_t *colp; - - for (rowp = tbl_obj->next_row; rowp != NULL; rowp = rowp->next_col) - for (colp = rowp; colp != NULL; colp = colp->next_row) - unpiclize_obj(colp); - unpiclize_obj(tbl_obj); -} - -static void -unpiclize_prop(picl_obj_t *propp) -{ - picl_obj_t *tbl_obj; - picl_prophdl_t tblh; - - if (!IS_PICLIZED(propp)) - return; - unpiclize_obj(propp); - if (!(propp->prop_mode & PICL_VOLATILE) && - (propp->prop_type == PICL_PTYPE_TABLE)) { - tblh = *(picl_prophdl_t *)propp->prop_val; - tbl_obj = hash_lookup_obj(&ptreetbl, tblh); - unpiclize_table(tbl_obj); - } -} - -/* - * Function to remove PICL handles for a subtree and its - * properties - */ -static void -unpiclize_node(picl_obj_t *nodep) -{ - picl_obj_t *propp; - picl_obj_t *chdp; - - - if (!IS_PICLIZED(nodep)) - return; - - unpiclize_obj(nodep); - propp = nodep->first_prop; - while (propp != NULL) { - unpiclize_prop(propp); - propp = propp->next_prop; - } - - /* go through the children */ - for (chdp = nodep->child_node; chdp != NULL; chdp = chdp->sibling_node) - unpiclize_node(chdp); -} - - -/* - * The caller holds the lock on the ptree_lock when calling this. - * If ret is not NULL then this function returns the referenced object. - */ -static int -lookup_verify_ref_prop(picl_obj_t *propp, picl_obj_t **ret) -{ - picl_nodehdl_t refh; - picl_obj_t *refobj; - - refh = *(picl_nodehdl_t *)propp->prop_val; - refobj = hash_lookup_obj(&ptreetbl, refh); - if (refobj == NULL) - return (ptree_hdl_error(refh)); - else if (refobj->obj_type != PICL_OBJ_NODE) - return (PICL_INVREFERENCE); - if (ret) - *ret = refobj; - return (PICL_SUCCESS); -} - -/* - * The caller holds the lock on ptree_lock when calling this. - * If ret is not NULL, then this function returns the table object - */ -static int -lookup_verify_table_prop(picl_obj_t *propp, picl_obj_t **ret) -{ - picl_prophdl_t tblh; - picl_obj_t *tbl_obj; - - tblh = *(picl_prophdl_t *)propp->prop_val; - tbl_obj = hash_lookup_obj(&ptreetbl, tblh); - if (tbl_obj == NULL) - return (ptree_hdl_error(tblh)); - else if (!(tbl_obj->obj_type & PICL_OBJ_TABLE)) - return (PICL_NOTTABLE); - if (ret) - *ret = tbl_obj; - return (PICL_SUCCESS); -} - -static int -lookup_verify_prop_handle(picl_prophdl_t proph, picl_obj_t **ret) -{ - picl_obj_t *propp; - - propp = hash_lookup_obj(&ptreetbl, proph); - if (propp == NULL) - return (ptree_hdl_error(proph)); - else if (!(propp->obj_type & PICL_OBJ_PROP)) - return (PICL_NOTPROP); - if (ret) - *ret = propp; - return (PICL_SUCCESS); -} - -static int -lookup_verify_node_handle(picl_nodehdl_t nodeh, picl_obj_t **ret) -{ - picl_obj_t *nodep; - - nodep = hash_lookup_obj(&ptreetbl, nodeh); - if (nodep == NULL) - return (ptree_hdl_error(nodeh)); - else if (nodep->obj_type != PICL_OBJ_NODE) - return (PICL_NOTNODE); - if (ret) - *ret = nodep; - return (PICL_SUCCESS); -} - -static int -lookup_prop_by_name(picl_obj_t *nodep, const char *pname, picl_obj_t **ret) -{ - picl_obj_t *propp; - - if (strcmp(pname, PICL_PROP_PARENT) == 0) { - if (nodep->parent_node == NULL) - return (PICL_PROPNOTFOUND); - else - return (PICL_SUCCESS); - } - if (strcmp(pname, PICL_PROP_CHILD) == 0) { - if (nodep->child_node == NULL) - return (PICL_PROPNOTFOUND); - else - return (PICL_SUCCESS); - } - if (strcmp(pname, PICL_PROP_PEER) == 0) { - if (nodep->sibling_node == NULL) - return (PICL_PROPNOTFOUND); - else - return (PICL_SUCCESS); - } - - propp = nodep->first_prop; - while (propp != NULL) { - if (strcmp(propp->prop_name, pname) == 0) { - if (ret) - *ret = propp; - return (PICL_SUCCESS); - } - propp = propp->next_prop; - } - return (PICL_PROPNOTFOUND); -} - -/* - * This function locks the ptree, verifies that the handle is a reference - * to a node of specified class name, releases the lock - */ -static int -check_ref_handle(picl_nodehdl_t refh, char *clname) -{ - picl_obj_t *refobj; - picl_obj_t *propp; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* Lock ptree */ - refobj = hash_lookup_obj(&ptreetbl, refh); - if ((refobj == NULL) || !(refobj->obj_type & PICL_OBJ_NODE)) { - (void) rw_unlock(&ptree_rwlock); - return (PICL_INVREFERENCE); - } - - err = lookup_prop_by_name(refobj, PICL_PROP_CLASSNAME, &propp); - if ((err != PICL_SUCCESS) || (propp->prop_val == NULL) || - (strcmp(propp->prop_val, clname) != 0)) - err = PICL_INVREFERENCE; - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -static int -check_table_handle(picl_prophdl_t tblh) -{ - picl_obj_t *tbl_obj; - int err; - - (void) rw_rdlock(&ptree_rwlock); - err = PICL_SUCCESS; - tbl_obj = hash_lookup_obj(&ptreetbl, tblh); - if ((tbl_obj == NULL) || !(tbl_obj->obj_type & PICL_OBJ_TABLE)) - err = PICL_NOTTABLE; - (void) rw_unlock(&ptree_rwlock); - return (err); -} - -/* - * PICLTree Interface routines for plug-in modules - */ -int -ptree_get_root(picl_nodehdl_t *rooth) -{ - *rooth = ptree_root_hdl; - return (PICL_SUCCESS); -} - -/* - * Lock free create a property object - */ -static int -create_propobj(const ptree_propinfo_t *pinfo, const void *valbuf, - picl_obj_t **pobjp) -{ - picl_obj_t *pobj; - - if (pinfo->version != PTREE_PROPINFO_VERSION_1) - return (PICL_NOTSUPPORTED); - - if (!(pinfo->piclinfo.accessmode & PICL_VOLATILE) && - (pinfo->piclinfo.type != PICL_PTYPE_VOID) && - (valbuf == NULL)) - return (PICL_INVALIDARG); - - pobj = malloc(sizeof (picl_obj_t)); - if (pobj == NULL) - return (PICL_FAILURE); - - pobj->obj_type = PICL_OBJ_PROP; - pobj->pinfo_ver = pinfo->version; - pobj->prop_type = pinfo->piclinfo.type; - pobj->prop_mode = pinfo->piclinfo.accessmode; - pobj->prop_size = pinfo->piclinfo.size; - (void) strcpy(pobj->prop_name, pinfo->piclinfo.name); - pobj->read_func = pinfo->read; - pobj->write_func = pinfo->write; - - pobj->prop_val = NULL; - if (!(pinfo->piclinfo.accessmode & PICL_VOLATILE)) { - pobj->prop_val = malloc(pinfo->piclinfo.size); - if (pobj->prop_val == NULL) { - free(pobj); - return (PICL_FAILURE); - } - if (pobj->prop_type == PICL_PTYPE_CHARSTRING) - (void) strlcpy(pobj->prop_val, valbuf, - pinfo->piclinfo.size); - else - (void) memcpy(pobj->prop_val, valbuf, - pinfo->piclinfo.size); - } - pobj->prop_node = NULL; - pobj->ptree_hdl = PICL_INVALID_PICLHDL; - pobj->picl_hdl = PICL_INVALID_PICLHDL; - pobj->next_prop = NULL; - pobj->next_row = NULL; - pobj->next_col = NULL; - - *pobjp = pobj; - return (PICL_SUCCESS); -} - -/* - * Check for valid arguments, create a property object, - * Lock ptree_rwlock, add the new property handle, release the lock - * For reference properties and table properties, the handles are verified - * before creating the property. - */ -int -ptree_create_prop(const ptree_propinfo_t *pinfo, const void *valbuf, - picl_prophdl_t *proph) -{ - picl_obj_t *pobj; - picl_nodehdl_t refh; - picl_prophdl_t tblh; - int err; - char *ptr; - int refflag; - char classname[PICL_PROPNAMELEN_MAX]; - - if (pinfo == NULL) - return (PICL_INVALIDARG); - if (pinfo->version != PTREE_PROPINFO_VERSION_1) - return (PICL_NOTSUPPORTED); - if (pinfo->piclinfo.size >= PICL_PROPSIZE_MAX) - return (PICL_VALUETOOBIG); - if (picl_restricted(pinfo->piclinfo.name)) - return (PICL_RESERVEDNAME); - - refflag = 0; - if ((pinfo->piclinfo.name[0] == '_') && - (strchr(&pinfo->piclinfo.name[1], '_') != NULL)) - refflag = 1; - - if (pinfo->piclinfo.type == PICL_PTYPE_REFERENCE) { - if (refflag == 0) - return (PICL_INVREFERENCE); - /* - * check valid reference handle for non-volatiles - */ - if (!(pinfo->piclinfo.accessmode & PICL_VOLATILE)) { - if (valbuf == NULL) - return (PICL_INVREFERENCE); - if (pinfo->piclinfo.size != sizeof (picl_nodehdl_t)) - return (PICL_INVREFERENCE); - (void) strcpy(classname, pinfo->piclinfo.name); - ptr = strchr(&classname[1], '_'); - *ptr = '\0'; - refh = *(picl_hdl_t *)valbuf; - err = check_ref_handle(refh, &classname[1]); - if (err != PICL_SUCCESS) - return (err); - } - } else if (refflag == 1) - return (PICL_INVREFERENCE); - else if ((pinfo->piclinfo.type == PICL_PTYPE_TABLE) && - (!(pinfo->piclinfo.accessmode & PICL_VOLATILE))) { - if (pinfo->piclinfo.size != sizeof (picl_prophdl_t)) - return (PICL_INVALIDARG); - tblh = *(picl_prophdl_t *)valbuf; - err = check_table_handle(tblh); - if (err != PICL_SUCCESS) - return (err); - } else if ((strcmp(pinfo->piclinfo.name, PICL_PROP_CLASSNAME) == 0) && - ((pinfo->piclinfo.type != PICL_PTYPE_CHARSTRING) || - (strlen(valbuf) >= PICL_CLASSNAMELEN_MAX))) - return (PICL_RESERVEDNAME); - else if ((strcmp(pinfo->piclinfo.name, PICL_PROP_NAME) == 0) && - (pinfo->piclinfo.type != PICL_PTYPE_CHARSTRING)) - return (PICL_RESERVEDNAME); - /* - * No locks held when you get here - */ - err = create_propobj(pinfo, valbuf, &pobj); - if (err != PICL_SUCCESS) - return (err); - - alloc_and_add_to_ptree(pobj); - *proph = pobj->ptree_hdl; - return (PICL_SUCCESS); -} - -/* - * Lock free routine to destroy table entries - * This function removes the destroyed handles from the hash table - * Uses lock free routines: hash_lookup() and hash_remove() - */ -static void -destroy_table(picl_obj_t *pobj) -{ - picl_prophdl_t tblh; - picl_obj_t *tbl_obj; - picl_obj_t *rowp; - picl_obj_t *colp; - picl_obj_t *freep; - - tblh = *(picl_prophdl_t *)pobj->prop_val; - tbl_obj = hash_lookup_obj(&ptreetbl, tblh); - if (tbl_obj == NULL) - return; - - assert(tbl_obj->obj_type & PICL_OBJ_TABLE); - - /* Delete all entries */ - rowp = tbl_obj->next_row; - while (rowp != NULL) { - colp = rowp; - rowp = rowp->next_col; - while (colp != NULL) { - freep = colp; - colp = colp->next_row; - (void) hash_remove(&ptreetbl, freep->ptree_hdl); - free(freep->prop_val); - free(freep); - } - } - - (void) hash_remove(&ptreetbl, tbl_obj->ptree_hdl); - free(tbl_obj); -} - - -/* - * Lock free function that frees up a property object and removes the - * handles from Ptree table - */ -static void -destroy_propobj(picl_obj_t *propp) -{ - if (propp->prop_type == PICL_PTYPE_TABLE) - destroy_table(propp); - - (void) hash_remove(&ptreetbl, propp->ptree_hdl); - free(propp->prop_val); - free(propp); -} - -/* - * This function destroys a previously deleted property. - * A deleted property does not have an associated node. - * All memory allocated for this property are freed - */ -int -ptree_destroy_prop(picl_prophdl_t proph) -{ - picl_obj_t *propp; - - (void) rw_wrlock(&ptree_rwlock); /* Exclusive Lock ptree */ - - propp = hash_lookup_obj(&ptreetbl, proph); - if (propp == NULL) { - (void) rw_unlock(&ptree_rwlock); /* Unlock ptree */ - return (ptree_hdl_error(proph)); - } - - /* Is the prop still attached to a node? */ - if (propp->prop_node != NULL) { - (void) rw_unlock(&ptree_rwlock); /* Unlock ptree */ - return (PICL_CANTDESTROY); - } - - destroy_propobj(propp); - - (void) rw_unlock(&ptree_rwlock); /* Unlock ptree */ - return (PICL_SUCCESS); -} - -/* - * This function adds a property to the property list of a node and adds - * it to the PICL table if the node has a PICL handle. - * This function locks the picl_rwlock and ptree_rwlock. - */ -int -ptree_add_prop(picl_nodehdl_t nodeh, picl_prophdl_t proph) -{ - int err; - picl_obj_t *nodep; - picl_obj_t *propp; - picl_obj_t *tbl_obj; - picl_obj_t *refobj; - - (void) rw_rdlock(&ptree_rwlock); /* RDLock ptree */ - - /* - * Verify property handle - */ - err = lookup_verify_prop_handle(proph, &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* Unlock ptree */ - return (err); - } - - if (propp->prop_node != NULL) { - (void) rw_unlock(&ptree_rwlock); - return (PICL_INVALIDARG); - } - - nodep = NULL; - /* - * Exclusive Lock the node's properties - */ - err = lookup_and_lock_node(WRLOCK_NODE, nodeh, &nodep); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* Unlock ptree */ - return (err); - } - - /* - * check if prop already exists - */ - err = lookup_prop_by_name(nodep, propp->prop_name, NULL); - if (err == PICL_SUCCESS) { - unlock_node(nodep); /* Unlock node */ - (void) rw_unlock(&ptree_rwlock); /* Unlock table */ - return (PICL_PROPEXISTS); - } - - /* - * Verify property's value - */ - tbl_obj = NULL; - switch (propp->prop_type) { - case PICL_PTYPE_TABLE: - if (propp->prop_mode & PICL_VOLATILE) - break; - err = lookup_verify_table_prop(propp, &tbl_obj); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - tbl_obj->prop_node = nodep; /* set table's nodep */ - tbl_obj->table_prop = propp; /* set table prop */ - break; - case PICL_PTYPE_REFERENCE: - if (propp->prop_mode & PICL_VOLATILE) - break; - err = lookup_verify_ref_prop(propp, &refobj); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - if (IS_PICLIZED(nodep) && !IS_PICLIZED(refobj)) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - break; - default: - break; - } - - if (IS_PICLIZED(nodep)) - piclize_prop(propp); - /* - * Add prop to beginning of list - */ - propp->prop_node = nodep; /* set prop's nodep */ - propp->next_prop = nodep->first_prop; - nodep->first_prop = propp; - - unlock_node(nodep); /* Unlock node */ - (void) rw_unlock(&ptree_rwlock); /* Unlock table */ - return (PICL_SUCCESS); -} - -/* - * Lock free function that unlinks a property from its node - */ -static int -unlink_prop(picl_obj_t *nodep, picl_obj_t *propp) -{ - picl_obj_t *iterp; - - iterp = nodep->first_prop; - if (iterp == propp) { /* first property */ - nodep->first_prop = iterp->next_prop; - return (PICL_SUCCESS); - } - while ((iterp != NULL) && (iterp->next_prop != propp)) - iterp = iterp->next_prop; - if (iterp == NULL) - return (PICL_PROPNOTFOUND); - iterp->next_prop = propp->next_prop; - return (PICL_SUCCESS); -} - -/* - * This function deletes the specified property from the property list - * of its node and removes the handle from PICL table, if the node - * was piclized. - */ -int -ptree_delete_prop(picl_prophdl_t proph) -{ - int err; - picl_obj_t *nodep; - picl_obj_t *propp; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - /* - * Lookup the property's node and lock it if there is one - * return the objects for the property and the node - */ - nodep = propp = NULL; - err = lookup_and_lock_propnode(WRLOCK_NODE, proph, &nodep, &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } else if (nodep == NULL) { - /* Nothing to do - already deleted! */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); - } - - if (propp->obj_type & PICL_OBJ_TABLEENTRY) { - unlock_node(nodep); /* Unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_NOTPROP); - } - - err = unlink_prop(nodep, propp); - if (err != PICL_SUCCESS) { - unlock_node(nodep); /* Unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - propp->prop_node = NULL; /* reset prop's nodep */ - propp->next_prop = NULL; - - unpiclize_prop(propp); - - unlock_node(nodep); /* Unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); -} - -/* - * Create a table object and return its handle - */ -int -ptree_create_table(picl_prophdl_t *tblh) -{ - picl_obj_t *pobj; - - pobj = malloc(sizeof (picl_obj_t)); - if (pobj == NULL) - return (PICL_FAILURE); - pobj->obj_type = PICL_OBJ_TABLE; - pobj->prop_val = NULL; - pobj->prop_node = NULL; - pobj->ptree_hdl = PICL_INVALID_PICLHDL; - pobj->picl_hdl = PICL_INVALID_PICLHDL; - pobj->table_prop = NULL; - pobj->next_row = NULL; - pobj->next_col = NULL; - - alloc_and_add_to_ptree(pobj); - *tblh = pobj->ptree_hdl; - return (PICL_SUCCESS); -} - -/* - * Add the properties in array as a row in the table - * Add PICL handles if the table has a valid PICL handle - */ -int -ptree_add_row_to_table(picl_prophdl_t tblh, int nprops, - const picl_prophdl_t *props) -{ - picl_obj_t *tbl_obj; - picl_obj_t *nodep; - picl_obj_t *lastrow; - picl_obj_t **newrow; - int i; - int err; - picl_obj_t *pobj; - int picl_it; - - if (nprops < 1) - return (PICL_INVALIDARG); - - newrow = malloc(sizeof (picl_obj_t *) * nprops); - if (newrow == NULL) - return (PICL_FAILURE); - - (void) rw_rdlock(&ptree_rwlock); /* Lock ptree */ - - err = lookup_and_lock_tablenode(WRLOCK_NODE, tblh, &nodep, &tbl_obj); - if (err != PICL_SUCCESS) { - free(newrow); - (void) rw_unlock(&ptree_rwlock); /* Unlock table */ - return (err); - } - - /* - * make sure all are either props or table handles - */ - for (i = 0; i < nprops; ++i) { - pobj = newrow[i] = hash_lookup_obj(&ptreetbl, props[i]); - if (pobj == NULL) { /* no object */ - err = ptree_hdl_error(props[i]); - break; - } - if ((!(pobj->obj_type & PICL_OBJ_PROP)) && - (!(pobj->obj_type & PICL_OBJ_TABLE))) { - err = PICL_NOTPROP; - break; - } - if (IS_PICLIZED(pobj) || (pobj->prop_table != NULL) || - (pobj->prop_node != NULL)) { - err = PICL_INVALIDARG; - break; - } - - } - if (err != PICL_SUCCESS) { - free(newrow); - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); /* Unlock table */ - return (err); - } - - /* - * Mark all props as table entries, set up row linkages - */ - picl_it = 0; - if (IS_PICLIZED(tbl_obj)) - picl_it = 1; - for (i = 0; i < nprops; ++i) { - newrow[i]->obj_type |= PICL_OBJ_TABLEENTRY; - newrow[i]->prop_table = tbl_obj; - newrow[i]->next_prop = NULL; - newrow[i]->next_col = NULL; - if (picl_it) - piclize_obj(newrow[i]); - if (i != nprops - 1) - newrow[i]->next_row = newrow[i+1]; - } - newrow[nprops - 1]->next_row = NULL; - - if (tbl_obj->next_row == NULL) { /* add first row */ - tbl_obj->next_row = newrow[0]; - tbl_obj->next_col = newrow[0]; - } else { - lastrow = tbl_obj->next_row; - while (lastrow->next_col != NULL) - lastrow = lastrow->next_col; - i = 0; - while (lastrow != NULL) { - lastrow->next_col = newrow[i]; - lastrow = lastrow->next_row; - ++i; - } - } - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* Unlock ptree */ - free(newrow); - return (PICL_SUCCESS); -} - -/* - * This function returns the handle of the next property in the row - */ -int -ptree_get_next_by_row(picl_prophdl_t proph, picl_prophdl_t *nextrowh) -{ - int err; - picl_obj_t *nodep; - picl_obj_t *propp; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - - nodep = propp = NULL; - /* - * proph could be a table handle or a table entry handle - * Look it up as a table entry handle first, check error code - * to see if it is a table handle - */ - err = lookup_and_lock_tableprop_node(RDLOCK_NODE, proph, &nodep, - &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - if (propp->next_row) - *nextrowh = propp->next_row->ptree_hdl; - else - err = PICL_ENDOFLIST; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -int -ptree_get_next_by_col(picl_prophdl_t proph, picl_prophdl_t *nextcolh) -{ - int err; - picl_obj_t *propp; - picl_obj_t *nodep; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = propp = NULL; - /* - * proph could be a table handle or a table entry handle - * Look it up as a table entry handle first, check error code - * to see if it is a table handle - */ - err = lookup_and_lock_tableprop_node(RDLOCK_NODE, proph, &nodep, - &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - if (propp->next_col) - *nextcolh = propp->next_col->ptree_hdl; - else - err = PICL_ENDOFLIST; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -/* - * This function creates node object and adds its handle to the Ptree - */ -int -ptree_create_node(const char *name, const char *clname, picl_nodehdl_t *nodeh) -{ - picl_obj_t *pobj; - ptree_propinfo_t propinfo; - picl_prophdl_t phdl; - picl_prophdl_t cphdl; - int err; - - if ((name == NULL) || (*name == '\0') || - (clname == NULL) || (*clname == '\0')) - return (PICL_INVALIDARG); - - if ((strlen(name) >= PICL_PROPNAMELEN_MAX) || - (strlen(clname) >= PICL_CLASSNAMELEN_MAX)) - return (PICL_VALUETOOBIG); - - /* - * Create the picl object for node - */ - pobj = malloc(sizeof (picl_obj_t)); - if (pobj == NULL) - return (PICL_FAILURE); - pobj->obj_type = PICL_OBJ_NODE; - pobj->first_prop = NULL; - pobj->ptree_hdl = PICL_INVALID_PICLHDL; - pobj->picl_hdl = PICL_INVALID_PICLHDL; - pobj->parent_node = NULL; - pobj->sibling_node = NULL; - pobj->child_node = NULL; - pobj->node_classname = strdup(clname); - if (pobj->node_classname == NULL) { - free(pobj); - return (PICL_FAILURE); - } - (void) rwlock_init(&pobj->node_lock, USYNC_THREAD, NULL); - - alloc_and_add_to_ptree(pobj); /* commit the node */ - - /* - * create name property - */ - propinfo.version = PTREE_PROPINFO_VERSION_1; - propinfo.piclinfo.type = PICL_PTYPE_CHARSTRING; - propinfo.piclinfo.accessmode = PICL_READ; - propinfo.piclinfo.size = strlen(name) + 1; - (void) strcpy(propinfo.piclinfo.name, PICL_PROP_NAME); - propinfo.read = NULL; - propinfo.write = NULL; - err = ptree_create_prop(&propinfo, (const void *)name, &phdl); - if (err != PICL_SUCCESS) { - (void) ptree_destroy_node(pobj->ptree_hdl); - return (err); - } - err = ptree_add_prop(pobj->ptree_hdl, phdl); - if (err != PICL_SUCCESS) { - (void) ptree_destroy_prop(phdl); - (void) ptree_destroy_node(pobj->ptree_hdl); - return (err); - } - - /* - * create picl classname property - */ - propinfo.piclinfo.size = strlen(clname) + 1; - (void) strcpy(propinfo.piclinfo.name, PICL_PROP_CLASSNAME); - propinfo.read = NULL; - propinfo.write = NULL; - err = ptree_create_prop(&propinfo, (const void *)clname, &cphdl); - if (err != PICL_SUCCESS) { - (void) ptree_destroy_node(pobj->ptree_hdl); - return (err); - } - err = ptree_add_prop(pobj->ptree_hdl, cphdl); - if (err != PICL_SUCCESS) { - (void) ptree_destroy_prop(cphdl); - (void) ptree_destroy_node(pobj->ptree_hdl); - return (err); - } - - *nodeh = pobj->ptree_hdl; - return (PICL_SUCCESS); -} - -/* - * Destroy a node/subtree freeing up space - * Removed destroyed objects' handles from PTree table - */ -static void -destroy_subtree(picl_obj_t *nodep) -{ - picl_obj_t *iterp; - picl_obj_t *freep; - picl_obj_t *chdp; - - if (nodep == NULL) - return; - - chdp = nodep->child_node; - while (chdp != NULL) { - freep = chdp; - chdp = chdp->sibling_node; - destroy_subtree(freep); - } - - /* - * Lock the node - */ - (void) lock_obj(WRLOCK_NODE, nodep); - - /* - * destroy all properties associated with this node - */ - iterp = nodep->first_prop; - while (iterp != NULL) { - freep = iterp; - iterp = iterp->next_prop; - destroy_propobj(freep); - } - - (void) hash_remove(&ptreetbl, nodep->ptree_hdl); - (void) rwlock_destroy(&nodep->node_lock); - free(nodep->node_classname); - free(nodep); -} - -/* - * This function destroys a previously deleted node/subtree. All the properties - * are freed and removed from the PTree table. - * Only one destroy is in progress at any time. - */ -int -ptree_destroy_node(picl_nodehdl_t nodeh) -{ - picl_obj_t *nodep; - picl_obj_t *parp; - picl_obj_t *np; - int err; - - (void) rw_wrlock(&ptree_rwlock); /* exclusive wrlock ptree */ - nodep = NULL; - err = lookup_verify_node_handle(nodeh, &nodep); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - /* - * Has this node/subtree been deleted? - */ - if (IS_PICLIZED(nodep)) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_CANTDESTROY); - } - - /* - * update parent's child list to repair the tree when - * parent is not null - */ - parp = nodep->parent_node; - if (parp == NULL) { /* root */ - destroy_subtree(nodep); - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); - } - - np = parp->child_node; - if (np == nodep) { /* first child */ - parp->child_node = nodep->sibling_node; - } else { - while ((np != NULL) && (np->sibling_node != nodep)) - np = np->sibling_node; - if (np != NULL) - np->sibling_node = nodep->sibling_node; - } - - destroy_subtree(nodep); - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); -} - -/* - * This function deletes a node/subtree from the tree and removes the handles - * from PICL table - */ -int -ptree_delete_node(picl_nodehdl_t nodeh) -{ - picl_obj_t *nodep; - picl_obj_t *parp; - picl_obj_t *np; - int err; - - (void) rw_wrlock(&ptree_rwlock); /* exclusive wrlock ptree */ - - nodep = NULL; - err = lookup_verify_node_handle(nodeh, &nodep); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - /* - * unparent it - */ - parp = nodep->parent_node; - if (parp != NULL) { - np = parp->child_node; - if (np == nodep) /* first child */ - parp->child_node = nodep->sibling_node; - else { - while ((np != NULL) && (np->sibling_node != nodep)) - np = np->sibling_node; - if (np != NULL) - np->sibling_node = nodep->sibling_node; - } - } - - nodep->parent_node = NULL; - nodep->sibling_node = NULL; - - unpiclize_node(nodep); - - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); -} - -/* - * This function adds a node as a child of another node - */ -int -ptree_add_node(picl_nodehdl_t parh, picl_nodehdl_t chdh) -{ - picl_obj_t *pnodep; - picl_obj_t *cnodep; - picl_obj_t *nodep; - int err; - - (void) rw_wrlock(&ptree_rwlock); /* exclusive lock ptree */ - - pnodep = cnodep = NULL; - err = lookup_verify_node_handle(parh, &pnodep); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - err = lookup_verify_node_handle(chdh, &cnodep); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - /* is chdh already a child? */ - if (cnodep->parent_node != NULL) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_CANTPARENT); - } - - /* - * append child to children list - */ - cnodep->parent_node = pnodep; - if (pnodep->child_node == NULL) - pnodep->child_node = cnodep; - else { - for (nodep = pnodep->child_node; nodep->sibling_node != NULL; - nodep = nodep->sibling_node) - continue; - nodep->sibling_node = cnodep; - - } - - /* piclize */ - if (IS_PICLIZED(pnodep)) - piclize_node(cnodep); - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); -} - -static void -copy_propinfo_ver_1(ptree_propinfo_t *pinfo, picl_obj_t *propp) -{ - pinfo->version = propp->pinfo_ver; - pinfo->piclinfo.type = propp->prop_type; - pinfo->piclinfo.accessmode = propp->prop_mode; - pinfo->piclinfo.size = propp->prop_size; - (void) strcpy(pinfo->piclinfo.name, propp->prop_name); - pinfo->read = propp->read_func; - pinfo->write = propp->write_func; -} - -static void -copy_reserved_propinfo_ver_1(ptree_propinfo_t *pinfo, const char *pname) -{ - pinfo->version = PTREE_PROPINFO_VERSION_1; - pinfo->piclinfo.type = PICL_PTYPE_REFERENCE; - pinfo->piclinfo.accessmode = PICL_READ; - pinfo->piclinfo.size = sizeof (picl_nodehdl_t); - (void) strcpy(pinfo->piclinfo.name, pname); - pinfo->read = NULL; - pinfo->write = NULL; -} - -/* - * This function returns the property information to a plug-in - */ -int -ptree_get_propinfo(picl_prophdl_t proph, ptree_propinfo_t *pinfo) -{ - int err; - picl_obj_t *nodep; - picl_obj_t *propp; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = propp = NULL; - err = lookup_and_lock_propnode(RDLOCK_NODE, proph, &nodep, &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - if (propp->pinfo_ver == PTREE_PROPINFO_VERSION_1) - copy_propinfo_ver_1(pinfo, propp); - else - err = PICL_FAILURE; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -/* - * This function returns the property information to a plug-in - */ -int -xptree_get_propinfo_by_name(picl_nodehdl_t nodeh, const char *pname, - ptree_propinfo_t *pinfo) -{ - int err; - picl_obj_t *nodep; - picl_obj_t *propp; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = propp = NULL; - err = lookup_and_lock_node(RDLOCK_NODE, nodeh, &nodep); /* lock node */ - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - err = lookup_prop_by_name(nodep, pname, &propp); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - if (picl_restricted(pname)) - copy_reserved_propinfo_ver_1(pinfo, pname); - else if (propp->pinfo_ver == PTREE_PROPINFO_VERSION_1) - copy_propinfo_ver_1(pinfo, propp); - else - err = PICL_FAILURE; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -/* - * This function must be called only after a lookup_prop_by_name() returns - * success and only if picl_restricted() returns true. - */ -static int -read_reserved_propval_and_unlock(picl_obj_t *nodep, const char *pname, - void *vbuf, size_t size) -{ - void *srcp; - - if (size != sizeof (picl_nodehdl_t)) - return (PICL_VALUETOOBIG); - - if (strcmp(pname, PICL_PROP_PARENT) == 0) - srcp = &nodep->parent_node->ptree_hdl; - else if (strcmp(pname, PICL_PROP_CHILD) == 0) - srcp = &nodep->child_node->ptree_hdl; - else if (strcmp(pname, PICL_PROP_PEER) == 0) - srcp = &nodep->sibling_node->ptree_hdl; - else - return (PICL_FAILURE); - - (void) memcpy(vbuf, srcp, sizeof (picl_nodehdl_t)); - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (PICL_SUCCESS); -} - -/* - * Returns the property value in the buffer and releases the node and - * ptree locks. - * For volatile properties, this function releases the locks on ptree - * table and the node before calling the plug-in provided access function - */ -static int -read_propval_and_unlock(picl_obj_t *nodep, picl_obj_t *propp, void *vbuf, - door_cred_t cred) -{ - int err; - int (*volrd)(ptree_rarg_t *arg, void *buf); - - err = PICL_SUCCESS; - if (propp->prop_mode & PICL_VOLATILE) { - ptree_rarg_t rarg; - - if (nodep) - rarg.nodeh = nodep->ptree_hdl; - else - rarg.nodeh = PICL_INVALID_PICLHDL; - rarg.proph = propp->ptree_hdl; - rarg.cred = cred; - volrd = propp->read_func; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - - if (volrd == NULL) - err = PICL_FAILURE; - else - err = (volrd)(&rarg, vbuf); - return (err); - } else if (propp->prop_type == PICL_PTYPE_CHARSTRING) - (void) strlcpy(vbuf, propp->prop_val, propp->prop_size); - else - (void) memcpy(vbuf, propp->prop_val, propp->prop_size); - - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); -} - -int -xptree_get_propval_with_cred(picl_prophdl_t proph, void *vbuf, size_t size, - door_cred_t cred) -{ - picl_obj_t *propp; - picl_obj_t *nodep; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = propp = NULL; - err = lookup_and_lock_propnode(RDLOCK_NODE, proph, &nodep, &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - err = check_propsize(PROP_READ, propp, size); - if (err != PICL_SUCCESS) { - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - return (read_propval_and_unlock(nodep, propp, vbuf, cred)); -} - -/* - * This function gets the credentials and calls get_propval_with_cred. - */ -int -ptree_get_propval(picl_prophdl_t proph, void *vbuf, size_t size) -{ - return (xptree_get_propval_with_cred(proph, vbuf, size, picld_cred)); -} - -/* - * This function retrieves a property's value by by its name - * For volatile properties, the locks on ptree and node are released - * before calling the plug-in provided access function - */ -int -xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh, const char *pname, - void *vbuf, size_t size, door_cred_t cred) -{ - picl_obj_t *nodep; - picl_obj_t *propp; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - - nodep = NULL; - err = lookup_and_lock_node(RDLOCK_NODE, nodeh, &nodep); /* lock node */ - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - err = lookup_prop_by_name(nodep, pname, &propp); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - if (picl_restricted(pname)) - return (read_reserved_propval_and_unlock(nodep, pname, vbuf, - size)); - - err = check_propsize(PROP_READ, propp, size); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - return (read_propval_and_unlock(nodep, propp, vbuf, cred)); -} - -/* - * This function is used by plugins to get a value of a property - * looking it up by its name. - */ -int -ptree_get_propval_by_name(picl_nodehdl_t nodeh, const char *pname, void *vbuf, - size_t size) -{ - return (xptree_get_propval_by_name_with_cred(nodeh, pname, vbuf, size, - picld_cred)); -} - -/* - * This function updates a property's value. - * For volatile properties, the locks on the node and the ptree table - * are released before calling the plug-in provided access function. - */ -static int -write_propval_and_unlock(picl_obj_t *nodep, picl_obj_t *propp, const void *vbuf, - size_t size, door_cred_t cred) -{ - int err; - int (*volwr)(ptree_warg_t *arg, const void *buf); - - err = PICL_SUCCESS; - if (propp->prop_mode & PICL_VOLATILE) { - ptree_warg_t warg; - - if (nodep) - warg.nodeh = nodep->ptree_hdl; - else - warg.nodeh = PICL_INVALID_PICLHDL; - warg.proph = propp->ptree_hdl; - warg.cred = cred; - volwr = propp->write_func; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - - if (volwr == NULL) - err = PICL_FAILURE; - else - err = (volwr)(&warg, vbuf); - return (err); - } else - (void) memcpy(propp->prop_val, vbuf, size); - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -int -xptree_update_propval_with_cred(picl_prophdl_t proph, const void *vbuf, - size_t size, door_cred_t cred) -{ - picl_obj_t *nodep; - picl_obj_t *propp; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = propp = NULL; - err = lookup_and_lock_propnode(WRLOCK_NODE, proph, &nodep, &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - err = check_propsize(PROP_WRITE, propp, size); - if (err != PICL_SUCCESS) { - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - return (write_propval_and_unlock(nodep, propp, vbuf, size, cred)); -} - -/* - * Ptree function used by plug-ins to update a property's value - * calls update_propval_with_cred(), which releases locks for volatile props - */ -int -ptree_update_propval(picl_prophdl_t proph, const void *vbuf, size_t size) -{ - return (xptree_update_propval_with_cred(proph, vbuf, size, picld_cred)); -} - -/* - * This function writes/updates a property's value by looking it up - * by its name. - * For volatile properties this function releases the locks on the - * node and the ptree table. - */ -int -xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh, const char *pname, - const void *vbuf, size_t size, door_cred_t cred) -{ - picl_obj_t *nodep; - picl_obj_t *propp; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = NULL; - err = lookup_and_lock_node(WRLOCK_NODE, nodeh, &nodep); /* lock node */ - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - if (picl_restricted(pname)) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (PICL_RESERVEDNAME); - } - - err = lookup_prop_by_name(nodep, pname, &propp); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - err = check_propsize(PROP_WRITE, propp, size); - if (err != PICL_SUCCESS) { - unlock_node(nodep); - (void) rw_unlock(&ptree_rwlock); - return (err); - } - - return (write_propval_and_unlock(nodep, propp, vbuf, size, cred)); -} - -/* - * This function updates the value of a property specified by its name - */ -int -ptree_update_propval_by_name(picl_nodehdl_t nodeh, const char *pname, - const void *vbuf, size_t size) -{ - return (xptree_update_propval_by_name_with_cred(nodeh, pname, vbuf, - size, picld_cred)); -} - -/* - * This function retrieves the handle of a property by its name - */ -int -ptree_get_prop_by_name(picl_nodehdl_t nodeh, const char *pname, - picl_prophdl_t *proph) -{ - picl_obj_t *nodep; - picl_obj_t *propp; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = NULL; - err = lookup_and_lock_node(RDLOCK_NODE, nodeh, &nodep); /* lock node */ - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - if (picl_restricted(pname)) { - err = PICL_RESERVEDNAME; - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - err = lookup_prop_by_name(nodep, pname, &propp); - if (err == PICL_SUCCESS) - *proph = propp->ptree_hdl; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -/* - * This function returns the handle of the first property - */ -int -ptree_get_first_prop(picl_nodehdl_t nodeh, picl_prophdl_t *proph) -{ - picl_obj_t *pobj; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - pobj = NULL; - err = lookup_and_lock_node(RDLOCK_NODE, nodeh, &pobj); /* lock node */ - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - if (pobj->first_prop) - *proph = pobj->first_prop->ptree_hdl; - else - err = PICL_ENDOFLIST; - - unlock_node(pobj); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -/* - * This function returns the handle of next property in the list - */ -int -ptree_get_next_prop(picl_prophdl_t proph, picl_prophdl_t *nextproph) -{ - picl_obj_t *nodep; - picl_obj_t *propp; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - nodep = propp = NULL; - err = lookup_and_lock_propnode(RDLOCK_NODE, proph, &nodep, &propp); - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); - } - - if (propp->next_prop) { - *nextproph = propp->next_prop->ptree_hdl; - } else - err = PICL_ENDOFLIST; - - unlock_node(nodep); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (err); -} - -/* - * These functions are called by ptree_get_node_by_path() - * Append a prop expression entry to the list - */ -static prop_list_t * -append_entry_to_list(prop_list_t *el, prop_list_t *list) -{ - prop_list_t *ptr; - - if (el == NULL) - return (list); - - if (list == NULL) { - list = el; - return (list); - } - - /* - * Add it to the end of list - */ - ptr = list; - - while (ptr->next != NULL) - ptr = ptr->next; - - ptr->next = el; - - return (list); -} - -/* - * Free the property expression list - */ -static void -free_list(prop_list_t *list) -{ - prop_list_t *ptr; - prop_list_t *tmp; - - for (ptr = list; ptr != NULL; ptr = tmp) { - tmp = ptr->next; - free(ptr); - } -} - -static int -parse_prl(char *prl, char **name, char **baddr, prop_list_t **plist) -{ - char *propptr; - char *ptr; - char *pname; - char *pval; - prop_list_t *el; - - if (prl == NULL) - return (PICL_FAILURE); - - if ((prl[0] == '@') || (prl[0] == '?')) - return (PICL_FAILURE); - - *name = prl; - - /* - * get property expression - */ - ptr = strchr(prl, '?'); - - if (ptr != NULL) { - *ptr = '\0'; - propptr = ptr + 1; - } else - propptr = NULL; - - /* - * get bus value - */ - ptr = strchr(prl, '@'); - - if (ptr != NULL) { - *ptr = '\0'; - *baddr = ptr + 1; - if (strlen(*baddr) == 0) /* no bus value after @ */ - return (PICL_FAILURE); - } - - /* - * create the prop list - */ - while (propptr != NULL) { - pname = propptr; - pval = NULL; - - ptr = strchr(propptr, '?'); - - if (ptr != NULL) { /* more ?= */ - *ptr = '\0'; - propptr = ptr + 1; - } else - propptr = NULL; - - if (strlen(pname) == 0) /* no prop exp after ? */ - return (PICL_FAILURE); - - ptr = strchr(pname, '='); - if (ptr != NULL) { /* not void prop */ - *ptr = '\0'; - pval = ptr + 1; - /* - * = is treated as void property - */ - if (strlen(pval) == 0) - pval = NULL; - } - - el = (prop_list_t *)malloc(sizeof (prop_list_t)); - el->pname = pname; - el->pval = pval; - el->next = NULL; - *plist = append_entry_to_list(el, *plist); - } - - return (PICL_SUCCESS); -} - -static int -prop_match(ptree_propinfo_t pinfo, void *vbuf, char *val) -{ - int8_t cval; - uint8_t ucval; - int16_t sval; - uint16_t usval; - int32_t intval; - uint32_t uintval; - int64_t llval; - uint64_t ullval; - float fval; - double dval; - - switch (pinfo.piclinfo.type) { - case PICL_PTYPE_CHARSTRING: - if (strcasecmp(pinfo.piclinfo.name, PICL_PROP_CLASSNAME) == 0) { - if (strcmp(val, PICL_CLASS_PICL) == 0) - return (1); - } - if (strcmp(val, (char *)vbuf) == 0) - return (1); - else - return (0); - case PICL_PTYPE_INT: - switch (pinfo.piclinfo.size) { - case sizeof (int8_t): - cval = (int8_t)strtol(val, (char **)NULL, 0); - return (cval == *(char *)vbuf); - case sizeof (int16_t): - sval = (int16_t)strtol(val, (char **)NULL, 0); - return (sval == *(int16_t *)vbuf); - case sizeof (int32_t): - intval = (int32_t)strtol(val, (char **)NULL, 0); - return (intval == *(int32_t *)vbuf); - case sizeof (int64_t): - llval = strtoll(val, (char **)NULL, 0); - return (llval == *(int64_t *)vbuf); - default: - return (0); - } - case PICL_PTYPE_UNSIGNED_INT: - switch (pinfo.piclinfo.size) { - case sizeof (uint8_t): - ucval = (uint8_t)strtoul(val, (char **)NULL, 0); - return (ucval == *(uint8_t *)vbuf); - case sizeof (uint16_t): - usval = (uint16_t)strtoul(val, (char **)NULL, 0); - return (usval == *(uint16_t *)vbuf); - case sizeof (uint32_t): - uintval = (uint32_t)strtoul(val, (char **)NULL, 0); - return (uintval == *(uint32_t *)vbuf); - case sizeof (uint64_t): - ullval = strtoull(val, (char **)NULL, 0); - return (ullval == *(uint64_t *)vbuf); - default: - return (0); - } - case PICL_PTYPE_FLOAT: - switch (pinfo.piclinfo.size) { - case sizeof (float): - fval = (float)strtod(val, (char **)NULL); - return (fval == *(float *)vbuf); - case sizeof (double): - dval = strtod(val, (char **)NULL); - return (dval == *(double *)vbuf); - default: - return (0); - } - case PICL_PTYPE_VOID: - case PICL_PTYPE_TIMESTAMP: - case PICL_PTYPE_TABLE: - case PICL_PTYPE_REFERENCE: - case PICL_PTYPE_BYTEARRAY: - case PICL_PTYPE_UNKNOWN: - default: - return (0); - } -} - -static int -check_propval(picl_nodehdl_t nodeh, char *pname, char *pval) -{ - int err; - picl_prophdl_t proph; - ptree_propinfo_t pinfo; - void *vbuf; - - err = ptree_get_prop_by_name(nodeh, pname, &proph); - if (err != PICL_SUCCESS) - return (err); - - err = ptree_get_propinfo(proph, &pinfo); - if (err != PICL_SUCCESS) - return (err); - - if (pval == NULL) { /* void type */ - if (pinfo.piclinfo.type != PICL_PTYPE_VOID) - return (PICL_FAILURE); - } else { - vbuf = alloca(pinfo.piclinfo.size); - if (vbuf == NULL) - return (PICL_FAILURE); - err = ptree_get_propval(proph, vbuf, - pinfo.piclinfo.size); - if (err != PICL_SUCCESS) - return (err); - - if (!prop_match(pinfo, vbuf, pval)) - return (PICL_FAILURE); - } - return (PICL_SUCCESS); -} - -static int -get_child_by_path(picl_nodehdl_t rooth, char *prl, - picl_nodehdl_t *nodeh, char *pname) -{ - picl_nodehdl_t chdh; - int err; - char *nameval; - char *nodename; - char *path; - char *baddr; - char *busval; - prop_list_t *plist; - prop_list_t *ptr; - - if (prl == NULL) - return (PICL_FAILURE); - - path = strdupa(prl); - if (path == NULL) - return (PICL_FAILURE); - - plist = NULL; - nodename = NULL; - baddr = NULL; - - err = parse_prl(path, &nodename, &baddr, &plist); - if (err != PICL_SUCCESS) { - free_list(plist); - return (err); - } - - if (nodename == NULL) - return (PICL_FAILURE); - - nameval = alloca(strlen(nodename) + 1); - if (nameval == NULL) { - free_list(plist); - return (PICL_FAILURE); - } - - if (baddr != NULL) { - busval = alloca(strlen(baddr) + 1); - if (busval == NULL) { - free_list(plist); - return (PICL_FAILURE); - } - } - - for (err = ptree_get_propval_by_name(rooth, PICL_PROP_CHILD, &chdh, - sizeof (picl_nodehdl_t)); err != PICL_PROPNOTFOUND; - err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (picl_nodehdl_t))) { - if (err != PICL_SUCCESS) { - free_list(plist); - return (PICL_FAILURE); - } - - /* - * compare name - */ - if ((strcmp(pname, PICL_PROP_CLASSNAME) != 0) || - (strcmp(nodename, PICL_CLASS_PICL) != 0)) { - err = ptree_get_propval_by_name(chdh, pname, - nameval, (strlen(nodename) + 1)); - - if (err != PICL_SUCCESS) - continue; - if (strcmp(nameval, nodename) != 0) - continue; - } - - /* - * compare device address with bus-addr prop first - * then with UnitAddress property - */ - if (baddr != NULL) { /* compare bus-addr prop */ - if ((ptree_get_propval_by_name(chdh, PICL_PROP_BUS_ADDR, - busval, (strlen(baddr) + 1)) != PICL_SUCCESS) && - (ptree_get_propval_by_name(chdh, - PICL_PROP_UNIT_ADDRESS, busval, - (strlen(baddr) + 1)) != PICL_SUCCESS)) - continue; - - if (strcmp(busval, baddr) != 0) - continue; /* not match */ - } - - if (plist == NULL) { /* no prop expression */ - *nodeh = chdh; - return (PICL_SUCCESS); - } - - /* - * compare the property expression list - */ - ptr = plist; - - while (ptr != NULL) { - err = check_propval(chdh, ptr->pname, ptr->pval); - if (err != PICL_SUCCESS) - break; - - ptr = ptr->next; - } - if (ptr == NULL) { - *nodeh = chdh; - free_list(plist); - return (PICL_SUCCESS); - } - } - free_list(plist); - return (PICL_NOTNODE); -} - -/* - * This functions returns the handle of node specified by its path - */ -int -ptree_get_node_by_path(const char *piclprl, picl_nodehdl_t *handle) -{ - picl_nodehdl_t rooth; - picl_nodehdl_t chdh; - char *path; - char *ptr; - char *defprop; - char *tokindex; - int err; - int len; - int npflg; /* namepath flag */ - - - path = strdupa(piclprl); - if (path == NULL) - return (PICL_FAILURE); - - npflg = 1; /* default */ - defprop = path; - if (path[0] == '/') { - ptr = &path[1]; - } else if ((tokindex = strchr(path, ':')) != NULL) { - *tokindex = '\0'; - ++tokindex; - if (*tokindex == '/') - ptr = tokindex + 1; - else - return (PICL_NOTNODE); - npflg = 0; - } else - return (PICL_NOTNODE); - - err = ptree_get_root(&rooth); - if (err != PICL_SUCCESS) - return (err); - - for (chdh = rooth, tokindex = strchr(ptr, '/'); - tokindex != NULL; - ptr = tokindex + 1, tokindex = strchr(ptr, '/')) { - *tokindex = '\0'; - if (npflg) - err = get_child_by_path(chdh, ptr, &chdh, - PICL_PROP_NAME); - else - err = get_child_by_path(chdh, ptr, &chdh, - defprop); - - if (err != PICL_SUCCESS) - return (err); - } - - /* - * check if last token is empty or not - * eg. /a/b/c/ or /a/b/c - */ - if (*ptr == '\0') { - *handle = chdh; - return (PICL_SUCCESS); - } - - len = strcspn(ptr, " \t\n"); - if (len == 0) { - *handle = chdh; - return (PICL_SUCCESS); - } - - ptr[len] = '\0'; - if (npflg) - err = get_child_by_path(chdh, ptr, &chdh, PICL_PROP_NAME); - else - err = get_child_by_path(chdh, ptr, &chdh, defprop); - - if (err != PICL_SUCCESS) - return (err); - - *handle = chdh; - return (PICL_SUCCESS); -} - -/* - * Initialize propinfo - */ -int -ptree_init_propinfo(ptree_propinfo_t *infop, int version, int ptype, int pmode, - size_t psize, char *pname, int (*readfn)(ptree_rarg_t *, void *), - int (*writefn)(ptree_warg_t *, const void *)) -{ - if (version != PTREE_PROPINFO_VERSION_1) - return (PICL_NOTSUPPORTED); - if ((infop == NULL) || (pname == NULL)) - return (PICL_INVALIDARG); - infop->version = version; - infop->piclinfo.type = ptype; - infop->piclinfo.accessmode = pmode; - infop->piclinfo.size = psize; - infop->read = readfn; - infop->write = writefn; - (void) strlcpy(infop->piclinfo.name, pname, PICL_PROPNAMELEN_MAX); - return (PICL_SUCCESS); -} - -/* - * Creates a property, adds it to the node, and returns the property - * handle to the caller if successful and proph is not NULL - */ -int -ptree_create_and_add_prop(picl_nodehdl_t nodeh, ptree_propinfo_t *infop, - void *vbuf, picl_prophdl_t *proph) -{ - int err; - picl_prophdl_t tmph; - - err = ptree_create_prop(infop, vbuf, &tmph); - if (err != PICL_SUCCESS) - return (err); - err = ptree_add_prop(nodeh, tmph); - if (err != PICL_SUCCESS) { - (void) ptree_destroy_prop(tmph); - return (err); - } - if (proph) - *proph = tmph; - return (PICL_SUCCESS); -} - -/* - * Creates a node, adds it to its parent node, and returns the node - * handle to the caller if successful - */ -int -ptree_create_and_add_node(picl_nodehdl_t rooth, const char *name, - const char *classname, picl_nodehdl_t *nodeh) -{ - picl_nodehdl_t tmph; - int err; - - err = ptree_create_node(name, classname, &tmph); - - if (err != PICL_SUCCESS) - return (err); - - err = ptree_add_node(rooth, tmph); - if (err != PICL_SUCCESS) { - (void) ptree_destroy_node(tmph); - return (err); - } - - *nodeh = tmph; - return (PICL_SUCCESS); -} - - -/* - * recursively visit all nodes - */ -static int -do_walk(picl_nodehdl_t rooth, const char *classname, - void *c_args, int (*callback_fn)(picl_nodehdl_t hdl, void *args)) -{ - int err; - picl_nodehdl_t chdh; - char classval[PICL_CLASSNAMELEN_MAX]; - - err = ptree_get_propval_by_name(rooth, PICL_PROP_CHILD, &chdh, - sizeof (chdh)); - while (err == PICL_SUCCESS) { - err = ptree_get_propval_by_name(chdh, PICL_PROP_CLASSNAME, - classval, sizeof (classval)); - if (err != PICL_SUCCESS) - return (err); - - if ((classname == NULL) || (strcmp(classname, classval) == 0)) { - err = callback_fn(chdh, c_args); - if (err != PICL_WALK_CONTINUE) - return (err); - } - - if ((err = do_walk(chdh, classname, c_args, callback_fn)) != - PICL_WALK_CONTINUE) - return (err); - - err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (chdh)); - } - if (err == PICL_PROPNOTFOUND) /* end of a branch */ - return (PICL_WALK_CONTINUE); - return (err); - -} - -/* - * This function visits all the nodes in the subtree rooted at . - * For each node that matches the class name specified, the callback - * function is invoked. - */ -int -ptree_walk_tree_by_class(picl_nodehdl_t rooth, const char *classname, - void *c_args, int (*callback_fn)(picl_nodehdl_t hdl, void *args)) -{ - int err; - - if (callback_fn == NULL) - return (PICL_INVALIDARG); - err = do_walk(rooth, classname, c_args, callback_fn); - if ((err == PICL_WALK_CONTINUE) || (err == PICL_WALK_TERMINATE)) - return (PICL_SUCCESS); - return (err); -} - -static int -compare_propval(picl_nodehdl_t nodeh, char *pname, picl_prop_type_t ptype, - void *pval, size_t valsize) -{ - int err; - picl_prophdl_t proph; - ptree_propinfo_t propinfo; - void *vbuf; - - err = ptree_get_prop_by_name(nodeh, pname, &proph); - if (err != PICL_SUCCESS) - return (0); - err = ptree_get_propinfo(proph, &propinfo); - if (err != PICL_SUCCESS) - return (0); - if (propinfo.piclinfo.type != ptype) - return (0); - if (propinfo.piclinfo.type == PICL_PTYPE_VOID) - return (1); - if (pval == NULL) - return (0); - if (valsize > propinfo.piclinfo.size) - return (0); - vbuf = alloca(propinfo.piclinfo.size); - if (vbuf == NULL) - return (0); - err = ptree_get_propval(proph, vbuf, propinfo.piclinfo.size); - if (err != PICL_SUCCESS) - return (0); - if (memcmp(vbuf, pval, valsize) == 0) - return (1); - return (0); -} - - -/* - * This function traverses the subtree and finds a node that has a property - * of the specified name and type with the specified value. - * The matched node in the tree is returned in retnodeh. If there is - * no node with that property, then PICL_NODENOTFOUND is returned. - */ -int -ptree_find_node(picl_nodehdl_t rooth, char *pname, picl_prop_type_t ptype, - void *pval, size_t valsize, picl_nodehdl_t *retnodeh) -{ - int err; - picl_nodehdl_t chdh; - - if (pname == NULL) - return (PICL_INVALIDARG); - err = ptree_get_propval_by_name(rooth, PICL_PROP_CHILD, &chdh, - sizeof (chdh)); - - while (err == PICL_SUCCESS) { - if (compare_propval(chdh, pname, ptype, pval, valsize)) { - if (retnodeh) - *retnodeh = chdh; - return (PICL_SUCCESS); - } - - err = ptree_find_node(chdh, pname, ptype, pval, valsize, - retnodeh); - if (err != PICL_NODENOTFOUND) - return (err); - - err = ptree_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh, - sizeof (chdh)); - } - if (err == PICL_PROPNOTFOUND) - return (PICL_NODENOTFOUND); - return (err); -} - -/* - * This function gets the frutree parent for a given node. - * Traverse up the tree and look for the following properties: - * Frutree parent reference properties: - * _fru_parent - * _location_parent - * _port_parent - * If the frutree reference property is found, return its value. - * Else, return the handle of /frutree/chassis. - */ -int -ptree_get_frutree_parent(picl_nodehdl_t nodeh, picl_nodehdl_t *fruh) -{ - int err; - picl_nodehdl_t nparh; - picl_nodehdl_t fruparh; - - err = PICL_SUCCESS; - nparh = nodeh; - while (err == PICL_SUCCESS) { - err = ptree_get_propval_by_name(nparh, PICL_REFPROP_FRU_PARENT, - &fruparh, sizeof (fruparh)); - if (err == PICL_SUCCESS) { - *fruh = fruparh; - return (PICL_SUCCESS); - } - err = ptree_get_propval_by_name(nparh, - PICL_REFPROP_LOC_PARENT, &fruparh, sizeof (fruparh)); - if (err == PICL_SUCCESS) { - *fruh = fruparh; - return (PICL_SUCCESS); - } - err = ptree_get_propval_by_name(nparh, PICL_REFPROP_PORT_PARENT, - &fruparh, sizeof (fruparh)); - if (err == PICL_SUCCESS) { - *fruh = fruparh; - return (PICL_SUCCESS); - } - - err = ptree_get_propval_by_name(nparh, PICL_PROP_PARENT, &nparh, - sizeof (nparh)); - } - - if (err == PICL_PROPNOTFOUND) { /* return /frutree/chassis handle */ - err = ptree_get_node_by_path(PICL_FRUTREE_CHASSIS, &fruparh); - if (err == PICL_SUCCESS) { - *fruh = fruparh; - return (PICL_SUCCESS); - } - } - return (err); -} - -/* - * This function is called by plug-ins to register with the daemon - */ -int -picld_plugin_register(picld_plugin_reg_t *regp) -{ - picld_plugin_reg_list_t *el; - picld_plugin_reg_list_t *tmp; - - if (regp == NULL) - return (PICL_FAILURE); - - if (regp->version != PICLD_PLUGIN_VERSION_1) - return (PICL_NOTSUPPORTED); - - el = malloc(sizeof (picld_plugin_reg_list_t)); - if (el == NULL) - return (PICL_FAILURE); - el->reg.version = regp->version; - el->reg.critical = regp->critical; - if (regp->name) - el->reg.name = strdup(regp->name); - if (el->reg.name == NULL) - return (PICL_FAILURE); - - el->reg.plugin_init = regp->plugin_init; - el->reg.plugin_fini = regp->plugin_fini; - el->next = NULL; - - if (plugin_reg_list == NULL) { - plugin_reg_list = el; - } else { /* add to end */ - tmp = plugin_reg_list; - while (tmp->next != NULL) - tmp = tmp->next; - tmp->next = el; - } - - return (PICL_SUCCESS); -} - -/* - * Call fini routines of the registered plugins - */ -static void -plugin_fini(picld_plugin_reg_list_t *p) -{ - if (p == NULL) - return; - - plugin_fini(p->next); - if (p->reg.plugin_fini) - (p->reg.plugin_fini)(); -} - -/* - * Create PICL Tree - */ - -static void -init_plugin_reg_list(void) -{ - plugin_reg_list = NULL; -} - -static int -picltree_set_root(picl_nodehdl_t rooth) -{ - picl_obj_t *pobj; - int err; - - (void) rw_rdlock(&ptree_rwlock); /* lock ptree */ - pobj = NULL; - err = lookup_and_lock_node(RDLOCK_NODE, rooth, &pobj); /* lock node */ - if (err != PICL_SUCCESS) { - (void) rw_unlock(&ptree_rwlock); - return (PICL_FAILURE); - } - piclize_node(pobj); - picl_root_obj = pobj; - ptree_root_hdl = pobj->ptree_hdl; - unlock_node(pobj); /* unlock node */ - (void) rw_unlock(&ptree_rwlock); /* unlock ptree */ - return (PICL_SUCCESS); -} - -static int -picltree_init(void) -{ - (void) rwlock_init(&ptree_rwlock, USYNC_THREAD, NULL); - (void) rwlock_init(&picltbl_rwlock, USYNC_THREAD, NULL); - - if (hash_init(&picltbl) < 0) - return (PICL_FAILURE); - if (hash_init(&ptreetbl) < 0) - return (PICL_FAILURE); - - if (pthread_mutex_init(&ptreehdl_lock, NULL) != 0) - return (PICL_FAILURE); - - if (pthread_mutex_init(&piclhdl_lock, NULL) != 0) - return (PICL_FAILURE); - - if (pthread_mutex_init(&evtq_lock, NULL) != 0) - return (PICL_FAILURE); - if (pthread_cond_init(&evtq_cv, NULL) != 0) - return (PICL_FAILURE); - if (pthread_mutex_init(&evthandler_lock, NULL) != 0) - return (PICL_FAILURE); - - picl_root_obj = NULL; - eventqp = NULL; - evt_handlers = NULL; - ptree_root_hdl = PICL_INVALID_PICLHDL; - - return (PICL_SUCCESS); -} - -static void -add_unique_plugin_to_list(char *path, char *name) -{ - picld_plugin_desc_t *pl; - picld_plugin_desc_t *tmp; - - pl = plugin_desc; - while (pl != NULL) { - if (strcmp(pl->libname, name) == 0) - return; - else - pl = pl->next; - } - - pl = malloc(sizeof (picld_plugin_desc_t)); - if (pl == NULL) - return; - - pl->libname = strdup(name); - if (pl->libname == NULL) - return; - - if (asprintf(&pl->pathname, "%s/%s", path, name) < 0) - pl->pathname = NULL; - if (pl->pathname == NULL) - return; - - pl->next = NULL; - - if (plugin_desc == NULL) - plugin_desc = pl; - else { - tmp = plugin_desc; - while (tmp->next != NULL) - tmp = tmp->next; - tmp->next = pl; - } -} - -static void -get_plugins_from_dir(char *dirname) -{ - struct dirent *ent; - DIR *dir; - int len; - int solen = strlen(SO_VERS) + 1; - - if ((dir = opendir(dirname)) == NULL) - return; - - while ((ent = readdir(dir)) != NULL) { - if ((strcmp(ent->d_name, ".") == 0) || - (strcmp(ent->d_name, "..") == 0)) - continue; - - len = strlen(ent->d_name) + 1; - if (len < solen) - continue; - - if (strcmp(ent->d_name + (len - solen), SO_VERS) == 0) - add_unique_plugin_to_list(dirname, ent->d_name); - } - - (void) closedir(dir); -} - - -static void -init_plugin_list(void) -{ - get_plugins_from_dir(PICLD_PLAT_PLUGIN_DIR); - get_plugins_from_dir(PICLD_COMMON_PLUGIN_DIR); -} - -static void -load_plugins(void) -{ - picld_plugin_desc_t *pl; - - pl = plugin_desc; - while (pl != NULL) { - pl->dlh = dlopen(pl->pathname, RTLD_LAZY|RTLD_LOCAL); - if (pl->dlh == NULL) { - syslog(LOG_CRIT, dlerror()); - return; - } - pl = pl->next; - } -} - - - -static int -add_root_props(picl_nodehdl_t rooth) -{ - int err; - picl_prophdl_t proph; - ptree_propinfo_t pinfo; - float picl_vers; - -#define PICL_PROP_PICL_VERSION "PICLVersion" -#define PICL_VERSION 1.1 - - err = ptree_init_propinfo(&pinfo, PTREE_PROPINFO_VERSION_1, - PICL_PTYPE_FLOAT, PICL_READ, sizeof (picl_vers), - PICL_PROP_PICL_VERSION, NULL, NULL); - if (err != PICL_SUCCESS) - return (err); - - picl_vers = PICL_VERSION; - err = ptree_create_and_add_prop(rooth, &pinfo, &picl_vers, &proph); - return (err); -} - -static int -construct_picltree(void) -{ - int err; - picld_plugin_reg_list_t *iter; - picl_nodehdl_t rhdl; - - /* - * Create "/" node - */ - if ((err = ptree_create_node(PICL_NODE_ROOT, PICL_CLASS_PICL, - &rhdl)) != PICL_SUCCESS) { - return (err); - } - - if (picltree_set_root(rhdl) != PICL_SUCCESS) { - return (PICL_FAILURE); - } - - err = add_root_props(rhdl); - if (err != PICL_SUCCESS) - return (err); - - /* - * Initialize the registered plug-in modules - */ - iter = plugin_reg_list; - while (iter != NULL) { - if (iter->reg.plugin_init) - (iter->reg.plugin_init)(); - iter = iter->next; - } - return (PICL_SUCCESS); -} - -void -xptree_destroy(void) -{ - dbg_print(1, "xptree_destroy: picl_root_obj = %s\n", - (picl_root_obj == NULL ? "NULL" : "not-NULL")); - - if (picl_root_obj == NULL) - return; - - dbg_print(1, "xptree_destroy: call plugin_fini\n"); - plugin_fini(plugin_reg_list); - dbg_print(1, "xptree_destroy: plugin_fini DONE\n"); - - (void) ptree_delete_node(picl_root_obj->ptree_hdl); - (void) ptree_destroy_node(picl_root_obj->ptree_hdl); - - (void) rw_wrlock(&ptree_rwlock); - picl_root_obj = NULL; - (void) rw_unlock(&ptree_rwlock); -} - -/*ARGSUSED*/ -int -xptree_initialize(int flg) -{ - int err; - pthread_attr_t attr; - pthread_t tid; - - picld_pid = getpid(); - picld_cred.dc_euid = geteuid(); - picld_cred.dc_egid = getegid(); - picld_cred.dc_ruid = getuid(); - picld_cred.dc_rgid = getgid(); - picld_cred.dc_pid = getpid(); - - picl_hdl_hi = 1; - ptree_hdl_hi = 1; - ptree_generation = 1; - qempty_wait = 0; - - if (pthread_mutex_init(&ptree_refresh_mutex, NULL) != 0) - return (PICL_FAILURE); - - if (picltree_init() != PICL_SUCCESS) - return (PICL_FAILURE); - - init_plugin_reg_list(); - init_plugin_list(); - load_plugins(); - - err = construct_picltree(); - if (err != PICL_SUCCESS) - return (err); - - /* - * Dispatch events after all plug-ins have initialized - */ - if (pthread_attr_init(&attr) != 0) - return (PICL_FAILURE); - - (void) pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); - if (pthread_create(&tid, &attr, ptree_event_thread, NULL)) - return (PICL_FAILURE); - - return (PICL_SUCCESS); -} - -int -xptree_reinitialize(void) -{ - int err; - - /* - * Wait for eventq to become empty - */ - dbg_print(1, "xptree_reinitialize: wait for evtq empty\n"); - (void) pthread_mutex_lock(&evtq_lock); - qempty_wait = 1; - while (eventqp != NULL) - (void) pthread_cond_wait(&evtq_empty, &evtq_lock); - qempty_wait = 0; - (void) pthread_mutex_unlock(&evtq_lock); - dbg_print(1, "xptree_reinitialize: evtq empty is EMPTY\n"); - - (void) rw_wrlock(&ptree_rwlock); - picl_root_obj = NULL; - ptree_root_hdl = PICL_INVALID_PICLHDL; - (void) rw_unlock(&ptree_rwlock); - (void) pthread_mutex_lock(&ptree_refresh_mutex); - ++ptree_generation; - (void) pthread_mutex_unlock(&ptree_refresh_mutex); - - err = construct_picltree(); - (void) pthread_mutex_lock(&ptree_refresh_mutex); - (void) pthread_cond_broadcast(&ptree_refresh_cond); - (void) pthread_mutex_unlock(&ptree_refresh_mutex); - - (void) pthread_mutex_lock(&evtq_lock); - (void) pthread_cond_broadcast(&evtq_cv); - (void) pthread_mutex_unlock(&evtq_lock); - - return (err); -} - -/* - * This function is called by the PICL daemon on behalf of clients to - * wait for a tree refresh - */ -int -xptree_refresh_notify(uint32_t secs) -{ - int curgen; - int ret; - timespec_t to; - - if (secs != 0) { - if (pthread_mutex_lock(&ptree_refresh_mutex) != 0) - return (PICL_FAILURE); - - curgen = ptree_generation; - - while (curgen == ptree_generation) { - if (secs == UINT32_MAX) /* wait forever */ - (void) pthread_cond_wait(&ptree_refresh_cond, - &ptree_refresh_mutex); - else { - to.tv_sec = secs; - to.tv_nsec = 0; - ret = pthread_cond_reltimedwait_np( - &ptree_refresh_cond, - &ptree_refresh_mutex, &to); - if (ret == ETIMEDOUT) - break; - } - } - - (void) pthread_mutex_unlock(&ptree_refresh_mutex); - } - - return (PICL_SUCCESS); -} - -/*VARARGS2*/ -void -dbg_print(int level, const char *fmt, ...) -{ - if (verbose_level >= level) { - va_list ap; - - va_start(ap, fmt); - (void) vprintf(fmt, ap); - va_end(ap); - } -} - -/*ARGSUSED*/ -void -dbg_exec(int level, void (*fn)(void *args), void *args) -{ - if (verbose_level > level) - (*fn)(args); -} diff --git a/usr/src/lib/libpicltree/picltree.h b/usr/src/lib/libpicltree/picltree.h deleted file mode 100644 index 9e6b18d70b..0000000000 --- a/usr/src/lib/libpicltree/picltree.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _PICLTREE_H -#define _PICLTREE_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * PTree Interface - */ - -#include - -/* - * Plug-in directories - */ -#define PICLD_COMMON_PLUGIN_DIR "/usr/lib/picl/plugins" -#define PICLD_PLAT_PLUGIN_DIR "/usr/platform/lib/picl/plugins" - -typedef struct { - picl_nodehdl_t nodeh; - picl_prophdl_t proph; - door_cred_t cred; -} ptree_rarg_t; - -typedef struct { - picl_nodehdl_t nodeh; - picl_prophdl_t proph; - door_cred_t cred; -} ptree_warg_t; -/* - * Volatile type properties must specify their maximum size in 'size' - * of propinfo_t at the time of creation. That guarantees clients - * accessing those properties an upper limit on value size. - * The two property types that have to specify a maximum are: - * PICL_PTYPE_BYTEARRAY, and PICL_PTYPE_CHARSTRING - */ -#define PTREE_PROPINFO_VERSION_1 1 -#define PTREE_PROPINFO_VERSION PTREE_PROPINFO_VERSION_1 - -typedef struct { - int version; - picl_propinfo_t piclinfo; /* client info */ - int (*read)(ptree_rarg_t *arg, void *buf); - int (*write)(ptree_warg_t *arg, const void *buf); -} ptree_propinfo_t; - -/* - * -------------------------------------------------- - * Function prototypes of PTree Interface primitives - * -------------------------------------------------- - */ -/* - * create/destroy/add/delete a node/property instance - */ -extern int ptree_get_root(picl_nodehdl_t *nodeh); -extern int ptree_create_node(const char *name, const char *clname, - picl_nodehdl_t *nodeh); -extern int ptree_destroy_node(picl_nodehdl_t nodeh); -extern int ptree_add_node(picl_nodehdl_t parh, picl_nodehdl_t chdh); -extern int ptree_delete_node(picl_nodehdl_t nodeh); - -extern int ptree_create_prop(const ptree_propinfo_t *pi, const void *vbuf, - picl_prophdl_t *proph); -extern int ptree_destroy_prop(picl_prophdl_t proph); -extern int ptree_delete_prop(picl_prophdl_t proph); -extern int ptree_add_prop(picl_nodehdl_t nodeh, picl_prophdl_t proph); -extern int ptree_create_table(picl_prophdl_t *tbl_hdl); -extern int ptree_add_row_to_table(picl_prophdl_t tbl, int nprops, - const picl_prophdl_t *props); -extern int ptree_update_propval_by_name(picl_nodehdl_t nodeh, - const char *name, const void *vbuf, size_t sz); -extern int ptree_update_propval(picl_prophdl_t proph, const void *buf, - size_t sz); -extern int ptree_get_propval(picl_prophdl_t proph, void *buf, - size_t sz); -extern int ptree_get_propval_by_name(picl_nodehdl_t nodeh, - const char *name, void *buf, size_t sz); -extern int ptree_get_propinfo(picl_prophdl_t proph, ptree_propinfo_t *pi); -extern int ptree_get_first_prop(picl_nodehdl_t nodeh, - picl_prophdl_t *proph); -extern int ptree_get_next_prop(picl_prophdl_t thish, - picl_prophdl_t *proph); -extern int ptree_get_prop_by_name(picl_nodehdl_t nodeh, const char *name, - picl_prophdl_t *proph); -extern int ptree_get_next_by_row(picl_prophdl_t proph, - picl_prophdl_t *rowh); -extern int ptree_get_next_by_col(picl_prophdl_t proph, - picl_prophdl_t *colh); -extern int ptree_init_propinfo(ptree_propinfo_t *infop, int version, - int ptype, int pmode, size_t psize, char *pname, - int (*readfn)(ptree_rarg_t *, void *), - int (*writefn)(ptree_warg_t *, const void *)); -extern int ptree_create_and_add_prop(picl_nodehdl_t nodeh, - ptree_propinfo_t *infop, void *vbuf, - picl_prophdl_t *proph); -extern int ptree_create_and_add_node(picl_nodehdl_t rooth, - const char *name, const char *classname, - picl_nodehdl_t *nodeh); -extern int ptree_get_node_by_path(const char *piclurl, - picl_nodehdl_t *handle); -extern int ptree_walk_tree_by_class(picl_nodehdl_t rooth, - const char *classname, void *c_args, - int (*callback_fn)(picl_nodehdl_t hdl, void *args)); -extern int ptree_find_node(picl_nodehdl_t rooth, char *pname, - picl_prop_type_t ptype, void *pval, size_t valsize, - picl_nodehdl_t *retnodeh); -extern int ptree_post_event(const char *ename, const void *earg, - size_t size, void (*completion_handler)(char *ename, - void *earg, size_t size)); -extern int ptree_register_handler(const char *ename, - void (*evt_handler)(const char *ename, const void *earg, - size_t size, void *cookie), void *cookie); -extern void ptree_unregister_handler(const char *ename, - void (*evt_handler)(const char *ename, const void *earg, - size_t size, void *cookie), void *cookie); -extern int ptree_get_frutree_parent(picl_nodehdl_t nodeh, - picl_nodehdl_t *retnodeh); - -/* - * PICL plug-in revision - */ -#define PICLD_PLUGIN_VERSION_1 1 -#define PICLD_PLUGIN_VERSION_2 2 - -#define PICLD_PLUGIN_VERSION PICLD_PLUGIN_VERSION_1 - -#define PICLD_PLUGIN_NON_CRITICAL 0 -#define PICLD_PLUGIN_CRITICAL 1 - -/* - * PICL plug-in registration interface - */ -typedef struct { - int version; - int critical; - char *name; - void (*plugin_init)(void); - void (*plugin_fini)(void); -} picld_plugin_reg_t; - -extern int picld_plugin_register(picld_plugin_reg_t *regp); - -#ifdef __cplusplus -} -#endif - -#endif /* _PICLTREE_H */ diff --git a/usr/src/lib/libpicltree/ptree_impl.h b/usr/src/lib/libpicltree/ptree_impl.h deleted file mode 100644 index 3ac74b3a5e..0000000000 --- a/usr/src/lib/libpicltree/ptree_impl.h +++ /dev/null @@ -1,252 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 1999-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef _PTREE_IMPL_H -#define _PTREE_IMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef uint64_t picl_hdl_t; - -/* - * Hash table size of Ptree and PICL tables - */ -#define HASH_TBL_SIZE 128 -#define HASH_INDEX(s, x) ((int)((x) & ((s) - 1))) - -/* - * Invalid PICL handle - */ -#define PICL_INVALID_PICLHDL (picl_hdl_t)0 - -/* - * Is the object PICLized? - */ -#define IS_PICLIZED(x) ((x)->picl_hdl != 0) - -/* - * A handle is a 64-bit quantity with the daemon's pid value in top 32 bits - * and the raw handle value in the lower 32 bits. - */ -#define HASH_VAL(x) ((x) & 0xFFFFFFFF) -#define GET_PID(x) ((x) >> 32) -#define MAKE_HANDLE(x, y) (((picl_hdl_t)(x) << 32) | (y)) - -/* - * Lock type when locking a node - */ -#define RDLOCK_NODE 1 -#define WRLOCK_NODE 2 - -/* - * Property access operation - */ -#define PROP_READ 1 -#define PROP_WRITE 2 - -/* - * PICL object type - */ -typedef struct picl_obj picl_obj_t; - -/* - * Hash table structure - */ -struct hash_elem { - uint32_t hdl; - union { - void *data; - uint32_t ptreeh; - } u; - struct hash_elem *next; -}; -typedef struct hash_elem hash_elem_t; -#define hash_obj u.data -#define hash_hdl u.ptreeh - -typedef struct { - int hash_size; - hash_elem_t **tbl; -} hash_t; - -/* - * Property expression list - */ -typedef struct prop_list { - char *pname; - char *pval; - struct prop_list *next; -} prop_list_t; - -/* - * PICL property (scalar or a table entry) - */ -struct picl_prop { - ptree_propinfo_t info; - void *pvalue; - picl_obj_t *nodep; /* prop's node or table */ - picl_obj_t *next_in_list; - picl_obj_t *next_by_row; - picl_obj_t *next_by_col; -}; -typedef struct picl_prop picl_prop_t; - -/* - * PICL node - */ -struct picl_node { - rwlock_t rwlock; /* protects properties */ - picl_obj_t *firstprop; - char *classname; - picl_obj_t *parent; /* protected by ptree lock */ - picl_obj_t *child; /* protected by ptree lock */ - picl_obj_t *sibling; /* protected by ptree lock */ -}; -typedef struct picl_node picl_node_t; - -/* - * PICL object types - */ -#define PICL_OBJ_NODE 0x1 -#define PICL_OBJ_PROP 0x2 -#define PICL_OBJ_TABLE 0x4 -#define PICL_OBJ_TABLEENTRY 0x8 - -/* - * PICL object - */ -struct picl_obj { - uint32_t obj_type; - picl_hdl_t ptree_hdl; /* ptree handle */ - picl_hdl_t picl_hdl; /* client handle */ - union { - picl_node_t node; - picl_prop_t prop; - } u; -}; - -#define pinfo_ver u.prop.info.version -#define prop_type u.prop.info.piclinfo.type -#define prop_size u.prop.info.piclinfo.size -#define prop_mode u.prop.info.piclinfo.accessmode -#define prop_name u.prop.info.piclinfo.name -#define prop_val u.prop.pvalue -#define next_row u.prop.next_by_row -#define next_col u.prop.next_by_col -#define next_prop u.prop.next_in_list -#define table_prop u.prop.next_in_list -#define prop_node u.prop.nodep -#define prop_table u.prop.nodep -#define read_func u.prop.info.read -#define write_func u.prop.info.write - -#define first_prop u.node.firstprop -#define node_lock u.node.rwlock -#define child_node u.node.child -#define sibling_node u.node.sibling -#define parent_node u.node.parent -#define node_classname u.node.classname - -/* - * PICL event queue structures - */ -struct eventq { - const char *ename; - const void *earg; - size_t size; - void (*completion_handler)(char *ename, void *earg, - size_t size); - struct eventq *next; -}; -typedef struct eventq eventq_t; - -/* - * Event handler list - */ -struct eh_list { - char *ename; - void *cookie; - void (*evt_handler)(const char *ename, const void *earg, - size_t size, void *cookie); - short execflg; - short wakeupflg; - pthread_cond_t cv; - struct eh_list *next; -}; -typedef struct eh_list evt_handler_t; - -#define SUPER_USER 0 - -#define MIN(x, y) ((x) < (y) ? (x) : (y)) - -typedef struct picld_plugin_reg_list { - picld_plugin_reg_t reg; - struct picld_plugin_reg_list *next; -} picld_plugin_reg_list_t; - -typedef struct picld_plinfo { - char *libname; - char *pathname; - void *dlh; - struct picld_plinfo *next; -} picld_plugin_desc_t; - -extern int xptree_initialize(int); -extern void xptree_destroy(void); -extern int xptree_reinitialize(void); -extern int xptree_refresh_notify(uint32_t secs); -extern int cvt_picl2ptree(picl_hdl_t piclh, picl_hdl_t *ptreeh); -extern void cvt_ptree2picl(picl_hdl_t *vbuf); -extern int xptree_get_propinfo_by_name(picl_nodehdl_t nodeh, - const char *pname, ptree_propinfo_t *pinfo); -extern int xptree_get_propval_with_cred(picl_prophdl_t proph, void *valbuf, - size_t size, door_cred_t cred); -extern int xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh, - const char *propname, void *valbuf, size_t sz, - door_cred_t cred); -extern int xptree_update_propval_with_cred(picl_prophdl_t proph, - const void *valbuf, size_t sz, door_cred_t cred); -extern int xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh, - const char *propname, const void *valbuf, size_t sz, - door_cred_t cred); - -/* - * PICL daemon verbose level flag - */ -extern int verbose_level; -extern void dbg_print(int level, const char *fmt, ...); -extern void dbg_exec(int level, void (*fn)(void *), void *arg); - -#ifdef __cplusplus -} -#endif - -#endif /* _PTREE_IMPL_H */ diff --git a/usr/src/pkg/manifests/service-picl.inc b/usr/src/pkg/manifests/service-picl.inc deleted file mode 100644 index 8bd580fcd9..0000000000 --- a/usr/src/pkg/manifests/service-picl.inc +++ /dev/null @@ -1,60 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# - -# -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright 2012 Nexenta Systems, Inc. All rights reserved. -# - -dir path=lib variant.opensolaris.zone=global -dir path=lib/svc variant.opensolaris.zone=global -dir path=lib/svc/manifest group=sys variant.opensolaris.zone=global -dir path=usr group=sys -dir path=usr/lib -dir path=usr/lib/$(ARCH64) -dir path=usr/lib/picl group=sys -dir path=usr/lib/picl/plugins group=sys -dir path=usr/lib/sysevent -dir path=usr/lib/sysevent/modules -dir path=usr/sbin -file path=lib/svc/manifest/system/picl.xml group=sys mode=0444 \ - variant.opensolaris.zone=global -file path=usr/lib/$(ARCH64)/libpicl.so.1 -file path=usr/lib/libpicl.so.1 -file path=usr/lib/libpicld_pluginutil.so.1 -file path=usr/lib/libpicltree.so.1 -file path=usr/lib/picl/picld mode=0555 -file path=usr/lib/picl/plugins/libpicldevtree.so.1 group=sys -file path=usr/lib/picl/plugins/libpiclevent.so.1 group=sys -file path=usr/lib/picl/plugins/libpiclfrutree.so.1 group=sys -file path=usr/lib/picl/plugins/libpiclmemcfg.so.1 group=sys -file path=usr/lib/sysevent/modules/picl_slm.so -file path=usr/sbin/prtpicl mode=0755 -license cr_Sun license=cr_Sun -license lic_CDDL license=lic_CDDL -link path=usr/lib/$(ARCH64)/libpicl.so target=./libpicl.so.1 -link path=usr/lib/libpicl.so target=./libpicl.so.1 -link path=usr/lib/libpicld_pluginutil.so target=./libpicld_pluginutil.so.1 -link path=usr/lib/libpicltree.so target=./libpicltree.so.1 -link path=usr/lib/picl/plugins/libpicldevtree.so target=./libpicldevtree.so.1 -link path=usr/lib/picl/plugins/libpiclevent.so target=./libpiclevent.so.1 -link path=usr/lib/picl/plugins/libpiclfrutree.so target=./libpiclfrutree.so.1 -link path=usr/lib/picl/plugins/libpiclmemcfg.so target=./libpiclmemcfg.so.1 diff --git a/usr/src/pkg/manifests/system-core-os.mf b/usr/src/pkg/manifests/system-core-os.mf index 9adb67d1ec..1dfd3b97c5 100644 --- a/usr/src/pkg/manifests/system-core-os.mf +++ b/usr/src/pkg/manifests/system-core-os.mf @@ -41,7 +41,6 @@ - diff --git a/usr/src/pkg/manifests/system-header-header-picl.mf b/usr/src/pkg/manifests/system-header-header-picl.mf dissimilarity index 95% index 244d517f84..233eff61c8 100644 --- a/usr/src/pkg/manifests/system-header-header-picl.mf +++ b/usr/src/pkg/manifests/system-header-header-picl.mf @@ -1,36 +1,3 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# - -# -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. -# - -set name=pkg.fmri value=pkg:/system/header/header-picl@$(PKGVERS) -set name=pkg.description value="PICL Header Files" -set name=pkg.summary value="PICL Header Files" -set name=info.classification value=org.opensolaris.category.2008:System/Core -set name=variant.arch value=$(ARCH) -dir path=usr group=sys -dir path=usr/include -file path=usr/include/picl.h mode=0644 -file path=usr/include/picltree.h mode=0644 -license cr_Sun license=cr_Sun -license lic_CDDL license=lic_CDDL +set name=pkg.fmri value=pkg:/system/header/header-picl@$(PKGVERS) +set name=pkg.obsolete value=true +set name=variant.arch value=i386 -- 2.11.4.GIT