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
53138Sfrits * Common Development and Distribution License (the "License").
63138Sfrits * 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 */
210Sstevel@tonic-gate /*
22*5148Srz201010 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * ddi_dki_impl.c - A pseudo-kernel to use when analyzing drivers with warlock.
300Sstevel@tonic-gate *
310Sstevel@tonic-gate * The main idea here is to represent all of the ways that the kernel can
320Sstevel@tonic-gate * call into the driver, so that warlock has the correct view of the call
330Sstevel@tonic-gate * graph.
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * This version differs from ddi_dki_spec.c in that it represents the
360Sstevel@tonic-gate * current implementation of the DDI/DKI rather than the specification.
370Sstevel@tonic-gate */
380Sstevel@tonic-gate #include "ddi_dki_comm.inc"
390Sstevel@tonic-gate #include <sys/esunddi.h>
400Sstevel@tonic-gate #include <sys/sunndi.h>
410Sstevel@tonic-gate #include <sys/ddi.h>
420Sstevel@tonic-gate #include <sys/epm.h>
430Sstevel@tonic-gate #include <sys/proc.h>
440Sstevel@tonic-gate
453138Sfrits int warlock_dummy(void);
463138Sfrits int _init(void);
473138Sfrits int _fini(void);
48*5148Srz201010 int _info(struct modinfo *a);
493138Sfrits int scsi_init(void);
500Sstevel@tonic-gate
main(void)513138Sfrits int main(void) {
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * The following call will cause warlock to know about
550Sstevel@tonic-gate * warlock_dummy as a func that can be used to satisfy
560Sstevel@tonic-gate * unbound function pointers. It shouldn't be needed
570Sstevel@tonic-gate * with the new warlock on suntools.
580Sstevel@tonic-gate */
590Sstevel@tonic-gate warlock_dummy();
600Sstevel@tonic-gate
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate * When the following functions are called, there is never
630Sstevel@tonic-gate * more than one thread running in the driver.
640Sstevel@tonic-gate */
650Sstevel@tonic-gate _init();
660Sstevel@tonic-gate _fini();
67*5148Srz201010 _info(0);
680Sstevel@tonic-gate (*devops_p->devo_identify)(0);
690Sstevel@tonic-gate (*devops_p->devo_probe)(0);
700Sstevel@tonic-gate (*devops_p->devo_attach)(0, 0);
710Sstevel@tonic-gate
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate * When the following functions are called, there may be
740Sstevel@tonic-gate * more than one thread running in the driver.
750Sstevel@tonic-gate */
760Sstevel@tonic-gate _NOTE(COMPETING_THREADS_NOW)
770Sstevel@tonic-gate
780Sstevel@tonic-gate
790Sstevel@tonic-gate scsi_init();
800Sstevel@tonic-gate
810Sstevel@tonic-gate (*devops_p->devo_getinfo)(0, 0, 0, 0);
820Sstevel@tonic-gate (*devops_p->devo_reset)(0, 0);
830Sstevel@tonic-gate (*devops_p->devo_power)(0, 0, 0);
840Sstevel@tonic-gate
850Sstevel@tonic-gate (*cbops_p->cb_open)(0, 0, 0, 0);
860Sstevel@tonic-gate (*cbops_p->cb_close)(0, 0, 0, 0);
870Sstevel@tonic-gate (*cbops_p->cb_strategy)(0);
880Sstevel@tonic-gate (*cbops_p->cb_print)(0, 0);
890Sstevel@tonic-gate (*cbops_p->cb_dump)(0, 0, 0, 0);
900Sstevel@tonic-gate (*cbops_p->cb_read)(0, 0, 0);
910Sstevel@tonic-gate (*cbops_p->cb_write)(0, 0, 0);
920Sstevel@tonic-gate (*cbops_p->cb_ioctl)(0, 0, 0, 0, 0, 0);
930Sstevel@tonic-gate (*cbops_p->cb_devmap)(0, 0, 0, 0, 0, 0);
940Sstevel@tonic-gate (*cbops_p->cb_mmap)(0, 0, 0);
950Sstevel@tonic-gate (*cbops_p->cb_segmap)(0, 0, 0, 0, 0, 0, 0, 0, 0);
960Sstevel@tonic-gate (*cbops_p->cb_chpoll)(0, 0, 0, 0, 0);
970Sstevel@tonic-gate (*cbops_p->cb_prop_op)(0, 0, 0, 0, 0, 0, 0);
980Sstevel@tonic-gate (*cbops_p->cb_aread)(0, 0, 0);
990Sstevel@tonic-gate (*cbops_p->cb_awrite)(0, 0, 0);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate (*busops_p->bus_map)(0, 0, 0, 0, 0, 0);
1020Sstevel@tonic-gate (*busops_p->bus_get_intrspec)(0, 0, 0);
1030Sstevel@tonic-gate (*busops_p->bus_add_intrspec)(0, 0, 0, 0, 0, 0, 0, 0);
1040Sstevel@tonic-gate (*busops_p->bus_remove_intrspec)(0, 0, 0, 0);
1050Sstevel@tonic-gate (*busops_p->bus_map_fault)(0, 0, 0, 0, 0, 0, 0, 0, 0);
1060Sstevel@tonic-gate (*busops_p->bus_dma_map)(0, 0, 0, 0);
1070Sstevel@tonic-gate (*busops_p->bus_dma_allochdl)(0, 0, 0, 0, 0, 0);
1080Sstevel@tonic-gate (*busops_p->bus_dma_freehdl)(0, 0, 0);
1090Sstevel@tonic-gate (*busops_p->bus_dma_bindhdl)(0, 0, 0, 0, 0, 0);
1100Sstevel@tonic-gate (*busops_p->bus_dma_unbindhdl)(0, 0, 0);
1110Sstevel@tonic-gate (*busops_p->bus_dma_flush)(0, 0, 0, 0, 0, 0);
1120Sstevel@tonic-gate (*busops_p->bus_dma_win)(0, 0, 0, 0, 0, 0, 0, 0);
1130Sstevel@tonic-gate (*busops_p->bus_dma_ctl)(0, 0, 0, 0, 0, 0, 0, 0);
1140Sstevel@tonic-gate (*busops_p->bus_ctl)(0, 0, 0, 0, 0);
1150Sstevel@tonic-gate (*busops_p->bus_prop_op)(0, 0, 0, 0, 0, 0, 0, 0);
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate (*busops_p->bus_get_eventcookie)(0, 0, 0, 0);
1180Sstevel@tonic-gate (*busops_p->bus_add_eventcall)(0, 0, 0, 0, 0, 0);
1190Sstevel@tonic-gate (*busops_p->bus_remove_eventcall)(0, 0);
1200Sstevel@tonic-gate (*busops_p->bus_post_event)(0, 0, 0, 0);
1210Sstevel@tonic-gate (*busops_p->bus_intr_ctl)(0, 0, 0, 0, 0);
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate (*busops_p->bus_config)(0, 0, 0, 0, 0);
1240Sstevel@tonic-gate (*busops_p->bus_unconfig)(0, 0, 0, 0);
1250Sstevel@tonic-gate
1263138Sfrits #ifndef __lock_lint
1273138Sfrits /* this causes warnings and it is unclear how to handle this */
1283138Sfrits (*busops_p->bus_fm_init)(0, 0, 0, 0);
1293138Sfrits (*busops_p->bus_fm_fini)(0, 0);
1303138Sfrits (*busops_p->bus_fm_access_enter)(0, 0);
1313138Sfrits (*busops_p->bus_fm_access_exit)(0, 0);
1323138Sfrits (*busops_p->bus_power)(0, 0, 0, 0, 0);
1333138Sfrits (*busops_p->bus_intr_op)(0, 0, 0, 0, 0);
1343138Sfrits #endif
1353138Sfrits
1360Sstevel@tonic-gate ndi_devi_offline(0, 0);
1370Sstevel@tonic-gate _NOTE(NO_COMPETING_THREADS_NOW)
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /* Power managment framework calls */
1410Sstevel@tonic-gate int
pm_set_power(dev_info_t * dip,int comp,int level,int direction,pm_canblock_t canblock,int scan,int * retp)1420Sstevel@tonic-gate pm_set_power(dev_info_t *dip, int comp, int level, int direction,
1430Sstevel@tonic-gate pm_canblock_t canblock, int scan, int *retp)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate (*devops_p->devo_power)(0, 0, 0);
1460Sstevel@tonic-gate }
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate int
pm_raise_power(dev_info_t * dip,int comp,int level)1490Sstevel@tonic-gate pm_raise_power(dev_info_t *dip, int comp, int level) {
1500Sstevel@tonic-gate (*devops_p->devo_power)(0, 0, 0);
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate int
pm_lower_power(dev_info_t * dip,int comp,int level)1540Sstevel@tonic-gate pm_lower_power(dev_info_t *dip, int comp, int level) {
1550Sstevel@tonic-gate (*devops_p->devo_power)(0, 0, 0);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate static kmutex_t mutex;
1590Sstevel@tonic-gate static kcondvar_t cv;
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate void
delay(clock_t ticks)1620Sstevel@tonic-gate delay(clock_t ticks)
1630Sstevel@tonic-gate {
1640Sstevel@tonic-gate mutex_enter(&mutex);
1650Sstevel@tonic-gate cv_wait(&cv, &mutex);
1660Sstevel@tonic-gate mutex_exit(&mutex);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate void
putnext(queue_t * q,mblk_t * mp)1700Sstevel@tonic-gate putnext(queue_t *q, mblk_t *mp)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate mutex_enter(&mutex);
1730Sstevel@tonic-gate cv_wait(&cv, &mutex);
1740Sstevel@tonic-gate mutex_exit(&mutex);
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate int
ndi_devi_offline(dev_info_t * dip,uint_t flags)1780Sstevel@tonic-gate ndi_devi_offline(dev_info_t *dip, uint_t flags) {
1790Sstevel@tonic-gate (*busops_p->bus_dma_ctl)(0, 0, 0, 0, 0, 0, 0, 0);
1800Sstevel@tonic-gate (*busops_p->bus_ctl)(0, 0, 0, 0, 0);
1810Sstevel@tonic-gate (*busops_p->bus_get_eventcookie)(0, 0, 0, 0);
1820Sstevel@tonic-gate (*busops_p->bus_add_eventcall)(0, 0, 0, 0, 0, 0);
1830Sstevel@tonic-gate (*busops_p->bus_remove_eventcall)(0, 0);
1840Sstevel@tonic-gate (*busops_p->bus_post_event)(0, 0, 0, 0);
1850Sstevel@tonic-gate (*busops_p->bus_unconfig)(0, 0, 0, 0);
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate int
ndi_devi_online(dev_info_t * dip,uint_t flags)1890Sstevel@tonic-gate ndi_devi_online(dev_info_t *dip, uint_t flags) {
1900Sstevel@tonic-gate (*busops_p->bus_config)(0, 0, 0, 0, 0);
1910Sstevel@tonic-gate }
192