Annotation of XNU/pexpert/ppc/pe_init.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*
                     23:  * file: pe_init.c
                     24:  *    PPC platform expert initialization.
                     25:  */
                     26: #include <mach/boot_info.h>
                     27: #include <mach/time_value.h>
                     28: #include <pexpert/protos.h>
                     29: #include <pexpert/pexpert.h>
                     30: #include <pexpert/ppc/powermac.h>
                     31: #include <pexpert/ppc/interrupts.h>
                     32: #include <pexpert/device_tree.h>
                     33: #include <kern/debug.h>
                     34: #include "pe_images.h"
                     35: 
                     36: /* extern references */
                     37: void pe_identify_machine(void);
                     38: 
                     39: /* private globals */
                     40: PE_state_t PE_state;
                     41: /* powermac specific info */
                     42: powermac_info_t                powermac_info;
                     43: 
                     44: static int DEBUGFlag;
                     45: 
                     46: static int PE_stub_read_write_time_of_day(unsigned int options, long * secs)
                     47: {
                     48:     // believe it or, BSD crashes if invalid time returned. FIXME.
                     49:     if( options == kPEReadTOD)
                     50:         *secs = 0xb2383c72;
                     51: 
                     52:     return 0;
                     53: }
                     54: 
                     55: static int PE_stub_poll_input(unsigned int options, char * c)
                     56: {
                     57:     *c = 0xff;
                     58: 
                     59:     return 1;
                     60: }
                     61: 
                     62: static int PE_stub_write_IIC(unsigned char addr, unsigned char reg,
                     63:                                unsigned char data)
                     64: {
                     65:     return 1;
                     66: }
                     67: 
                     68: int (*PE_read_write_time_of_day)(unsigned int options, long * secs)
                     69:        = PE_stub_read_write_time_of_day;
                     70: int (*PE_poll_input)(unsigned int options, char * c)
                     71:        = PE_stub_poll_input;
                     72: 
                     73: int (*PE_write_IIC)(unsigned char addr, unsigned char reg,
                     74:                                unsigned char data)
                     75:        = PE_stub_write_IIC;
                     76: 
                     77: 
                     78: int PE_initialize_console( PE_Video * info, int op )
                     79: {
                     80:     static int         last_console = -1;
                     81:     Boot_Video         bootInfo;
                     82:     Boot_Video *       bInfo;
                     83: 
                     84:     if( info) {
                     85:         bootInfo.v_baseAddr            = info->v_baseAddr;
                     86:         bootInfo.v_rowBytes            = info->v_rowBytes;
                     87:         bootInfo.v_width               = info->v_width;
                     88:         bootInfo.v_height              = info->v_height;
                     89:         bootInfo.v_depth               = info->v_depth;
                     90:         bootInfo.v_display             = 0;
                     91:        bInfo = &bootInfo;
                     92:     } else
                     93:        bInfo = 0;
                     94: 
                     95:     switch( op ) {
                     96: 
                     97:        case kPEDisableScreen:
                     98:             initialize_screen((void *) bInfo, op);
                     99:             last_console = switch_to_serial_console();
                    100:            break;
                    101: 
                    102:        case kPEEnableScreen:
                    103:             initialize_screen((void *) bInfo, op);
                    104:             if( last_console != -1)
                    105:                 switch_to_old_console( last_console);
                    106:            break;
                    107:        
                    108:        default:
                    109:             initialize_screen((void *) bInfo, op);
                    110:            break;
                    111:     }
                    112: 
                    113:     return 0;
                    114: }
                    115: 
                    116: static boolean_t find_image( const char * name,
                    117:                                void ** desc,
                    118:                                unsigned char ** data,
                    119:                                unsigned char ** clut )
                    120: {
                    121:     boolean_t  ok;
                    122:     DTEntry    entry;
                    123:     int                size;
                    124: 
                    125: #if 0
                    126:     // This is a little flawed now the device tree data
                    127:     // is freed.
                    128:     if( (kSuccess == DTLookupEntry(0, "/AAPL,images", &entry))
                    129:      && (kSuccess == DTLookupEntry(entry, name, &entry)) ) {
                    130: 
                    131:        ok = ( (kSuccess == DTGetProperty(entry, "desc",
                    132:                                desc, &size))
                    133:             && (kSuccess == DTGetProperty(entry, "data",
                    134:                                (void **)data, &size)));
                    135: 
                    136:         if( clut && (kSuccess != DTGetProperty(entry, "clut",
                    137:                                (void **)clut, &size)))
                    138:            *clut = appleClut8;
                    139:     } else
                    140: #endif
                    141:        ok = FALSE;
                    142: 
                    143:     return( ok );
                    144: }
                    145: 
                    146: void PE_init_iokit(void)
                    147: {
                    148:     kern_return_t      ret;
                    149:     void *             desc;
                    150:     unsigned char *    data;
                    151:     unsigned char *    clut;
                    152: 
                    153:     PE_init_kprintf(TRUE);
                    154:     PE_init_printf(TRUE);
                    155: 
                    156:     // init this now to get mace debugger for iokit startup
                    157:     PE_init_ethernet_debugger();
                    158: 
                    159:     if( !find_image( "progress", &desc, &data, &clut)) {
                    160:         clut = appleClut8;
                    161:         desc = &default_progress;
                    162:         data = default_progress_data;
                    163:     }
                    164:     vc_progress_initialize( desc, data, clut );
                    165: 
                    166:     PE_initialize_console( (PE_Video *) 0, kPEAcquireScreen );
                    167: 
                    168:     ret = StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs,
                    169:                        (void *)0, (void *)0);
                    170: }
                    171: 
                    172: void PE_init_platform(boolean_t vm_initialized, void *_args)
                    173: {
                    174:         boot_args *args = (boot_args *)_args;
                    175: 
                    176:        if (PE_state.initialized == FALSE)
                    177:        {
                    178:          PE_state.initialized          = TRUE;
                    179:          PE_state.bootArgs             = _args;
                    180:          PE_state.deviceTreeHead       = args->deviceTreeP;
                    181:          PE_state.video.v_baseAddr     = args->Video.v_baseAddr;
                    182:          PE_state.video.v_rowBytes     = args->Video.v_rowBytes;
                    183:          PE_state.video.v_width        = args->Video.v_width;
                    184:          PE_state.video.v_height       = args->Video.v_height;
                    185:          PE_state.video.v_depth        = args->Video.v_depth;
                    186:          PE_state.video.v_display      = args->Video.v_display;
                    187:          strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP");
                    188:        }
                    189: 
                    190:        if (!vm_initialized)
                    191:        {
                    192:             /*
                    193:              * Setup the OpenFirmware Device Tree routines
                    194:              * so the console can be found and the right I/O space
                    195:              * can be used..
                    196:              */
                    197:             DTInit(PE_state.deviceTreeHead);
                    198:        
                    199:             /* Setup powermac_info and structures */
                    200:             pe_identify_machine();
                    201:        }
                    202:        else
                    203:        {
                    204:            pe_init_debug();
                    205:        }
                    206: }
                    207: 
                    208: void PE_create_console( void )
                    209: {
                    210:   if (PE_state.video.v_display)
                    211:     PE_initialize_console( &PE_state.video, kPEGraphicsMode );
                    212:   else
                    213:     PE_initialize_console( &PE_state.video, kPETextMode );
                    214: }
                    215: 
                    216: int PE_current_console( PE_Video * info )
                    217: {
                    218:     *info = PE_state.video;
                    219:     return( 0);
                    220: }
                    221: 
                    222: void PE_display_icon(  unsigned int flags,
                    223:                        const char * name )
                    224: {
                    225:     void *             desc;
                    226:     unsigned char *    data;
                    227: 
                    228:     if( !find_image( name, &desc, &data, 0)) {
                    229:         desc = &default_roroot;
                    230:         data = default_noroot_data;
                    231:     }
                    232:     vc_display_icon( desc, data );
                    233: }
                    234: 
                    235: extern boolean_t PE_get_hotkey(
                    236:        unsigned char   key)
                    237: {
                    238:     unsigned char * adbKeymap;
                    239:     int                size;
                    240:     DTEntry    entry;
                    241: 
                    242:     if( (kSuccess != DTLookupEntry( 0, "/", &entry))
                    243:     ||  (kSuccess != DTGetProperty( entry, "AAPL,adb-keymap",
                    244:             (void **)&adbKeymap, &size))
                    245:     || (size != 16))
                    246: 
                    247:         return( FALSE);
                    248: 
                    249:     if( key > 127)
                    250:        return( FALSE);
                    251: 
                    252:     return( adbKeymap[ key / 8 ] & (0x80 >> (key & 7)));
                    253: }
                    254: 
                    255: void PE_pause(int seconds)
                    256: {
                    257:     int x, y, z;
                    258: 
                    259:     for (x = 0; x < (500000*seconds); x++)
                    260:         for (y = 0; y < 100; y++)
                    261:             z = x ^ y;
                    262: }
                    263: 
                    264: void NO_ENTRY() { }
                    265: 
                    266: void PE_register_timebase_callback(timebase_callback_func callback)
                    267: {
                    268:   powermac_info.timebase_callback = callback;
                    269:   
                    270:   PE_call_timebase_callback();
                    271: }
                    272: 
                    273: void PE_call_timebase_callback(void)
                    274: {
                    275:   struct timebase_freq_t timebase_freq;
                    276:   unsigned long          num, den, cnt;
                    277:   
                    278:   num = powermac_info.bus_clock_rate_num * powermac_info.bus_to_dec_rate_num;
                    279:   den = powermac_info.bus_clock_rate_den * powermac_info.bus_to_dec_rate_den;
                    280:   
                    281:   cnt = 2;
                    282:   while (cnt <= den) {
                    283:     if ((num % cnt) || (den % cnt)) {
                    284:       cnt++;
                    285:       continue;
                    286:     }
                    287:     
                    288:     num /= cnt;
                    289:     den /= cnt;
                    290:   }
                    291:   
                    292:   timebase_freq.timebase_num = num;
                    293:   timebase_freq.timebase_den = den;
                    294:   
                    295:   if (powermac_info.timebase_callback)
                    296:     powermac_info.timebase_callback(&timebase_freq);
                    297: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.