Subversion Repositories HelenOS-historic

Rev

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

Rev Author Line No. Line
740 jermar 1
/*
2
 * Copyright (C) 2006 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
 
29
/*
30
 * ASID management.
31
 *
32
 * Because ia64 has much wider ASIDs (18-24 bits) compared to other
742 jermar 33
 * architectures (e.g. 8 bits on mips32 and 13 bits on sparc64), it is
740 jermar 34
 * inappropriate to use same methods (i.e. genarch/mm/asid_fifo.c) for
35
 * all of them.
36
 *
37
 * Instead, ia64 assigns ASID values from a counter that eventually
38
 * overflows. When this happens, the counter is reset and all TLBs are
39
 * entirely invalidated. Furthermore, all address space structures,
40
 * except for the one with asid == ASID_KERNEL, are assigned new ASID.
41
 *
42
 * It is important to understand that, in SPARTAN, one ASID represents
43
 * RIDS_PER_ASID consecutive hardware RIDs (Region ID's).
44
 *
45
 * Note that the algorithm used can handle only the maximum of
46
 * ASID_OVERFLOW-ASID_START address spaces at a time.
47
 */
48
 
49
#include <arch/mm/asid.h>
50
#include <mm/asid.h>
51
#include <mm/as.h>
749 jermar 52
#include <genarch/mm/page_ht.h>
740 jermar 53
#include <mm/tlb.h>
54
#include <list.h>
55
#include <typedefs.h>
56
#include <debug.h>
57
 
58
/**
59
 * Stores the ASID to be returned next.
60
 * Must be only accessed when asidlock is held.
61
 */
62
static asid_t next_asid = ASID_START;
63
 
64
/** Assign next ASID.
65
 *
66
 * On ia64, this function is used only to allocate ASID
67
 * for a newly created address space. As a side effect,
68
 * it might attempt to shootdown TLBs and reassign
69
 * ASIDs to existing address spaces.
70
 *
71
 * When calling this function, interrupts must be disabled
72
 * and the asidlock must be held.
73
 *
74
 * @return ASID for new address space.
75
 */
76
asid_t asid_find_free(void)
77
{
78
    as_t *as;
79
    link_t *cur;
80
 
81
    if (next_asid == ASID_OVERFLOW) {
82
        /*
83
         * The counter has overflown.
84
         */
85
 
86
        /*
87
         * Reset the counter.
88
         */
89
        next_asid = ASID_START;
90
 
91
        /*
92
         * Initiate TLB shootdown.
93
         */
94
        tlb_shootdown_start(TLB_INVL_ALL, 0, 0, 0);
95
 
96
        /*
97
         * Reassign ASIDs to existing address spaces.
98
         */
99
        for (cur = as_with_asid_head.next; cur != &as_with_asid_head; cur = cur->next) {
100
            ASSERT(next_asid < ASID_OVERFLOW);
101
 
102
            as = list_get_instance(cur, as_t, as_with_asid_link);
103
 
104
            spinlock_lock(&as->lock);
105
            as->asid = next_asid++;
106
            spinlock_unlock(&as->lock);
107
        }
749 jermar 108
 
109
        /*
110
         * The page hash table uses VHPT long format PTE's.
111
         * Unfortunatelly, this format has no space to
112
         * store as_t pointer, so it is necessary to
113
         * invalidate the whole structure after all ASIDs
114
         * have been reassigned. The information swept out
115
         * from the page hash table can be later reconstructed
116
         * from as_t structures on demand.
117
         */
118
        ht_invalidate_all();
740 jermar 119
 
120
        /*
121
         * Finish TLB shootdown.
122
         */
123
        tlb_shootdown_finalize();
124
        tlb_invalidate_all();
125
    }
126
 
127
    ASSERT(next_asid < ASID_OVERFLOW);
128
    return next_asid++;
129
}