openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

smp.h (6585B)


      1 /* Copyright 1998-1999, Brian J. Swetland. All rights reserved.
      2 ** Distributed under the terms of the OpenBLT License
      3 */
      4 
      5 #ifndef _SMP_H_
      6 #define _SMP_H_
      7 
      8 #include <blt/os.h>
      9 
     10 #ifndef __SMP__
     11 #  ifndef __SMP_ONLY__
     12 #    define UP_OR_SMP(u,s)     { u; }
     13 #  else
     14 #    error defined __SMP_ONLY__ without __SMP__
     15 #  endif
     16 #else
     17 #  if !defined (__SMP_ONLY__)
     18 #    define UP_OR_SMP(u,s)     if (!smp_configured) { u; } else { s; }
     19 #  else
     20 #    define UP_OR_SMP(u,s)     { s; }
     21 #  endif
     22 #endif
     23 
     24 #define CPUID_GEN_EBX      0x756e6547 /* Genu */
     25 #define CPUID_GEN_ECX      0x49656369 /* ineI */
     26 #define CPUID_GEN_EDX      0x6c65746e /* ntel */
     27 
     28 #define MP_FLT_SIGNATURE   (('_' << 24) | ('P' << 16) | ('M' << 8) | ('_'))
     29 #define MP_CTH_SIGNATURE   (('P' << 24) | ('C' << 16) | ('M' << 8) | ('P'))
     30 
     31 #define MP_DEF_LOCAL_APIC  0xfee00000 /* default local apic address */
     32 #define MP_DEF_IO_APIC     0xfec00000 /* default i/o apic address */
     33 
     34 #define APIC_DM_INIT       (5 << 8)
     35 #define APIC_DM_STARTUP    (6 << 8)
     36 #define APIC_LEVEL_TRIG    (1 << 14)
     37 #define APIC_ASSERT        (1 << 13)
     38 
     39 #define APIC_ENABLE        0x100
     40 #define APIC_FOCUS         (~(1 << 9))
     41 #define APIC_SIV           (0xff)
     42 
     43 #define MP_EXT_PE          0
     44 #define MP_EXT_BUS         1
     45 #define MP_EXT_IO_APIC     2
     46 #define MP_EXT_IO_INT      3
     47 #define MP_EXT_LOCAL_INT   4
     48 
     49 #define MP_EXT_PE_LEN          20
     50 #define MP_EXT_BUS_LEN         8
     51 #define MP_EXT_IO_APIC_LEN     8
     52 #define MP_EXT_IO_INT_LEN      8
     53 #define MP_EXT_LOCAL_INT_LEN   8
     54 
     55 #define SET_APIC_DEST(x)       (x << 24)
     56 
     57 #ifndef __ASM__
     58 
     59 #include "kernel.h"
     60 
     61 extern unsigned int *apic, *apic_virt;
     62 
     63 #define SMP_ERROR(x)       { kprintf (x); return; }
     64 
     65 #define APIC_ID            ((unsigned int *) ((unsigned int) apic_virt + 0x020))
     66 #define APIC_VERSION       ((unsigned int *) ((unsigned int) apic_virt + 0x030))
     67 #define APIC_TPRI          ((unsigned int *) ((unsigned int) apic_virt + 0x080))
     68 #define APIC_EOI           ((unsigned int *) ((unsigned int) apic_virt + 0x0b0))
     69 #define APIC_SIVR          ((unsigned int *) ((unsigned int) apic_virt + 0x0f0))
     70 #define APIC_ESR           ((unsigned int *) ((unsigned int) apic_virt + 0x280))
     71 #define APIC_ICR1          ((unsigned int *) ((unsigned int) apic_virt + 0x300))
     72 #define APIC_ICR2          ((unsigned int *) ((unsigned int) apic_virt + 0x310))
     73 #define APIC_LVTT          ((unsigned int *) ((unsigned int) apic_virt + 0x320))
     74 #define APIC_LINT0         ((unsigned int *) ((unsigned int) apic_virt + 0x350))
     75 #define APIC_LVT3          ((unsigned int *) ((unsigned int) apic_virt + 0x370))
     76 #define APIC_ICRT          ((unsigned int *) ((unsigned int) apic_virt + 0x380))
     77 #define APIC_CCRT          ((unsigned int *) ((unsigned int) apic_virt + 0x390))
     78 #define APIC_TDCR          ((unsigned int *) ((unsigned int) apic_virt + 0x3e0))
     79 
     80 #define APIC_TDCR_2        0x00
     81 #define APIC_TDCR_4        0x01
     82 #define APIC_TDCR_8        0x02
     83 #define APIC_TDCR_16       0x03
     84 #define APIC_TDCR_32       0x08
     85 #define APIC_TDCR_64       0x09
     86 #define APIC_TDCR_128      0x0a
     87 #define APIC_TDCR_1        0x0b
     88 
     89 #define APIC_LVTT_VECTOR   0x000000ff
     90 #define APIC_LVTT_DS       0x00001000
     91 #define APIC_LVTT_M        0x00010000
     92 #define APIC_LVTT_TM       0x00020000
     93 
     94 #define APIC_LVT_DM        0x00000700
     95 #define APIC_LVT_IIPP      0x00002000
     96 #define APIC_LVT_TM        0x00008000
     97 #define APIC_LVT_M         0x00010000
     98 #define APIC_LVT_OS        0x00020000
     99 
    100 #define APIC_TPR_PRIO      0x000000ff
    101 #define APIC_TPR_INT       0x000000f0
    102 #define APIC_TPR_SUB       0x0000000f
    103 
    104 #define APIC_SVR_SWEN      0x00000100
    105 #define APIC_SVR_FOCUS     0x00000200
    106 
    107 #define APIC_DEST_STARTUP  0x00600
    108 
    109 #define LOPRIO_LEVEL       0x00000010
    110 
    111 #define APIC_DEST_FIELD          (0)
    112 #define APIC_DEST_SELF           (1 << 18)
    113 #define APIC_DEST_ALL            (2 << 18)
    114 #define APIC_DEST_ALL_BUT_SELF   (3 << 18)
    115 
    116 #define IOAPIC_ID          0x0
    117 #define IOAPIC_VERSION     0x1
    118 #define IOAPIC_ARB         0x2
    119 #define IOAPIC_REDIR_TABLE 0x10
    120 
    121 #define IPI_CACHE_FLUSH    0x40
    122 #define IPI_INV_TLB        0x41
    123 #define IPI_INV_PTE        0x42
    124 #define IPI_INV_RESCHED    0x43
    125 #define IPI_STOP           0x44
    126 
    127 typedef struct
    128 {
    129 	unsigned int signature;       /* "PCMP" */
    130 	unsigned short table_len;     /* length of this structure */
    131 	unsigned char mp_rev;         /* spec supported, 1 for 1.1 or 4 for 1.4 */
    132 	unsigned char checksum;       /* checksum, all bytes add up to zero */
    133 	char oem[8];                  /* oem identification, not null-terminated */
    134 	char product[12];             /* product name, not null-terminated */
    135 	void *oem_table_ptr;          /* addr of oem-defined table, zero if none */
    136 	unsigned short oem_len;       /* length of oem table */
    137 	unsigned short num_entries;   /* number of entries in base table */
    138 	unsigned int apic;            /* address of apic */
    139 	unsigned short ext_len;       /* length of extended section */
    140 	unsigned char ext_checksum;   /* checksum of extended table entries */
    141 } mp_config_table;
    142 
    143 typedef struct
    144 {
    145 	unsigned int signature;       /* "_MP_" */
    146 	mp_config_table *mpc;         /* address of mp configuration table */
    147 	unsigned char mpc_len;        /* length of this structure in 16-byte units */
    148 	unsigned char mp_rev;         /* spec supported, 1 for 1.1 or 4 for 1.4 */
    149 	unsigned char checksum;       /* checksum, all bytes add up to zero */
    150 	unsigned char mp_feature_1;   /* mp system configuration type if no mpc */
    151 	unsigned char mp_feature_2;   /* imcrp */
    152 	unsigned char mp_feature_3, mp_feature_4, mp_feature_5; /* reserved */
    153 } mp_flt_ptr;
    154 
    155 typedef struct
    156 {
    157 	unsigned char type;
    158 	unsigned char apic_id;
    159 	unsigned char apic_version;
    160 	unsigned char cpu_flags;
    161 	unsigned int signature;       /* stepping, model, family, each four bits */
    162 	unsigned int feature_flags;
    163 	unsigned int res1, res2;
    164 } mp_ext_pe;
    165 
    166 typedef struct
    167 {
    168 	unsigned char type;
    169 	unsigned char ioapic_id;
    170 	unsigned char ioapic_version;
    171 	unsigned char ioapic_flags;
    172 	unsigned int *addr;
    173 } mp_ext_ioapic;
    174 
    175 extern char smp_num_cpus, *trampoline, *trampoline_end;
    176 extern volatile char smp_configured, smp_begun;
    177 
    178 int smp_check_cpu (void);
    179 void smp_init (void);
    180 void smp_cpu_setup (void);
    181 void smp_cpu_ready (void);
    182 void smp_begin (void);
    183 void ioapic_init (void);
    184 
    185 /* these are more interesting functions for use by the rest of the kernel */
    186 
    187 int smp_my_cpu (void);
    188 
    189 void ipi_dest (int num, int pe);
    190 void ipi_self (int num);
    191 void ipi_all (int num);
    192 void ipi_all_but_self (int num);
    193 
    194 volatile unsigned int ioapic_read (unsigned int offset);
    195 void ioapic_write (unsigned int offset, unsigned int data);
    196 
    197 #endif /* __ASM__ */
    198 
    199 #endif /* __SMP__ */
    200