17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217257d1b4Sraf 227c478bd9Sstevel@tonic-gate /* 237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h> 287c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h> 297c478bd9Sstevel@tonic-gate #include <mdb/mdb_io.h> 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #define UMEM_STANDALONE 327c478bd9Sstevel@tonic-gate #include <umem_impl.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * The standalone umem requires that kmdb provide some error-handling 367c478bd9Sstevel@tonic-gate * services. These are them. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 407c478bd9Sstevel@tonic-gate int 417c478bd9Sstevel@tonic-gate __umem_assert_failed(const char *assertion, const char *file, int line) 427c478bd9Sstevel@tonic-gate { 437c478bd9Sstevel@tonic-gate #ifdef DEBUG 447c478bd9Sstevel@tonic-gate (void) mdb_dassert(assertion, file, line); 457c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate return (0); 487c478bd9Sstevel@tonic-gate } 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate void 517c478bd9Sstevel@tonic-gate umem_panic(const char *format, ...) 527c478bd9Sstevel@tonic-gate { 537c478bd9Sstevel@tonic-gate va_list alist; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate va_start(alist, format); 567c478bd9Sstevel@tonic-gate vfail(format, alist); 577c478bd9Sstevel@tonic-gate va_end(alist); 587c478bd9Sstevel@tonic-gate } 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate void 617c478bd9Sstevel@tonic-gate umem_err_recoverable(const char *format, ...) 627c478bd9Sstevel@tonic-gate { 637c478bd9Sstevel@tonic-gate va_list alist; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate va_start(alist, format); 667c478bd9Sstevel@tonic-gate vwarn(format, alist); 677c478bd9Sstevel@tonic-gate va_end(alist); 687c478bd9Sstevel@tonic-gate } 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate int 717c478bd9Sstevel@tonic-gate umem_vsnprintf(char *s, size_t n, const char *format, va_list ap) 727c478bd9Sstevel@tonic-gate { 737c478bd9Sstevel@tonic-gate return (mdb_iob_vsnprintf(s, n, format, ap)); 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate int 777c478bd9Sstevel@tonic-gate umem_snprintf(char *s, size_t n, const char *format, ...) 787c478bd9Sstevel@tonic-gate { 797c478bd9Sstevel@tonic-gate va_list ap; 807c478bd9Sstevel@tonic-gate int rc; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate va_start(ap, format); 837c478bd9Sstevel@tonic-gate rc = umem_vsnprintf(s, n, format, ap); 847c478bd9Sstevel@tonic-gate va_end(ap); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate return (rc); 877c478bd9Sstevel@tonic-gate } 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* These aren't atomic, but we're not MT, so it doesn't matter */ 907c478bd9Sstevel@tonic-gate uint32_t 917257d1b4Sraf umem_atomic_add_32_nv(uint32_t *target, int32_t delta) 927c478bd9Sstevel@tonic-gate { 937c478bd9Sstevel@tonic-gate return (*target = *target + delta); 947c478bd9Sstevel@tonic-gate } 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate void 977257d1b4Sraf umem_atomic_add_64(uint64_t *target, int64_t delta) 987c478bd9Sstevel@tonic-gate { 997c478bd9Sstevel@tonic-gate *target = *target + delta; 1007c478bd9Sstevel@tonic-gate } 1017c478bd9Sstevel@tonic-gate 102*4f364e7cSRobert Mustacchi uint64_t 103*4f364e7cSRobert Mustacchi umem_atomic_swap_64(volatile uint64_t *t, uint64_t v) 104*4f364e7cSRobert Mustacchi { 105*4f364e7cSRobert Mustacchi uint64_t old = *t; 106*4f364e7cSRobert Mustacchi *t = v; 107*4f364e7cSRobert Mustacchi return (old); 108*4f364e7cSRobert Mustacchi } 109*4f364e7cSRobert Mustacchi 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * Standalone umem must be manually initialized 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate void 1147c478bd9Sstevel@tonic-gate mdb_umem_startup(caddr_t base, size_t len, size_t pgsize) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate umem_startup(base, len, pgsize, base, base + len); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * The kernel will tell us when there's more memory available for us to use. 1217c478bd9Sstevel@tonic-gate * This is most common on amd64, which boots with only 4G of VA available, and 1227c478bd9Sstevel@tonic-gate * later expands to the full 64-bit address space. 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate int 1257c478bd9Sstevel@tonic-gate mdb_umem_add(caddr_t base, size_t len) 1267c478bd9Sstevel@tonic-gate { 1277c478bd9Sstevel@tonic-gate return (umem_add(base, len)); 1287c478bd9Sstevel@tonic-gate } 129