source: mainline/kernel/arch/amd64/src/ddi/ddi.c@ 83dab11

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 83dab11 was 83dab11, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Replace usage of typedefs.h with includes of more specific, standard headers, where applicable.

  • Property mode set to 100644
File size: 3.4 KB
Line 
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/** @addtogroup amd64ddi
30 * @{
31 */
32/** @file
33 */
34
35#include <ddi/ddi.h>
36#include <arch/ddi/ddi.h>
37#include <proc/task.h>
38#include <adt/bitmap.h>
39#include <mm/slab.h>
40#include <arch/pm.h>
41#include <errno.h>
42#include <arch/cpu.h>
43#include <cpu.h>
44#include <arch.h>
45#include <align.h>
46#include <stdbool.h>
47
48/** Install I/O Permission bitmap.
49 *
50 * Current task's I/O permission bitmap, if any, is installed
51 * in the current CPU's TSS.
52 *
53 * Interrupts must be disabled prior this call.
54 *
55 */
56void io_perm_bitmap_install(void)
57{
58 /* First, copy the I/O Permission Bitmap. */
59 irq_spinlock_lock(&TASK->lock, false);
60
61 size_t ver = TASK->arch.iomapver;
62 size_t elements = TASK->arch.iomap.elements;
63
64 if (elements > 0) {
65 ASSERT(TASK->arch.iomap.bits);
66
67 bitmap_t iomap;
68 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8,
69 CPU->arch.tss->iomap);
70 bitmap_copy(&iomap, &TASK->arch.iomap, elements);
71
72 /*
73 * Set the trailing bits in the last byte of the map to disable
74 * I/O access.
75 */
76 bitmap_set_range(&iomap, elements,
77 ALIGN_UP(elements, 8) - elements);
78
79 /*
80 * It is safe to set the trailing eight bits because of the
81 * extra convenience byte in TSS_IOMAP_SIZE.
82 */
83 bitmap_set_range(&iomap, ALIGN_UP(elements, 8), 8);
84 }
85
86 irq_spinlock_unlock(&TASK->lock, false);
87
88 /*
89 * Second, adjust TSS segment limit.
90 * Take the extra ending byte with all bits set into account.
91 */
92 ptr_16_64_t cpugdtr;
93 gdtr_store(&cpugdtr);
94
95 descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
96 size_t size = bitmap_size(elements);
97 gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size);
98 gdtr_load(&cpugdtr);
99
100 /*
101 * Before we load new TSS limit, the current TSS descriptor
102 * type must be changed to describe inactive TSS.
103 */
104 tss_descriptor_t *tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
105 tss_desc->type = AR_TSS;
106 tr_load(GDT_SELECTOR(TSS_DES));
107
108 /*
109 * Update the generation count so that faults caused by
110 * early accesses can be serviced.
111 */
112 CPU->arch.iomapver_copy = ver;
113}
114
115/** @}
116 */
Note: See TracBrowser for help on using the repository browser.