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 "paging.h" 32 #include "irq.h" 33 34 extern vidinfo_t panel_info; 35 36 void next_pixel(unsigned short *x, unsigned short *y) 37 { 38 (*x)++; 39 if (*x >= panel_info.vl_col) { 40 *x = 0; 41 (*y)++; 42 if (*y >= panel_info.vl_row) 43 *y = 0; 44 } 45 } 46 47 /* Task management. */ 48 49 enum { max_tasks = 3 }; 50 static u32 stack_pointers[max_tasks]; 51 static u32 registers[max_tasks][32]; 52 53 u8 current_task; 54 u32 *current_stack_pointer; 55 u32 *current_registers; 56 57 extern u32 _got_copy_start; 58 59 const u32 stack_start = 0x00080000; 60 const u32 stack_size = 0x00002000; 61 const u32 pagesize = 4 * 1024; 62 63 /* Tasks. */ 64 65 void plot_pattern(unsigned short pixel_type, unsigned short x, unsigned short y) 66 { 67 while (1) { 68 if (pixel_type) 69 test_pixel(x, y, pixel_type); 70 else 71 clear_pixel(x, y); 72 next_pixel(&x, &y); 73 udelay(100); 74 } 75 } 76 77 /* Initialisation and handling. */ 78 79 void irq_init() 80 { 81 handle_error_level(); 82 timer_init_irq(); 83 init_interrupts(); 84 } 85 86 void irq_handle() 87 { 88 unsigned short i; 89 90 /* Check interrupt identity. */ 91 92 if (REG_INTC_IPR & (1 << TIMER_CHAN_IRQ)) { 93 94 /* Switch task. */ 95 96 switch_task(); 97 98 /* Clear interrupt status. */ 99 100 __intc_ack_irq(TIMER_CHAN_IRQ); 101 __tcu_clear_full_match_flag(TIMER_CHAN); 102 103 /* Handle other interrupts, anyway. */ 104 105 } else { 106 for (i = 0; i < 32; i++) { 107 if (REG_INTC_IPR & (1 << i)) 108 __intc_ack_irq(i); 109 } 110 } 111 } 112 113 void init_tasks() 114 { 115 current_task = 0; 116 current_stack_pointer = &stack_pointers[current_task]; 117 current_registers = registers[current_task]; 118 } 119 120 void start_task(unsigned short task) 121 { 122 u32 args[] = {task, 0, (task - 1) * 60}; 123 u32 virtual, physical; 124 125 /* 126 Each task employs a stack at a multiple of the given start address in 127 physical memory, but at the same address in virtual memory. 128 */ 129 130 virtual = stack_start; 131 physical = stack_start - stack_size * task; 132 133 init_page_table(page_table_start, virtual - pagesize * 2, physical - pagesize * 2, pagesize, 0x1e, task); 134 135 stack_pointers[task] = virtual - 12; 136 137 /* 138 Set the registers for the new task, initialising the global pointer and 139 return address. 140 */ 141 142 init_registers(registers[task], _got_copy_start, (void (*)()) plot_pattern, args, 3); 143 } 144 145 void switch_task() 146 { 147 /* Switch the current task. */ 148 149 current_task++; 150 if (current_task == max_tasks) current_task = 0; 151 152 /* Indicate the current stack pointer and task registers. */ 153 154 current_stack_pointer = &stack_pointers[current_task]; 155 current_registers = registers[current_task]; 156 }