aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/include')
-rw-r--r--os/hal/include/hal_usbh.h44
-rw-r--r--os/hal/include/usbh/dev/aoa.h4
-rw-r--r--os/hal/include/usbh/dev/ftdi.h7
-rw-r--r--os/hal/include/usbh/dev/hid.h8
-rw-r--r--os/hal/include/usbh/dev/hub.h4
-rw-r--r--os/hal/include/usbh/dev/msd.h33
-rw-r--r--os/hal/include/usbh/dev/uvc.h14
-rw-r--r--os/hal/include/usbh/internal.h6
-rw-r--r--os/hal/include/usbh/list.h347
9 files changed, 209 insertions, 258 deletions
diff --git a/os/hal/include/hal_usbh.h b/os/hal/include/hal_usbh.h
index b8c229a..1ed6416 100644
--- a/os/hal/include/hal_usbh.h
+++ b/os/hal/include/hal_usbh.h
@@ -48,6 +48,10 @@
#define HAL_USBH_USE_HID FALSE
#endif
+#ifndef HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS
+#define HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS FALSE
+#endif
+
#define HAL_USBH_USE_IAD HAL_USBH_USE_UVC
#if (HAL_USE_USBH == TRUE) || defined(__DOXYGEN__)
@@ -56,13 +60,6 @@
#include "usbh/list.h"
#include "usbh/defs.h"
-/* TODO:
- *
- * - Integrate VBUS power switching functionality to the API.
- *
- */
-
-
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
@@ -79,6 +76,7 @@ enum usbh_status {
USBH_STATUS_SUSPENDED,
};
+/* These correspond to the USB spec */
enum usbh_devstatus {
USBH_DEVSTATUS_DISCONNECTED = 0,
USBH_DEVSTATUS_ATTACHED,
@@ -354,10 +352,8 @@ extern "C" {
osalDbgCheck(ep != 0);
osalDbgCheckClassS();
osalDbgAssert(ep->status != USBH_EPSTATUS_UNINITIALIZED, "invalid state");
- if (ep->status == USBH_EPSTATUS_CLOSED) {
- osalOsRescheduleS();
+ if (ep->status == USBH_EPSTATUS_CLOSED)
return;
- }
usbh_lld_ep_close(ep);
}
static inline void usbhEPClose(usbh_ep_t *ep) {
@@ -388,6 +384,22 @@ extern "C" {
void usbhURBCancelAndWaitS(usbh_urb_t *urb);
msg_t usbhURBWaitTimeoutS(usbh_urb_t *urb, systime_t timeout);
+ static inline void usbhURBSubmit(usbh_urb_t *urb) {
+ osalSysLock();
+ usbhURBSubmitI(urb);
+ osalOsRescheduleS();
+ osalSysUnlock();
+ }
+
+ static inline bool usbhURBCancel(usbh_urb_t *urb) {
+ bool ret;
+ osalSysLock();
+ ret = usbhURBCancelI(urb);
+ osalOsRescheduleS();
+ osalSysUnlock();
+ return ret;
+ }
+
/* Main loop */
void usbhMainLoop(USBHDriver *usbh);
@@ -402,14 +414,13 @@ extern "C" {
typedef struct usbh_classdriver_vmt usbh_classdriver_vmt_t;
struct usbh_classdriver_vmt {
+ void (*init)(void);
usbh_baseclassdriver_t *(*load)(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem);
void (*unload)(usbh_baseclassdriver_t *drv);
+ /* TODO: add power control, suspend, etc */
};
struct usbh_classdriverinfo {
- int16_t class;
- int16_t subclass;
- int16_t protocol;
const char *name;
const usbh_classdriver_vmt_t *vmt;
};
@@ -423,13 +434,6 @@ struct usbh_baseclassdriver {
_usbh_base_classdriver_data
};
-
-/*===========================================================================*/
-/* Helper functions. */
-/*===========================================================================*/
-#include <usbh/desciter.h> /* descriptor iterators */
-#include <usbh/debug.h> /* debug */
-
#endif
#endif /* HAL_USBH_H_ */
diff --git a/os/hal/include/usbh/dev/aoa.h b/os/hal/include/usbh/dev/aoa.h
index 636768a..a7f1c1b 100644
--- a/os/hal/include/usbh/dev/aoa.h
+++ b/os/hal/include/usbh/dev/aoa.h
@@ -140,12 +140,8 @@ extern USBHAOADriver USBHAOAD[HAL_USBHAOA_MAX_INSTANCES];
extern "C" {
#endif
/* AOA device driver */
- void usbhaoaObjectInit(USBHAOADriver *aoap);
void usbhaoaChannelStart(USBHAOADriver *aoap);
void usbhaoaChannelStop(USBHAOADriver *aoap);
-
- /* global initializer */
- void usbhaoaInit(void);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/usbh/dev/ftdi.h b/os/hal/include/usbh/dev/ftdi.h
index bfa3103..eedb056 100644
--- a/os/hal/include/usbh/dev/ftdi.h
+++ b/os/hal/include/usbh/dev/ftdi.h
@@ -138,16 +138,9 @@ extern USBHFTDIPortDriver FTDIPD[HAL_USBHFTDI_MAX_PORTS];
#ifdef __cplusplus
extern "C" {
#endif
- /* FTDI device driver */
- void usbhftdiObjectInit(USBHFTDIDriver *ftdip);
-
/* FTDI port driver */
- void usbhftdipObjectInit(USBHFTDIPortDriver *ftdipp);
void usbhftdipStart(USBHFTDIPortDriver *ftdipp, const USBHFTDIPortConfig *config);
void usbhftdipStop(USBHFTDIPortDriver *ftdipp);
-
- /* global initializer */
- void usbhftdiInit(void);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/usbh/dev/hid.h b/os/hal/include/usbh/dev/hid.h
index 0d6b894..c7371ee 100644
--- a/os/hal/include/usbh/dev/hid.h
+++ b/os/hal/include/usbh/dev/hid.h
@@ -95,6 +95,8 @@ struct USBHHIDDriver {
usbh_urb_t in_urb;
const USBHHIDConfig *config;
+
+ semaphore_t sem;
};
@@ -112,9 +114,6 @@ extern USBHHIDDriver USBHHIDD[HAL_USBHHID_MAX_INSTANCES];
#ifdef __cplusplus
extern "C" {
#endif
- /* HID Driver */
- void usbhHIDObjectInit(USBHHIDDriver *hidp);
-
/* HID Common API */
usbh_urbstatus_t usbhhidGetReport(USBHHIDDriver *hidp,
uint8_t report_id, usbhhid_reporttype_t report_type,
@@ -136,9 +135,6 @@ extern "C" {
}
void usbhhidStart(USBHHIDDriver *hidp, const USBHHIDConfig *cfg);
-
- /* global initializer */
- void usbhhidInit(void);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/usbh/dev/hub.h b/os/hal/include/usbh/dev/hub.h
index 924ebec..406fbaf 100644
--- a/os/hal/include/usbh/dev/hub.h
+++ b/os/hal/include/usbh/dev/hub.h
@@ -88,10 +88,6 @@ static inline usbh_urbstatus_t usbhhubSetFeaturePort(usbh_port_t *port, uint8_t
0);
}
-void usbhhubObjectInit(USBHHubDriver *hubdp);
-
-void usbhhubInit(void);
-
#else
static inline usbh_urbstatus_t usbhhubControlRequest(USBHDriver *host,
diff --git a/os/hal/include/usbh/dev/msd.h b/os/hal/include/usbh/dev/msd.h
index 84179c5..eedd474 100644
--- a/os/hal/include/usbh/dev/msd.h
+++ b/os/hal/include/usbh/dev/msd.h
@@ -58,30 +58,15 @@ struct USBHMassStorageLUNDriver {
const struct USBHMassStorageDriverVMT *vmt;
_base_block_device_data
+ /* for serializing access to the LUN driver */
+ semaphore_t sem;
+
BlockDeviceInfo info;
USBHMassStorageDriver *msdp;
USBHMassStorageLUNDriver *next;
};
-struct USBHMassStorageDriver {
- /* inherited from abstract class driver */
- _usbh_base_classdriver_data
-
- /* for LUN request serialization, can be removed
- * if the driver is configured to support only one LUN
- * per USBHMassStorageDriver instance */
- mutex_t mtx;
-
- usbh_ep_t epin;
- usbh_ep_t epout;
- uint8_t ifnum;
- uint8_t max_lun;
- uint32_t tag;
-
- USBHMassStorageLUNDriver *luns;
-};
-
/*===========================================================================*/
/* Driver macros. */
@@ -93,18 +78,13 @@ struct USBHMassStorageDriver {
/*===========================================================================*/
extern USBHMassStorageLUNDriver MSBLKD[HAL_USBHMSD_MAX_LUNS];
-extern USBHMassStorageDriver USBHMSD[HAL_USBHMSD_MAX_INSTANCES];
#ifdef __cplusplus
extern "C" {
#endif
- /* Mass Storage Driver */
- void usbhmsdObjectInit(USBHMassStorageDriver *msdp);
-
/* Mass Storage LUN Driver (block driver) */
- void usbhmsdLUNObjectInit(USBHMassStorageLUNDriver *lunp);
- void usbhmsdLUNStart(USBHMassStorageLUNDriver *lunp);
- void usbhmsdLUNStop(USBHMassStorageLUNDriver *lunp);
+// void usbhmsdLUNStart(USBHMassStorageLUNDriver *lunp);
+// void usbhmsdLUNStop(USBHMassStorageLUNDriver *lunp);
bool usbhmsdLUNConnect(USBHMassStorageLUNDriver *lunp);
bool usbhmsdLUNDisconnect(USBHMassStorageLUNDriver *lunp);
bool usbhmsdLUNRead(USBHMassStorageLUNDriver *lunp, uint32_t startblk,
@@ -115,9 +95,6 @@ extern "C" {
bool usbhmsdLUNGetInfo(USBHMassStorageLUNDriver *lunp, BlockDeviceInfo *bdip);
bool usbhmsdLUNIsInserted(USBHMassStorageLUNDriver *lunp);
bool usbhmsdLUNIsProtected(USBHMassStorageLUNDriver *lunp);
-
- /* global initializer */
- void usbhmsdInit(void);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/usbh/dev/uvc.h b/os/hal/include/usbh/dev/uvc.h
index c68a082..817d465 100644
--- a/os/hal/include/usbh/dev/uvc.h
+++ b/os/hal/include/usbh/dev/uvc.h
@@ -22,11 +22,7 @@
#if HAL_USE_USBH && HAL_USBH_USE_UVC
-/* TODO:
- *
- *
- */
-
+#include "usbh/desciter.h"
/*===========================================================================*/
/* Driver pre-compile time settings. */
@@ -394,9 +390,6 @@ extern USBHUVCDriver USBHUVCD[HAL_USBHUVC_MAX_INSTANCES];
#ifdef __cplusplus
extern "C" {
#endif
-
- void usbhuvcObjectInit(USBHUVCDriver *uvcd);
-
static inline usbhuvc_state_t usbhuvcGetState(USBHUVCDriver *uvcd) {
return uvcd->state;
}
@@ -457,11 +450,6 @@ extern "C" {
static inline void usbhuvcFreeStatusMessage(USBHUVCDriver *uvcdp, usbhuvc_message_status_t *msg) {
chPoolFree(&uvcdp->mp_status, msg);
}
-
-
- /* global initializer */
- void usbhuvcInit(void);
-
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/include/usbh/internal.h b/os/hal/include/usbh/internal.h
index 70d2f7a..f6f17b7 100644
--- a/os/hal/include/usbh/internal.h
+++ b/os/hal/include/usbh/internal.h
@@ -54,6 +54,9 @@ void _usbh_urb_completeI(usbh_urb_t *urb, usbh_urbstatus_t status);
bool _usbh_urb_abortI(usbh_urb_t *urb, usbh_urbstatus_t status);
void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status);
+bool _usbh_match_vid_pid(usbh_device_t *dev, int32_t vid, int32_t pid);
+bool _usbh_match_descriptor(const uint8_t *descriptor, uint16_t rem,
+ int16_t type, int16_t _class, int16_t subclass, int16_t protocol);
#define USBH_REQTYPE_CLASSIN(type) \
(USBH_REQTYPE_DIR_IN | type | USBH_REQTYPE_TYPE_CLASS)
@@ -137,6 +140,9 @@ void _usbh_urb_abort_and_waitS(usbh_urb_t *urb, usbh_urbstatus_t status);
#define sizeof_array(x) (sizeof(x)/sizeof(*(x)))
+#include "usbh/desciter.h" /* descriptor iterators */
+#include "usbh/debug.h"
+
#endif
#endif /* USBH_INTERNAL_H_ */
diff --git a/os/hal/include/usbh/list.h b/os/hal/include/usbh/list.h
index 317e51b..cdcca04 100644
--- a/os/hal/include/usbh/list.h
+++ b/os/hal/include/usbh/list.h
@@ -41,21 +41,15 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-#ifndef CONFIG_DEBUG_LIST
-static inline void __list_add(struct list_head *new,
+static inline void __list_add(struct list_head *_new,
struct list_head *prev,
struct list_head *next)
{
- next->prev = new;
- new->next = next;
- new->prev = prev;
- prev->next = new;
+ next->prev = _new;
+ _new->next = next;
+ _new->prev = prev;
+ prev->next = _new;
}
-#else
-extern void __list_add(struct list_head *new,
- struct list_head *prev,
- struct list_head *next);
-#endif
/**
* list_add - add a new entry
@@ -65,9 +59,9 @@ extern void __list_add(struct list_head *new,
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
-static inline void list_add(struct list_head *new, struct list_head *head)
+static inline void list_add(struct list_head *_new, struct list_head *head)
{
- __list_add(new, head, head->next);
+ __list_add(_new, head, head->next);
}
@@ -79,9 +73,9 @@ static inline void list_add(struct list_head *new, struct list_head *head)
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
+static inline void list_add_tail(struct list_head *_new, struct list_head *head)
{
- __list_add(new, head->prev, head);
+ __list_add(_new, head->prev, head);
}
/*
@@ -103,7 +97,7 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
* Note: list_empty() on entry does not return true after this, the entry is
* in an undefined state.
*/
-#ifndef CONFIG_DEBUG_LIST
+
static inline void __list_del_entry(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
@@ -112,35 +106,6 @@ static inline void __list_del_entry(struct list_head *entry)
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
- // entry->next = LIST_POISON1;
- // entry->prev = LIST_POISON2;
-}
-#else
-extern void __list_del_entry(struct list_head *entry);
-extern void list_del(struct list_head *entry);
-#endif
-
-/**
- * list_replace - replace old entry by new one
- * @old : the element to be replaced
- * @new : the new element to insert
- *
- * If @old was empty, it will be overwritten.
- */
-static inline void list_replace(struct list_head *old,
- struct list_head *new)
-{
- new->next = old->next;
- new->next->prev = new;
- new->prev = old->prev;
- new->prev->next = new;
-}
-
-static inline void list_replace_init(struct list_head *old,
- struct list_head *new)
-{
- list_replace(old, new);
- INIT_LIST_HEAD(old);
}
/**
@@ -154,26 +119,159 @@ static inline void list_del_init(struct list_head *entry)
}
/**
- * list_move - delete from one list and add as another's head
+ * list_move_tail - delete from one list and add as another's tail
* @list: the entry to move
- * @head: the head that will precede our entry
+ * @head: the head that will follow our entry
*/
-static inline void list_move(struct list_head *list, struct list_head *head)
+static inline void list_move_tail(struct list_head *list,
+ struct list_head *head)
{
__list_del_entry(list);
- list_add(list, head);
+ list_add_tail(list, head);
}
+
/**
- * list_move_tail - delete from one list and add as another's tail
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int list_empty(const struct list_head *head)
+{
+ return head->next == head;
+}
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_entry(ptr, type, member) \
+ container_of(ptr, type, member)
+
+/**
+ * list_first_entry - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_head within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+/**
+ * list_next_entry - get the next element in list
+ * @pos: the type * to cursor
+ * @member: the name of the list_head within the struct.
+ */
+#define list_next_entry(pos, type, member) \
+ list_entry((pos)->member.next, type, member)
+
+/**
+ * list_for_each_entry - iterate over list of given type
+ * @pos: the type * to use as a loop cursor.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_for_each_entry(pos, type, head, member) \
+ for (pos = list_first_entry(head, type, member); \
+ &pos->member != (head); \
+ pos = list_next_entry(pos, type, member))
+
+
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_for_each_entry_safe(pos, type, n, head, member) \
+ for (pos = list_first_entry(head, type, member), \
+ n = list_next_entry(pos, type, member); \
+ &pos->member != (head); \
+ pos = n, n = list_next_entry(n, type, member))
+
+#if 0
+
+/**
+ * list_for_each - iterate over a list
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ */
+#define list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); pos = pos->next)
+
+/**
+ * list_for_each_safe - iterate over a list safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @n: another &struct list_head to use as temporary storage
+ * @head: the head for your list.
+ */
+#define list_for_each_safe(pos, n, head) \
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
+
+/**
+ * list_prev_entry - get the prev element in list
+ * @pos: the type * to cursor
+ * @member: the name of the list_head within the struct.
+ */
+#define list_prev_entry(pos, type, member) \
+ list_entry((pos)->member.prev, type, member)
+
+/**
+ * list_for_each_prev - iterate over a list backwards
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ */
+#define list_for_each_prev(pos, head) \
+ for (pos = (head)->prev; pos != (head); pos = pos->prev)
+
+/**
+ * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @n: another &struct list_head to use as temporary storage
+ * @head: the head for your list.
+ */
+#define list_for_each_prev_safe(pos, n, head) \
+ for (pos = (head)->prev, n = pos->prev; \
+ pos != (head); \
+ pos = n, n = pos->prev)
+
+/**
+ * list_last_entry - get the last element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_head within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_last_entry(ptr, type, member) \
+ list_entry((ptr)->prev, type, member)
+
+/**
+ * list_first_entry_or_null - get the first element from a list
+ * @ptr: the list head to take the element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_head within the struct.
+ *
+ * Note that if the list is empty, it returns NULL.
+ */
+#define list_first_entry_or_null(ptr, type, member) \
+ (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
+
+
+/**
+ * list_move - delete from one list and add as another's head
* @list: the entry to move
- * @head: the head that will follow our entry
+ * @head: the head that will precede our entry
*/
-static inline void list_move_tail(struct list_head *list,
- struct list_head *head)
+static inline void list_move(struct list_head *list, struct list_head *head)
{
__list_del_entry(list);
- list_add_tail(list, head);
+ list_add(list, head);
}
/**
@@ -188,15 +286,6 @@ static inline int list_is_last(const struct list_head *list,
}
/**
- * list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static inline int list_empty(const struct list_head *head)
-{
- return head->next == head;
-}
-
-/**
* list_empty_careful - tests whether a list is empty and not being modified
* @head: the list to test
*
@@ -350,110 +439,28 @@ static inline void list_splice_tail_init(struct list_head *list,
}
/**
- * list_entry - get the struct for this entry
- * @ptr: the &struct list_head pointer.
- * @type: the type of the struct this is embedded in.
- * @member: the name of the list_head within the struct.
- */
-#define list_entry(ptr, type, member) \
- container_of(ptr, type, member)
-
-/**
- * list_first_entry - get the first element from a list
- * @ptr: the list head to take the element from.
- * @type: the type of the struct this is embedded in.
- * @member: the name of the list_head within the struct.
- *
- * Note, that list is expected to be not empty.
- */
-#define list_first_entry(ptr, type, member) \
- list_entry((ptr)->next, type, member)
-
-/**
- * list_last_entry - get the last element from a list
- * @ptr: the list head to take the element from.
- * @type: the type of the struct this is embedded in.
- * @member: the name of the list_head within the struct.
- *
- * Note, that list is expected to be not empty.
- */
-#define list_last_entry(ptr, type, member) \
- list_entry((ptr)->prev, type, member)
-
-/**
- * list_first_entry_or_null - get the first element from a list
- * @ptr: the list head to take the element from.
- * @type: the type of the struct this is embedded in.
- * @member: the name of the list_head within the struct.
+ * list_replace - replace old entry by new one
+ * @old : the element to be replaced
+ * @new : the new element to insert
*
- * Note that if the list is empty, it returns NULL.
- */
-#define list_first_entry_or_null(ptr, type, member) \
- (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
-
-/**
- * list_next_entry - get the next element in list
- * @pos: the type * to cursor
- * @member: the name of the list_head within the struct.
- */
-#define list_next_entry(pos, type, member) \
- list_entry((pos)->member.next, type, member)
-
-/**
- * list_prev_entry - get the prev element in list
- * @pos: the type * to cursor
- * @member: the name of the list_head within the struct.
- */
-#define list_prev_entry(pos, type, member) \
- list_entry((pos)->member.prev, type, member)
-
-/**
- * list_for_each - iterate over a list
- * @pos: the &struct list_head to use as a loop cursor.
- * @head: the head for your list.
- */
-#define list_for_each(pos, head) \
- for (pos = (head)->next; pos != (head); pos = pos->next)
-
-/**
- * list_for_each_prev - iterate over a list backwards
- * @pos: the &struct list_head to use as a loop cursor.
- * @head: the head for your list.
- */
-#define list_for_each_prev(pos, head) \
- for (pos = (head)->prev; pos != (head); pos = pos->prev)
-
-/**
- * list_for_each_safe - iterate over a list safe against removal of list entry
- * @pos: the &struct list_head to use as a loop cursor.
- * @n: another &struct list_head to use as temporary storage
- * @head: the head for your list.
+ * If @old was empty, it will be overwritten.
*/
-#define list_for_each_safe(pos, n, head) \
- for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, n = pos->next)
+static inline void list_replace(struct list_head *old,
+ struct list_head *_new)
+{
+ _new->next = old->next;
+ _new->next->prev = _new;
+ _new->prev = old->prev;
+ _new->prev->next = _new;
+}
-/**
- * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
- * @pos: the &struct list_head to use as a loop cursor.
- * @n: another &struct list_head to use as temporary storage
- * @head: the head for your list.
- */
-#define list_for_each_prev_safe(pos, n, head) \
- for (pos = (head)->prev, n = pos->prev; \
- pos != (head); \
- pos = n, n = pos->prev)
+static inline void list_replace_init(struct list_head *old,
+ struct list_head *_new)
+{
+ list_replace(old, _new);
+ INIT_LIST_HEAD(old);
+}
-/**
- * list_for_each_entry - iterate over list of given type
- * @pos: the type * to use as a loop cursor.
- * @head: the head for your list.
- * @member: the name of the list_head within the struct.
- */
-#define list_for_each_entry(pos, type, head, member) \
- for (pos = list_first_entry(head, type, member); \
- &pos->member != (head); \
- pos = list_next_entry(pos, type, member))
/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
@@ -518,19 +525,6 @@ static inline void list_splice_tail_init(struct list_head *list,
pos = list_next_entry(pos, type, member))
/**
- * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @pos: the type * to use as a loop cursor.
- * @n: another type * to use as temporary storage
- * @head: the head for your list.
- * @member: the name of the list_head within the struct.
- */
-#define list_for_each_entry_safe(pos, type, n, head, member) \
- for (pos = list_first_entry(head, type, member), \
- n = list_next_entry(pos, type, member); \
- &pos->member != (head); \
- pos = n, n = list_next_entry(n, type, member))
-
-/**
* list_for_each_entry_safe_continue - continue list iteration safe against removal
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
@@ -591,5 +585,6 @@ static inline void list_splice_tail_init(struct list_head *list,
*/
#define list_safe_reset_next(pos, type, n, member) \
n = list_next_entry(pos, type, member)
+#endif
#endif /* USBH_LIST_H_ */