Print this page
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    9259 libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>

@@ -1,7 +1,5 @@
-/*      $NetBSD: queue.h,v 1.42 2005/07/13 15:08:24 wiz Exp $   */
-
 /*
  * Copyright (c) 1991, 1993
  *      The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

@@ -37,10 +35,11 @@
 
 #ifndef _SYS_QUEUE_H
 #define _SYS_QUEUE_H
 
 #include <sys/note.h>
+#include <sys/stddef.h>
 
 #ifdef  __cplusplus
 extern "C" {
 #endif
 

@@ -106,10 +105,30 @@
         struct type *le_next;   /* next element */                      \
         struct type **le_prev;  /* address of previous next element */  \
 }
 
 /*
+ * List access methods.
+ */
+#define LIST_EMPTY(head)                ((head)->lh_first == NULL)
+#define LIST_FIRST(head)                ((head)->lh_first)
+#define LIST_NEXT(elm, field)           ((elm)->field.le_next)
+#define LIST_PREV(elm, head, type, field)                               \
+        ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL :           \
+        container_of((elm)->field.le_prev, type, field.le_next))
+
+#define LIST_FOREACH(var, head, field)                                  \
+        for ((var) = LIST_FIRST((head));                                \
+                (var);                                                  \
+                (var) = LIST_NEXT((var), field))
+
+#define LIST_FOREACH_SAFE(var, head, field, tvar)                       \
+        for ((var) = LIST_FIRST((head));                                \
+                (var) && ((tvar) = LIST_NEXT((var), field), 1);         \
+                (var) = (tvar))
+
+/*
  * List functions.
  */
 #if defined(_KERNEL) && defined(QUEUEDEBUG)
 #define QUEUEDEBUG_LIST_INSERT_HEAD(head, elm, field)                   \
         if ((head)->lh_first &&                                         \

@@ -172,24 +191,12 @@
         *(elm)->field.le_prev = (elm)->field.le_next;                   \
         QUEUEDEBUG_LIST_POSTREMOVE((elm), field)                        \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
-#define LIST_FOREACH(var, head, field)                                  \
-        for ((var) = ((head)->lh_first);                                \
-                (var);                                                  \
-                (var) = ((var)->field.le_next))
 
 /*
- * List access methods.
- */
-#define LIST_EMPTY(head)                ((head)->lh_first == NULL)
-#define LIST_FIRST(head)                ((head)->lh_first)
-#define LIST_NEXT(elm, field)           ((elm)->field.le_next)
-
-
-/*
  * Singly-linked List definitions.
  */
 #define SLIST_HEAD(name, type)                                          \
 struct name {                                                           \
         struct type *slh_first; /* first element */                     \

@@ -202,10 +209,27 @@
 struct {                                                                \
         struct type *sle_next;  /* next element */                      \
 }
 
 /*
+ * Singly-linked List access methods.
+ */
+#define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
+#define SLIST_FIRST(head)       ((head)->slh_first)
+#define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
+
+#define SLIST_FOREACH(var, head, field)                                 \
+        for ((var) = SLIST_FIRST((head));                               \
+                (var);                                                  \
+                (var) = SLIST_NEXT((var), field))
+
+#define SLIST_FOREACH_SAFE(var, head, field, tvar)                      \
+        for ((var) = SLIST_FIRST((head));                               \
+                (var) && ((tvar) = SLIST_NEXT((var), field), 1);        \
+                (var) = (tvar))
+
+/*
  * Singly-linked List functions.
  */
 #define SLIST_INIT(head) do {                                           \
         (head)->slh_first = NULL;                                       \
         _NOTE(CONSTCOND)                                                \

@@ -240,22 +264,12 @@
                     curelm->field.sle_next->field.sle_next;             \
         }                                                               \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
-#define SLIST_FOREACH(var, head, field)                                 \
-        for ((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
 
 /*
- * Singly-linked List access methods.
- */
-#define SLIST_EMPTY(head)       ((head)->slh_first == NULL)
-#define SLIST_FIRST(head)       ((head)->slh_first)
-#define SLIST_NEXT(elm, field)  ((elm)->field.sle_next)
-
-
-/*
  * Singly-linked Tail queue declarations.
  */
 #define STAILQ_HEAD(name, type)                                         \
 struct name {                                                           \
         struct type *stqh_first;        /* first element */             \

@@ -269,18 +283,44 @@
 struct {                                                                \
         struct type *stqe_next; /* next element */              \
 }
 
 /*
+ * Singly-linked Tail queue access methods.
+ */
+#define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
+#define STAILQ_FIRST(head)      ((head)->stqh_first)
+#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
+
+#define STAILQ_FOREACH(var, head, field)                                \
+        for ((var) = STAILQ_FIRST(head);                                \
+                (var);                                                  \
+                (var) = STAILQ_NEXT((var), field))
+
+#define STAILQ_FOREACH_SAFE(var, head, field, tvar)                     \
+        for ((var) = STAILQ_FIRST(head);                                \
+                (var) && ((tvar) = STAILQ_NEXT((var), field), 1);       \
+                (var) = (tvar))
+
+/*
  * Singly-linked Tail queue functions.
  */
 #define STAILQ_INIT(head) do {                                          \
         (head)->stqh_first = NULL;                                      \
         (head)->stqh_last = &(head)->stqh_first;                        \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
+#define STAILQ_CONCAT(head1, head2) do {                                \
+        if (!STAILQ_EMPTY((head2))) {                                   \
+                *(head1)->stqh_last = (head2)->stqh_first;              \
+                (head1)->stqh_last = (head2)->stqh_last;                \
+                STAILQ_INIT((head2));                                   \
+        }                                                               \
+        _NOTE(CONSTCOND)                                                \
+} while (0)
+
 #define STAILQ_INSERT_HEAD(head, elm, field) do {                       \
         if (((elm)->field.stqe_next = (head)->stqh_first) == NULL)      \
                 (head)->stqh_last = &(elm)->field.stqe_next;            \
         (head)->stqh_first = (elm);                                     \
         _NOTE(CONSTCOND)                                                \

@@ -306,38 +346,34 @@
             == NULL)                                                    \
                 (head)->stqh_last = &(head)->stqh_first;                \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
+#define STAILQ_REMOVE_AFTER(head, elm, field) do {                      \
+        if ((STAILQ_NEXT(elm, field) =                                  \
+            STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL)       \
+                (head)->stqh_last = &STAILQ_NEXT((elm), field);         \
+        _NOTE(CONSTCOND)                                                \
+} while (0)
+
 #define STAILQ_REMOVE(head, elm, type, field) do {                      \
-        if ((head)->stqh_first == (elm)) {                              \
+        if (STAILQ_FIRST((head)) == (elm)) {                            \
                 STAILQ_REMOVE_HEAD((head), field);                      \
         } else {                                                        \
-                struct type *curelm = (head)->stqh_first;               \
-                while (curelm->field.stqe_next != (elm))                \
-                        curelm = curelm->field.stqe_next;               \
-                if ((curelm->field.stqe_next =                          \
-                        curelm->field.stqe_next->field.stqe_next) == NULL) \
-                            (head)->stqh_last = &(curelm)->field.stqe_next; \
+                struct type *curelm = STAILQ_FIRST(head);               \
+                while (STAILQ_NEXT(curelm, field) != (elm))             \
+                        curelm = STAILQ_NEXT(curelm, field);            \
+                STAILQ_REMOVE_AFTER(head, curelm, field);               \
         }                                                               \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
-#define STAILQ_FOREACH(var, head, field)                                \
-        for ((var) = ((head)->stqh_first);                              \
-                (var);                                                  \
-                (var) = ((var)->field.stqe_next))
+#define STAILQ_LAST(head, type, field)                                  \
+        (STAILQ_EMPTY((head)) ? NULL :                                  \
+            container_of((head)->stqh_last, struct type, field.stqe_next))
 
 /*
- * Singly-linked Tail queue access methods.
- */
-#define STAILQ_EMPTY(head)      ((head)->stqh_first == NULL)
-#define STAILQ_FIRST(head)      ((head)->stqh_first)
-#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
-
-
-/*
  * Simple queue definitions.
  */
 #define SIMPLEQ_HEAD(name, type)                                        \
 struct name {                                                           \
         struct type *sqh_first; /* first element */             \

@@ -351,10 +387,27 @@
 struct {                                                                \
         struct type *sqe_next;  /* next element */                      \
 }
 
 /*
+ * Simple queue access methods.
+ */
+#define SIMPLEQ_EMPTY(head)             ((head)->sqh_first == NULL)
+#define SIMPLEQ_FIRST(head)             ((head)->sqh_first)
+#define SIMPLEQ_NEXT(elm, field)        ((elm)->field.sqe_next)
+
+#define SIMPLEQ_FOREACH(var, head, field)                               \
+        for ((var) = SIMPLEQ_FIRST((head));                             \
+                (var);                                                  \
+                (var) = SIMPLEQ_NEXT((var), field))
+
+#define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar)                    \
+        for ((var) = SIMPLEQ_FIRST((head));                             \
+                (var) && ((tvar) = SIMPLEQ_NEXT((var), field), 1);      \
+                (var) = (tvar))
+
+/*
  * Simple queue functions.
  */
 #define SIMPLEQ_INIT(head) do {                                         \
         (head)->sqh_first = NULL;                                       \
         (head)->sqh_last = &(head)->sqh_first;                          \

@@ -400,24 +453,12 @@
                             (head)->sqh_last = &(curelm)->field.sqe_next; \
         }                                                               \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
-#define SIMPLEQ_FOREACH(var, head, field)                               \
-        for ((var) = ((head)->sqh_first);                               \
-                (var);                                                  \
-                (var) = ((var)->field.sqe_next))
 
 /*
- * Simple queue access methods.
- */
-#define SIMPLEQ_EMPTY(head)             ((head)->sqh_first == NULL)
-#define SIMPLEQ_FIRST(head)             ((head)->sqh_first)
-#define SIMPLEQ_NEXT(elm, field)        ((elm)->field.sqe_next)
-
-
-/*
  * Tail queue definitions.
  */
 #define _TAILQ_HEAD(name, type)                                         \
 struct name {                                                           \
         type *tqh_first;                /* first element */             \

@@ -434,10 +475,42 @@
         type **tqe_prev;        /* address of previous next element */\
 }
 #define TAILQ_ENTRY(type)       _TAILQ_ENTRY(struct type)
 
 /*
+ * Tail queue access methods.
+ */
+#define TAILQ_EMPTY(head)               ((head)->tqh_first == NULL)
+#define TAILQ_FIRST(head)               ((head)->tqh_first)
+#define TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
+#define TAILQ_LAST(head, headname) \
+        (*(((struct headname *)((head)->tqh_last))->tqh_last))
+#define TAILQ_PREV(elm, headname, field) \
+        (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+
+#define TAILQ_FOREACH(var, head, field)                                 \
+        for ((var) = TAILQ_FIRST((head));                               \
+                (var);                                                  \
+                (var) = TAILQ_NEXT((var), field))
+
+#define TAILQ_FOREACH_SAFE(var, head, field, tvar)                      \
+        for ((var) = TAILQ_FIRST((head));                               \
+                (var) && ((tvar) = TAILQ_NEXT((var), field), 1);        \
+                (var) = (tvar))
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
+        for ((var) = TAILQ_LAST((head), headname);                      \
+                (var);                                                  \
+                (var) = TAILQ_PREV((var), headname, field))
+
+#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)    \
+        for ((var) = TAILQ_LAST((head), headname);                      \
+                (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \
+                (var) = (tvar))
+
+/*
  * Tail queue functions.
  */
 #if defined(_KERNEL) && defined(QUEUEDEBUG)
 #define QUEUEDEBUG_TAILQ_INSERT_HEAD(head, elm, field)                  \
         if ((head)->tqh_first &&                                        \

@@ -532,35 +605,12 @@
         *(elm)->field.tqe_prev = (elm)->field.tqe_next;                 \
         QUEUEDEBUG_TAILQ_POSTREMOVE((elm), field);                      \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
-#define TAILQ_FOREACH(var, head, field)                                 \
-        for ((var) = ((head)->tqh_first);                               \
-                (var);                                                  \
-                (var) = ((var)->field.tqe_next))
 
-#define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
-        for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));\
-                (var);                                                  \
-                (var) =                                                 \
-                    (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
-
 /*
- * Tail queue access methods.
- */
-#define TAILQ_EMPTY(head)               ((head)->tqh_first == NULL)
-#define TAILQ_FIRST(head)               ((head)->tqh_first)
-#define TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
-
-#define TAILQ_LAST(head, headname) \
-        (*(((struct headname *)((head)->tqh_last))->tqh_last))
-#define TAILQ_PREV(elm, headname, field) \
-        (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
-
-
-/*
  * Circular queue definitions.
  */
 #define CIRCLEQ_HEAD(name, type)                                        \
 struct name {                                                           \
         struct type *cqh_first;         /* first element */     \

@@ -575,10 +625,38 @@
         struct type *cqe_next;          /* next element */              \
         struct type *cqe_prev;          /* previous element */          \
 }
 
 /*
+ * Circular queue access methods.
+ */
+#define CIRCLEQ_EMPTY(head)             ((head)->cqh_first == (void *)(head))
+#define CIRCLEQ_FIRST(head)             ((head)->cqh_first)
+#define CIRCLEQ_LAST(head)              ((head)->cqh_last)
+#define CIRCLEQ_NEXT(elm, field)        ((elm)->field.cqe_next)
+#define CIRCLEQ_PREV(elm, field)        ((elm)->field.cqe_prev)
+
+#define CIRCLEQ_LOOP_NEXT(head, elm, field)                             \
+        (((elm)->field.cqe_next == (void *)(head))                      \
+            ? ((head)->cqh_first)                                       \
+            : (elm->field.cqe_next))
+#define CIRCLEQ_LOOP_PREV(head, elm, field)                             \
+        (((elm)->field.cqe_prev == (void *)(head))                      \
+            ? ((head)->cqh_last)                                        \
+            : (elm->field.cqe_prev))
+
+#define CIRCLEQ_FOREACH(var, head, field)                               \
+        for ((var) = CIRCLEQ_FIRST((head));                             \
+                (var) != (void *)(head);                                \
+                (var) = CIRCLEQ_NEXT((var), field))
+
+#define CIRCLEQ_FOREACH_REVERSE(var, head, field)                       \
+        for ((var) = CIRCLEQ_LAST((head));                              \
+                (var) != (void *)(head);                                \
+                (var) = CIRCLEQ_PREV((var), field))
+
+/*
  * Circular queue functions.
  */
 #define CIRCLEQ_INIT(head) do {                                         \
         (head)->cqh_first = (void *)(head);                             \
         (head)->cqh_last = (void *)(head);                              \

@@ -641,38 +719,11 @@
                 (elm)->field.cqe_prev->field.cqe_next =                 \
                     (elm)->field.cqe_next;                              \
         _NOTE(CONSTCOND)                                                \
 } while (0)
 
-#define CIRCLEQ_FOREACH(var, head, field)                               \
-        for ((var) = ((head)->cqh_first);                               \
-                (var) != (void *)(head);                                \
-                (var) = ((var)->field.cqe_next))
 
-#define CIRCLEQ_FOREACH_REVERSE(var, head, field)                       \
-        for ((var) = ((head)->cqh_last);                                \
-                (var) != (void *)(head);                                \
-                (var) = ((var)->field.cqe_prev))
-
-/*
- * Circular queue access methods.
- */
-#define CIRCLEQ_EMPTY(head)             ((head)->cqh_first == (void *)(head))
-#define CIRCLEQ_FIRST(head)             ((head)->cqh_first)
-#define CIRCLEQ_LAST(head)              ((head)->cqh_last)
-#define CIRCLEQ_NEXT(elm, field)        ((elm)->field.cqe_next)
-#define CIRCLEQ_PREV(elm, field)        ((elm)->field.cqe_prev)
-
-#define CIRCLEQ_LOOP_NEXT(head, elm, field)                             \
-        (((elm)->field.cqe_next == (void *)(head))                      \
-            ? ((head)->cqh_first)                                       \
-            : (elm->field.cqe_next))
-#define CIRCLEQ_LOOP_PREV(head, elm, field)                             \
-        (((elm)->field.cqe_prev == (void *)(head))                      \
-            ? ((head)->cqh_last)                                        \
-            : (elm->field.cqe_prev))
-
 #ifdef  __cplusplus
 }
 #endif
 
 #endif  /* !_SYS_QUEUE_H */