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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c8da69d was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

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