1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/systm.h> 31*0Sstevel@tonic-gate #include <sys/bootconf.h> 32*0Sstevel@tonic-gate #include <sys/thread.h> 33*0Sstevel@tonic-gate #include <sys/ddi.h> 34*0Sstevel@tonic-gate #include <sys/sunddi.h> 35*0Sstevel@tonic-gate #include <vm/seg_kmem.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #define VIDEOMEM 0xa0000 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate extern void outb(int, uchar_t); 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate static int graphics_mode; 42*0Sstevel@tonic-gate static int cursor_y = 400; 43*0Sstevel@tonic-gate static int cursor_x = 210; 44*0Sstevel@tonic-gate static uchar_t bar[4][32]; 45*0Sstevel@tonic-gate static kthread_t *progressbar_tid; 46*0Sstevel@tonic-gate static kmutex_t pbar_lock; 47*0Sstevel@tonic-gate static kcondvar_t pbar_cv; 48*0Sstevel@tonic-gate static char *videomem = (caddr_t)VIDEOMEM; 49*0Sstevel@tonic-gate static int videomem_size; 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate static void 52*0Sstevel@tonic-gate mapmask(int value) 53*0Sstevel@tonic-gate { 54*0Sstevel@tonic-gate outb(0x3c4, 2); 55*0Sstevel@tonic-gate outb(0x3c5, value); 56*0Sstevel@tonic-gate } 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate static void 59*0Sstevel@tonic-gate bitmask(int value) 60*0Sstevel@tonic-gate { 61*0Sstevel@tonic-gate outb(0x3ce, 8); 62*0Sstevel@tonic-gate outb(0x3cf, value); 63*0Sstevel@tonic-gate } 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate static void 66*0Sstevel@tonic-gate progressbar_show(void) 67*0Sstevel@tonic-gate { 68*0Sstevel@tonic-gate int i, j, k, offset; 69*0Sstevel@tonic-gate uchar_t *mem, *ptr; 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate offset = cursor_y * 80 + cursor_x / 8; 72*0Sstevel@tonic-gate mem = (uchar_t *)videomem + offset; 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate for (i = 0; i < 4; i++) { 75*0Sstevel@tonic-gate mapmask(1 << i); 76*0Sstevel@tonic-gate for (j = 0; j < 16; j++) { /* bar height 16 pixel */ 77*0Sstevel@tonic-gate ptr = mem + j * 80; 78*0Sstevel@tonic-gate for (k = 0; k < 32; k++, ptr++) 79*0Sstevel@tonic-gate *ptr = bar[i][k]; 80*0Sstevel@tonic-gate } 81*0Sstevel@tonic-gate } 82*0Sstevel@tonic-gate mapmask(15); 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate /* 86*0Sstevel@tonic-gate * Initialize a rectangle area for progress bar 87*0Sstevel@tonic-gate * 88*0Sstevel@tonic-gate * Multiboot has initialized graphics mode to 640x480 89*0Sstevel@tonic-gate * with 16 colors. 90*0Sstevel@tonic-gate */ 91*0Sstevel@tonic-gate void 92*0Sstevel@tonic-gate progressbar_init() 93*0Sstevel@tonic-gate { 94*0Sstevel@tonic-gate int i; 95*0Sstevel@tonic-gate char cons[10]; 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate /* see if we are in graphics mode */ 98*0Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "console") != sizeof ("graphics")) 99*0Sstevel@tonic-gate return; 100*0Sstevel@tonic-gate (void) BOP_GETPROP(bootops, "console", cons); 101*0Sstevel@tonic-gate if (strncmp(cons, "graphics", strlen("graphics")) != 0) 102*0Sstevel@tonic-gate return; 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate graphics_mode = 1; 105*0Sstevel@tonic-gate bitmask(0xff); 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate for (i = 0; i < 32; i++) { 108*0Sstevel@tonic-gate bar[0][i] = bar[1][i] = 0xf0; 109*0Sstevel@tonic-gate bar[2][i] = bar[3][i] = 0xf0; 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate progressbar_show(); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate static void 116*0Sstevel@tonic-gate progressbar_step() 117*0Sstevel@tonic-gate { 118*0Sstevel@tonic-gate static int limit = 0; 119*0Sstevel@tonic-gate int i; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate if (limit == 0) { /* reset */ 122*0Sstevel@tonic-gate for (i = 0; i < 32; i++) 123*0Sstevel@tonic-gate bar[3][i] = 0xf0; 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate bar[3][limit] = 0xff; 126*0Sstevel@tonic-gate limit++; 127*0Sstevel@tonic-gate if (limit == 32) 128*0Sstevel@tonic-gate limit = 0; 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate progressbar_show(); 131*0Sstevel@tonic-gate } 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate /*ARGSUSED*/ 134*0Sstevel@tonic-gate static void 135*0Sstevel@tonic-gate progressbar_thread(void *arg) 136*0Sstevel@tonic-gate { 137*0Sstevel@tonic-gate clock_t end; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate mutex_enter(&pbar_lock); 140*0Sstevel@tonic-gate while (graphics_mode) { 141*0Sstevel@tonic-gate progressbar_step(); 142*0Sstevel@tonic-gate end = ddi_get_lbolt() + drv_usectohz(200000); 143*0Sstevel@tonic-gate (void) cv_timedwait(&pbar_cv, &pbar_lock, end); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate mutex_exit(&pbar_lock); 146*0Sstevel@tonic-gate } 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate void 149*0Sstevel@tonic-gate progressbar_start(void) 150*0Sstevel@tonic-gate { 151*0Sstevel@tonic-gate extern pri_t minclsyspri; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate if (graphics_mode == 0) 154*0Sstevel@tonic-gate return; 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate /* map video memory to kernel heap */ 157*0Sstevel@tonic-gate videomem_size = ptob(btopr(38400)); /* 640 x 480 / 8 bytes */ 158*0Sstevel@tonic-gate videomem = vmem_alloc(heap_arena, videomem_size, VM_SLEEP); 159*0Sstevel@tonic-gate if (videomem == NULL) { 160*0Sstevel@tonic-gate cmn_err(CE_NOTE, "!failed to start progress bar"); 161*0Sstevel@tonic-gate graphics_mode = 0; 162*0Sstevel@tonic-gate return; 163*0Sstevel@tonic-gate } 164*0Sstevel@tonic-gate hat_devload(kas.a_hat, videomem, videomem_size, 165*0Sstevel@tonic-gate btop(VIDEOMEM), (PROT_READ | PROT_WRITE), 166*0Sstevel@tonic-gate HAT_LOAD_NOCONSIST | HAT_LOAD_LOCK); 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate progressbar_tid = thread_create(NULL, 0, progressbar_thread, 169*0Sstevel@tonic-gate NULL, 0, &p0, TS_RUN, minclsyspri); 170*0Sstevel@tonic-gate } 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate void 173*0Sstevel@tonic-gate progressbar_stop(void) 174*0Sstevel@tonic-gate { 175*0Sstevel@tonic-gate if (graphics_mode == 0) 176*0Sstevel@tonic-gate return; 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate graphics_mode = 0; 179*0Sstevel@tonic-gate mutex_enter(&pbar_lock); 180*0Sstevel@tonic-gate cv_signal(&pbar_cv); 181*0Sstevel@tonic-gate mutex_exit(&pbar_lock); 182*0Sstevel@tonic-gate if (progressbar_tid != NULL) 183*0Sstevel@tonic-gate thread_join(progressbar_tid->t_did); 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate /* unmap video memory */ 186*0Sstevel@tonic-gate hat_unload(kas.a_hat, videomem, videomem_size, HAT_UNLOAD_UNLOCK); 187*0Sstevel@tonic-gate vmem_free(heap_arena, videomem, videomem_size); 188*0Sstevel@tonic-gate } 189