Changeset c621f4aa in mainline for kernel/genarch/src


Ignore:
Timestamp:
2010-07-25T10:11:13Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
377cce8
Parents:
24a2517 (diff), a2da43c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline.

Location:
kernel/genarch/src
Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/acpi/acpi.c

    r24a2517 rc621f4aa  
    3333/**
    3434 * @file
    35  * @brief       Advanced Configuration and Power Interface (ACPI) initialization.
    36  */
    37  
     35 * @brief Advanced Configuration and Power Interface (ACPI) initialization.
     36 */
     37
    3838#include <genarch/acpi/acpi.h>
    3939#include <genarch/acpi/madt.h>
     
    4343#include <print.h>
    4444
    45 #define RSDP_SIGNATURE          "RSD PTR "
    46 #define RSDP_REVISION_OFFS      15
     45#define RSDP_SIGNATURE      "RSD PTR "
     46#define RSDP_REVISION_OFFS  15
    4747
    4848#define CMP_SIGNATURE(left, right) \
     
    6464};
    6565
    66 static int rsdp_check(uint8_t *rsdp) {
    67         struct acpi_rsdp *r = (struct acpi_rsdp *) rsdp;
     66static int rsdp_check(uint8_t *_rsdp) {
     67        struct acpi_rsdp *rsdp = (struct acpi_rsdp *) _rsdp;
     68        uint8_t sum = 0;
     69        uint32_t i;
     70       
     71        for (i = 0; i < 20; i++)
     72                sum = (uint8_t) (sum + _rsdp[i]);
     73       
     74        if (sum)
     75                return 0; /* bad checksum */
     76       
     77        if (rsdp->revision == 0)
     78                return 1; /* ACPI 1.0 */
     79       
     80        for (; i < rsdp->length; i++)
     81                sum = (uint8_t) (sum + _rsdp[i]);
     82       
     83        return !sum;
     84}
     85
     86int acpi_sdt_check(uint8_t *sdt)
     87{
     88        struct acpi_sdt_header *hdr = (struct acpi_sdt_header *) sdt;
    6889        uint8_t sum = 0;
    6990        unsigned int i;
    7091       
    71         for (i = 0; i < 20; i++)
    72                 sum = (uint8_t) (sum + rsdp[i]);
    73                
    74         if (sum)       
    75                 return 0; /* bad checksum */
    76 
    77         if (r->revision == 0)
    78                 return 1; /* ACPI 1.0 */
    79                
    80         for (; i < r->length; i++)
    81                 sum = (uint8_t) (sum + rsdp[i]);
    82                
     92        for (i = 0; i < hdr->length; i++)
     93                sum = (uint8_t) (sum + sdt[i]);
     94       
    8395        return !sum;
    84        
    85 }
    86 
    87 int acpi_sdt_check(uint8_t *sdt)
    88 {
    89         struct acpi_sdt_header *h = (struct acpi_sdt_header *) sdt;
    90         uint8_t sum = 0;
    91         unsigned int i;
    92 
    93         for (i = 0; i < h->length; i++)
    94                 sum = (uint8_t) (sum + sdt[i]);
    95                
    96         return !sum;
    9796}
    9897
    9998static void map_sdt(struct acpi_sdt_header *sdt)
    10099{
    101         page_mapping_insert(AS_KERNEL, (uintptr_t) sdt, (uintptr_t) sdt, PAGE_NOT_CACHEABLE | PAGE_WRITE);
     100        page_table_lock(AS_KERNEL, true);
     101        page_mapping_insert(AS_KERNEL, (uintptr_t) sdt, (uintptr_t) sdt,
     102            PAGE_NOT_CACHEABLE | PAGE_WRITE);
    102103        map_structure((uintptr_t) sdt, sdt->length);
     104        page_table_unlock(AS_KERNEL, true);
    103105}
    104106
    105107static void configure_via_rsdt(void)
    106108{
    107         unsigned int i, j, cnt = (acpi_rsdt->header.length - sizeof(struct acpi_sdt_header)) / sizeof(uint32_t);
     109        size_t i;
     110        size_t j;
     111        size_t cnt = (acpi_rsdt->header.length - sizeof(struct acpi_sdt_header))
     112            / sizeof(uint32_t);
    108113       
    109114        for (i = 0; i < cnt; i++) {
    110                 for (j = 0; j < sizeof(signature_map) / sizeof(struct acpi_signature_map); j++) {
    111                         struct acpi_sdt_header *h = (struct acpi_sdt_header *) (unative_t) acpi_rsdt->entry[i];
    112                
    113                         map_sdt(h);
    114                         if (CMP_SIGNATURE(h->signature, signature_map[j].signature)) {
    115                                 if (!acpi_sdt_check((uint8_t *) h))
    116                                         goto next;
    117                                 *signature_map[j].sdt_ptr = h;
    118                                 LOG("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);
     115                for (j = 0; j < sizeof(signature_map)
     116                    / sizeof(struct acpi_signature_map); j++) {
     117                        struct acpi_sdt_header *hdr =
     118                            (struct acpi_sdt_header *) (unative_t) acpi_rsdt->entry[i];
     119                       
     120                        map_sdt(hdr);
     121                        if (CMP_SIGNATURE(hdr->signature, signature_map[j].signature)) {
     122                                if (!acpi_sdt_check((uint8_t *) hdr))
     123                                        break;
     124                               
     125                                *signature_map[j].sdt_ptr = hdr;
     126                                LOG("%p: ACPI %s", *signature_map[j].sdt_ptr,
     127                                    signature_map[j].description);
    119128                        }
    120129                }
    121 next:
    122                 ;
    123130        }
    124131}
     
    126133static void configure_via_xsdt(void)
    127134{
    128         unsigned int i, j, cnt = (acpi_xsdt->header.length - sizeof(struct acpi_sdt_header)) / sizeof(uint64_t);
     135        size_t i;
     136        size_t j;
     137        size_t cnt = (acpi_xsdt->header.length - sizeof(struct acpi_sdt_header))
     138            / sizeof(uint64_t);
    129139       
    130140        for (i = 0; i < cnt; i++) {
    131                 for (j = 0; j < sizeof(signature_map) / sizeof(struct acpi_signature_map); j++) {
    132                         struct acpi_sdt_header *h = (struct acpi_sdt_header *) ((uintptr_t) acpi_rsdt->entry[i]);
    133 
    134                         map_sdt(h);
    135                         if (CMP_SIGNATURE(h->signature, signature_map[j].signature)) {
    136                                 if (!acpi_sdt_check((uint8_t *) h))
    137                                         goto next;
    138                                 *signature_map[j].sdt_ptr = h;
    139                                 LOG("%p: ACPI %s\n", *signature_map[j].sdt_ptr, signature_map[j].description);
     141                for (j = 0; j < sizeof(signature_map)
     142                    / sizeof(struct acpi_signature_map); j++) {
     143                        struct acpi_sdt_header *hdr =
     144                            (struct acpi_sdt_header *) ((uintptr_t) acpi_xsdt->entry[i]);
     145                       
     146                        map_sdt(hdr);
     147                        if (CMP_SIGNATURE(hdr->signature, signature_map[j].signature)) {
     148                                if (!acpi_sdt_check((uint8_t *) hdr))
     149                                        break;
     150                               
     151                                *signature_map[j].sdt_ptr = hdr;
     152                                LOG("%p: ACPI %s", *signature_map[j].sdt_ptr,
     153                                    signature_map[j].description);
    140154                        }
    141155                }
    142 next:
    143                 ;
    144         }
    145 
     156        }
    146157}
    147158
     
    149160{
    150161        uint8_t *addr[2] = { NULL, (uint8_t *) PA2KA(0xe0000) };
    151         int i, j, length[2] = { 1024, 128*1024 };
     162        unsigned int i;
     163        unsigned int j;
     164        unsigned int length[2] = { 1024, 128 * 1024 };
    152165        uint64_t *sig = (uint64_t *) RSDP_SIGNATURE;
    153 
     166       
    154167        /*
    155168         * Find Root System Description Pointer
     
    157170         * 2. search 128K starting at 0xe0000
    158171         */
    159 
     172       
    160173        addr[0] = (uint8_t *) PA2KA(ebda);
    161174        for (i = (ebda ? 0 : 1); i < 2; i++) {
    162175                for (j = 0; j < length[i]; j += 16) {
    163                         if (*((uint64_t *) &addr[i][j]) == *sig && rsdp_check(&addr[i][j])) {
     176                        if ((*((uint64_t *) &addr[i][j]) == *sig)
     177                            && (rsdp_check(&addr[i][j]))) {
    164178                                acpi_rsdp = (struct acpi_rsdp *) &addr[i][j];
    165179                                goto rsdp_found;
     
    167181                }
    168182        }
    169 
     183       
    170184        return;
    171 
     185       
    172186rsdp_found:
    173         LOG("%p: ACPI Root System Description Pointer\n", acpi_rsdp);
    174 
    175         acpi_rsdt = (struct acpi_rsdt *) (unative_t) acpi_rsdp->rsdt_address;
     187        LOG("%p: ACPI Root System Description Pointer", acpi_rsdp);
     188       
     189        acpi_rsdt = (struct acpi_rsdt *) ((uintptr_t) acpi_rsdp->rsdt_address);
    176190        if (acpi_rsdp->revision)
    177191                acpi_xsdt = (struct acpi_xsdt *) ((uintptr_t) acpi_rsdp->xsdt_address);
    178 
     192       
    179193        if (acpi_rsdt)
    180194                map_sdt((struct acpi_sdt_header *) acpi_rsdt);
     195       
    181196        if (acpi_xsdt)
    182197                map_sdt((struct acpi_sdt_header *) acpi_xsdt);
    183 
    184         if (acpi_rsdt && !acpi_sdt_check((uint8_t *) acpi_rsdt)) {
     198       
     199        if ((acpi_rsdt) && (!acpi_sdt_check((uint8_t *) acpi_rsdt))) {
    185200                printf("RSDT: bad checksum\n");
    186201                return;
    187202        }
    188         if (acpi_xsdt && !acpi_sdt_check((uint8_t *) acpi_xsdt)) {
     203       
     204        if ((acpi_xsdt) && (!acpi_sdt_check((uint8_t *) acpi_xsdt))) {
    189205                printf("XSDT: bad checksum\n");
    190206                return;
    191207        }
    192 
     208       
    193209        if (acpi_xsdt)
    194210                configure_via_xsdt();
    195211        else if (acpi_rsdt)
    196212                configure_via_rsdt();
    197 
    198213}
    199214
  • kernel/genarch/src/acpi/madt.c

    r24a2517 rc621f4aa  
    2727 */
    2828
    29 /** @addtogroup genarch 
     29/** @addtogroup genarch
    3030 * @{
    3131 */
    3232/**
    3333 * @file
    34  * @brief       Multiple APIC Description Table (MADT) parsing.
    35  */
    36 
    37 #include <arch/types.h>
     34 * @brief Multiple APIC Description Table (MADT) parsing.
     35 */
     36
     37#include <typedefs.h>
    3838#include <genarch/acpi/acpi.h>
    3939#include <genarch/acpi/madt.h>
     
    5252#ifdef CONFIG_SMP
    5353
    54 /** Standard ISA IRQ map; can be overriden by Interrupt Source Override entries of MADT. */
    55 int isa_irq_map[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
    56 
    57 static void madt_l_apic_entry(struct madt_l_apic *la, uint32_t index);
    58 static void madt_io_apic_entry(struct madt_io_apic *ioa, uint32_t index);
    59 static void madt_intr_src_ovrd_entry(struct madt_intr_src_ovrd *override, uint32_t index);
    60 static int madt_cmp(void * a, void * b);
     54/**
     55 * Standard ISA IRQ map; can be overriden by
     56 * Interrupt Source Override entries of MADT.
     57 */
     58static int isa_irq_map[] =
     59    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
    6160
    6261struct madt_l_apic *madt_l_apic_entries = NULL;
    6362struct madt_io_apic *madt_io_apic_entries = NULL;
    6463
    65 size_t madt_l_apic_entry_index = 0;
    66 size_t madt_io_apic_entry_index = 0;
    67 size_t madt_l_apic_entry_cnt = 0;
    68 size_t madt_io_apic_entry_cnt = 0;
    69 size_t cpu_count = 0;
    70 
    71 struct madt_apic_header * * madt_entries_index = NULL;
    72 unsigned int madt_entries_index_cnt = 0;
    73 
    74 char *entry[] = {
     64static size_t madt_l_apic_entry_index = 0;
     65static size_t madt_io_apic_entry_index = 0;
     66static size_t madt_l_apic_entry_cnt = 0;
     67static size_t madt_io_apic_entry_cnt = 0;
     68
     69static struct madt_apic_header **madt_entries_index = NULL;
     70
     71const char *entry[] = {
    7572        "L_APIC",
    7673        "IO_APIC",
     
    8481};
    8582
    86 /*
    87  * ACPI MADT Implementation of SMP configuration interface.
    88  */
    89 static size_t madt_cpu_count(void);
    90 static bool madt_cpu_enabled(size_t i);
    91 static bool madt_cpu_bootstrap(size_t i);
    92 static uint8_t madt_cpu_apic_id(size_t i);
    93 static int madt_irq_to_pin(unsigned int irq);
    94 
     83static uint8_t madt_cpu_apic_id(size_t i)
     84{
     85        ASSERT(i < madt_l_apic_entry_cnt);
     86       
     87        return ((struct madt_l_apic *)
     88            madt_entries_index[madt_l_apic_entry_index + i])->apic_id;
     89}
     90
     91static bool madt_cpu_enabled(size_t i)
     92{
     93        ASSERT(i < madt_l_apic_entry_cnt);
     94       
     95        /*
     96         * FIXME: The current local APIC driver limits usable
     97         * CPU IDs to 8.
     98         *
     99         */
     100        if (i > 7)
     101                return false;
     102       
     103        return ((struct madt_l_apic *)
     104            madt_entries_index[madt_l_apic_entry_index + i])->flags & 0x1;
     105}
     106
     107static bool madt_cpu_bootstrap(size_t i)
     108{
     109        ASSERT(i < madt_l_apic_entry_cnt);
     110       
     111        return ((struct madt_l_apic *)
     112            madt_entries_index[madt_l_apic_entry_index + i])->apic_id ==
     113            bsp_l_apic;
     114}
     115
     116static int madt_irq_to_pin(unsigned int irq)
     117{
     118        ASSERT(irq < sizeof(isa_irq_map) / sizeof(int));
     119       
     120        return isa_irq_map[irq];
     121}
     122
     123/** ACPI MADT Implementation of SMP configuration interface.
     124 *
     125 */
    95126struct smp_config_operations madt_config_operations = {
    96         .cpu_count = madt_cpu_count,
    97127        .cpu_enabled = madt_cpu_enabled,
    98128        .cpu_bootstrap = madt_cpu_bootstrap,
     
    101131};
    102132
    103 size_t madt_cpu_count(void)
    104 {
    105         return madt_l_apic_entry_cnt;
    106 }
    107 
    108 bool madt_cpu_enabled(size_t i)
    109 {
    110         ASSERT(i < madt_l_apic_entry_cnt);
    111         return ((struct madt_l_apic *) madt_entries_index[madt_l_apic_entry_index + i])->flags & 0x1;
    112 
    113 }
    114 
    115 bool madt_cpu_bootstrap(size_t i)
    116 {
    117         ASSERT(i < madt_l_apic_entry_cnt);
    118         return ((struct madt_l_apic *) madt_entries_index[madt_l_apic_entry_index + i])->apic_id == l_apic_id();
    119 }
    120 
    121 uint8_t madt_cpu_apic_id(size_t i)
    122 {
    123         ASSERT(i < madt_l_apic_entry_cnt);
    124         return ((struct madt_l_apic *) madt_entries_index[madt_l_apic_entry_index + i])->apic_id;
    125 }
    126 
    127 int madt_irq_to_pin(unsigned int irq)
    128 {
    129         ASSERT(irq < sizeof(isa_irq_map) / sizeof(int));
    130         return isa_irq_map[irq];
    131 }
    132 
    133 int madt_cmp(void * a, void * b)
    134 {
    135         return
    136                 (((struct madt_apic_header *) a)->type > ((struct madt_apic_header *) b)->type) ?
    137                 1 :
    138                 ((((struct madt_apic_header *) a)->type < ((struct madt_apic_header *) b)->type) ? -1 : 0);
    139 }
    140        
    141 void acpi_madt_parse(void)
    142 {
    143         struct madt_apic_header *end = (struct madt_apic_header *) (((uint8_t *) acpi_madt) + acpi_madt->header.length);
    144         struct madt_apic_header *h;
    145        
    146         l_apic = (uint32_t *) (unative_t) acpi_madt->l_apic_address;
    147 
    148         /* calculate madt entries */
    149         for (h = &acpi_madt->apic_header[0]; h < end; h = (struct madt_apic_header *) (((uint8_t *) h) + h->length)) {
    150                 madt_entries_index_cnt++;
    151         }
    152 
    153         /* create madt apic entries index array */
    154         madt_entries_index = (struct madt_apic_header * *) malloc(madt_entries_index_cnt * sizeof(struct madt_apic_header * *), FRAME_ATOMIC);
    155         if (!madt_entries_index)
    156                 panic("Memory allocation error.");
    157 
    158         uint32_t index = 0;
    159 
    160         for (h = &acpi_madt->apic_header[0]; h < end; h = (struct madt_apic_header *) (((uint8_t *) h) + h->length)) {
    161                 madt_entries_index[index++] = h;
    162         }
    163 
    164         /* Quicksort MADT index structure */
    165         qsort(madt_entries_index, madt_entries_index_cnt, sizeof(uintptr_t), &madt_cmp);
    166 
    167         /* Parse MADT entries */
    168         if (madt_entries_index_cnt > 0) {       
    169                 for (index = 0; index < madt_entries_index_cnt - 1; index++) {
    170                         h = madt_entries_index[index];
    171                         switch (h->type) {
    172                                 case MADT_L_APIC:
    173                                         madt_l_apic_entry((struct madt_l_apic *) h, index);
    174                                         break;
    175                                 case MADT_IO_APIC:
    176                                         madt_io_apic_entry((struct madt_io_apic *) h, index);
    177                                         break;
    178                                 case MADT_INTR_SRC_OVRD:
    179                                         madt_intr_src_ovrd_entry((struct madt_intr_src_ovrd *) h, index);
    180                                         break;
    181                                 case MADT_NMI_SRC:
    182                                 case MADT_L_APIC_NMI:
    183                                 case MADT_L_APIC_ADDR_OVRD:
    184                                 case MADT_IO_SAPIC:
    185                                 case MADT_L_SAPIC:
    186                                 case MADT_PLATFORM_INTR_SRC:
    187                                         printf("MADT: skipping %s entry (type=%" PRIu8 ")\n", entry[h->type], h->type);
    188                                         break;
    189        
    190                                 default:
    191                                         if (h->type >= MADT_RESERVED_SKIP_BEGIN && h->type <= MADT_RESERVED_SKIP_END) {
    192                                                 printf("MADT: skipping reserved entry (type=%" PRIu8 ")\n", h->type);
    193                                         }
    194                                         if (h->type >= MADT_RESERVED_OEM_BEGIN) {
    195                                                 printf("MADT: skipping OEM entry (type=%" PRIu8 ")\n", h->type);
    196                                         }
    197                                         break;
    198                         }
    199                 }
    200         }
    201 
    202         if (cpu_count)
    203                 config.cpu_count = cpu_count;
    204 }
    205  
    206 
    207 void madt_l_apic_entry(struct madt_l_apic *la, uint32_t index)
    208 {
    209         if (!madt_l_apic_entry_cnt++) {
    210                 madt_l_apic_entry_index = index;
    211         }
    212                
     133static int madt_cmp(void *a, void *b, void *arg)
     134{
     135        uint8_t typea = (*((struct madt_apic_header **) a))->type;
     136        uint8_t typeb = (*((struct madt_apic_header **) b))->type;
     137       
     138        if (typea > typeb)
     139                return 1;
     140       
     141        if (typea < typeb)
     142                return -1;
     143       
     144        return 0;
     145}
     146
     147static void madt_l_apic_entry(struct madt_l_apic *la, size_t i)
     148{
     149        if (madt_l_apic_entry_cnt == 0)
     150                madt_l_apic_entry_index = i;
     151       
     152        madt_l_apic_entry_cnt++;
     153       
    213154        if (!(la->flags & 0x1)) {
    214155                /* Processor is unusable, skip it. */
     
    216157        }
    217158       
    218         cpu_count++;   
    219         apic_id_mask |= 1<<la->apic_id;
    220 }
    221 
    222 void madt_io_apic_entry(struct madt_io_apic *ioa, uint32_t index)
    223 {
    224         if (!madt_io_apic_entry_cnt++) {
    225                 /* remember index of the first io apic entry */
    226                 madt_io_apic_entry_index = index;
     159        apic_id_mask |= 1 << la->apic_id;
     160}
     161
     162static void madt_io_apic_entry(struct madt_io_apic *ioa, size_t i)
     163{
     164        if (madt_io_apic_entry_cnt == 0) {
     165                /* Remember index of the first io apic entry */
     166                madt_io_apic_entry_index = i;
    227167                io_apic = (uint32_t *) (unative_t) ioa->io_apic_address;
    228168        } else {
    229                 /* currently not supported */
    230                 return;
    231         }
    232 }
    233 
    234 void madt_intr_src_ovrd_entry(struct madt_intr_src_ovrd *override, uint32_t index)
     169                /* Currently not supported */
     170        }
     171       
     172        madt_io_apic_entry_cnt++;
     173}
     174
     175static void madt_intr_src_ovrd_entry(struct madt_intr_src_ovrd *override,
     176    size_t i)
    235177{
    236178        ASSERT(override->source < sizeof(isa_irq_map) / sizeof(int));
    237         printf("MADT: ignoring %s entry: bus=%" PRIu8 ", source=%" PRIu8 ", global_int=%" PRIu32 ", flags=%#" PRIx16 "\n",
    238                 entry[override->header.type], override->bus, override->source,
    239                 override->global_int, override->flags);
     179       
     180        printf("MADT: Ignoring %s entry: bus=%" PRIu8 ", source=%" PRIu8
     181            ", global_int=%" PRIu32 ", flags=%#" PRIx16 "\n",
     182            entry[override->header.type], override->bus, override->source,
     183            override->global_int, override->flags);
     184}
     185
     186void acpi_madt_parse(void)
     187{
     188        struct madt_apic_header *end = (struct madt_apic_header *)
     189            (((uint8_t *) acpi_madt) + acpi_madt->header.length);
     190        struct madt_apic_header *hdr;
     191       
     192        l_apic = (uint32_t *) (unative_t) acpi_madt->l_apic_address;
     193       
     194        /* Count MADT entries */
     195        unsigned int madt_entries_index_cnt = 0;
     196        for (hdr = acpi_madt->apic_header; hdr < end;
     197            hdr = (struct madt_apic_header *) (((uint8_t *) hdr) + hdr->length))
     198                madt_entries_index_cnt++;
     199       
     200        /* Create MADT APIC entries index array */
     201        madt_entries_index = (struct madt_apic_header **)
     202            malloc(madt_entries_index_cnt * sizeof(struct madt_apic_header *),
     203            FRAME_ATOMIC);
     204        if (!madt_entries_index)
     205                panic("Memory allocation error.");
     206       
     207        size_t i = 0;
     208       
     209        for (hdr = acpi_madt->apic_header; hdr < end;
     210            hdr = (struct madt_apic_header *) (((uint8_t *) hdr) + hdr->length)) {
     211                madt_entries_index[i] = hdr;
     212                i++;
     213        }
     214       
     215        /* Sort MADT index structure */
     216        if (!gsort(madt_entries_index, madt_entries_index_cnt,
     217            sizeof(struct madt_apic_header *), madt_cmp, NULL))
     218                panic("Sorting error.");
     219       
     220        /* Parse MADT entries */
     221        for (i = 0; i < madt_entries_index_cnt; i++) {
     222                hdr = madt_entries_index[i];
     223               
     224                switch (hdr->type) {
     225                case MADT_L_APIC:
     226                        madt_l_apic_entry((struct madt_l_apic *) hdr, i);
     227                        break;
     228                case MADT_IO_APIC:
     229                        madt_io_apic_entry((struct madt_io_apic *) hdr, i);
     230                break;
     231                case MADT_INTR_SRC_OVRD:
     232                        madt_intr_src_ovrd_entry((struct madt_intr_src_ovrd *) hdr, i);
     233                        break;
     234                case MADT_NMI_SRC:
     235                case MADT_L_APIC_NMI:
     236                case MADT_L_APIC_ADDR_OVRD:
     237                case MADT_IO_SAPIC:
     238                case MADT_L_SAPIC:
     239                case MADT_PLATFORM_INTR_SRC:
     240                        printf("MADT: Skipping %s entry (type=%" PRIu8 ")\n",
     241                            entry[hdr->type], hdr->type);
     242                        break;
     243                default:
     244                        if ((hdr->type >= MADT_RESERVED_SKIP_BEGIN)
     245                            && (hdr->type <= MADT_RESERVED_SKIP_END))
     246                                printf("MADT: Skipping reserved entry (type=%" PRIu8 ")\n",
     247                                    hdr->type);
     248                               
     249                        if (hdr->type >= MADT_RESERVED_OEM_BEGIN)
     250                                printf("MADT: Skipping OEM entry (type=%" PRIu8 ")\n",
     251                                    hdr->type);
     252                       
     253                        break;
     254                }
     255        }
     256       
     257        if (madt_l_apic_entry_cnt > 0)
     258                config.cpu_count = madt_l_apic_entry_cnt;
    240259}
    241260
  • kernel/genarch/src/drivers/dsrln/dsrlnout.c

    r24a2517 rc621f4aa  
    4141#include <console/console.h>
    4242#include <sysinfo/sysinfo.h>
    43 #include <string.h>
     43#include <str.h>
    4444
    4545typedef struct {
  • kernel/genarch/src/drivers/ega/ega.c

    r24a2517 rc621f4aa  
    4242#include <arch/mm/page.h>
    4343#include <synch/spinlock.h>
    44 #include <arch/types.h>
     44#include <typedefs.h>
    4545#include <arch/asm.h>
    4646#include <memstr.h>
    47 #include <string.h>
     47#include <str.h>
    4848#include <console/chardev.h>
    4949#include <console/console.h>
     
    6363
    6464typedef struct {
    65         SPINLOCK_DECLARE(lock);
     65        IRQ_SPINLOCK_DECLARE(lock);
    6666       
    6767        uint32_t cursor;
     
    7171} ega_instance_t;
    7272
    73 static void ega_putchar(outdev_t *dev, wchar_t ch, bool silent);
    74 static void ega_redraw(outdev_t *dev);
     73static void ega_putchar(outdev_t *, wchar_t, bool);
     74static void ega_redraw(outdev_t *);
    7575
    7676static outdev_operations_t egadev_ops = {
     
    540540        ega_instance_t *instance = (ega_instance_t *) dev->data;
    541541       
    542         ipl_t ipl = interrupts_disable();
    543         spinlock_lock(&instance->lock);
     542        irq_spinlock_lock(&instance->lock, true);
    544543       
    545544        switch (ch) {
     
    564563        ega_move_cursor(instance, silent);
    565564       
    566         spinlock_unlock(&instance->lock);
    567         interrupts_restore(ipl);
     565        irq_spinlock_unlock(&instance->lock, true);
    568566}
    569567
     
    572570        ega_instance_t *instance = (ega_instance_t *) dev->data;
    573571       
    574         ipl_t ipl = interrupts_disable();
    575         spinlock_lock(&instance->lock);
     572        irq_spinlock_lock(&instance->lock, true);
    576573       
    577574        memcpy(instance->addr, instance->backbuf, EGA_VRAM_SIZE);
     
    579576        ega_show_cursor(instance, silent);
    580577       
    581         spinlock_unlock(&instance->lock);
    582         interrupts_restore(ipl);
     578        irq_spinlock_unlock(&instance->lock, true);
    583579}
    584580
     
    598594        egadev->data = instance;
    599595       
    600         spinlock_initialize(&instance->lock, "*ega_lock");
     596        irq_spinlock_initialize(&instance->lock, "*ega.instance.lock");
    601597       
    602598        instance->base = base;
  • kernel/genarch/src/drivers/i8042/i8042.c

    r24a2517 rc621f4aa  
    6767        i8042_instance_t *instance = irq->instance;
    6868        i8042_t *dev = instance->i8042;
    69         uint8_t status;
    7069       
    71         if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) {
     70        if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK) {
    7271                uint8_t data = pio_read_8(&dev->data);
    7372                indev_push_character(instance->kbrdin, data);
  • kernel/genarch/src/drivers/via-cuda/cuda.c

    r24a2517 rc621f4aa  
    9999                instance->snd_bytes = 0;
    100100
    101                 spinlock_initialize(&instance->dev_lock, "cuda_dev");
     101                spinlock_initialize(&instance->dev_lock, "cuda.instance.dev_lock");
    102102
    103103                /* Disable all interrupts from CUDA. */
  • kernel/genarch/src/fb/fb.c

    r24a2517 rc621f4aa  
    4949#include <bitops.h>
    5050#include <print.h>
    51 #include <string.h>
     51#include <str.h>
    5252#include <ddi/ddi.h>
    53 #include <arch/types.h>
     53#include <typedefs.h>
    5454#include <byteorder.h>
    5555
     
    554554        fbdev->data = instance;
    555555       
    556         spinlock_initialize(&instance->lock, "*fb_lock");
     556        spinlock_initialize(&instance->lock, "*fb.instance.lock");
    557557        instance->rgb_conv = rgb_conv;
    558558        instance->pixelbytes = pixelbytes;
  • kernel/genarch/src/kbrd/kbrd.c

    r24a2517 rc621f4aa  
    169169                indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops);
    170170               
    171                 spinlock_initialize(&instance->keylock, "instance_keylock");
     171                spinlock_initialize(&instance->keylock, "kbrd.instance.keylock");
    172172                instance->keyflags = 0;
    173173                instance->lockflags = 0;
  • kernel/genarch/src/kbrd/kbrd_pl050.c

    r24a2517 rc621f4aa  
    181181                indev_initialize("kbrd", &instance->raw, &kbrd_raw_ops);
    182182               
    183                 spinlock_initialize(&instance->keylock, "instance_keylock");
     183                spinlock_initialize(&instance->keylock, "kbrd_pl050.instance.keylock");
    184184                instance->keyflags = 0;
    185185                instance->lockflags = 0;
  • kernel/genarch/src/kbrd/scanc_mac.c

    r24a2517 rc621f4aa  
    3737#include <genarch/kbrd/scanc.h>
    3838#include <typedefs.h>
    39 #include <string.h>
     39#include <str.h>
    4040
    4141/** Primary meaning of scancodes. */
  • kernel/genarch/src/kbrd/scanc_pc.c

    r24a2517 rc621f4aa  
    3737#include <genarch/kbrd/scanc.h>
    3838#include <typedefs.h>
    39 #include <string.h>
     39#include <str.h>
    4040
    4141/** Primary meaning of scancodes. */
  • kernel/genarch/src/kbrd/scanc_pl050.c

    r24a2517 rc621f4aa  
    3636#include <genarch/kbrd/scanc.h>
    3737#include <typedefs.h>
    38 #include <string.h>
     38#include <str.h>
    3939
    4040
  • kernel/genarch/src/kbrd/scanc_sun.c

    r24a2517 rc621f4aa  
    3737#include <genarch/kbrd/scanc.h>
    3838#include <typedefs.h>
    39 #include <string.h>
     39#include <str.h>
    4040
    4141/** Primary meaning of scancodes. */
  • kernel/genarch/src/mm/as_ht.c

    r24a2517 rc621f4aa  
    3030 * @{
    3131 */
    32  
     32
    3333/**
    3434 * @file
    35  * @brief       Address space functions for global page hash table.
     35 * @brief Address space functions for global page hash table.
    3636 */
    3737
     
    4141#include <mm/as.h>
    4242#include <mm/frame.h>
    43 #include <arch/types.h>
     43#include <typedefs.h>
    4444#include <memstr.h>
    4545#include <adt/hash_table.h>
    4646#include <synch/mutex.h>
    4747
    48 static pte_t *ht_create(int flags);
    49 static void ht_destroy(pte_t *page_table);
     48static pte_t *ht_create(unsigned int);
     49static void ht_destroy(pte_t *);
    5050
    51 static void ht_lock(as_t *as, bool lock);
    52 static void ht_unlock(as_t *as, bool unlock);
     51static void ht_lock(as_t *, bool);
     52static void ht_unlock(as_t *, bool);
     53static bool ht_locked(as_t *);
    5354
    5455as_operations_t as_ht_operations = {
     
    5758        .page_table_lock = ht_lock,
    5859        .page_table_unlock = ht_unlock,
     60        .page_table_locked = ht_locked,
    5961};
    6062
     
    6870 *
    6971 * @return Returns NULL.
     72 *
    7073 */
    71 pte_t *ht_create(int flags)
     74pte_t *ht_create(unsigned int flags)
    7275{
    7376        if (flags & FLAG_AS_KERNEL) {
     
    7578                mutex_initialize(&page_ht_lock, MUTEX_PASSIVE);
    7679        }
     80       
    7781        return NULL;
    7882}
     
    8387 *
    8488 * @param page_table This parameter is ignored.
     89 *
    8590 */
    8691void ht_destroy(pte_t *page_table)
     
    9499 * Interrupts must be disabled.
    95100 *
    96  * @param as Address space.
     101 * @param as   Address space.
    97102 * @param lock If false, do not attempt to lock the address space.
     103 *
    98104 */
    99105void ht_lock(as_t *as, bool lock)
     
    101107        if (lock)
    102108                mutex_lock(&as->lock);
     109       
    103110        mutex_lock(&page_ht_lock);
    104111}
     
    109116 * Interrupts must be disabled.
    110117 *
    111  * @param as Address space.
     118 * @param as     Address space.
    112119 * @param unlock If false, do not attempt to lock the address space.
     120 *
    113121 */
    114122void ht_unlock(as_t *as, bool unlock)
    115123{
    116124        mutex_unlock(&page_ht_lock);
     125       
    117126        if (unlock)
    118127                mutex_unlock(&as->lock);
    119128}
    120129
     130/** Test whether page tables are locked.
     131 *
     132 * @param as            Address space where the page tables belong.
     133 *
     134 * @return              True if the page tables belonging to the address soace
     135 *                      are locked, otherwise false.
     136 */
     137bool ht_locked(as_t *as)
     138{
     139        return (mutex_locked(&page_ht_lock) && mutex_locked(&as->lock));
     140}
     141
    121142/** @}
    122143 */
  • kernel/genarch/src/mm/as_pt.c

    r24a2517 rc621f4aa  
    3333/**
    3434 * @file
    35  * @brief       Address space functions for 4-level hierarchical pagetables.
     35 * @brief Address space functions for 4-level hierarchical pagetables.
    3636 */
    3737
     
    4343#include <arch/mm/page.h>
    4444#include <arch/mm/as.h>
    45 #include <arch/types.h>
     45#include <typedefs.h>
    4646#include <memstr.h>
    4747#include <arch.h>
    4848
    49 static pte_t *ptl0_create(int flags);
    50 static void ptl0_destroy(pte_t *page_table);
     49static pte_t *ptl0_create(unsigned int);
     50static void ptl0_destroy(pte_t *);
    5151
    52 static void pt_lock(as_t *as, bool lock);
    53 static void pt_unlock(as_t *as, bool unlock);
     52static void pt_lock(as_t *, bool);
     53static void pt_unlock(as_t *, bool);
     54static bool pt_locked(as_t *);
    5455
    5556as_operations_t as_pt_operations = {
     
    5758        .page_table_destroy = ptl0_destroy,
    5859        .page_table_lock = pt_lock,
    59         .page_table_unlock = pt_unlock
     60        .page_table_unlock = pt_unlock,
     61        .page_table_locked = pt_locked,
    6062};
    6163
     
    6769 *
    6870 * @return New PTL0.
     71 *
    6972 */
    70 pte_t *ptl0_create(int flags)
     73pte_t *ptl0_create(unsigned int flags)
    7174{
    72         pte_t *src_ptl0, *dst_ptl0;
    73         ipl_t ipl;
    74         int table_size;
    75 
    76         dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE, FRAME_KA);
    77         table_size = FRAME_SIZE << PTL0_SIZE;
    78 
    79         if (flags & FLAG_AS_KERNEL) {
     75        pte_t *dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE, FRAME_KA);
     76        size_t table_size = FRAME_SIZE << PTL0_SIZE;
     77       
     78        if (flags & FLAG_AS_KERNEL)
    8079                memsetb(dst_ptl0, table_size, 0);
    81         } else {
    82                 uintptr_t src, dst;
    83        
     80        else {
    8481                /*
    8582                 * Copy the kernel address space portion to new PTL0.
     83                 *
    8684                 */
    87                  
    88                 ipl = interrupts_disable();
    89                 mutex_lock(&AS_KERNEL->lock);           
    90                 src_ptl0 = (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
    91 
    92                 src = (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
    93                 dst = (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
    94 
     85               
     86                mutex_lock(&AS_KERNEL->lock);
     87               
     88                pte_t *src_ptl0 =
     89                    (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
     90               
     91                uintptr_t src =
     92                    (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
     93                uintptr_t dst =
     94                    (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
     95               
    9596                memsetb(dst_ptl0, table_size, 0);
    96                 memcpy((void *) dst, (void *) src, table_size - (src - (uintptr_t) src_ptl0));
     97                memcpy((void *) dst, (void *) src,
     98                    table_size - (src - (uintptr_t) src_ptl0));
     99               
    97100                mutex_unlock(&AS_KERNEL->lock);
    98                 interrupts_restore(ipl);
    99101        }
    100 
     102       
    101103        return (pte_t *) KA2PA((uintptr_t) dst_ptl0);
    102104}
     
    107109 *
    108110 * @param page_table Physical address of PTL0.
     111 *
    109112 */
    110113void ptl0_destroy(pte_t *page_table)
    111114{
    112         frame_free((uintptr_t)page_table);
     115        frame_free((uintptr_t) page_table);
    113116}
    114117
     
    118121 * Interrupts must be disabled.
    119122 *
    120  * @param as Address space.
     123 * @param as   Address space.
    121124 * @param lock If false, do not attempt to lock the address space.
     125 *
    122126 */
    123127void pt_lock(as_t *as, bool lock)
     
    132136 * Interrupts must be disabled.
    133137 *
    134  * @param as Address space.
     138 * @param as     Address space.
    135139 * @param unlock If false, do not attempt to unlock the address space.
     140 *
    136141 */
    137142void pt_unlock(as_t *as, bool unlock)
     
    141146}
    142147
     148/** Test whether page tables are locked.
     149 *
     150 * @param as            Address space where the page tables belong.
     151 *
     152 * @return              True if the page tables belonging to the address soace
     153 *                      are locked, otherwise false.
     154 */
     155bool pt_locked(as_t *as)
     156{
     157        return mutex_locked(&as->lock);
     158}
     159
    143160/** @}
    144161 */
  • kernel/genarch/src/mm/asid.c

    r24a2517 rc621f4aa  
    7070/** Allocate free address space identifier.
    7171 *
    72  * Interrupts must be disabled and inactive_as_with_asid_lock must be held
    73  * prior to this call
    74  *
    7572 * @return New ASID.
    7673 */
     
    8077        link_t *tmp;
    8178        as_t *as;
     79
     80        ASSERT(interrupts_disabled());
     81        ASSERT(spinlock_locked(&asidlock));
    8282
    8383        /*
     
    126126                 * Get the system rid of the stolen ASID.
    127127                 */
    128                 tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
     128                ipl_t ipl = tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
    129129                tlb_invalidate_asid(asid);
    130                 tlb_shootdown_finalize();
     130                tlb_shootdown_finalize(ipl);
    131131        } else {
    132132
     
    142142                 * Purge the allocated ASID from TLBs.
    143143                 */
    144                 tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
     144                ipl_t ipl = tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
    145145                tlb_invalidate_asid(asid);
    146                 tlb_shootdown_finalize();
     146                tlb_shootdown_finalize(ipl);
    147147        }
    148148       
  • kernel/genarch/src/mm/page_ht.c

    r24a2517 rc621f4aa  
    3333/**
    3434 * @file
    35  * @brief       Virtual Address Translation (VAT) for global page hash table.
     35 * @brief Virtual Address Translation (VAT) for global page hash table.
    3636 */
    3737
     
    4343#include <mm/as.h>
    4444#include <arch/mm/asid.h>
    45 #include <arch/types.h>
     45#include <typedefs.h>
    4646#include <arch/asm.h>
    4747#include <synch/spinlock.h>
     
    5252#include <align.h>
    5353
    54 static size_t hash(unative_t key[]);
    55 static bool compare(unative_t key[], size_t keys, link_t *item);
    56 static void remove_callback(link_t *item);
    57 
    58 static void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
    59     int flags);
    60 static void ht_mapping_remove(as_t *as, uintptr_t page);
    61 static pte_t *ht_mapping_find(as_t *as, uintptr_t page);
     54static size_t hash(unative_t[]);
     55static bool compare(unative_t[], size_t, link_t *);
     56static void remove_callback(link_t *);
     57
     58static void ht_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
     59static void ht_mapping_remove(as_t *, uintptr_t);
     60static pte_t *ht_mapping_find(as_t *, uintptr_t);
    6261
    6362/**
     
    6564 * after address space lock and after any address space area
    6665 * locks.
     66 *
    6767 */
    6868mutex_t page_ht_lock;
    6969
    70 /**
    71  * Page hash table.
     70/** Page hash table.
     71 *
    7272 * The page hash table may be accessed only when page_ht_lock is held.
     73 *
    7374 */
    7475hash_table_t page_ht;
     
    9394 *
    9495 * @return Index into page hash table.
     96 *
    9597 */
    9698size_t hash(unative_t key[])
     
    98100        as_t *as = (as_t *) key[KEY_AS];
    99101        uintptr_t page = (uintptr_t) key[KEY_PAGE];
    100         size_t index;
    101102       
    102103        /*
     
    104105         * of occurring. Least significant bits of VPN compose the
    105106         * hash index.
    106          */
    107         index = ((page >> PAGE_WIDTH) & (PAGE_HT_ENTRIES - 1));
     107         *
     108         */
     109        size_t index = ((page >> PAGE_WIDTH) & (PAGE_HT_ENTRIES - 1));
    108110       
    109111        /*
     
    111113         * similar addresses. Least significant bits compose the
    112114         * hash index.
     115         *
    113116         */
    114117        index |= ((unative_t) as) & (PAGE_HT_ENTRIES - 1);
     
    119122/** Compare page hash table item with page and/or address space.
    120123 *
    121  * @param key Array of one or two keys (i.e. page and/or address space).
     124 * @param key  Array of one or two keys (i.e. page and/or address space).
    122125 * @param keys Number of keys passed.
    123126 * @param item Item to compare the keys with.
    124127 *
    125128 * @return true on match, false otherwise.
     129 *
    126130 */
    127131bool compare(unative_t key[], size_t keys, link_t *item)
    128132{
    129         pte_t *t;
    130 
    131133        ASSERT(item);
    132         ASSERT((keys > 0) && (keys <= PAGE_HT_KEYS));
    133 
     134        ASSERT(keys > 0);
     135        ASSERT(keys <= PAGE_HT_KEYS);
     136       
    134137        /*
    135138         * Convert item to PTE.
    136          */
    137         t = hash_table_get_instance(item, pte_t, link);
    138 
    139         if (keys == PAGE_HT_KEYS) {
    140                 return (key[KEY_AS] == (uintptr_t) t->as) &&
    141                     (key[KEY_PAGE] == t->page);
    142         } else {
    143                 return (key[KEY_AS] == (uintptr_t) t->as);
    144         }
     139         *
     140         */
     141        pte_t *pte = hash_table_get_instance(item, pte_t, link);
     142       
     143        if (keys == PAGE_HT_KEYS)
     144                return (key[KEY_AS] == (uintptr_t) pte->as) &&
     145                    (key[KEY_PAGE] == pte->page);
     146       
     147        return (key[KEY_AS] == (uintptr_t) pte->as);
    145148}
    146149
     
    148151 *
    149152 * @param item Page hash table item being removed.
     153 *
    150154 */
    151155void remove_callback(link_t *item)
    152156{
    153         pte_t *t;
    154 
    155157        ASSERT(item);
    156 
     158       
    157159        /*
    158160         * Convert item to PTE.
    159          */
    160         t = hash_table_get_instance(item, pte_t, link);
    161 
    162         free(t);
     161         *
     162         */
     163        pte_t *pte = hash_table_get_instance(item, pte_t, link);
     164       
     165        free(pte);
    163166}
    164167
     
    166169 *
    167170 * Map virtual address page to physical address frame
    168  * using flags.
    169  *
    170  * The page table must be locked and interrupts must be disabled.
    171  *
    172  * @param as Address space to which page belongs.
    173  * @param page Virtual address of the page to be mapped.
     171 * using flags.
     172 *
     173 * @param as    Address space to which page belongs.
     174 * @param page  Virtual address of the page to be mapped.
    174175 * @param frame Physical address of memory frame to which the mapping is done.
    175176 * @param flags Flags to be used for mapping.
    176  */
    177 void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
    178 {
    179         pte_t *t;
     177 *
     178 */
     179void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
     180    unsigned int flags)
     181{
    180182        unative_t key[2] = {
    181183                (uintptr_t) as,
    182184                page = ALIGN_DOWN(page, PAGE_SIZE)
    183185        };
     186
     187        ASSERT(page_table_locked(as));
    184188       
    185189        if (!hash_table_find(&page_ht, key)) {
    186                 t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
    187                 ASSERT(t != NULL);
    188 
    189                 t->g = (flags & PAGE_GLOBAL) != 0;
    190                 t->x = (flags & PAGE_EXEC) != 0;
    191                 t->w = (flags & PAGE_WRITE) != 0;
    192                 t->k = !(flags & PAGE_USER);
    193                 t->c = (flags & PAGE_CACHEABLE) != 0;
    194                 t->p = !(flags & PAGE_NOT_PRESENT);
    195                 t->a = false;
    196                 t->d = false;
    197 
    198                 t->as = as;
    199                 t->page = ALIGN_DOWN(page, PAGE_SIZE);
    200                 t->frame = ALIGN_DOWN(frame, FRAME_SIZE);
    201 
    202                 hash_table_insert(&page_ht, key, &t->link);
     190                pte_t *pte = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
     191                ASSERT(pte != NULL);
     192               
     193                pte->g = (flags & PAGE_GLOBAL) != 0;
     194                pte->x = (flags & PAGE_EXEC) != 0;
     195                pte->w = (flags & PAGE_WRITE) != 0;
     196                pte->k = !(flags & PAGE_USER);
     197                pte->c = (flags & PAGE_CACHEABLE) != 0;
     198                pte->p = !(flags & PAGE_NOT_PRESENT);
     199                pte->a = false;
     200                pte->d = false;
     201               
     202                pte->as = as;
     203                pte->page = ALIGN_DOWN(page, PAGE_SIZE);
     204                pte->frame = ALIGN_DOWN(frame, FRAME_SIZE);
     205               
     206                hash_table_insert(&page_ht, key, &pte->link);
    203207        }
    204208}
     
    210214 * this call visible.
    211215 *
    212  * The page table must be locked and interrupts must be disabled.
    213  *
    214  * @param as Address space to wich page belongs.
     216 * @param as   Address space to wich page belongs.
    215217 * @param page Virtual address of the page to be demapped.
     218 *
    216219 */
    217220void ht_mapping_remove(as_t *as, uintptr_t page)
     
    221224                page = ALIGN_DOWN(page, PAGE_SIZE)
    222225        };
     226
     227        ASSERT(page_table_locked(as));
    223228       
    224229        /*
     
    234239 * Find mapping for virtual page.
    235240 *
    236  * The page table must be locked and interrupts must be disabled.
    237  *
    238  * @param as Address space to wich page belongs.
     241 * @param as   Address space to wich page belongs.
    239242 * @param page Virtual page.
    240243 *
    241244 * @return NULL if there is no such mapping; requested mapping otherwise.
     245 *
    242246 */
    243247pte_t *ht_mapping_find(as_t *as, uintptr_t page)
    244248{
    245         link_t *hlp;
    246         pte_t *t = NULL;
    247249        unative_t key[2] = {
    248250                (uintptr_t) as,
    249251                page = ALIGN_DOWN(page, PAGE_SIZE)
    250252        };
    251        
    252         hlp = hash_table_find(&page_ht, key);
    253         if (hlp)
    254                 t = hash_table_get_instance(hlp, pte_t, link);
    255 
    256         return t;
     253
     254        ASSERT(page_table_locked(as));
     255       
     256        link_t *cur = hash_table_find(&page_ht, key);
     257        if (cur)
     258                return hash_table_get_instance(cur, pte_t, link);
     259       
     260        return NULL;
    257261}
    258262
  • kernel/genarch/src/mm/page_pt.c

    r24a2517 rc621f4aa  
    3333/**
    3434 * @file
    35  * @brief       Virtual Address Translation for hierarchical 4-level page tables.
     35 * @brief Virtual Address Translation for hierarchical 4-level page tables.
    3636 */
    3737
     
    4242#include <arch/mm/page.h>
    4343#include <arch/mm/as.h>
    44 #include <arch/types.h>
     44#include <typedefs.h>
    4545#include <arch/asm.h>
    4646#include <memstr.h>
    4747
    48 static void pt_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags);
    49 static void pt_mapping_remove(as_t *as, uintptr_t page);
    50 static pte_t *pt_mapping_find(as_t *as, uintptr_t page);
     48static void pt_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
     49static void pt_mapping_remove(as_t *, uintptr_t);
     50static pte_t *pt_mapping_find(as_t *, uintptr_t);
    5151
    5252page_mapping_operations_t pt_mapping_operations = {
     
    6161 * using flags.
    6262 *
    63  * The page table must be locked and interrupts must be disabled.
    64  *
    65  * @param as Address space to wich page belongs.
    66  * @param page Virtual address of the page to be mapped.
     63 * @param as    Address space to wich page belongs.
     64 * @param page  Virtual address of the page to be mapped.
    6765 * @param frame Physical address of memory frame to which the mapping is done.
    6866 * @param flags Flags to be used for mapping.
    69  */
    70 void pt_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
     67 *
     68 */
     69void pt_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
     70    unsigned int flags)
    7171{
    72         pte_t *ptl0, *ptl1, *ptl2, *ptl3;
    73         pte_t *newpt;
    74 
    75         ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    76 
     72        pte_t *ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
     73
     74        ASSERT(page_table_locked(as));
     75       
    7776        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
    78                 newpt = (pte_t *)frame_alloc(PTL1_SIZE, FRAME_KA);
     77                pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE, FRAME_KA);
    7978                memsetb(newpt, FRAME_SIZE << PTL1_SIZE, 0);
    8079                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
    8180                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
    8281        }
    83 
    84         ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    85 
     82       
     83        pte_t *ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
     84       
    8685        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
    87                 newpt = (pte_t *)frame_alloc(PTL2_SIZE, FRAME_KA);
     86                pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE, FRAME_KA);
    8887                memsetb(newpt, FRAME_SIZE << PTL2_SIZE, 0);
    8988                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
    9089                SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
    9190        }
    92 
    93         ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    94 
     91       
     92        pte_t *ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
     93       
    9594        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
    96                 newpt = (pte_t *)frame_alloc(PTL3_SIZE, FRAME_KA);
     95                pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE, FRAME_KA);
    9796                memsetb(newpt, FRAME_SIZE << PTL3_SIZE, 0);
    9897                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
    9998                SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
    10099        }
    101 
    102         ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
    103 
     100       
     101        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
     102       
    104103        SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(page), frame);
    105104        SET_FRAME_FLAGS(ptl3, PTL3_INDEX(page), flags);
     
    114113 * Empty page tables except PTL0 are freed.
    115114 *
    116  * The page table must be locked and interrupts must be disabled.
    117  *
    118  * @param as Address space to wich page belongs.
     115 * @param as   Address space to wich page belongs.
    119116 * @param page Virtual address of the page to be demapped.
     117 *
    120118 */
    121119void pt_mapping_remove(as_t *as, uintptr_t page)
    122120{
    123         pte_t *ptl0, *ptl1, *ptl2, *ptl3;
    124         bool empty = true;
    125         int i;
     121        ASSERT(page_table_locked(as));
    126122
    127123        /*
    128124         * First, remove the mapping, if it exists.
     125         *
    129126         */
    130 
    131         ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    132 
     127       
     128        pte_t *ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    133129        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
    134130                return;
    135 
    136         ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    137 
     131       
     132        pte_t *ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    138133        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT)
    139134                return;
    140 
    141         ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    142 
     135       
     136        pte_t *ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    143137        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT)
    144138                return;
    145 
    146         ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
    147 
     139       
     140        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
     141       
    148142        /* Destroy the mapping. Setting to PAGE_NOT_PRESENT is not sufficient. */
    149143        memsetb(&ptl3[PTL3_INDEX(page)], sizeof(pte_t), 0);
    150 
     144       
    151145        /*
    152146         * Second, free all empty tables along the way from PTL3 down to PTL0.
     147         *
    153148         */
    154149       
    155         /* check PTL3 */
     150        /* Check PTL3 */
     151        bool empty = true;
     152       
     153        unsigned int i;
    156154        for (i = 0; i < PTL3_ENTRIES; i++) {
    157155                if (PTE_VALID(&ptl3[i])) {
     
    160158                }
    161159        }
     160       
    162161        if (empty) {
    163162                /*
    164163                 * PTL3 is empty.
    165164                 * Release the frame and remove PTL3 pointer from preceding table.
     165                 *
    166166                 */
    167167                frame_free(KA2PA((uintptr_t) ptl3));
    168                 if (PTL2_ENTRIES)
    169                         memsetb(&ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
    170                 else if (PTL1_ENTRIES)
    171                         memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
    172                 else
    173                         memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
     168#if (PTL2_ENTRIES != 0)
     169                memsetb(&ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
     170#elif (PTL1_ENTRIES != 0)
     171                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
     172#else
     173                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
     174#endif
    174175        } else {
    175176                /*
     
    177178                 * Therefore, there must be a path from PTL0 to PTL3 and
    178179                 * thus nothing to free in higher levels.
    179                  */
    180                 return;
    181         }
    182        
    183         /* check PTL2, empty is still true */
    184         if (PTL2_ENTRIES) {
    185                 for (i = 0; i < PTL2_ENTRIES; i++) {
    186                         if (PTE_VALID(&ptl2[i])) {
    187                                 empty = false;
    188                                 break;
    189                         }
     180                 *
     181                 */
     182                return;
     183        }
     184       
     185        /* Check PTL2, empty is still true */
     186#if (PTL2_ENTRIES != 0)
     187        for (i = 0; i < PTL2_ENTRIES; i++) {
     188                if (PTE_VALID(&ptl2[i])) {
     189                        empty = false;
     190                        break;
    190191                }
    191                 if (empty) {
    192                         /*
    193                          * PTL2 is empty.
    194                          * Release the frame and remove PTL2 pointer from preceding table.
    195                          */
    196                         frame_free(KA2PA((uintptr_t) ptl2));
    197                         if (PTL1_ENTRIES)
    198                                 memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
    199                         else
    200                                 memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
     192        }
     193       
     194        if (empty) {
     195                /*
     196                 * PTL2 is empty.
     197                 * Release the frame and remove PTL2 pointer from preceding table.
     198                 *
     199                 */
     200                frame_free(KA2PA((uintptr_t) ptl2));
     201#if (PTL1_ENTRIES != 0)
     202                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
     203#else
     204                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
     205#endif
     206        } else {
     207                /*
     208                 * PTL2 is not empty.
     209                 * Therefore, there must be a path from PTL0 to PTL2 and
     210                 * thus nothing to free in higher levels.
     211                 *
     212                 */
     213                return;
     214        }
     215#endif /* PTL2_ENTRIES != 0 */
     216       
     217        /* check PTL1, empty is still true */
     218#if (PTL1_ENTRIES != 0)
     219        for (i = 0; i < PTL1_ENTRIES; i++) {
     220                if (PTE_VALID(&ptl1[i])) {
     221                        empty = false;
     222                        break;
    201223                }
    202                 else {
    203                         /*
    204                          * PTL2 is not empty.
    205                          * Therefore, there must be a path from PTL0 to PTL2 and
    206                          * thus nothing to free in higher levels.
    207                          */
    208                         return;
    209                 }
    210         }
    211 
    212         /* check PTL1, empty is still true */
    213         if (PTL1_ENTRIES) {
    214                 for (i = 0; i < PTL1_ENTRIES; i++) {
    215                         if (PTE_VALID(&ptl1[i])) {
    216                                 empty = false;
    217                                 break;
    218                         }
    219                 }
    220                 if (empty) {
    221                         /*
    222                          * PTL1 is empty.
    223                          * Release the frame and remove PTL1 pointer from preceding table.
    224                          */
    225                         frame_free(KA2PA((uintptr_t) ptl1));
    226                         memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    227                 }
    228         }
    229 
     224        }
     225       
     226        if (empty) {
     227                /*
     228                 * PTL1 is empty.
     229                 * Release the frame and remove PTL1 pointer from preceding table.
     230                 *
     231                 */
     232                frame_free(KA2PA((uintptr_t) ptl1));
     233                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
     234        }
     235#endif /* PTL1_ENTRIES != 0 */
    230236}
    231237
     
    234240 * Find mapping for virtual page.
    235241 *
    236  * The page table must be locked and interrupts must be disabled.
    237  *
    238  * @param as Address space to which page belongs.
     242 * @param as   Address space to which page belongs.
    239243 * @param page Virtual page.
    240244 *
    241  * @return NULL if there is no such mapping; entry from PTL3 describing the mapping otherwise.
     245 * @return NULL if there is no such mapping; entry from PTL3 describing
     246 *         the mapping otherwise.
     247 *
    242248 */
    243249pte_t *pt_mapping_find(as_t *as, uintptr_t page)
    244250{
    245         pte_t *ptl0, *ptl1, *ptl2, *ptl3;
    246 
    247         ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    248 
     251        ASSERT(page_table_locked(as));
     252
     253        pte_t *ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    249254        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
    250255                return NULL;
    251 
    252         ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    253 
     256       
     257        pte_t *ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    254258        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT)
    255259                return NULL;
    256 
    257         ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    258 
     260       
     261        pte_t *ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    259262        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT)
    260263                return NULL;
    261 
    262         ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
    263 
     264       
     265        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
     266       
    264267        return &ptl3[PTL3_INDEX(page)];
    265268}
  • kernel/genarch/src/multiboot/multiboot.c

    r24a2517 rc621f4aa  
    3434
    3535#include <genarch/multiboot/multiboot.h>
    36 #include <arch/types.h>
    3736#include <typedefs.h>
    3837#include <config.h>
    39 #include <string.h>
     38#include <str.h>
    4039#include <macros.h>
    4140
  • kernel/genarch/src/ofw/ebus.c

    r24a2517 rc621f4aa  
    4040#include <genarch/ofw/pci.h>
    4141#include <arch/memstr.h>
    42 #include <string.h>
     42#include <str.h>
    4343#include <panic.h>
    4444#include <debug.h>
  • kernel/genarch/src/ofw/fhc.c

    r24a2517 rc621f4aa  
    4040#include <arch/drivers/fhc.h>
    4141#include <arch/memstr.h>
    42 #include <string.h>
     42#include <str.h>
    4343#include <panic.h>
    4444#include <macros.h>
  • kernel/genarch/src/ofw/ofw_tree.c

    r24a2517 rc621f4aa  
    3939#include <arch/memstr.h>
    4040#include <mm/slab.h>
    41 #include <string.h>
     41#include <str.h>
    4242#include <panic.h>
    4343#include <print.h>
     
    6565    const char *name)
    6666{
    67         unsigned int i;
     67        size_t i;
    6868       
    6969        for (i = 0; i < node->properties; i++) {
     
    170170 */
    171171ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *root,
    172     uint32_t handle)
     172    phandle handle)
    173173{
    174174        ofw_tree_node_t *cur;
  • kernel/genarch/src/ofw/pci.c

    r24a2517 rc621f4aa  
    4141#include <arch/trap/interrupt.h>
    4242#include <arch/memstr.h>
    43 #include <string.h>
     43#include <str.h>
    4444#include <panic.h>
    4545#include <macros.h>
    4646
    4747#define PCI_SPACE_MASK          0x03000000
    48 #define PCI_ABS_MASK            0x80000000     
     48#define PCI_ABS_MASK            0x80000000
    4949#define PCI_REG_MASK            0x000000ff
    5050
  • kernel/genarch/src/srln/srln.c

    r24a2517 rc621f4aa  
    4040#include <proc/thread.h>
    4141#include <arch.h>
    42 #include <string.h>
     42#include <str.h>
    4343
    4444static indev_operations_t srln_raw_ops = {
Note: See TracChangeset for help on using the changeset viewer.