darwin-xnu/osfmk/i386/cpu.c
<<
>>
Prefs
   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:   i386/cpu.c
  24 *
  25 *      cpu specific routines
  26 */
  27
  28#include <kern/kalloc.h>
  29#include <kern/misc_protos.h>
  30#include <kern/machine.h>
  31#include <mach/processor_info.h>
  32#include <i386/mp.h>
  33#include <i386/machine_cpu.h>
  34#include <i386/machine_routines.h>
  35#include <i386/pmap.h>
  36#include <i386/misc_protos.h>
  37#include <i386/cpu_threads.h>
  38#include <vm/vm_kern.h>
  39
  40
  41struct processor        processor_master;
  42
  43/*ARGSUSED*/
  44kern_return_t
  45cpu_control(
  46        int                     slot_num,
  47        processor_info_t        info,
  48        unsigned int            count)
  49{
  50        printf("cpu_control(%d,0x%x,%d) not implemented\n",
  51                slot_num, info, count);
  52        return (KERN_FAILURE);
  53}
  54
  55/*ARGSUSED*/
  56kern_return_t
  57cpu_info_count(
  58        __unused processor_flavor_t      flavor,
  59        unsigned int                    *count)
  60{
  61        *count = 0;
  62        return (KERN_FAILURE);
  63}
  64
  65/*ARGSUSED*/
  66kern_return_t
  67cpu_info(
  68        processor_flavor_t      flavor,
  69        int                     slot_num,
  70        processor_info_t        info,
  71        unsigned int            *count)
  72{
  73        printf("cpu_info(%d,%d,0x%x,0x%x) not implemented\n",
  74                flavor, slot_num, info, count);
  75        return (KERN_FAILURE);
  76}
  77
  78void
  79cpu_sleep(void)
  80{
  81        cpu_data_t      *proc_info = current_cpu_datap();
  82
  83        PE_cpu_machine_quiesce(proc_info->cpu_id);
  84
  85        cpu_thread_halt();
  86}
  87
  88void
  89cpu_init(void)
  90{
  91        cpu_data_t      *cdp = current_cpu_datap();
  92
  93#ifdef  MACH_BSD
  94        /* FIXME */
  95        cdp->cpu_type = CPU_TYPE_I386;
  96        cdp->cpu_subtype = CPU_SUBTYPE_PENTPRO;
  97#else
  98        cdp->cpu_type = cpuid_cputype(0);
  99        cdp->cpu_subtype = CPU_SUBTYPE_AT386;
 100#endif
 101        cdp->cpu_running = TRUE;
 102}
 103
 104kern_return_t
 105cpu_start(
 106        int cpu)
 107{
 108        kern_return_t           ret;
 109
 110        if (cpu == cpu_number()) {
 111                cpu_machine_init();
 112                return KERN_SUCCESS;
 113        } else {
 114                /*
 115                 * Should call out through PE.
 116                 * But take the shortcut here.
 117                 */
 118                ret = intel_startCPU(cpu);
 119                return(ret);
 120        }
 121}
 122
 123void
 124cpu_exit_wait(
 125        __unused int cpu)
 126{
 127}
 128
 129void
 130cpu_machine_init(
 131        void)
 132{
 133        int     cpu;
 134
 135        cpu = get_cpu_number();
 136        PE_cpu_machine_init(cpu_datap(cpu)->cpu_id, TRUE);
 137#if 0
 138        if (cpu_datap(cpu)->hibernate)
 139        {
 140            cpu_datap(cpu)->hibernate = 0;
 141            hibernate_machine_init();
 142        }
 143#endif
 144        ml_init_interrupt();
 145}
 146
 147processor_t
 148cpu_processor_alloc(boolean_t is_boot_cpu)
 149{
 150        int             ret;
 151        processor_t     proc;
 152
 153        if (is_boot_cpu)
 154                return &processor_master;
 155
 156        ret = kmem_alloc(kernel_map, (vm_offset_t *) &proc, sizeof(*proc));
 157        if (ret != KERN_SUCCESS)
 158                return NULL;
 159
 160        bzero((void *) proc, sizeof(*proc));
 161        return proc;
 162}
 163
 164void
 165cpu_processor_free(processor_t proc)
 166{
 167        if (proc != NULL && proc != &processor_master)
 168                kfree((void *) proc, sizeof(*proc));
 169}
 170
 171processor_t
 172current_processor(void)
 173{
 174        return current_cpu_datap()->cpu_processor;
 175}
 176
 177processor_t
 178cpu_to_processor(
 179        int                     cpu)
 180{
 181        return cpu_datap(cpu)->cpu_processor;
 182}
 183
 184ast_t *
 185ast_pending(void)
 186{
 187        return (&current_cpu_datap()->cpu_pending_ast);
 188}
 189
 190cpu_type_t
 191slot_type(
 192        int             slot_num)
 193{
 194        return (cpu_datap(slot_num)->cpu_type);
 195}
 196
 197cpu_subtype_t
 198slot_subtype(
 199        int             slot_num)
 200{
 201        return (cpu_datap(slot_num)->cpu_subtype);
 202}
 203
 204cpu_threadtype_t
 205slot_threadtype(
 206        int             slot_num)
 207{
 208        return (cpu_datap(slot_num)->cpu_threadtype);
 209}
 210
 211cpu_type_t
 212cpu_type(void)
 213{
 214        return (current_cpu_datap()->cpu_type);
 215}
 216
 217cpu_subtype_t
 218cpu_subtype(void)
 219{
 220        return (current_cpu_datap()->cpu_subtype);
 221}
 222
 223cpu_threadtype_t
 224cpu_threadtype(void)
 225{
 226        return (current_cpu_datap()->cpu_threadtype);
 227}
 228
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.