10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*1106Smrj * Common Development and Distribution License (the "License").
6*1106Smrj * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*1106Smrj
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/kmem.h>
310Sstevel@tonic-gate #include <sys/sysmacros.h>
320Sstevel@tonic-gate #include <sys/cmn_err.h>
330Sstevel@tonic-gate #include <sys/systm.h>
340Sstevel@tonic-gate #include <sys/modctl.h>
350Sstevel@tonic-gate #include <sys/kobj.h>
360Sstevel@tonic-gate #include <vm/hat.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate * PSARC 2004/405 made hat_getkpfnum(9F) obsolete. As part of the
400Sstevel@tonic-gate * obsolecense, the original documented behavior will begin to be
410Sstevel@tonic-gate * enforced in the future; namely, hat_getkpfnum(9F) may _only_
420Sstevel@tonic-gate * be called with device-mapped memory virtual addresses. Since
430Sstevel@tonic-gate * changing hat_getkpfnum(9F) to return PFN_INVALID on kernel memory
440Sstevel@tonic-gate * would break a lot of modules without any warning, we've implemented
450Sstevel@tonic-gate * the following mechanism as a stop-gap. In a future release, this
460Sstevel@tonic-gate * can all be ripped out and hat_getkpfnum(9F) changed to return
470Sstevel@tonic-gate * PFN_INVALID if it isn't called with a device-mapped memory address.
480Sstevel@tonic-gate *
490Sstevel@tonic-gate * We keep track of each module that has used hat_getkpfnum(9F)
500Sstevel@tonic-gate * incorrectly. This allows us to avoid flooding the console/logs
510Sstevel@tonic-gate * with too many warnings about a bad module that has already been
520Sstevel@tonic-gate * flagged.
530Sstevel@tonic-gate *
540Sstevel@tonic-gate * On amd64 hat_getkpfnum() is never supported.
550Sstevel@tonic-gate */
560Sstevel@tonic-gate
570Sstevel@tonic-gate #if !defined(__amd64)
580Sstevel@tonic-gate
590Sstevel@tonic-gate #define HAT_STACK_MAXDEPTH 15
600Sstevel@tonic-gate
610Sstevel@tonic-gate struct badcall_node {
620Sstevel@tonic-gate char *bc_modname;
630Sstevel@tonic-gate int bc_stackdepth;
640Sstevel@tonic-gate pc_t bc_callstack[HAT_STACK_MAXDEPTH];
650Sstevel@tonic-gate struct badcall_node *bc_linkage;
660Sstevel@tonic-gate };
670Sstevel@tonic-gate
680Sstevel@tonic-gate static struct badcall_node *bad_getkpfnum_callers;
690Sstevel@tonic-gate
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate * Common VM HAT routines.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate
740Sstevel@tonic-gate static void
printwarn(struct badcall_node * bc)750Sstevel@tonic-gate printwarn(struct badcall_node *bc)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate int sf;
780Sstevel@tonic-gate char *ksym;
790Sstevel@tonic-gate ulong_t off;
800Sstevel@tonic-gate
810Sstevel@tonic-gate cmn_err(CE_WARN, "Module %s is using the obsolete hat_getkpfnum(9F)",
820Sstevel@tonic-gate bc->bc_modname);
830Sstevel@tonic-gate cmn_err(CE_CONT, "interface in a way that will not be supported in\n");
840Sstevel@tonic-gate cmn_err(CE_CONT, "a future release of Solaris. Please contact the\n");
850Sstevel@tonic-gate cmn_err(CE_CONT, "vendor that supplied the module for assistance,\n");
860Sstevel@tonic-gate cmn_err(CE_CONT, "or consult the Writing Device Drivers guide,\n");
870Sstevel@tonic-gate cmn_err(CE_CONT, "available from http://www.sun.com for migration\n");
880Sstevel@tonic-gate cmn_err(CE_CONT, "advice.\n");
890Sstevel@tonic-gate cmn_err(CE_CONT, "---\n");
900Sstevel@tonic-gate cmn_err(CE_CONT, "Callstack of bad caller:\n");
910Sstevel@tonic-gate
920Sstevel@tonic-gate for (sf = 0; sf < bc->bc_stackdepth; sf++) {
930Sstevel@tonic-gate ksym = kobj_getsymname(bc->bc_callstack[sf], &off);
940Sstevel@tonic-gate cmn_err(CE_CONT, "\t%s+%lx\n", ksym? ksym : "?", off);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate }
970Sstevel@tonic-gate
980Sstevel@tonic-gate
990Sstevel@tonic-gate void
hat_getkpfnum_badcall(void * caller)1000Sstevel@tonic-gate hat_getkpfnum_badcall(void *caller)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate struct badcall_node bcs;
1030Sstevel@tonic-gate char *modname = mod_containing_pc((caddr_t)caller);
1040Sstevel@tonic-gate struct badcall_node *bc;
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate #ifdef __sparc
1070Sstevel@tonic-gate /*
1080Sstevel@tonic-gate * This is a hack until the ifb and jfb framebuffer drivers
1090Sstevel@tonic-gate * are fixed. Right now they use hat_getkpfnum() in a way that
1100Sstevel@tonic-gate * is really safe but will be incorrectly flagged as being
1110Sstevel@tonic-gate * buggy.
1120Sstevel@tonic-gate */
1130Sstevel@tonic-gate if (strcmp(modname, "ifb") == 0 || strcmp(modname, "jfb") == 0)
1140Sstevel@tonic-gate return;
1150Sstevel@tonic-gate #elif defined(__i386)
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate * This is a hack until these ethernet drivers can be fixed
1180Sstevel@tonic-gate * or EOL'd. hat_getkpfnum() will continue to work correctly
1190Sstevel@tonic-gate * until this list can be removed.
1200Sstevel@tonic-gate */
1210Sstevel@tonic-gate if (strcmp(modname, "dnet") == 0 || strcmp(modname, "pcn") == 0 ||
122*1106Smrj strcmp(modname, "adp") == 0)
1230Sstevel@tonic-gate return;
1240Sstevel@tonic-gate #endif /* __sparc / __i386 */
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate for (bc = bad_getkpfnum_callers; bc != NULL; bc = bc->bc_linkage)
1270Sstevel@tonic-gate if (strcmp(bc->bc_modname, modname) == 0)
1280Sstevel@tonic-gate return;
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate * We haven't seen this caller before, so create a log of
1320Sstevel@tonic-gate * the callstack and module name, and emit a warning to the
1330Sstevel@tonic-gate * user.
1340Sstevel@tonic-gate */
1350Sstevel@tonic-gate bc = kmem_zalloc(sizeof (struct badcall_node), KM_NOSLEEP);
1360Sstevel@tonic-gate if (bc != NULL) {
1370Sstevel@tonic-gate bc->bc_linkage = bad_getkpfnum_callers;
1380Sstevel@tonic-gate bc->bc_modname = modname;
1390Sstevel@tonic-gate bad_getkpfnum_callers = bc;
1400Sstevel@tonic-gate } else {
1410Sstevel@tonic-gate bc = &bcs;
1420Sstevel@tonic-gate bc->bc_modname = modname;
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate bc->bc_stackdepth = getpcstack(bc->bc_callstack, HAT_STACK_MAXDEPTH);
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate printwarn(bc);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate #endif /* __amd64 */
150