From c2d5a92f8c738e820d1d6fa2ca6890039072a151 Mon Sep 17 00:00:00 2001 From: mglocker Date: Thu, 8 Sep 2022 18:16:26 +0000 Subject: [PATCH] Move bitmap functions to a new home. ok kettenis@ --- sys/dev/usb/dwc2/bitmap.h | 137 +++++++++++++++++++++++++++++++ sys/dev/usb/dwc2/dwc2_hcdqueue.c | 121 +-------------------------- 2 files changed, 139 insertions(+), 119 deletions(-) create mode 100644 sys/dev/usb/dwc2/bitmap.h diff --git a/sys/dev/usb/dwc2/bitmap.h b/sys/dev/usb/dwc2/bitmap.h new file mode 100644 index 00000000000..9e32e8b18f1 --- /dev/null +++ b/sys/dev/usb/dwc2/bitmap.h @@ -0,0 +1,137 @@ +/* $OpenBSD: bitmap.h,v 1.1 2022/09/08 18:16:26 mglocker Exp $ */ + +/* + * Copyright 2004 Eric Anholt + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +static inline void +__clear_bit(u_int b, volatile void *p) +{ + volatile u_int *ptr = (volatile u_int *)p; + ptr[b >> 5] &= ~(1 << (b & 0x1f)); +} + +static inline void +__set_bit(u_int b, volatile void *p) +{ + volatile u_int *ptr = (volatile u_int *)p; + ptr[b >> 5] |= (1 << (b & 0x1f)); +} + +static inline int +find_next_zero_bit(volatile void *p, int max, int b) +{ + volatile u_int *ptr = (volatile u_int *)p; + + for (; b < max; b += 32) { + if (ptr[b >> 5] != ~0) { + for (;;) { + if ((ptr[b >> 5] & (1 << (b & 0x1f))) == 0) + return b; + b++; + } + } + } + return max; +} + +static inline int +find_next_bit(volatile void *p, int max, int b) +{ + volatile u_int *ptr = (volatile u_int *)p; + + for (; b < max; b+= 32) { + if (ptr[b >> 5] != 0) { + for (;;) { + if (ptr[b >> 5] & (1 << (b & 0x1f))) + return b; + b++; + } + } + } + return max; +} + +/* + * Copyright (c) 2013, 2014, 2015 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +static inline void +bitmap_set(void *p, int b, u_int n) +{ + u_int end = b + n; + + for (; b < end; b++) + __set_bit(b, p); +} + +static inline void +bitmap_clear(void *p, int b, u_int n) +{ + u_int end = b + n; + + for (; b < end; b++) + __clear_bit(b, p); +} + +static inline u_long +bitmap_find_next_zero_area_off(void *p, u_long size, u_long start, u_long n, + u_long align_mask, u_long align_offset) +{ + u_long index, end, i; + + while (1) { + index = (((find_next_zero_bit(p, size, start) + + align_offset) + align_mask) & ~align_mask) - align_offset; + + end = index + n; + if (end > size) + return end; + + i = find_next_bit(p, end, index); + if (i >= end) + break; + start = i + 1; + } + + return index; +} + +static inline unsigned long +bitmap_find_next_zero_area(void *p, u_long size, u_long start, u_long n, + u_long align_mask) +{ + return bitmap_find_next_zero_area_off(p, size, start, n, align_mask, 0); +} diff --git a/sys/dev/usb/dwc2/dwc2_hcdqueue.c b/sys/dev/usb/dwc2/dwc2_hcdqueue.c index 9f56c2655c7..7a0013d0410 100644 --- a/sys/dev/usb/dwc2/dwc2_hcdqueue.c +++ b/sys/dev/usb/dwc2/dwc2_hcdqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwc2_hcdqueue.c,v 1.13 2022/09/04 08:42:40 mglocker Exp $ */ +/* $OpenBSD: dwc2_hcdqueue.c,v 1.14 2022/09/08 18:16:26 mglocker Exp $ */ /* $NetBSD: dwc2_hcdqueue.c,v 1.11 2014/09/03 10:00:08 skrll Exp $ */ /* @@ -60,124 +60,7 @@ #include #include - -/* - * XXX: Include from dev/pci/drm/include/linux? Although, - * bitmap_find_next_zero_area() is missing there currently ... - */ -static inline void -__set_bit(u_int b, volatile void *p) -{ - volatile u_int *ptr = (volatile u_int *)p; - ptr[b >> 5] |= (1 << (b & 0x1f)); -} - -static inline void -__clear_bit(u_int b, volatile void *p) -{ - volatile u_int *ptr = (volatile u_int *)p; - ptr[b >> 5] &= ~(1 << (b & 0x1f)); -} - -static inline int -find_next_bit(volatile void *p, int max, int b) -{ - volatile u_int *ptr = (volatile u_int *)p; - - for (; b < max; b+= 32) { - if (ptr[b >> 5] != 0) { - for (;;) { - if (ptr[b >> 5] & (1 << (b & 0x1f))) - return b; - b++; - } - } - } - return max; -} - -static inline int -find_next_zero_bit(volatile void *p, int max, int b) -{ - volatile u_int *ptr = (volatile u_int *)p; - - for (; b < max; b += 32) { - if (ptr[b >> 5] != ~0) { - for (;;) { - if ((ptr[b >> 5] & (1 << (b & 0x1f))) == 0) - return b; - b++; - } - } - } - return max; -} - -unsigned long -bitmap_find_next_zero_area_off(unsigned long *, - unsigned long, - unsigned long, - unsigned int, - unsigned long, - unsigned long); - -#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) -#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) - -unsigned long -bitmap_find_next_zero_area_off(unsigned long *map, - unsigned long size, - unsigned long start, - unsigned int nr, - unsigned long align_mask, - unsigned long align_offset) -{ - unsigned long index, end, i; -again: - index = find_next_zero_bit(map, size, start); - - /* Align allocation */ - index = __ALIGN_MASK(index + align_offset, align_mask) - align_offset; - - end = index + nr; - if (end > size) - return end; - i = find_next_bit(map, end, index); - if (i < end) { - start = i + 1; - goto again; - } - return index; -} - -static inline unsigned long -bitmap_find_next_zero_area(unsigned long *map, - unsigned long size, - unsigned long start, - unsigned int nr, - unsigned long align_mask) -{ - return bitmap_find_next_zero_area_off(map, size, start, nr, - align_mask, 0); -} - -static inline void -bitmap_set(void *p, int b, u_int n) -{ - u_int end = b + n; - - for (; b < end; b++) - __set_bit(b, p); -} - -static inline void -bitmap_clear(void *p, int b, u_int n) -{ - u_int end = b + n; - - for (; b < end; b++) - __clear_bit(b, p); -} +#include STATIC void dwc2_wait_timer_fn(void *); -- 2.20.1