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 | init_interrupts(); |
paul@86 | 66 | enable_interrupts(); |
paul@68 | 67 | } |
paul@68 | 68 | |
paul@68 | 69 | void irq_handle() |
paul@68 | 70 | { |
paul@68 | 71 | unsigned short i; |
paul@68 | 72 | |
paul@68 | 73 | /* Check interrupt identity. */ |
paul@68 | 74 | |
paul@68 | 75 | if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { |
paul@68 | 76 | |
paul@68 | 77 | /* Update the pixel type. */ |
paul@68 | 78 | |
paul@121 | 79 | /* pixel_type = __gpio_get_pin(GPIO_POWER); */ |
paul@68 | 80 | |
paul@68 | 81 | /* Clear interrupt status. */ |
paul@68 | 82 | |
paul@68 | 83 | __intc_ack_irq(TIMER_CHAN_IRQ); |
paul@68 | 84 | __tcu_clear_full_match_flag(TIMER_CHAN); |
paul@68 | 85 | |
paul@68 | 86 | /* Handle other interrupts, anyway. */ |
paul@68 | 87 | |
paul@68 | 88 | } else { |
paul@68 | 89 | for (i = 0; i < 32; i++) { |
paul@68 | 90 | if (REG_INTC_IPR & (1 << i)) |
paul@68 | 91 | __intc_ack_irq(i); |
paul@68 | 92 | } |
paul@68 | 93 | } |
paul@68 | 94 | } |
paul@68 | 95 | |
paul@68 | 96 | void start_task() |
paul@68 | 97 | { |
paul@125 | 98 | /* enter_user_mode(); */ |
paul@121 | 99 | plot_pattern(1, 0, 0); |
paul@68 | 100 | } |
paul@118 | 101 | |
paul@118 | 102 | void tlb_handle() |
paul@118 | 103 | { |
paul@131 | 104 | u32 asid, virtual, physical; |
paul@118 | 105 | |
paul@118 | 106 | /* Obtain the bad virtual address. */ |
paul@118 | 107 | |
paul@118 | 108 | asm volatile( |
paul@131 | 109 | "mfc0 %0, $10\n" /* CP0_ENTRYHI */ |
paul@131 | 110 | "nop\n" |
paul@131 | 111 | : "=r" (virtual) |
paul@118 | 112 | ); |
paul@131 | 113 | |
paul@118 | 114 | /* Obtain a virtual address region with 8KB resolution. */ |
paul@131 | 115 | |
paul@131 | 116 | asid = virtual & 0xff; |
paul@131 | 117 | virtual = virtual & 0xffffe000; |
paul@131 | 118 | |
paul@131 | 119 | /* The appropriate physical address should depend on the current task. */ |
paul@118 | 120 | |
paul@118 | 121 | physical = virtual; |
paul@118 | 122 | |
paul@118 | 123 | /* |
paul@118 | 124 | Request a physical region mapping two 4KB pages. |
paul@118 | 125 | Pages employ C=3, dirty, valid, with the task number as the ASID. |
paul@118 | 126 | */ |
paul@131 | 127 | |
paul@131 | 128 | map_page(virtual, physical, 4 * 1024, 0x1e, asid); |
paul@131 | 129 | } |