paul@68 | 1 | /* |
paul@68 | 2 | * Interrupt handling. |
paul@68 | 3 | * |
paul@121 | 4 | * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@68 | 5 | * |
paul@68 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@68 | 7 | * it under the terms of the GNU General Public License as published by |
paul@68 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@68 | 9 | * (at your option) any later version. |
paul@68 | 10 | * |
paul@68 | 11 | * This program is distributed in the hope that it will be useful, |
paul@68 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@68 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@68 | 14 | * GNU General Public License for more details. |
paul@68 | 15 | * |
paul@68 | 16 | * You should have received a copy of the GNU General Public License |
paul@68 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@68 | 18 | */ |
paul@68 | 19 | |
paul@108 | 20 | #ifdef CONFIG_CPU_JZ4730_MINIPC |
paul@108 | 21 | #include "minipc.h" |
paul@108 | 22 | #else |
paul@108 | 23 | #include "nanonote.h" |
paul@108 | 24 | #endif |
paul@108 | 25 | |
paul@68 | 26 | #include "board-specific.h" |
paul@68 | 27 | #include "board.h" |
paul@68 | 28 | #include "lcd.h" |
paul@68 | 29 | #include "jzlcd.h" |
paul@68 | 30 | #include "cpu.h" |
paul@121 | 31 | #include "irq.h" |
paul@68 | 32 | |
paul@68 | 33 | extern vidinfo_t panel_info; |
paul@68 | 34 | |
paul@121 | 35 | void next_pixel(unsigned short *x, unsigned short *y) |
paul@68 | 36 | { |
paul@121 | 37 | (*x)++; |
paul@121 | 38 | if (*x >= panel_info.vl_col) { |
paul@121 | 39 | *x = 0; |
paul@121 | 40 | (*y)++; |
paul@121 | 41 | if (*y >= panel_info.vl_row) |
paul@121 | 42 | *y = 0; |
paul@68 | 43 | } |
paul@68 | 44 | } |
paul@68 | 45 | |
paul@132 | 46 | /* Task management. */ |
paul@132 | 47 | |
paul@132 | 48 | const u32 stack_start = 0x00080000; |
paul@132 | 49 | const u32 stack_size = 0x00002000; |
paul@132 | 50 | const u32 pagesize = 4 * 1024; |
paul@132 | 51 | const u32 framesize = 120; /* see the handlers */ |
paul@132 | 52 | |
paul@68 | 53 | /* Tasks. */ |
paul@68 | 54 | |
paul@121 | 55 | void plot_pattern(unsigned short pixel_type, unsigned short x, unsigned short y) |
paul@68 | 56 | { |
paul@68 | 57 | while (1) { |
paul@68 | 58 | if (pixel_type) |
paul@68 | 59 | test_pixel(x, y); |
paul@68 | 60 | else |
paul@68 | 61 | clear_pixel(x, y); |
paul@121 | 62 | next_pixel(&x, &y); |
paul@68 | 63 | udelay(100); |
paul@68 | 64 | } |
paul@68 | 65 | } |
paul@68 | 66 | |
paul@68 | 67 | /* Initialisation and handling. */ |
paul@68 | 68 | |
paul@68 | 69 | void irq_init() |
paul@68 | 70 | { |
paul@68 | 71 | timer_init_irq(); |
paul@84 | 72 | init_interrupts(); |
paul@86 | 73 | enable_interrupts(); |
paul@68 | 74 | } |
paul@68 | 75 | |
paul@68 | 76 | void irq_handle() |
paul@68 | 77 | { |
paul@68 | 78 | unsigned short i; |
paul@68 | 79 | |
paul@68 | 80 | /* Check interrupt identity. */ |
paul@68 | 81 | |
paul@68 | 82 | if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { |
paul@68 | 83 | |
paul@68 | 84 | /* Update the pixel type. */ |
paul@68 | 85 | |
paul@121 | 86 | /* pixel_type = __gpio_get_pin(GPIO_POWER); */ |
paul@68 | 87 | |
paul@68 | 88 | /* Clear interrupt status. */ |
paul@68 | 89 | |
paul@68 | 90 | __intc_ack_irq(TIMER_CHAN_IRQ); |
paul@68 | 91 | __tcu_clear_full_match_flag(TIMER_CHAN); |
paul@68 | 92 | |
paul@68 | 93 | /* Handle other interrupts, anyway. */ |
paul@68 | 94 | |
paul@68 | 95 | } else { |
paul@68 | 96 | for (i = 0; i < 32; i++) { |
paul@68 | 97 | if (REG_INTC_IPR & (1 << i)) |
paul@68 | 98 | __intc_ack_irq(i); |
paul@68 | 99 | } |
paul@68 | 100 | } |
paul@68 | 101 | } |
paul@68 | 102 | |
paul@68 | 103 | void start_task() |
paul@68 | 104 | { |
paul@125 | 105 | /* enter_user_mode(); */ |
paul@121 | 106 | plot_pattern(1, 0, 0); |
paul@68 | 107 | } |
paul@118 | 108 | |
paul@118 | 109 | void tlb_handle() |
paul@118 | 110 | { |
paul@132 | 111 | u32 asid, virtual, physical, bottom, top; |
paul@118 | 112 | |
paul@118 | 113 | /* Obtain the bad virtual address. */ |
paul@118 | 114 | |
paul@118 | 115 | asm volatile( |
paul@131 | 116 | "mfc0 %0, $10\n" /* CP0_ENTRYHI */ |
paul@131 | 117 | "nop\n" |
paul@131 | 118 | : "=r" (virtual) |
paul@118 | 119 | ); |
paul@131 | 120 | |
paul@118 | 121 | /* Obtain a virtual address region with 8KB resolution. */ |
paul@131 | 122 | |
paul@131 | 123 | asid = virtual & 0xff; |
paul@131 | 124 | virtual = virtual & 0xffffe000; |
paul@131 | 125 | |
paul@132 | 126 | /* The appropriate physical address depends on the current task. */ |
paul@132 | 127 | |
paul@132 | 128 | bottom = (stack_start - stack_size) & 0xffffe000; |
paul@132 | 129 | top = stack_start & 0xffffe000; |
paul@118 | 130 | |
paul@132 | 131 | if ((asid != 0) && (virtual >= bottom) && (virtual < top)) |
paul@132 | 132 | physical = virtual + asid * stack_size; |
paul@132 | 133 | else |
paul@132 | 134 | physical = virtual; |
paul@118 | 135 | |
paul@118 | 136 | /* |
paul@118 | 137 | Request a physical region mapping two 4KB pages. |
paul@118 | 138 | Pages employ C=3, dirty, valid, with the task number as the ASID. |
paul@118 | 139 | */ |
paul@131 | 140 | |
paul@132 | 141 | map_page(virtual, physical, pagesize, 0x1e, asid); |
paul@131 | 142 | } |