Subversion Repositories HelenOS

Rev

Rev 3672 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3672 Rev 4490
1
/*
1
/*
2
 * Copyright (c) 2006 Jakub Jermar
2
 * Copyright (c) 2006 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup sparc64
29
/** @addtogroup sparc64
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <smp/smp.h>
35
#include <smp/smp.h>
36
#include <genarch/ofw/ofw_tree.h>
36
#include <genarch/ofw/ofw_tree.h>
37
#include <cpu.h>
37
#include <cpu.h>
38
#include <arch/cpu_family.h>
38
#include <arch/cpu_family.h>
39
#include <arch/cpu.h>
39
#include <arch/cpu.h>
40
#include <arch.h>
40
#include <arch.h>
41
#include <config.h>
41
#include <config.h>
42
#include <macros.h>
42
#include <macros.h>
43
#include <arch/types.h>
43
#include <arch/types.h>
44
#include <synch/synch.h>
44
#include <synch/synch.h>
45
#include <synch/waitq.h>
45
#include <synch/waitq.h>
46
#include <print.h>
46
#include <print.h>
47
#include <arch/cpu_node.h>
47
#include <arch/cpu_node.h>
48
 
48
 
49
/**
49
/**
50
 * This global variable is used to pick-up application processors
50
 * This global variable is used to pick-up application processors
51
 * from their active loop in start.S. When a processor looping in
51
 * from their active loop in start.S. When a processor looping in
52
 * start.S sees that this variable contains its MID, it can
52
 * start.S sees that this variable contains its MID, it can
53
 * proceed with its initialization.
53
 * proceed with its initialization.
54
 *
54
 *
55
 * This variable is modified only by the bootstrap processor.
55
 * This variable is modified only by the bootstrap processor.
56
 * Other processors access it read-only.
56
 * Other processors access it read-only.
57
 */
57
 */
58
volatile uint64_t waking_up_mid = (uint64_t) -1;
58
volatile uint64_t waking_up_mid = (uint64_t) -1;
59
 
59
 
60
/** Determine number of processors. */
60
/** Determine number of processors. */
61
void smp_init(void)
61
void smp_init(void)
62
{
62
{
63
    ofw_tree_node_t *node;
63
    ofw_tree_node_t *node;
64
    count_t cnt = 0;
64
    size_t cnt = 0;
65
   
65
   
66
    if (is_us() || is_us_iii()) {
66
    if (is_us() || is_us_iii()) {
67
        node = ofw_tree_find_child_by_device_type(cpus_parent(), "cpu");
67
        node = ofw_tree_find_child_by_device_type(cpus_parent(), "cpu");
68
        while (node) {
68
        while (node) {
69
            cnt++;
69
            cnt++;
70
            node = ofw_tree_find_peer_by_device_type(node, "cpu");
70
            node = ofw_tree_find_peer_by_device_type(node, "cpu");
71
        }
71
        }
72
    } else if (is_us_iv()) {
72
    } else if (is_us_iv()) {
73
        node = ofw_tree_find_child(cpus_parent(), "cmp");
73
        node = ofw_tree_find_child(cpus_parent(), "cmp");
74
        while (node) {
74
        while (node) {
75
            cnt += 2;
75
            cnt += 2;
76
            node = ofw_tree_find_peer_by_name(node, "cmp");
76
            node = ofw_tree_find_peer_by_name(node, "cmp");
77
        }
77
        }
78
    }
78
    }
79
   
79
   
80
    config.cpu_count = max(1, cnt);
80
    config.cpu_count = max(1, cnt);
81
}
81
}
82
 
82
 
83
/**
83
/**
84
 * Wakes up the CPU which is represented by the "node" OFW tree node.
84
 * Wakes up the CPU which is represented by the "node" OFW tree node.
85
 * If "node" represents the current CPU, calling the function has
85
 * If "node" represents the current CPU, calling the function has
86
 * no effect.
86
 * no effect.
87
 */
87
 */
88
static void wakeup_cpu(ofw_tree_node_t *node)
88
static void wakeup_cpu(ofw_tree_node_t *node)
89
{
89
{
90
    uint32_t mid;
90
    uint32_t mid;
91
    ofw_tree_property_t *prop;
91
    ofw_tree_property_t *prop;
92
       
92
       
93
    /* 'upa-portid' for US, 'portid' for US-III, 'cpuid' for US-IV */
93
    /* 'upa-portid' for US, 'portid' for US-III, 'cpuid' for US-IV */
94
    prop = ofw_tree_getprop(node, "upa-portid");
94
    prop = ofw_tree_getprop(node, "upa-portid");
95
    if ((!prop) || (!prop->value))
95
    if ((!prop) || (!prop->value))
96
        prop = ofw_tree_getprop(node, "portid");
96
        prop = ofw_tree_getprop(node, "portid");
97
    if ((!prop) || (!prop->value))
97
    if ((!prop) || (!prop->value))
98
        prop = ofw_tree_getprop(node, "cpuid");
98
        prop = ofw_tree_getprop(node, "cpuid");
99
       
99
       
100
    if (!prop || prop->value == NULL)
100
    if (!prop || prop->value == NULL)
101
        return;
101
        return;
102
       
102
       
103
    mid = *((uint32_t *) prop->value);
103
    mid = *((uint32_t *) prop->value);
104
    if (CPU->arch.mid == mid)
104
    if (CPU->arch.mid == mid)
105
        return;
105
        return;
106
 
106
 
107
    waking_up_mid = mid;
107
    waking_up_mid = mid;
108
       
108
       
109
    if (waitq_sleep_timeout(&ap_completion_wq, 1000000, SYNCH_FLAGS_NONE) ==
109
    if (waitq_sleep_timeout(&ap_completion_wq, 1000000, SYNCH_FLAGS_NONE) ==
110
        ESYNCH_TIMEOUT)
110
        ESYNCH_TIMEOUT)
111
        printf("%s: waiting for processor (mid = %" PRIu32
111
        printf("%s: waiting for processor (mid = %" PRIu32
112
            ") timed out\n", __func__, mid);
112
            ") timed out\n", __func__, mid);
113
}
113
}
114
 
114
 
115
/** Wake application processors up. */
115
/** Wake application processors up. */
116
void kmp(void *arg)
116
void kmp(void *arg)
117
{
117
{
118
    ofw_tree_node_t *node;
118
    ofw_tree_node_t *node;
119
    int i;
119
    int i;
120
   
120
   
121
    if (is_us() || is_us_iii()) {
121
    if (is_us() || is_us_iii()) {
122
        node = ofw_tree_find_child_by_device_type(cpus_parent(), "cpu");
122
        node = ofw_tree_find_child_by_device_type(cpus_parent(), "cpu");
123
        for (i = 0; node;
123
        for (i = 0; node;
124
                     node = ofw_tree_find_peer_by_device_type(node, "cpu"), i++)
124
                     node = ofw_tree_find_peer_by_device_type(node, "cpu"), i++)
125
            wakeup_cpu(node);
125
            wakeup_cpu(node);
126
    } else if (is_us_iv()) {
126
    } else if (is_us_iv()) {
127
        node = ofw_tree_find_child(cpus_parent(), "cmp");
127
        node = ofw_tree_find_child(cpus_parent(), "cmp");
128
        while (node) {
128
        while (node) {
129
            wakeup_cpu(ofw_tree_find_child(node, "cpu@0"));
129
            wakeup_cpu(ofw_tree_find_child(node, "cpu@0"));
130
            wakeup_cpu(ofw_tree_find_child(node, "cpu@1"));
130
            wakeup_cpu(ofw_tree_find_child(node, "cpu@1"));
131
            node = ofw_tree_find_peer_by_name(node, "cmp");
131
            node = ofw_tree_find_peer_by_name(node, "cmp");
132
        }
132
        }
133
    }
133
    }
134
}
134
}
135
 
135
 
136
/** @}
136
/** @}
137
 */
137
 */
138
 
138