Changeset 0c2d9bb in mainline for kernel/genarch


Ignore:
Timestamp:
2013-12-25T22:54:29Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b51cf2c
Parents:
f7a33de (diff), ac36aed (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 mainline changes

Location:
kernel/genarch
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/include/genarch/drivers/am335x/irc.h

    rf7a33de r0c2d9bb  
    3838#define KERN_AM335x_IRQC_H_
    3939
    40 #define AM335x_IRC_BASE_ADDRESS 0x48200000
    41 #define AM335x_IRC_SIZE         4096
     40#define AM335x_IRC_BASE_ADDRESS     0x48200000
     41#define AM335x_IRC_SIZE             4096
    4242
    43 #define AM335x_IRC_IRQ_COUNT    128
     43#define AM335x_IRC_IRQ_COUNT        128
     44#define AM335x_IRC_IRQ_GROUPS_COUNT 4
    4445
    45 #include <typedefs.h>
     46#define OMAP_IRC_IRQ_COUNT        AM335x_IRC_IRQ_COUNT
     47#define OMAP_IRC_IRQ_GROUPS_COUNT AM335x_IRC_IRQ_GROUPS_COUNT
    4648
    47 typedef struct {
    48         const ioport32_t revision;
    49 #define AM335x_IRC_REV_MASK 0xFF
    50 
    51         const uint8_t padd0[12];
    52 
    53         /* This register controls the various parameters
    54          * of the OCP interface.
    55          */
    56         ioport32_t sysconfig;
    57 #define AM335x_IRC_SYSCONFIG_AUTOIDLE_FLAG   (1 << 0)
    58 #define AM335x_IRC_SYSCONFIG_SOFTRESET_FLAG  (1 << 1)
    59 
    60         /* This register provides status information about the module */
    61         const ioport32_t sysstatus;
    62 #define AM335x_IRC_SYSSTATUS_RESET_DONE_FLAG (1 << 0)
    63 
    64         const uint8_t padd1[40];
    65 
    66         /* This register supplies the currently active IRQ interrupt number */
    67         ioport32_t sir_irq;
    68 #define AM335x_IRC_SIR_IRQ_ACTIVEIRQ_MASK       0x7F
    69 #define AM335x_IRC_SIR_IRQ_SPURIOUSIRQFLAG_MASK 0xFFFFFFF8
    70 
    71         /* This register supplies the currently active FIQ interrupt number */
    72         const ioport32_t sir_fiq;
    73 #define AM335x_IRC_FIQ_IRQ_ACTIVEFIQ_MASK       0x7F
    74 #define AM335x_IRC_FIQ_IRQ_SPURIOUSFIQFLAG_MASK 0xFFFFFFF8
    75 
    76         /* This register contains the new interrupt agreement bits */
    77         ioport32_t control;
    78 #define AM335x_IRC_CONTROL_NEWIRQAGR_FLAG       (1 << 0)
    79 #define AM335x_IRC_CONTROL_NEWFIQAGR_FLAG       (1 << 1)
    80 
    81         /* This register controls protection of the other registers.
    82          * This register can only be accessed in priviledged mode, regardless
    83          * of the current value of the protection bit.
    84          */
    85         ioport32_t protection;
    86 #define AM335x_IRC_PROTECTION_FLAG              (1 << 0)
    87 
    88         /* This register controls the clock auto-idle for the functional
    89          * clock and the input synchronizers.
    90          */
    91         ioport32_t idle;
    92 #define AM335x_IRC_IDLE_FUNCIDLE_FLAG           (1 << 0)
    93 #define AM335x_IRC_IDLE_TURBO_FLAG              (1 << 1)
    94 
    95         const uint8_t padd2[12];
    96 
    97         /* This register supplies the currently active IRQ priority level */
    98         const ioport32_t irq_priority;
    99 #define AM335x_IRC_IRQ_PRIORITY_IRQPRIORITY_MASK     0x7F
    100 #define AM335x_IRC_IRQ_PRIORITY_SPURIOUSIRQFLAG_MASK 0xFFFFFFF8
    101 
    102         /* This register supplies the currently active FIQ priority level */
    103         const ioport32_t fiq_priority;
    104 #define AM335x_IRC_FIQ_PRIORITY_FIQPRIORITY_MASK     0x7F
    105 #define AM335x_IRC_FIQ_PRIORITY_SPURIOUSIRQFLAG_MASK 0xFFFFFFF8
    106 
    107         /* This register sets the priority threshold */
    108         ioport32_t threshold;
    109 #define AM335x_IRC_THRESHOLD_PRIORITYTHRESHOLD_MASK     0xFF
    110 #define AM335x_IRC_THRESHOLD_PRIORITYTHRESHOLD_ENABLED  0x00
    111 #define AM335x_IRC_THRESHOLD_PRIORITYTHRESHOLD_DISABLED 0xFF
    112 
    113         const uint8_t padd[20];
    114 
    115         struct {
    116                 /* Raw interrupt input status before masking */
    117                 const ioport32_t itr;
    118 
    119                 /* Interrupt mask */
    120                 ioport32_t mir;
    121 
    122                 /* This register is used to clear the interrupt mask bits,
    123                  * Write 1 clears the mask bit to 0.
    124                  */
    125                 ioport32_t mir_clear;
    126 
    127                 /* This register is used to set the interrupt mask bits,
    128                  * Write 1 sets the mask bit to 1.
    129                  */
    130                 ioport32_t mir_set;
    131 
    132                 /* This register is used to set the software interrupt bits,
    133                  * it is also used to read the current active software
    134                  * interrupts.
    135                  * Write 1 sets the software interrups bits to 1.
    136                  */
    137                 ioport32_t isr_set;
    138 
    139                 /* This register is used to clear the software interrups bits.
    140                  * Write 1 clears the software interrupt bits to 0.
    141                  */
    142                 ioport32_t isr_clear;
    143 
    144                 /* This register contains the IRQ status after masking. */
    145                 const ioport32_t pending_irq;
    146 
    147                 /* This register contains the FIQ status after masking. */
    148                 const ioport32_t pending_fiq;
    149         } interrupts[4];
    150 
    151         /* These registers contain the priority for the interrups and
    152          * the FIQ/IRQ steering.
    153          */
    154         ioport32_t ilr[AM335x_IRC_IRQ_COUNT];
    155 /* 0 = Interrupt routed to IRQ, 1 = interrupt routed to FIQ */
    156 #define AM335x_IRC_ILR_FIQNIRQ_FLAG    (1 << 0)
    157 #define AM335x_IRC_ILR_PRIORITY_MASK   0x3F
    158 #define AM335x_IRC_ILR_PRIORITY_SHIFT  2
    159 
    160 } am335x_irc_regs_t;
    161 
    162 static inline void am335x_irc_init(am335x_irc_regs_t *regs)
    163 {
    164         int i;
    165 
    166         /* Initialization sequence */
    167 
    168         /* 1 - Program the SYSCONFIG register: if necessary, enable the
    169          *     autogating by setting the AUTOIDLE bit.
    170          */
    171         regs->sysconfig &= ~AM335x_IRC_SYSCONFIG_AUTOIDLE_FLAG;
    172 
    173         /* 2 - Program the IDLE register: if necessary, disable functional
    174          *     clock autogating or enable synchronizer autogating by setting
    175          *     the FUNCIDLE bit or the TURBO bit accordingly.
    176          */
    177         regs->idle &= ~AM335x_IRC_IDLE_FUNCIDLE_FLAG;
    178         regs->idle &= ~AM335x_IRC_IDLE_TURBO_FLAG;
    179 
    180         /* 3 - Program ILRm register for each interrupt line: Assign a
    181          *     priority level and set the FIQNIRQ bit for an FIQ interrupt
    182          *     (by default, interrupts are mapped to IRQ and
    183          *     priority is 0 (highest).
    184          */
    185 
    186         for (i = 0; i < AM335x_IRC_IRQ_COUNT; ++i)
    187                 regs->ilr[i] = 0;
    188 
    189         /* 4 - Program the MIRn register: Enable interrupts (by default,
    190          *     all interrupt lines are masked).
    191          */
    192         for (i = 0; i < 4; ++i)
    193                 regs->interrupts[i].mir_set = 0xFFFFFFFF;
    194 }
    195 
    196 /** Get the currently active IRQ interrupt number
    197  *
    198  * @param regs     Pointer to the irc memory mapped registers
    199  *
    200  * @return         The active IRQ interrupt number
    201  */
    202 static inline unsigned am335x_irc_inum_get(am335x_irc_regs_t *regs)
    203 {
    204         return regs->sir_irq & AM335x_IRC_SIR_IRQ_ACTIVEIRQ_MASK;
    205 }
    206 
    207 /** Reset IRQ output and enable new IRQ generation
    208  *
    209  * @param regs    Pointer to the irc memory mapped registers
    210  */
    211 static inline void am335x_irc_irq_ack(am335x_irc_regs_t *regs)
    212 {
    213         regs->control = AM335x_IRC_CONTROL_NEWIRQAGR_FLAG;
    214 }
    215 
    216 /** Reset FIQ output and enable new FIQ generation
    217  *
    218  * @param regs    Pointer to the irc memory mapped registers
    219  */
    220 static inline void am335x_irc_fiq_ack(am335x_irc_regs_t *regs)
    221 {
    222         regs->control = AM335x_IRC_CONTROL_NEWFIQAGR_FLAG;
    223 }
    224 
    225 /** Clear an interrupt mask bit
    226  *
    227  * @param regs    Pointer to the irc memory mapped registers
    228  * @param inum    The interrupt to be enabled
    229  */
    230 static inline void am335x_irc_enable(am335x_irc_regs_t *regs, unsigned inum)
    231 {
    232         ASSERT(inum < AM335x_IRC_IRQ_COUNT);
    233         const unsigned set = inum / 32;
    234         const unsigned pos = inum % 32;
    235         regs->interrupts[set].mir_clear = (1 << pos);
    236 }
    237 
    238 /** Set an interrupt mask bit
    239  *
    240  * @param regs    Pointer to the irc memory mapped registers
    241  * @param inum    The interrupt to be disabled
    242  */
    243 static inline void am335x_irc_disable(am335x_irc_regs_t *regs, unsigned inum)
    244 {
    245         ASSERT(inum < AM335x_IRC_IRQ_COUNT);
    246         const unsigned set = inum / 32;
    247         const unsigned pos = inum % 32;
    248         regs->interrupts[set].mir_set = (1 << pos);
    249 }
     49#include <genarch/drivers/omap/irc.h>
    25050
    25151#endif
  • kernel/genarch/include/genarch/drivers/amdm37x/irc.h

    rf7a33de r0c2d9bb  
    3838
    3939/* AMDM37x TRM p. 1079 */
    40 #define AMDM37x_IRC_BASE_ADDRESS 0x48200000
    41 #define AMDM37x_IRC_SIZE 4096
     40#define AMDM37x_IRC_BASE_ADDRESS     0x48200000
     41#define AMDM37x_IRC_SIZE             4096
    4242
    43 #define AMDM37x_IRC_IRQ_COUNT 96
     43#define AMDM37x_IRC_IRQ_COUNT        96
     44#define AMDM37x_IRC_IRQ_GROUPS_COUNT 3
    4445
    45 #include <typedefs.h>
     46#define OMAP_IRC_IRQ_COUNT        AMDM37x_IRC_IRQ_COUNT
     47#define OMAP_IRC_IRQ_GROUPS_COUNT AMDM37x_IRC_IRQ_GROUPS_COUNT
    4648
    47 typedef struct {
    48         const ioport32_t revision; /**< Revision */
    49 #define AMDM37x_IRC_REV_MASK (0xff)
    50 
    51         uint8_t padd0_[12];
    52 
    53         ioport32_t sysconfig; /**< SYS config */
    54 #define AMDM37x_IRC_SYSCONFIG_AUTOIDLE_FLAG (1 << 0)
    55 #define AMDM37x_IRC_SYSCONFIG_SOFTRESET_FLAG (1 << 1)
    56 
    57         const ioport32_t sysstatus; /**< SYS status */
    58 #define AMDM37x_IRC_SYSSTATUS_RESET_DONE_FLAG (1 << 0)
    59 
    60         uint8_t padd1_[40];
    61 
    62         const ioport32_t sir_irq;   /**< Currently active irq number */
    63 #define AMDM37x_IRC_SIR_IRQ_ACTIVEIRQ_MASK (0x7f)
    64 #define AMDM37x_IRC_SIR_IRQ_SPURIOUSIRQFLAG_MASK (0xfffffff8)
    65 
    66         const ioport32_t sir_fiq;
    67 #define AMDM37x_IRC_SIR_FIQ_ACTIVEIRQ_MASK (0x7f)
    68 #define AMDM37x_IRC_SIR_FIQ_SPURIOUSIRQFLAG_MASK (0xfffffff8)
    69 
    70         ioport32_t control;   /**< New interrupt agreement. */
    71 #define AMDM37x_IRC_CONTROL_NEWIRQAGR_FLAG (1 << 0)
    72 #define AMDM37x_IRC_CONTROL_NEWFIQAGR_FLAG (1 << 1)
    73 
    74         ioport32_t protection;  /**< Protect other registers. */
    75 #define AMDM37x_IRC_PROTECTION_PROETCTION_FLAG (1 << 0)
    76 
    77         ioport32_t idle;   /**< Idle and autogating */
    78 #define AMDM37x_IRC_IDLE_FUNCIDLE_FLAG (1 << 0)
    79 #define AMDM37x_IRC_IDLE_TURBO_FLAG (1 << 1)
    80 
    81         uint8_t padd2_[12];
    82 
    83         ioport32_t irq_priority; /**< Active IRQ priority */
    84 #define AMDM37x_IRC_IRQ_PRIORITY_IRQPRIORITY_MASK (0x7f)
    85 #define AMDM37x_IRC_IRQ_PRIORITY_SPURIOUSIRQFLAG_MASK (0xfffffff8)
    86 
    87         ioport32_t fiq_priority; /**< Active FIQ priority */
    88 #define AMDM37x_IRC_FIQ_PRIORITY_FIQPRIORITY_MASK (0x7f)
    89 #define AMDM37x_IRC_FIQ_PRIORITY_SPURIOUSFIQFLAG_MASK (0xfffffff8)
    90 
    91         ioport32_t threshold; /**< Priority threshold */
    92 #define AMDM37x_IRC_THRESHOLD_PRIORITYTHRESHOLD_MASK (0xff)
    93 #define AMDM37x_IRC_THRESHOLD_PRIORITYTHRESHOLD_ENABLED (0x00)
    94 #define AMDM37x_IRC_THRESHOLD_PRIORITYTHRESHOLD_DISABLED (0xff)
    95 
    96         uint8_t padd3__[20];
    97 
    98         struct {
    99                 const ioport32_t itr;   /**< Interrupt input status before masking */
    100                 ioport32_t mir;   /**< Interrupt mask */
    101                 ioport32_t mir_clear; /**< Clear mir mask bits */
    102                 ioport32_t mir_set;   /**< Set mir mask bits */
    103                 ioport32_t isr_set;   /**< Set software interrupt bits */
    104                 ioport32_t isr_clear; /**< Clear software interrupt bits */
    105                 const ioport32_t pending_irq; /**< IRQ status after masking */
    106                 const ioport32_t pending_fiq; /**< FIQ status after masking */
    107         } interrupts[3];
    108 
    109         uint8_t padd4_[32];
    110 
    111         ioport32_t ilr[96];   /**< FIQ/IRQ steering */
    112 #define AMDM37x_IRC_ILR_FIQNIRQ (1 << 0)
    113 #define AMDM37x_IRC_ILR_PRIORITY_MASK (0x3f)
    114 #define AMDM37x_IRC_ILR_PRIORITY_SHIFT (2)
    115 
    116 } amdm37x_irc_regs_t;
    117 
    118 static inline void amdm37x_irc_dump(amdm37x_irc_regs_t *regs)
    119 {
    120 #define DUMP_REG(name) \
    121         printf("%s %p(%x).\n", #name, &regs->name, regs->name);
    122 
    123         DUMP_REG(revision);
    124         DUMP_REG(sysconfig);
    125         DUMP_REG(sysstatus);
    126         DUMP_REG(sir_irq);
    127         DUMP_REG(sir_fiq);
    128         DUMP_REG(control);
    129         DUMP_REG(protection);
    130         DUMP_REG(idle);
    131         DUMP_REG(irq_priority);
    132         DUMP_REG(fiq_priority);
    133         DUMP_REG(threshold);
    134 
    135         for (int i = 0; i < 3; ++i) {
    136                 DUMP_REG(interrupts[i].itr);
    137                 DUMP_REG(interrupts[i].mir);
    138                 DUMP_REG(interrupts[i].isr_set);
    139                 DUMP_REG(interrupts[i].pending_irq);
    140                 DUMP_REG(interrupts[i].pending_fiq);
    141         }
    142         for (int i = 0; i < AMDM37x_IRC_IRQ_COUNT; ++i) {
    143                 DUMP_REG(ilr[i]);
    144         }
    145 
    146 #undef DUMP_REG
    147 }
    148 
    149 static inline void amdm37x_irc_init(amdm37x_irc_regs_t *regs)
    150 {
    151         /* AMDM37x TRM sec 12.5.1 p. 2425 */
    152         /* Program system config register */
    153         //TODO enable this when you know the meaning
    154         //regs->sysconfig |= AMDM37x_IRC_SYSCONFIG_AUTOIDLE_FLAG;
    155 
    156         /* Program idle register */
    157         //TODO enable this when you know the meaning
    158         //regs->sysconfig |= AMDM37x_IRC_IDLE_TURBO_FLAG;
    159 
    160         /* Program ilr[m] assign priority, decide fiq */
    161         for (unsigned i = 0; i < AMDM37x_IRC_IRQ_COUNT; ++i) {
    162                 regs->ilr[i] = 0; /* highest prio(default) route to irq */
    163         }
    164 
    165         /* Disable all interrupts */
    166         regs->interrupts[0].mir_set = 0xffffffff;
    167         regs->interrupts[1].mir_set = 0xffffffff;
    168         regs->interrupts[2].mir_set = 0xffffffff;
    169 }
    170 
    171 static inline unsigned amdm37x_irc_inum_get(amdm37x_irc_regs_t *regs)
    172 {
    173         return regs->sir_irq & AMDM37x_IRC_SIR_IRQ_ACTIVEIRQ_MASK;
    174 }
    175 
    176 static inline void amdm37x_irc_irq_ack(amdm37x_irc_regs_t *regs)
    177 {
    178         regs->control = AMDM37x_IRC_CONTROL_NEWIRQAGR_FLAG;
    179 }
    180 
    181 static inline void amdm37x_irc_fiq_ack(amdm37x_irc_regs_t *regs)
    182 {
    183         regs->control = AMDM37x_IRC_CONTROL_NEWFIQAGR_FLAG;
    184 }
    185 
    186 static inline void amdm37x_irc_enable(amdm37x_irc_regs_t *regs, unsigned inum)
    187 {
    188         ASSERT(inum < AMDM37x_IRC_IRQ_COUNT);
    189         const unsigned set = inum / 32;
    190         const unsigned pos = inum % 32;
    191         regs->interrupts[set].mir_clear = (1 << pos);
    192 }
    193 
    194 static inline void amdm37x_irc_disable(amdm37x_irc_regs_t *regs, unsigned inum)
    195 {
    196         ASSERT(inum < AMDM37x_IRC_IRQ_COUNT);
    197         const unsigned set = inum / 32;
    198         const unsigned pos = inum % 32;
    199         regs->interrupts[set].mir_set = (1 << pos);
    200 }
     49#include <genarch/drivers/omap/irc.h>
    20150
    20251#endif
  • kernel/genarch/include/genarch/mm/page_pt.h

    rf7a33de r0c2d9bb  
    5858#define PTL3_ENTRIES  PTL3_ENTRIES_ARCH
    5959
    60 /* Table sizes in each level */
    61 #define PTL0_SIZE  PTL0_SIZE_ARCH
    62 #define PTL1_SIZE  PTL1_SIZE_ARCH
    63 #define PTL2_SIZE  PTL2_SIZE_ARCH
    64 #define PTL3_SIZE  PTL3_SIZE_ARCH
     60/* Table sizes in each level (in frames) */
     61#define PTL0_FRAMES  PTL0_FRAMES_ARCH
     62#define PTL1_FRAMES  PTL1_FRAMES_ARCH
     63#define PTL2_FRAMES  PTL2_FRAMES_ARCH
     64#define PTL3_FRAMES  PTL3_FRAMES_ARCH
     65
     66/* Table sizes in each level (in bytes) */
     67#define PTL0_SIZE  FRAMES2SIZE(PTL0_FRAMES)
     68#define PTL1_SIZE  FRAMES2SIZE(PTL1_FRAMES)
     69#define PTL2_SIZE  FRAMES2SIZE(PTL2_FRAMES)
     70#define PTL3_SIZE  FRAMES2SIZE(PTL3_FRAMES)
    6571
    6672/*
  • kernel/genarch/src/mm/as_pt.c

    rf7a33de r0c2d9bb  
    7373pte_t *ptl0_create(unsigned int flags)
    7474{
    75         pte_t *dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE,
    76             FRAME_LOWMEM | FRAME_KA);
    77         size_t table_size = FRAME_SIZE << PTL0_SIZE;
     75        pte_t *dst_ptl0 = (pte_t *)
     76            PA2KA(frame_alloc(PTL0_FRAMES, FRAME_LOWMEM, PTL0_SIZE - 1));
    7877       
    7978        if (flags & FLAG_AS_KERNEL)
    80                 memsetb(dst_ptl0, table_size, 0);
     79                memsetb(dst_ptl0, PTL0_SIZE, 0);
    8180        else {
    8281                /*
    8382                 * Copy the kernel address space portion to new PTL0.
    84                  *
    8583                 */
    8684               
     
    9593                    &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
    9694               
    97                 memsetb(dst_ptl0, table_size, 0);
     95                memsetb(dst_ptl0, PTL0_SIZE, 0);
    9896                memcpy((void *) dst, (void *) src,
    99                     table_size - (src - (uintptr_t) src_ptl0));
     97                    PTL0_SIZE - (src - (uintptr_t) src_ptl0));
    10098               
    10199                mutex_unlock(&AS_KERNEL->lock);
     
    114112void ptl0_destroy(pte_t *page_table)
    115113{
    116         frame_free((uintptr_t) page_table);
     114        frame_free((uintptr_t) page_table, PTL0_FRAMES);
    117115}
    118116
  • kernel/genarch/src/mm/page_pt.c

    rf7a33de r0c2d9bb  
    7777    unsigned int flags)
    7878{
    79         //printf("pt_mapping_insert: as=%p, page=0x%08x, frame=0x%08x\n", as, page, frame);
    80 
    8179        pte_t *ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    8280
    83         //printf("ptl0 = %p\n", ptl0);
    84 
    8581        ASSERT(page_table_locked(as));
    86 
     82       
    8783        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
    88         //      printf("allocating ptl1\n");
    89 
    90                 pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE,
    91                     FRAME_LOWMEM | FRAME_KA);
    92 
    93         //      printf("newpt = %p, index = %d\n", newpt, PTL0_INDEX(page));
    94 
    95                 memsetb(newpt, FRAME_SIZE << PTL1_SIZE, 0);
     84                pte_t *newpt = (pte_t *)
     85                    PA2KA(frame_alloc(PTL1_FRAMES, FRAME_LOWMEM, PTL1_SIZE - 1));
     86                memsetb(newpt, PTL1_SIZE, 0);
    9687                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
    9788                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page),
     
    109100        pte_t *ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    110101       
    111 //      printf("ptl1 = %p\n", ptl1);
    112 
    113102        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
    114 //              printf("allocating ptl2\n");
    115 
    116                 pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE,
    117                     FRAME_LOWMEM | FRAME_KA);
    118 
    119 //              printf("newpt = %p, index = %d\n", newpt, PTL1_INDEX(page));
    120 
    121                 memsetb(newpt, FRAME_SIZE << PTL2_SIZE, 0);
     103                pte_t *newpt = (pte_t *)
     104                    PA2KA(frame_alloc(PTL2_FRAMES, FRAME_LOWMEM, PTL2_SIZE - 1));
     105                memsetb(newpt, PTL2_SIZE, 0);
    122106                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
    123107                SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page),
     
    133117        pte_t *ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    134118       
    135 //      printf("ptl2 = %p\n", ptl2);
    136 
    137119        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
    138 //              printf("allocating ptl3\n");
    139 
    140                 pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE,
    141                     FRAME_LOWMEM | FRAME_KA);
    142 
    143 //              printf("newpt = %p, index = %d\n", newpt, PTL2_INDEX(page));
    144 
    145                 memsetb(newpt, FRAME_SIZE << PTL3_SIZE, 0);
     120                pte_t *newpt = (pte_t *)
     121                    PA2KA(frame_alloc(PTL3_FRAMES, FRAME_LOWMEM, PTL2_SIZE - 1));
     122                memsetb(newpt, PTL2_SIZE, 0);
    146123                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
    147124                SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page),
     
    157134        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
    158135       
    159 //      printf("ptl3 = %p\n", ptl3);
    160 
    161136        SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(page), frame);
    162137        SET_FRAME_FLAGS(ptl3, PTL3_INDEX(page), flags | PAGE_NOT_PRESENT);
     
    244219                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    245220#endif
    246                 frame_free(KA2PA((uintptr_t) ptl3));
     221                frame_free(KA2PA((uintptr_t) ptl3), PTL3_FRAMES);
    247222        } else {
    248223                /*
     
    278253                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    279254#endif
    280                 frame_free(KA2PA((uintptr_t) ptl2));
     255                frame_free(KA2PA((uintptr_t) ptl2), PTL2_FRAMES);
    281256        } else {
    282257                /*
     
    309284
    310285                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    311                 frame_free(KA2PA((uintptr_t) ptl1));
     286                frame_free(KA2PA((uintptr_t) ptl1), PTL1_FRAMES);
    312287        }
    313288#endif /* PTL1_ENTRIES != 0 */
     
    388363 * @param size Size in bytes defining the range of PTL0 entries that will be
    389364 *             altered by this function.
     365 *
    390366 */
    391367void pt_mapping_make_global(uintptr_t base, size_t size)
    392368{
     369        ASSERT(size > 0);
     370       
    393371        uintptr_t ptl0 = PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
    394372        uintptr_t ptl0_step = ptl0_step_get();
    395         size_t order;
    396         uintptr_t addr;
    397 
     373        size_t frames;
     374       
    398375#if (PTL1_ENTRIES != 0)
    399         order = PTL1_SIZE;
     376        frames = PTL1_FRAMES;
    400377#elif (PTL2_ENTRIES != 0)
    401         order = PTL2_SIZE;
     378        frames = PTL2_FRAMES;
    402379#else
    403         order = PTL3_SIZE;
    404 #endif
    405 
    406         ASSERT(size > 0);
    407 
    408         for (addr = ALIGN_DOWN(base, ptl0_step); addr - 1 < base + size - 1;
     380        frames = PTL3_FRAMES;
     381#endif
     382       
     383        for (uintptr_t addr = ALIGN_DOWN(base, ptl0_step);
     384            addr - 1 < base + size - 1;
    409385            addr += ptl0_step) {
    410                 uintptr_t l1;
    411 
    412                 l1 = (uintptr_t) frame_alloc(order, FRAME_KA | FRAME_LOWMEM);
    413                 memsetb((void *) l1, FRAME_SIZE << order, 0);
     386                uintptr_t l1 = PA2KA(frame_alloc(frames, FRAME_LOWMEM, 0));
     387                memsetb((void *) l1, FRAMES2SIZE(frames), 0);
    414388                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(addr), KA2PA(l1));
    415389                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(addr),
Note: See TracChangeset for help on using the changeset viewer.