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