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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*1fac5a60Ssetje * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/systm.h> 317c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 327c478bd9Sstevel@tonic-gate #include <sys/thread.h> 337c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 347c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 357c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #define VIDEOMEM 0xa0000 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate extern void outb(int, uchar_t); 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate static int graphics_mode; 42*1fac5a60Ssetje static int cursor_y = 309; 43*1fac5a60Ssetje static int cursor_x = 136; 44*1fac5a60Ssetje 45*1fac5a60Ssetje #define BAR_STEPS 46 46*1fac5a60Ssetje 47*1fac5a60Ssetje static uchar_t bar[BAR_STEPS]; 487c478bd9Sstevel@tonic-gate static kthread_t *progressbar_tid; 497c478bd9Sstevel@tonic-gate static kmutex_t pbar_lock; 507c478bd9Sstevel@tonic-gate static kcondvar_t pbar_cv; 517c478bd9Sstevel@tonic-gate static char *videomem = (caddr_t)VIDEOMEM; 527c478bd9Sstevel@tonic-gate static int videomem_size; 537c478bd9Sstevel@tonic-gate 54*1fac5a60Ssetje /* select the plane(s) to draw to */ 557c478bd9Sstevel@tonic-gate static void 56*1fac5a60Ssetje mapmask(int plane) 577c478bd9Sstevel@tonic-gate { 587c478bd9Sstevel@tonic-gate outb(0x3c4, 2); 59*1fac5a60Ssetje outb(0x3c5, plane); 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate static void 637c478bd9Sstevel@tonic-gate bitmask(int value) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate outb(0x3ce, 8); 667c478bd9Sstevel@tonic-gate outb(0x3cf, value); 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate static void 707c478bd9Sstevel@tonic-gate progressbar_show(void) 717c478bd9Sstevel@tonic-gate { 72*1fac5a60Ssetje int j, k, offset; 737c478bd9Sstevel@tonic-gate uchar_t *mem, *ptr; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate offset = cursor_y * 80 + cursor_x / 8; 767c478bd9Sstevel@tonic-gate mem = (uchar_t *)videomem + offset; 777c478bd9Sstevel@tonic-gate 78*1fac5a60Ssetje bitmask(0xff); 79*1fac5a60Ssetje mapmask(0xff); /* write to all planes at once? */ 80*1fac5a60Ssetje for (j = 0; j < 4; j++) { /* bar height: 4 pixels */ 817c478bd9Sstevel@tonic-gate ptr = mem + j * 80; 82*1fac5a60Ssetje for (k = 0; k < BAR_STEPS; k++, ptr++) 83*1fac5a60Ssetje *ptr = bar[k]; 847c478bd9Sstevel@tonic-gate } 85*1fac5a60Ssetje bitmask(0x00); 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Initialize a rectangle area for progress bar 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * Multiboot has initialized graphics mode to 640x480 927c478bd9Sstevel@tonic-gate * with 16 colors. 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate void 957c478bd9Sstevel@tonic-gate progressbar_init() 967c478bd9Sstevel@tonic-gate { 977c478bd9Sstevel@tonic-gate int i; 987c478bd9Sstevel@tonic-gate char cons[10]; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* see if we are in graphics mode */ 1017c478bd9Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "console") != sizeof ("graphics")) 1027c478bd9Sstevel@tonic-gate return; 1037c478bd9Sstevel@tonic-gate (void) BOP_GETPROP(bootops, "console", cons); 1047c478bd9Sstevel@tonic-gate if (strncmp(cons, "graphics", strlen("graphics")) != 0) 1057c478bd9Sstevel@tonic-gate return; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate graphics_mode = 1; 1087c478bd9Sstevel@tonic-gate 109*1fac5a60Ssetje for (i = 0; i < BAR_STEPS; i++) { 110*1fac5a60Ssetje bar[i] = 0x00; 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate progressbar_show(); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate static void 1177c478bd9Sstevel@tonic-gate progressbar_step() 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate static int limit = 0; 1207c478bd9Sstevel@tonic-gate 121*1fac5a60Ssetje bar[limit] = 0xff; 122*1fac5a60Ssetje 123*1fac5a60Ssetje if (limit > 3) 124*1fac5a60Ssetje bar[limit - 4] = 0x00; 125*1fac5a60Ssetje else 126*1fac5a60Ssetje bar[limit + BAR_STEPS - 4] = 0x00; 127*1fac5a60Ssetje 1287c478bd9Sstevel@tonic-gate limit++; 129*1fac5a60Ssetje if (limit == BAR_STEPS) 1307c478bd9Sstevel@tonic-gate limit = 0; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate progressbar_show(); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1367c478bd9Sstevel@tonic-gate static void 1377c478bd9Sstevel@tonic-gate progressbar_thread(void *arg) 1387c478bd9Sstevel@tonic-gate { 1397c478bd9Sstevel@tonic-gate clock_t end; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate mutex_enter(&pbar_lock); 1427c478bd9Sstevel@tonic-gate while (graphics_mode) { 1437c478bd9Sstevel@tonic-gate progressbar_step(); 144*1fac5a60Ssetje end = ddi_get_lbolt() + drv_usectohz(150000); 1457c478bd9Sstevel@tonic-gate (void) cv_timedwait(&pbar_cv, &pbar_lock, end); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate mutex_exit(&pbar_lock); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate void 1517c478bd9Sstevel@tonic-gate progressbar_start(void) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate extern pri_t minclsyspri; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate if (graphics_mode == 0) 1567c478bd9Sstevel@tonic-gate return; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* map video memory to kernel heap */ 1597c478bd9Sstevel@tonic-gate videomem_size = ptob(btopr(38400)); /* 640 x 480 / 8 bytes */ 1607c478bd9Sstevel@tonic-gate videomem = vmem_alloc(heap_arena, videomem_size, VM_SLEEP); 1617c478bd9Sstevel@tonic-gate if (videomem == NULL) { 1627c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!failed to start progress bar"); 1637c478bd9Sstevel@tonic-gate graphics_mode = 0; 1647c478bd9Sstevel@tonic-gate return; 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate hat_devload(kas.a_hat, videomem, videomem_size, 1677c478bd9Sstevel@tonic-gate btop(VIDEOMEM), (PROT_READ | PROT_WRITE), 1687c478bd9Sstevel@tonic-gate HAT_LOAD_NOCONSIST | HAT_LOAD_LOCK); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate progressbar_tid = thread_create(NULL, 0, progressbar_thread, 1717c478bd9Sstevel@tonic-gate NULL, 0, &p0, TS_RUN, minclsyspri); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate void 1757c478bd9Sstevel@tonic-gate progressbar_stop(void) 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate if (graphics_mode == 0) 1787c478bd9Sstevel@tonic-gate return; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate graphics_mode = 0; 1817c478bd9Sstevel@tonic-gate mutex_enter(&pbar_lock); 1827c478bd9Sstevel@tonic-gate cv_signal(&pbar_cv); 1837c478bd9Sstevel@tonic-gate mutex_exit(&pbar_lock); 1847c478bd9Sstevel@tonic-gate if (progressbar_tid != NULL) 1857c478bd9Sstevel@tonic-gate thread_join(progressbar_tid->t_did); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* unmap video memory */ 1887c478bd9Sstevel@tonic-gate hat_unload(kas.a_hat, videomem, videomem_size, HAT_UNLOAD_UNLOCK); 1897c478bd9Sstevel@tonic-gate vmem_free(heap_arena, videomem, videomem_size); 1907c478bd9Sstevel@tonic-gate } 191