Date: Mon, 24 Aug 2020 10:46:09 +0000 (UTC) From: Emmanuel Vadot <manu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364654 - stable/12/sys/compat/linuxkpi/common/include/linux Message-ID: <202008241046.07OAk9Z4059378@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: manu Date: Mon Aug 24 10:46:09 2020 New Revision: 364654 URL: https://svnweb.freebsd.org/changeset/base/364654 Log: MFC r361007, r361138-r361140, r361245-r361246 r361007: linuxkpi: Add EBADRQC to errno.h This is used in the amdgpu driver from Linux 5.2 Sponsored-by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24807 r361138: linuxkpi: Add atomic_dec_and_mutex_lock This function decrement the counter and if the result is 0 it acquires the mutex and returns 1, if not it simply returns 0. Needed by DRM from Linux v5.3 Sponsored-by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24847 r361139: linuxkpi: Add __mutex_init Same as mutex_init, the lock_class_key argument seems to be only used for debug in Linux, simply ignore it for now. Needed by DRM in Linux v5.3 Sponsored-by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24848 r361140: linuxkpi: Add offsetofend macro This calculate the offset of the end of the member in the given struct. Needed by DRM in Linux v5.3 Sponsored-by: The FreeBSD Foudation Differential Revision: https://reviews.freebsd.org/D24849 r361245: linuxkpi: Add __init_waitqueue_head The only difference with init_waitqueue_head is that the name and the lock class key are provided but we don't use those so use init_waitqueue_head directly. Sponsored-by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24861 r361246: linuxkpi: add pci_dev_present pci_dev_present shows if a set of pci ids are present in the system. It just wraps pci_find_device. Needed by DRMv5.2 Submitted by: Austing Shafer (ashafer@badland.io) Differential Revision: https://reviews.freebsd.org/D24796 Modified: stable/12/sys/compat/linuxkpi/common/include/linux/errno.h stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h stable/12/sys/compat/linuxkpi/common/include/linux/mutex.h stable/12/sys/compat/linuxkpi/common/include/linux/pci.h stable/12/sys/compat/linuxkpi/common/include/linux/wait.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/include/linux/errno.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/errno.h Mon Aug 24 10:42:04 2020 (r364653) +++ stable/12/sys/compat/linuxkpi/common/include/linux/errno.h Mon Aug 24 10:46:09 2020 (r364654) @@ -33,6 +33,8 @@ #include <sys/errno.h> +#define EBADRQC 56 /* Bad request code */ + #define ECHRNG EDOM #define ETIME ETIMEDOUT #define ECOMM ESTALE Modified: stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h Mon Aug 24 10:42:04 2020 (r364653) +++ stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h Mon Aug 24 10:46:09 2020 (r364654) @@ -465,6 +465,9 @@ kstrtobool_from_user(const char __user *s, size_t coun type __max2 = (y); \ __max1 > __max2 ? __max1 : __max2; }) +#define offsetofend(t, m) \ + (offsetof(t, m) + sizeof((((t *)0)->m))) + #define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max) #define clamp(x, lo, hi) min( max(x,lo), hi) #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) Modified: stable/12/sys/compat/linuxkpi/common/include/linux/mutex.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/mutex.h Mon Aug 24 10:42:04 2020 (r364653) +++ stable/12/sys/compat/linuxkpi/common/include/linux/mutex.h Mon Aug 24 10:46:09 2020 (r364654) @@ -37,6 +37,7 @@ #include <sys/sx.h> #include <linux/spinlock.h> +#include <asm/atomic.h> typedef struct mutex { struct sx sx; @@ -107,6 +108,9 @@ mutex_trylock_recursive(struct mutex *lock) #define mutex_init(_m) \ linux_mutex_init(_m, mutex_name(#_m), SX_NOWITNESS) +#define __mutex_init(_m, _n, _l) \ + linux_mutex_init(_m, _n, SX_NOWITNESS) + #define mutex_init_witness(_m) \ linux_mutex_init(_m, mutex_name(#_m), SX_DUPOK) @@ -123,6 +127,16 @@ static inline bool mutex_is_owned(mutex_t *m) { return (sx_xlocked(&m->sx)); +} + +static inline int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *m) +{ + if (atomic_dec_and_test(cnt)) { + mutex_lock(m); + return (1); + } + + return (0); } #ifdef WITNESS_ALL Modified: stable/12/sys/compat/linuxkpi/common/include/linux/pci.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Mon Aug 24 10:42:04 2020 (r364653) +++ stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Mon Aug 24 10:46:09 2020 (r364654) @@ -1050,4 +1050,16 @@ extern int linux_pci_attach_device(device_t, struct pc const struct pci_device_id *, struct pci_dev *); extern int linux_pci_detach_device(struct pci_dev *); +static inline int +pci_dev_present(const struct pci_device_id *cur) +{ + while (cur != NULL && (cur->vendor || cur->device)) { + if (pci_find_device(cur->vendor, cur->device) != NULL) { + return (1); + } + cur++; + } + return (0); +} + #endif /* _LINUX_PCI_H_ */ Modified: stable/12/sys/compat/linuxkpi/common/include/linux/wait.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/wait.h Mon Aug 24 10:42:04 2020 (r364653) +++ stable/12/sys/compat/linuxkpi/common/include/linux/wait.h Mon Aug 24 10:46:09 2020 (r364654) @@ -119,6 +119,8 @@ extern wait_queue_func_t default_wake_function; INIT_LIST_HEAD(&(wqh)->task_list); \ } while (0) +#define __init_waitqueue_head(wqh, name, lk) init_waitqueue_head(wqh) + void linux_init_wait_entry(wait_queue_t *, int); void linux_wake_up(wait_queue_head_t *, unsigned int, int, bool);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008241046.07OAk9Z4059378>