Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Nicolas Pennequin | 396aeaf | 2009-03-23 17:08:46 +0000 | [diff] [blame] | 10 | * Copyright (C) 2002 by Björn Stenberg |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #ifndef _KERNEL_H_ |
| 22 | #define _KERNEL_H_ |
| 23 | |
Björn Stenberg | 29f8028 | 2002-05-23 09:22:07 +0000 | [diff] [blame] | 24 | #include <stdbool.h> |
Michael Sevakis | 4b90267 | 2006-12-19 16:50:07 +0000 | [diff] [blame] | 25 | #include <inttypes.h> |
Dave Chapman | 77372d1 | 2005-11-07 23:07:19 +0000 | [diff] [blame] | 26 | #include "config.h" |
Björn Stenberg | 29f8028 | 2002-05-23 09:22:07 +0000 | [diff] [blame] | 27 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 28 | #include "thread.h" |
| 29 | |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 30 | /* wrap-safe macros for tick comparison */ |
| 31 | #define TIME_AFTER(a,b) ((long)(b) - (long)(a) < 0) |
| 32 | #define TIME_BEFORE(a,b) TIME_AFTER(b,a) |
| 33 | |
| 34 | #define HZ 100 /* number of ticks per second */ |
| 35 | |
Jens Arnold | fed2c56 | 2005-11-23 08:51:48 +0000 | [diff] [blame] | 36 | #define MAX_NUM_TICK_TASKS 8 |
Linus Nielsen Feltzing | 150c5a7 | 2002-06-04 12:25:53 +0000 | [diff] [blame] | 37 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 38 | #define MAX_NUM_QUEUES 32 |
Linus Nielsen Feltzing | bd2561d | 2002-04-29 14:25:44 +0000 | [diff] [blame] | 39 | #define QUEUE_LENGTH 16 /* MUST be a power of 2 */ |
| 40 | #define QUEUE_LENGTH_MASK (QUEUE_LENGTH - 1) |
| 41 | |
Michael Sevakis | 58fc279 | 2007-07-28 08:12:05 +0000 | [diff] [blame] | 42 | /* System defined message ID's - |sign bit = 1|class|id| */ |
| 43 | /* Event class list */ |
| 44 | #define SYS_EVENT_CLS_QUEUE 0 |
| 45 | #define SYS_EVENT_CLS_USB 1 |
| 46 | #define SYS_EVENT_CLS_POWER 2 |
| 47 | #define SYS_EVENT_CLS_FILESYS 3 |
| 48 | #define SYS_EVENT_CLS_PLUG 4 |
Michael Sevakis | 0107dfc | 2007-09-09 01:59:07 +0000 | [diff] [blame] | 49 | #define SYS_EVENT_CLS_MISC 5 |
Michael Sevakis | adf2e4c | 2008-05-28 10:17:16 +0000 | [diff] [blame] | 50 | #define SYS_EVENT_CLS_PRIVATE 7 /* For use inside plugins */ |
Michael Sevakis | 58fc279 | 2007-07-28 08:12:05 +0000 | [diff] [blame] | 51 | /* make sure SYS_EVENT_CLS_BITS has enough range */ |
| 52 | |
Michael Sevakis | 5832b59 | 2007-07-28 08:45:57 +0000 | [diff] [blame] | 53 | /* Bit 31->|S|c...c|i...i| */ |
| 54 | #define SYS_EVENT ((long)(int)(1 << 31)) |
Michael Sevakis | 58fc279 | 2007-07-28 08:12:05 +0000 | [diff] [blame] | 55 | #define SYS_EVENT_CLS_BITS (3) |
Michael Sevakis | 5832b59 | 2007-07-28 08:45:57 +0000 | [diff] [blame] | 56 | #define SYS_EVENT_CLS_SHIFT (31-SYS_EVENT_CLS_BITS) |
Michael Sevakis | 58fc279 | 2007-07-28 08:12:05 +0000 | [diff] [blame] | 57 | #define SYS_EVENT_CLS_MASK (((1l << SYS_EVENT_CLS_BITS)-1) << SYS_EVENT_SHIFT) |
| 58 | #define MAKE_SYS_EVENT(cls, id) (SYS_EVENT | ((long)(cls) << SYS_EVENT_CLS_SHIFT) | (long)(id)) |
| 59 | /* Macros for extracting codes */ |
| 60 | #define SYS_EVENT_CLS(e) (((e) & SYS_EVENT_CLS_MASK) >> SYS_EVENT_SHIFT) |
| 61 | #define SYS_EVENT_ID(e) ((e) & ~(SYS_EVENT|SYS_EVENT_CLS_MASK)) |
| 62 | |
| 63 | #define SYS_TIMEOUT MAKE_SYS_EVENT(SYS_EVENT_CLS_QUEUE, 0) |
| 64 | #define SYS_USB_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 0) |
| 65 | #define SYS_USB_CONNECTED_ACK MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 1) |
| 66 | #define SYS_USB_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 2) |
Frank Gevaerts | b6a1af2 | 2009-02-28 14:47:18 +0000 | [diff] [blame] | 67 | #define SYS_USB_LUN_LOCKED MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 4) |
Frank Gevaerts | 3b141d9 | 2009-02-28 16:25:07 +0000 | [diff] [blame] | 68 | #define SYS_USB_READ_DATA MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 5) |
| 69 | #define SYS_USB_WRITE_DATA MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 6) |
Michael Sevakis | 58fc279 | 2007-07-28 08:12:05 +0000 | [diff] [blame] | 70 | #define SYS_POWEROFF MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 0) |
| 71 | #define SYS_CHARGER_CONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1) |
| 72 | #define SYS_CHARGER_DISCONNECTED MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2) |
Stéphane Doyon | da93299 | 2007-11-03 05:00:49 +0000 | [diff] [blame] | 73 | #define SYS_BATTERY_UPDATE MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 3) |
Michael Sevakis | 58fc279 | 2007-07-28 08:12:05 +0000 | [diff] [blame] | 74 | #define SYS_FS_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_FILESYS, 0) |
| 75 | #define SYS_HOTSWAP_INSERTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 0) |
| 76 | #define SYS_HOTSWAP_EXTRACTED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 1) |
| 77 | #define SYS_PHONE_PLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 2) |
| 78 | #define SYS_PHONE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 3) |
| 79 | #define SYS_REMOTE_PLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 4) |
| 80 | #define SYS_REMOTE_UNPLUGGED MAKE_SYS_EVENT(SYS_EVENT_CLS_PLUG, 5) |
Jens Arnold | 3e67e3b | 2009-02-20 17:13:08 +0000 | [diff] [blame] | 81 | #define SYS_CAR_ADAPTER_RESUME MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 0) |
| 82 | #define SYS_IAP_PERIODIC MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 1) |
| 83 | #define SYS_IAP_HANDLEPKT MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 2) |
Thomas Martitz | ca4439f | 2010-08-07 21:30:22 +0000 | [diff] [blame] | 84 | #define SYS_CALL_INCOMING MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 3) |
| 85 | #define SYS_CALL_HUNG_UP MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 4) |
Björn Stenberg | e50cc0e | 2011-03-14 12:25:48 +0000 | [diff] [blame] | 86 | #define SYS_VOLUME_CHANGED MAKE_SYS_EVENT(SYS_EVENT_CLS_MISC, 5) |
Jens Arnold | f5bdf69 | 2004-10-10 00:35:19 +0000 | [diff] [blame] | 87 | |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 88 | #define IS_SYSEVENT(ev) ((ev & SYS_EVENT) == SYS_EVENT) |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame^] | 89 | #define EVENT_RESERVED (~0) |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 90 | |
Michael Sevakis | bc192c9 | 2008-03-30 04:59:51 +0000 | [diff] [blame] | 91 | #ifndef TIMEOUT_BLOCK |
| 92 | #define TIMEOUT_BLOCK -1 |
| 93 | #define TIMEOUT_NOBLOCK 0 |
| 94 | #endif |
| 95 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 96 | struct queue_event |
Linus Nielsen Feltzing | bd2561d | 2002-04-29 14:25:44 +0000 | [diff] [blame] | 97 | { |
Michael Sevakis | 4b90267 | 2006-12-19 16:50:07 +0000 | [diff] [blame] | 98 | long id; |
| 99 | intptr_t data; |
Linus Nielsen Feltzing | bd2561d | 2002-04-29 14:25:44 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 102 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 103 | struct queue_sender_list |
| 104 | { |
| 105 | /* If non-NULL, there is a thread waiting for the corresponding event */ |
Michael Sevakis | 0caf3b8 | 2007-03-21 22:58:53 +0000 | [diff] [blame] | 106 | /* Must be statically allocated to put in non-cached ram. */ |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 107 | struct thread_entry *senders[QUEUE_LENGTH]; /* message->thread map */ |
| 108 | struct thread_entry *list; /* list of senders in map */ |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 109 | /* Send info for last message dequeued or NULL if replied or not sent */ |
Michael Sevakis | 7b4eb44 | 2010-12-27 10:05:09 +0000 | [diff] [blame] | 110 | struct thread_entry * volatile curr_sender; |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 111 | #ifdef HAVE_PRIORITY_SCHEDULING |
| 112 | struct blocker blocker; |
| 113 | #endif |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 114 | }; |
| 115 | #endif /* HAVE_EXTENDED_MESSAGING_AND_NAME */ |
| 116 | |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 117 | #ifdef HAVE_PRIORITY_SCHEDULING |
| 118 | #define QUEUE_GET_THREAD(q) \ |
| 119 | (((q)->send == NULL) ? NULL : (q)->send->blocker.thread) |
| 120 | #else |
| 121 | /* Queue without priority enabled have no owner provision _at this time_ */ |
| 122 | #define QUEUE_GET_THREAD(q) \ |
| 123 | (NULL) |
| 124 | #endif |
| 125 | |
Linus Nielsen Feltzing | bd2561d | 2002-04-29 14:25:44 +0000 | [diff] [blame] | 126 | struct event_queue |
| 127 | { |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 128 | struct thread_entry *queue; /* waiter list */ |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 129 | struct queue_event events[QUEUE_LENGTH]; /* list of events */ |
Michael Sevakis | 7b4eb44 | 2010-12-27 10:05:09 +0000 | [diff] [blame] | 130 | unsigned int volatile read; /* head of queue */ |
| 131 | unsigned int volatile write; /* tail of queue */ |
Michael Sevakis | 8b49700 | 2006-12-16 18:41:45 +0000 | [diff] [blame] | 132 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME |
Michael Sevakis | 7b4eb44 | 2010-12-27 10:05:09 +0000 | [diff] [blame] | 133 | struct queue_sender_list * volatile send; /* list of threads waiting for |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 134 | reply to an event */ |
| 135 | #ifdef HAVE_PRIORITY_SCHEDULING |
| 136 | struct blocker *blocker_p; /* priority inheritance info |
| 137 | for sync message senders */ |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 138 | #endif |
Michael Sevakis | 8b49700 | 2006-12-16 18:41:45 +0000 | [diff] [blame] | 139 | #endif |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 140 | IF_COP( struct corelock cl; ) /* multiprocessor sync */ |
Linus Nielsen Feltzing | bd2561d | 2002-04-29 14:25:44 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Linus Nielsen Feltzing | 7361340 | 2002-05-16 20:57:32 +0000 | [diff] [blame] | 143 | struct mutex |
| 144 | { |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 145 | struct thread_entry *queue; /* waiter list */ |
Michael Sevakis | f387cde | 2010-12-26 05:59:39 +0000 | [diff] [blame] | 146 | int recursion; /* lock owner recursion count */ |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 147 | #ifdef HAVE_PRIORITY_SCHEDULING |
| 148 | struct blocker blocker; /* priority inheritance info |
| 149 | for waiters */ |
| 150 | bool no_preempt; /* don't allow higher-priority thread |
| 151 | to be scheduled even if woken */ |
| 152 | #else |
Michael Sevakis | f387cde | 2010-12-26 05:59:39 +0000 | [diff] [blame] | 153 | struct thread_entry *thread; /* Indicates owner thread - an owner |
| 154 | implies a locked state - same goes |
| 155 | for priority scheduling |
| 156 | (in blocker struct for that) */ |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 157 | #endif |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 158 | IF_COP( struct corelock cl; ) /* multiprocessor sync */ |
Linus Nielsen Feltzing | 7361340 | 2002-05-16 20:57:32 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 161 | #ifdef HAVE_SEMAPHORE_OBJECTS |
| 162 | struct semaphore |
| 163 | { |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 164 | struct thread_entry *queue; /* Waiter list */ |
Michael Sevakis | 12375d1 | 2011-03-02 08:49:38 +0000 | [diff] [blame] | 165 | int volatile count; /* # of waits remaining before unsignaled */ |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 166 | int max; /* maximum # of waits to remain signaled */ |
| 167 | IF_COP( struct corelock cl; ) /* multiprocessor sync */ |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 168 | }; |
| 169 | #endif |
| 170 | |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 171 | /* global tick variable */ |
Michael Sevakis | 3a11277 | 2011-01-15 08:19:30 +0000 | [diff] [blame] | 172 | #if defined(CPU_PP) && defined(BOOTLOADER) && \ |
| 173 | !defined(HAVE_BOOTLOADER_USB_MODE) |
| 174 | /* We don't enable interrupts in the PP bootloader unless USB mode is |
| 175 | enabled for it, so we need to fake the current_tick variable */ |
Brandon Low | 780e8dd | 2006-03-05 18:40:51 +0000 | [diff] [blame] | 176 | #define current_tick (signed)(USEC_TIMER/10000) |
Michael Sevakis | 623cd1c | 2008-10-27 17:18:01 +0000 | [diff] [blame] | 177 | |
| 178 | static inline void call_tick_tasks(void) |
| 179 | { |
| 180 | } |
Dave Chapman | cb7e695 | 2006-01-05 17:02:48 +0000 | [diff] [blame] | 181 | #else |
Michael Sevakis | 6bba70b | 2007-06-25 20:46:54 +0000 | [diff] [blame] | 182 | extern volatile long current_tick; |
Michael Sevakis | 623cd1c | 2008-10-27 17:18:01 +0000 | [diff] [blame] | 183 | |
| 184 | /* inline helper for implementing target interrupt handler */ |
| 185 | static inline void call_tick_tasks(void) |
| 186 | { |
| 187 | extern void (*tick_funcs[MAX_NUM_TICK_TASKS+1])(void); |
Michael Sevakis | 580d91f | 2009-01-21 02:44:20 +0000 | [diff] [blame] | 188 | void (**p)(void) = tick_funcs; |
| 189 | void (*fn)(void); |
Michael Sevakis | 623cd1c | 2008-10-27 17:18:01 +0000 | [diff] [blame] | 190 | |
| 191 | current_tick++; |
| 192 | |
Michael Sevakis | 580d91f | 2009-01-21 02:44:20 +0000 | [diff] [blame] | 193 | for(fn = *p; fn != NULL; fn = *(++p)) |
| 194 | { |
| 195 | fn(); |
| 196 | } |
Michael Sevakis | 623cd1c | 2008-10-27 17:18:01 +0000 | [diff] [blame] | 197 | } |
Dave Chapman | cb7e695 | 2006-01-05 17:02:48 +0000 | [diff] [blame] | 198 | #endif |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 199 | |
| 200 | /* kernel functions */ |
Thomas Martitz | f8edc32 | 2010-03-03 23:20:32 +0000 | [diff] [blame] | 201 | extern void kernel_init(void) INIT_ATTR; |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 202 | extern void yield(void); |
Thomas Martitz | 6eaab4d | 2010-09-01 21:29:34 +0000 | [diff] [blame] | 203 | extern unsigned sleep(unsigned ticks); |
Linus Nielsen Feltzing | ba396f0 | 2002-05-06 19:26:56 +0000 | [diff] [blame] | 204 | int tick_add_task(void (*f)(void)); |
| 205 | int tick_remove_task(void (*f)(void)); |
Rafaël Carré | 435e08e | 2010-05-27 12:00:29 +0000 | [diff] [blame] | 206 | extern void tick_start(unsigned int interval_in_ms) INIT_ATTR; |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 207 | |
Rob Purchase | 75b27ea | 2009-07-14 20:04:26 +0000 | [diff] [blame] | 208 | #ifdef INCLUDE_TIMEOUT_API |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 209 | struct timeout; |
| 210 | |
| 211 | /* timeout callback type |
| 212 | * tmo - pointer to struct timeout associated with event |
Michael Sevakis | 580d91f | 2009-01-21 02:44:20 +0000 | [diff] [blame] | 213 | * return next interval or <= 0 to stop event |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 214 | */ |
Michael Sevakis | 580d91f | 2009-01-21 02:44:20 +0000 | [diff] [blame] | 215 | #define MAX_NUM_TIMEOUTS 8 |
| 216 | typedef int (* timeout_cb_type)(struct timeout *tmo); |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 217 | |
| 218 | struct timeout |
| 219 | { |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 220 | timeout_cb_type callback;/* callback - returning false cancels */ |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 221 | intptr_t data; /* data passed to callback */ |
Michael Sevakis | 580d91f | 2009-01-21 02:44:20 +0000 | [diff] [blame] | 222 | long expires; /* expiration tick */ |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | void timeout_register(struct timeout *tmo, timeout_cb_type callback, |
| 226 | int ticks, intptr_t data); |
| 227 | void timeout_cancel(struct timeout *tmo); |
Rob Purchase | 75b27ea | 2009-07-14 20:04:26 +0000 | [diff] [blame] | 228 | #endif /* INCLUDE_TIMEOUT_API */ |
Michael Sevakis | e64f7e3 | 2007-07-29 04:49:19 +0000 | [diff] [blame] | 229 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 230 | #define STATE_NONSIGNALED 0 |
| 231 | #define STATE_SIGNALED 1 |
| 232 | |
Michael Sevakis | 3c8d93e | 2008-04-01 03:55:02 +0000 | [diff] [blame] | 233 | #define OBJ_WAIT_TIMEDOUT (-1) |
| 234 | #define OBJ_WAIT_FAILED 0 |
| 235 | #define OBJ_WAIT_SUCCEEDED 1 |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 236 | |
Miika Pekkarinen | a85044b | 2006-09-16 16:18:11 +0000 | [diff] [blame] | 237 | extern void queue_init(struct event_queue *q, bool register_queue); |
Linus Nielsen Feltzing | 765e0f8 | 2006-01-23 10:53:47 +0000 | [diff] [blame] | 238 | extern void queue_delete(struct event_queue *q); |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 239 | extern void queue_wait(struct event_queue *q, struct queue_event *ev); |
| 240 | extern void queue_wait_w_tmo(struct event_queue *q, struct queue_event *ev, |
| 241 | int ticks); |
Michael Sevakis | 4b90267 | 2006-12-19 16:50:07 +0000 | [diff] [blame] | 242 | extern void queue_post(struct event_queue *q, long id, intptr_t data); |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 243 | #ifdef HAVE_EXTENDED_MESSAGING_AND_NAME |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 244 | extern void queue_enable_queue_send(struct event_queue *q, |
| 245 | struct queue_sender_list *send, |
Michael Sevakis | 8cfbd36 | 2008-12-10 08:57:10 +0000 | [diff] [blame] | 246 | unsigned int owner_id); |
Michael Sevakis | 4b90267 | 2006-12-19 16:50:07 +0000 | [diff] [blame] | 247 | extern intptr_t queue_send(struct event_queue *q, long id, intptr_t data); |
| 248 | extern void queue_reply(struct event_queue *q, intptr_t retval); |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 249 | extern bool queue_in_queue_send(struct event_queue *q); |
| 250 | #endif /* HAVE_EXTENDED_MESSAGING_AND_NAME */ |
Jens Arnold | c76c568 | 2004-08-16 23:37:23 +0000 | [diff] [blame] | 251 | extern bool queue_empty(const struct event_queue* q); |
Nicolas Pennequin | 1839edf | 2007-10-27 18:08:18 +0000 | [diff] [blame] | 252 | extern bool queue_peek(struct event_queue *q, struct queue_event *ev); |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame^] | 253 | |
| 254 | #define QPEEK_FILTER_COUNT_MASK (0xffu) /* 0x00=1 filter, 0xff=256 filters */ |
| 255 | #define QPEEK_FILTER_HEAD_ONLY (1u << 8) /* Ignored if no filters */ |
| 256 | #define QPEEK_REMOVE_EVENTS (1u << 9) /* Remove or discard events */ |
| 257 | extern bool queue_peek_ex(struct event_queue *q, |
| 258 | struct queue_event *ev, |
| 259 | unsigned int flags, |
| 260 | const long (*filters)[2]); |
| 261 | |
Michael Sevakis | 43c1592 | 2006-12-16 18:35:12 +0000 | [diff] [blame] | 262 | extern void queue_clear(struct event_queue* q); |
Linus Nielsen Feltzing | 4950b55 | 2006-10-19 11:43:13 +0000 | [diff] [blame] | 263 | extern void queue_remove_from_head(struct event_queue *q, long id); |
Miika Pekkarinen | 2eefb5a | 2007-03-11 10:52:36 +0000 | [diff] [blame] | 264 | extern int queue_count(const struct event_queue *q); |
Michael Sevakis | 4b90267 | 2006-12-19 16:50:07 +0000 | [diff] [blame] | 265 | extern int queue_broadcast(long id, intptr_t data); |
Björn Stenberg | 1acfd6b | 2002-04-21 22:06:12 +0000 | [diff] [blame] | 266 | |
Linus Nielsen Feltzing | 7361340 | 2002-05-16 20:57:32 +0000 | [diff] [blame] | 267 | extern void mutex_init(struct mutex *m); |
| 268 | extern void mutex_lock(struct mutex *m); |
| 269 | extern void mutex_unlock(struct mutex *m); |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 270 | #ifdef HAVE_PRIORITY_SCHEDULING |
Michael Sevakis | f387cde | 2010-12-26 05:59:39 +0000 | [diff] [blame] | 271 | /* Deprecated temporary function to disable mutex preempting a thread on |
| 272 | * unlock - firmware/drivers/fat.c and a couple places in apps/buffering.c - |
| 273 | * reliance on it is a bug! */ |
Michael Sevakis | 27cf677 | 2008-03-25 02:34:12 +0000 | [diff] [blame] | 274 | static inline void mutex_set_preempt(struct mutex *m, bool preempt) |
| 275 | { m->no_preempt = !preempt; } |
Michael Sevakis | f387cde | 2010-12-26 05:59:39 +0000 | [diff] [blame] | 276 | #else |
| 277 | /* Deprecated but needed for now - firmware/drivers/ata_mmc.c */ |
| 278 | static inline bool mutex_test(const struct mutex *m) |
| 279 | { return m->thread != NULL; } |
| 280 | #endif /* HAVE_PRIORITY_SCHEDULING */ |
| 281 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 282 | #ifdef HAVE_SEMAPHORE_OBJECTS |
| 283 | extern void semaphore_init(struct semaphore *s, int max, int start); |
Michael Sevakis | 12375d1 | 2011-03-02 08:49:38 +0000 | [diff] [blame] | 284 | extern int semaphore_wait(struct semaphore *s, int timeout); |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 285 | extern void semaphore_release(struct semaphore *s); |
| 286 | #endif /* HAVE_SEMAPHORE_OBJECTS */ |
Linus Nielsen Feltzing | ce726be | 2005-04-06 13:05:06 +0000 | [diff] [blame] | 287 | |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 288 | #endif /* _KERNEL_H_ */ |