fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_rmmap_inuse(nsc_rmmap_t *, ulong_t *, size_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _nsc_sprint_dec(char **, int, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void _nsc_sprint_hex(char **, unsigned int, int, int, int, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_decode_param(nsc_def_t *args, nsc_def_t *def, long *v)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((time_t)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * HACK increment nodeid in data parameter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_rmmap_init (nsc_rmmap_t *map, char *name, int nslot,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * size_t size, ulong_t offset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise a global resource map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns TRUE if the map was successfully created. Otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns FALSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialises a global resource map. If the map already exists
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the arguments are validated against it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* actually we only need to do this if an update occurred above */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint32_t)size != map->size || (int32_t)offset != map->offset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_rmmap_alloc (nsc_rmmap_t *map, char *name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * size_t size, void (*alloc)())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate entry in a global resource map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On success, returns the base of the allocated area. Otherwise,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns NULL. The function 'alloc' will be called if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocated area is not currently in use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocates an entry in the global resource map. If the entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * already exists but is a different size an error is returned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_rmmap_alloc(nsc_rmmap_t *map, char *name, size_t size, void (*alloc)())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((int32_t)offset < (map[0].offset + map[0].size)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nvmap) { /* update the map and hdr dirty bit. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_rmmap_free (nsc_rmmap_t *map, char *name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free entry in a global resource map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Frees an entry in the global resource map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_rmmap_free(nsc_rmmap_t *map, char *name, nsc_mem_t *mp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if dirty, set the inuse bit so this area
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will not be _nsc_global_zero'd on restart.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: _nsc_rmmap_free: invalid free");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_rmmap_size (nsc_rmmap_t *map, char *name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find size of area in map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns the size of the specified area in the map,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or 0 if it is currently unallocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(map[i].name, name, _NSC_MAXNAME) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_rmmap_avail (nsc_rmmap_t *map)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find available space in global resource map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns the size of the largest available area in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the global resource map.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((int32_t)offset < (map[0].offset + map[0].size))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_rmmap_inuse (nsc_rmmap_t *map, ulong_t *offsetp, size_t *sizep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if a section of the map is in use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The global lock must be held across calls to the function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns TRUE if the specified area is currently in use and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * updates offset to point just past the section that was found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to be in use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Otherwise, returns FALSE and updates size to reflect the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * amount of free space at the specified offset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Checks the specified global map to determine if any part
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the area is in use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_rmmap_inuse(nsc_rmmap_t *map, ulong_t *offsetp, size_t *sizep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (int32_t)offset < (map[i].offset + map[i].size)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_delay_sig (clock_t tics)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Delay for a number of clock ticks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns FALSE if the delay was interrupted by a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * signal, TRUE otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Delays execution for the specified number of ticks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or until a signal is received.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* timeout */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* signalled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_sprintf (char *s, char *fmt, ...)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * String printf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Builds a NULL terminated string in the buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pointed to by 's', using the format 'fmt'.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Simple version of sprintf supporting fairly
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * basic formats.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* PRINTFLIKE2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((c = *fmt++) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(c = *fmt++))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (c == 's') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_sprint_dec (char **sptr, int n, int zero, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Decimal to string conversion.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Stores a character representation of 'n' in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer referenced by 'sptr' and updates the pointer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * accordingly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Generates a string representation of a signed decimal
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_sprint_dec(char **sptr, int n, int zero, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned int v = (n < 0) ? (-n) : n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; v; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n < 0 && !zero)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(*sptr)++ = c[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_sprint_hex (char **sptr, unsigned int v,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * int up, int alt, int zero, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Hexadecimal to string conversion.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Stores a character representation of 'v' in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer referenced by 'sptr' and updates the pointer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * accordingly.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Generates a string representation of an unsigned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hexadecimal integer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_sprint_hex(char **sptr, uint_t v, int up, int alt, int zero, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; v; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(*sptr)++ = c[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_strdup (char *s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Duplicate string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns the address of the new string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocates a suitably sized area of memory and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copies the string into it. The string should be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free'd using nsc_strfree().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp = nsc_kmem_alloc(strlen(s) + 1, KM_SLEEP, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_strfree (char *s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Frees a string previously allocated by nsc_strdup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_strmatch (char *s, char *pat)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Match string against pattern.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns TRUE if the string matches against the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pattern, FALSE otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Compares string against regular expression which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * can contain '*', '?' and '[]' constructs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; *s; s++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (!*s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_strhash(char *str)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calculate a simple hash for the specified string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns a simple hash of the NULL terminated string, str.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_fatal(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fatal error stub function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns EINVAL (non-DEBUG) or forces a panic.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is a stub function suitable for default actions in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsctl i/o provider definitions. It should be used when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * calling the stub would be a programming error. The most
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * common reason for nsc_fatal() being called is that an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsctl client module has called an nsc_fd_t i/o function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * without the fd already reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The function will display a diagnostic message and when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * built -DDEBUG will force a panic and display the textual
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * name of the symbol closest to the caller address of this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte caller_sym = kobj_getsymname((uintptr_t)caller, &offset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* !DS_DDICT */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: nsc_fatal called at 0x%p (%s+0x%lx)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Force TRAP due to NULL pointer dereference
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - CE_PANIC can result in the stack trace being unreadable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by (k)adb.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(int *)0 = 0x12345678;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !DEBUG */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: nsc_fatal called at 0x%p", caller);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DEBUG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_commit_mem(void *src, void *dst, size_t len, nsc_mem_err_cb err_action)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_cm_errhdlr(void *src, void *dst, size_t len, int errval)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsc_cm_errhdlr: media down, forced_wrthru");
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!nsc_cm_errhdlr: this message "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "displayed every 100 errors");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_nsc_svc_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_nsc_delay_mutex, NULL, MUTEX_DRIVER, NULL);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "nsctl: services registered in _nsc_deinit_svc");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_register_svc(char *name, void (*service_fn)(intptr_t))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte new = nsc_kmem_zalloc(sizeof (*new), KM_SLEEP, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svc = nsc_kmem_zalloc(sizeof (*svc), KM_SLEEP, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (sp = _nsc_services; sp != NULL; sp = sp->s_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svcp = (svc->svc_fn == NULL) ? &sp->s_clients : &sp->s_servers;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sp->s_servers == NULL && sp->s_clients == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (spp = &_nsc_services; *spp; spp = &((*spp)->s_next))