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@68 | 46 | /* Tasks. */ |
paul@68 | 47 | |
paul@121 | 48 | void plot_pattern(unsigned short pixel_type, unsigned short x, unsigned short y) |
paul@68 | 49 | { |
paul@68 | 50 | while (1) { |
paul@68 | 51 | if (pixel_type) |
paul@68 | 52 | test_pixel(x, y); |
paul@68 | 53 | else |
paul@68 | 54 | clear_pixel(x, y); |
paul@121 | 55 | next_pixel(&x, &y); |
paul@68 | 56 | udelay(100); |
paul@68 | 57 | } |
paul@68 | 58 | } |
paul@68 | 59 | |
paul@68 | 60 | /* Initialisation and handling. */ |
paul@68 | 61 | |
paul@68 | 62 | void irq_init() |
paul@68 | 63 | { |
paul@68 | 64 | timer_init_irq(); |
paul@84 | 65 | handle_error_level(); |
paul@84 | 66 | init_interrupts(); |
paul@86 | 67 | enable_interrupts(); |
paul@68 | 68 | } |
paul@68 | 69 | |
paul@68 | 70 | void irq_handle() |
paul@68 | 71 | { |
paul@68 | 72 | unsigned short i; |
paul@68 | 73 | |
paul@68 | 74 | /* Check interrupt identity. */ |
paul@68 | 75 | |
paul@68 | 76 | if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { |
paul@68 | 77 | |
paul@68 | 78 | /* Update the pixel type. */ |
paul@68 | 79 | |
paul@121 | 80 | /* pixel_type = __gpio_get_pin(GPIO_POWER); */ |
paul@68 | 81 | |
paul@68 | 82 | /* Clear interrupt status. */ |
paul@68 | 83 | |
paul@68 | 84 | __intc_ack_irq(TIMER_CHAN_IRQ); |
paul@68 | 85 | __tcu_clear_full_match_flag(TIMER_CHAN); |
paul@68 | 86 | |
paul@68 | 87 | /* Handle other interrupts, anyway. */ |
paul@68 | 88 | |
paul@68 | 89 | } else { |
paul@68 | 90 | for (i = 0; i < 32; i++) { |
paul@68 | 91 | if (REG_INTC_IPR & (1 << i)) |
paul@68 | 92 | __intc_ack_irq(i); |
paul@68 | 93 | } |
paul@68 | 94 | } |
paul@68 | 95 | } |
paul@68 | 96 | |
paul@68 | 97 | void start_task() |
paul@68 | 98 | { |
paul@115 | 99 | enter_user_mode(); |
paul@121 | 100 | plot_pattern(1, 0, 0); |
paul@68 | 101 | } |
paul@118 | 102 | |
paul@118 | 103 | void tlb_handle() |
paul@118 | 104 | { |
paul@118 | 105 | u32 context, virtual, physical; |
paul@118 | 106 | |
paul@118 | 107 | /* Obtain the bad virtual address. */ |
paul@118 | 108 | |
paul@118 | 109 | asm volatile( |
paul@118 | 110 | "mfc0 %0, $4\n" /* CP0_CONTEXT */ |
paul@118 | 111 | : "=r" (context) |
paul@118 | 112 | ); |
paul@118 | 113 | |
paul@118 | 114 | /* Obtain a virtual address region with 8KB resolution. */ |
paul@118 | 115 | |
paul@118 | 116 | virtual = (context & 0x007ffff0) << 9; |
paul@118 | 117 | |
paul@118 | 118 | /* The appropriate physical address depends on the current task. */ |
paul@118 | 119 | |
paul@118 | 120 | physical = virtual; |
paul@118 | 121 | |
paul@118 | 122 | /* |
paul@118 | 123 | Request a physical region mapping two 4KB pages. |
paul@118 | 124 | Pages employ C=3, dirty, valid, with the task number as the ASID. |
paul@118 | 125 | */ |
paul@118 | 126 | |
paul@118 | 127 | map_page(virtual, physical, 4 * 1024, 0x1f, 0); |
paul@118 | 128 | } |