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