Files
geramyloveless 965c4af2be linuxu: library services the display code links against
- get_random_bytes()/get_random_u*() from the platform CSPRNG
  (arc4random_buf(), which DriverKit's libSystem also provides); DP MST
  uses it for sideband nonces.
- lib/uuid.c built unmodified as a helper (guid_gen(), guid_null for DP
  MST branch GUIDs), with hex_to_bin()/hex2bin()/bin2hex() from
  lib/hexdump.c and the upstream linux/hex.h.
- kstrtobool() and kstrtobool_from_user() from lib/kstrtox.c for the
  DC debugfs write handlers.
- vzalloc() for the DML/DML2 work areas.
- Upstream headers and helpers: linux/bitfield.h and linux/typecheck.h
  verbatim (kernel.h now uses the upstream typecheck()), the full
  linux/backlight.h and drm_privacy_screen_consumer.h (their
  !CONFIG inlines replace stray declarations), ffz(), might_sleep_if(),
  delayed_work_pending(), ARCH_KMALLOC_MINALIGN, linux/minmax.h, and
  linux/err.h from linux/dmi.h as the quirk tables need. ssleep() is the
  upstream inline now.
2026-10-02 20:56:28 -07:00

215 lines
7.4 KiB
C

/* linuxu: SHIM (third_party/linux/include/linux/workqueue.h)
*
* Workqueue API surface. Runtime: linuxu/src/work.c (per-queue worker
* pools on linuxu threads). All non-trivial functions declared extern.
*/
#ifndef __LINUX_WORKQUEUE_H
#define __LINUX_WORKQUEUE_H
#include <linux/types.h>
#include <linux/timer.h>
#include <linux/list.h>
#include <linux/wait.h>
#include <linux/atomic.h>
/* ---- types ---- */
struct workqueue_struct;
struct workqueue_attrs;
struct work_struct;
/* workqueue flags used by the driver */
#define WQ_HIGHPRI 0x01
#define WQ_UNBOUND 0x02
#define WQ_FREEZABLE 0x04
#define WQ_SYSTEM 0x04
#define WQ_MEM_RECLAIM 0x08
#ifndef __WQ_ORDERED
#define __WQ_ORDERED (1 << 17) /* internal: workqueue is ordered */
#endif
#ifndef WQ_MAX_ACTIVE
#define WQ_MAX_ACTIVE 2048
#define WQ_DFL_ACTIVE (WQ_MAX_ACTIVE / 2)
#endif
struct work_struct {
atomic_long_t atomic_flags;
struct list_head entry;
void (*func)(struct work_struct *work);
struct workqueue_struct *wq;
unsigned short color;
unsigned long queue_seq;
unsigned int disable; /* Linux WORK_OFFQ_DISABLE count */
};
struct delayed_work {
struct work_struct work;
struct timer_list timer;
struct list_head entry;
};
/* global workqueues (kernel: kernel/workqueue.c; shim: linuxu/src/work.c).
* Each is an independent pool, created by linuxu_workqueue_init() before
* any module init runs. */
extern struct workqueue_struct *system_wq;
extern struct workqueue_struct *system_highpri_wq;
extern struct workqueue_struct *system_unbound_wq;
#define system_percpu_wq system_unbound_wq
extern struct workqueue_struct *system_unbound_highpri_wq;
extern struct workqueue_struct *system_freezable_wq;
extern struct workqueue_struct *system_long_wq;
extern struct workqueue_struct *system_power_wq;
extern struct workqueue_struct *system_switch_wq;
extern struct workqueue_struct *system_freezable_highpri_wq;
extern struct workqueue_struct *system_dfl_wq;
extern struct workqueue_struct *system_unbound_dfl_wq;
/* Creates the system queues and the worker manager. Idempotent and
* thread-safe; returns 0 or a negative errno and may be retried. */
extern int linuxu_workqueue_init(void);
extern struct workqueue_struct *linuxu_default_wq(void);
typedef void (*work_func_t)(struct work_struct *work);
typedef void (*long_wq_work_func_t)(long);
#define WORK_BUSY_PENDING 1u
#define WORK_BUSY_RUNNING 2u
/* ---- init macros ---- */
#define WORK_STRUCT_FLAG_INIT(w, f)
static inline void init_work(struct work_struct *work, work_func_t func)
{
atomic_long_set(&work->atomic_flags, 0);
INIT_LIST_HEAD(&work->entry);
work->func = func;
work->wq = NULL;
work->color = 0;
work->queue_seq = 0;
work->disable = 0;
}
static inline void init_delayed_work(struct delayed_work *dwork,
work_func_t func)
{
init_work(&dwork->work, func);
dwork->timer = (struct timer_list) { };
INIT_LIST_HEAD(&dwork->entry);
}
#ifndef INIT_WORK
#define INIT_WORK(_work, _func) do { init_work(_work, _func); } while (0)
#endif
#define INIT_DELAYED_WORK(_dwork, _func) \
do { init_delayed_work(_dwork, _func); } while (0)
#define INIT_WORK(work_ptr, func) init_work(work_ptr, func)
#define INIT_WORK_ONSTACK(work_ptr, func) init_work(work_ptr, func)
#define INIT_WORK_ONSTACK_REINIT(work_ptr, func) init_work(work_ptr, func)
#define PREPARE_WORK(work_ptr, func) init_work(work_ptr, func)
#define DELAYED_WORK_INIT(name, _func) { \
.work = (struct work_struct) { .func = _func }, \
}
#define DELAYED_WORK_INIT_ONSTACK(name, _func) DELAYED_WORK_INIT(name, _func)
#define DEFINE_WORK(name, _func) \
struct work_struct name = { .func = _func }
#define DEFINE_WORK_ONSTACK(name, _func) \
struct work_struct name = { .func = _func }
static inline struct delayed_work *to_delayed_work(struct work_struct *work)
{
return (struct delayed_work *)work;
}
/* ---- runtime (linuxu/src/work.c) ---- */
extern bool schedule_work(struct work_struct *work);
extern bool queue_work(struct workqueue_struct *wq, struct work_struct *work);
extern bool queue_work_node(int node, struct workqueue_struct *wq,
struct work_struct *work);
extern bool queue_work_on(int cpu, struct workqueue_struct *wq,
struct work_struct *work);
extern bool schedule_delayed_work(struct delayed_work *dwork,
unsigned long delay);
extern bool queue_delayed_work(struct workqueue_struct *wq,
struct delayed_work *work, unsigned long delay);
extern bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
struct delayed_work *dwork,
unsigned long delay);
extern bool flush_work(struct work_struct *work);
extern void flush_workqueue(struct workqueue_struct *wq);
extern bool flush_delayed_work(struct delayed_work *dwork);
extern bool cancel_work(struct work_struct *work);
extern bool cancel_work_sync(struct work_struct *work);
extern bool cancel_delayed_work_sync(struct delayed_work *dwork);
extern bool cancel_delayed_work(struct delayed_work *dwork);
extern unsigned int work_busy(struct work_struct *work);
/* Disable/enable (Linux 6.10+): a disabled item cannot be queued until
* every disable is matched by an enable. */
extern bool disable_work(struct work_struct *work);
extern bool disable_work_sync(struct work_struct *work);
extern bool enable_work(struct work_struct *work);
extern bool disable_delayed_work(struct delayed_work *dwork);
extern bool disable_delayed_work_sync(struct delayed_work *dwork);
extern bool enable_delayed_work(struct delayed_work *dwork);
/* The work item the calling worker is executing, or NULL. */
extern struct work_struct *current_work(void);
extern int workqueue_congested(int cpu, struct workqueue_struct *wq);
/* ---- workqueue creation (runtime: linuxu/src/work.c) ---- */
extern struct workqueue_struct *create_workqueue(const char *name);
extern struct workqueue_struct *create_singlethread_workqueue(const char *name);
extern struct workqueue_struct *alloc_workqueue(const char *name,
unsigned int flags, int max_active);
extern struct workqueue_struct *alloc_ordered_workqueue(const char *name,
unsigned int flags,
int pwq_alloc);
static inline struct workqueue_struct *
linuxu_alloc_ordered_workqueue(const char *name, unsigned int flags)
{
return alloc_ordered_workqueue(name, flags, 0);
}
/*
* 2-arg call form (upstream CONFIG_DEBUG_OBJECTS_WORK=n); the extra
* upstream arg is simply not passed to the shim runtime.
*/
#define alloc_ordered_workqueue(name, flags) \
linuxu_alloc_ordered_workqueue(name, flags)
/*
* lockdep variant (upstream alloc_ordered_workqueue_lockdep_map): the shim
* has no lockdep, so the map pointer is unused and this just allocates.
*/
extern struct lockdep_map;
static inline struct workqueue_struct *
alloc_ordered_workqueue_lockdep_map(const char *name, unsigned int flags,
struct lockdep_map *map)
{
(void)map;
return linuxu_alloc_ordered_workqueue(name, flags);
}
extern bool mod_delayed_work(struct workqueue_struct *wq,
struct delayed_work *dwork,
unsigned long delay);
extern bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
struct delayed_work *dwork,
unsigned long delay);
extern void destroy_workqueue(struct workqueue_struct *wq);
extern void drain_workqueue(struct workqueue_struct *wq);
extern void workqueue_flush(int cpu);
extern bool workqueue_is_single_threaded(struct workqueue_struct *wq);
extern bool work_pending(struct work_struct *w);
#define delayed_work_pending(w) work_pending(&(w)->work)
static inline void destroy_work_on_stack(struct work_struct *work)
{
(void)work;
}
#endif /* __LINUX_WORKQUEUE_H */