Subversion Repositories HelenOS

Rev

Rev 129 | Rev 195 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 jermar 1
/*
2
 * Copyright (C) 2005 Jakub Jermar
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
34 jermar 29
#include <arch/types.h>
129 jermar 30
#include <typedefs.h>
33 jermar 31
#include <arch/acpi/acpi.h>
32
#include <arch/acpi/madt.h>
34 jermar 33
#include <arch/smp/apic.h>
129 jermar 34
#include <arch/smp/smp.h>
127 jermar 35
#include <panic.h>
129 jermar 36
#include <debug.h>
37
#include <config.h>
33 jermar 38
 
39
struct acpi_madt *acpi_madt = NULL;
34 jermar 40
 
41
#ifdef __SMP__
42
 
127 jermar 43
/*
44
 * NOTE: it is currently not completely clear to the authors of SPARTAN whether
45
 * MADT can exist in such a form that entries of the same type are not consecutive.
46
 * Because of this uncertainity, some entry types are explicitly checked for
47
 * being consecutive with other entries of the same kind.
48
 */
49
 
50
static void madt_l_apic_entry(struct madt_l_apic *la, __u8 prev_type);
51
static void madt_io_apic_entry(struct madt_io_apic *ioa, __u8 prev_type);
52
 
53
struct madt_l_apic *madt_l_apic_entries = NULL;
54
struct madt_io_apic *madt_io_apic_entries = NULL;
55
 
56
int madt_l_apic_entry_cnt = 0;
57
int madt_io_apic_entry_cnt = 0;
58
 
34 jermar 59
char *entry[] = {
60
    "L_APIC",
61
    "IO_APIC",
62
    "INTR_SRC_OVRD",
63
    "NMI_SRC",
64
    "L_APIC_NMI",
65
    "L_APIC_ADDR_OVRD",
66
    "IO_SAPIC",
67
    "L_SAPIC",
68
    "PLATFORM_INTR_SRC"
69
};
70
 
129 jermar 71
/*
72
 * ACPI MADT Implementation of SMP configuration interface.
73
 */
74
static count_t madt_cpu_count(void);
75
static bool madt_cpu_enabled(index_t i);
76
static bool madt_cpu_bootstrap(index_t i);
77
static __u8 madt_cpu_apic_id(index_t i);
78
 
79
struct smp_config_operations madt_config_operations = {
80
    .cpu_count = madt_cpu_count,
81
    .cpu_enabled = madt_cpu_enabled,
82
    .cpu_bootstrap = madt_cpu_bootstrap,
83
    .cpu_apic_id = madt_cpu_apic_id
84
};
85
 
86
static count_t madt_cpu_count(void)
87
{
88
    return madt_l_apic_entry_cnt;
89
}
90
 
91
static bool madt_cpu_enabled(index_t i)
92
{
93
    ASSERT(i < madt_l_apic_entry_cnt);
94
    return madt_l_apic_entries[i].flags & 0x1;
95
}
96
 
97
static bool madt_cpu_bootstrap(index_t i)
98
{
99
    ASSERT(i < madt_l_apic_entry_cnt);
100
    return madt_l_apic_entries[i].apic_id == l_apic_id();
101
}
102
 
103
static __u8 madt_cpu_apic_id(index_t i)
104
{
105
    ASSERT(i < madt_l_apic_entry_cnt);
106
    return madt_l_apic_entries[i].apic_id;
107
}
108
 
34 jermar 109
void acpi_madt_parse(void)
110
{
111
    struct madt_apic_header *end = (struct madt_apic_header *) (((__u8 *) acpi_madt) + acpi_madt->header.length);
112
    struct madt_apic_header *h = &acpi_madt->apic_header[0];
131 jermar 113
    __u8 prev_type = 0; /* used to detect inconsecutive entries */
34 jermar 114
 
127 jermar 115
 
34 jermar 116
    l_apic = (__u32 *) acpi_madt->l_apic_address;
117
 
118
    while (h < end) {
119
        switch (h->type) {
120
            case MADT_L_APIC:
127 jermar 121
                madt_l_apic_entry((struct madt_l_apic *) h, prev_type);
122
                break;
34 jermar 123
            case MADT_IO_APIC:
127 jermar 124
                madt_io_apic_entry((struct madt_io_apic *) h, prev_type);
125
                break;
34 jermar 126
            case MADT_INTR_SRC_OVRD:
127
            case MADT_NMI_SRC:
128
            case MADT_L_APIC_NMI:
129
            case MADT_L_APIC_ADDR_OVRD:
130
            case MADT_IO_SAPIC:
131
            case MADT_L_SAPIC:
132
            case MADT_PLATFORM_INTR_SRC:
133
                printf("MADT: skipping %s entry (type=%d)\n", entry[h->type], h->type);
134
                break;
135
 
136
            default:
137
                if (h->type >= MADT_RESERVED_SKIP_BEGIN && h->type <= MADT_RESERVED_SKIP_END) {
138
                    printf("MADT: skipping reserved entry (type=%d)\n", h->type);
139
                }
140
                if (h->type >= MADT_RESERVED_OEM_BEGIN) {
141
                    printf("MADT: skipping OEM entry (type=%d)\n", h->type);
142
                }
143
                break;
144
        }
127 jermar 145
        prev_type = h->type;
34 jermar 146
        h = (struct madt_apic_header *) (((__u8 *) h) + h->length);
147
    }
148
 
129 jermar 149
    if (madt_l_apic_entry_cnt)
150
        config.cpu_count = madt_l_apic_entry_cnt;
34 jermar 151
}
127 jermar 152
 
153
void madt_l_apic_entry(struct madt_l_apic *la, __u8 prev_type)
154
{
155
    /* check for consecutiveness */
156
    if (madt_l_apic_entry_cnt && prev_type != MADT_L_APIC)
157
    panic("%s entries are not consecuitve\n", entry[MADT_L_APIC]);
34 jermar 158
 
127 jermar 159
    if (!madt_l_apic_entry_cnt++)
160
        madt_l_apic_entries = la;
161
 
162
    if (!(la->flags & 0x1)) {
163
        /* Processor is unusable, skip it. */
164
        return;
165
    }
166
 
167
    apic_id_mask |= 1<<la->apic_id;
168
}
169
 
170
void madt_io_apic_entry(struct madt_io_apic *ioa, __u8 prev_type)
171
{
172
    /* check for consecutiveness */
173
    if (madt_io_apic_entry_cnt && prev_type != MADT_IO_APIC)
174
    panic("%s entries are not consecuitve\n", entry[MADT_IO_APIC]);
175
 
176
    if (!madt_io_apic_entry_cnt++) {
177
        madt_io_apic_entries = ioa;
178
        io_apic = (__u32 *) ioa->io_apic_address;
179
    }
180
    else {
181
        /* currently not supported */
182
        return;
183
    }
184
}
185
 
186
 
34 jermar 187
#endif /* __SMP__ */