100 Commits
Author SHA1 Message Date
ShengYi Hung 2734bbbcba libthr: Create landing pad in thr_once in C++ exception
In _thr_once, if init_routine fails with exception, the stack allocate
__cup will become invalid when unwinder walk back and free the stack of
thr_once. This cause cleanup linked list be dangling. In here, we give
the cleanup function a landing pad so that we td can correctly point
to previous cleanup function.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D61212
2026-11-06 03:01:55 +11:00
ShengYi Hung 71937d8e11 libthr: Predict libthr is initialized in _thr_check_init
_thr_check_init() is called on hot paths such as pthread_once(), and
the uninitialized case can only happen once. Mark it with
__predict_false so the compiler lays out the initialized case as the
fall-through path.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D61213
2026-11-06 03:00:27 +11:00
ShengYi Hung 1e1ce1f6f9 libthr: Fix whitespace in thr_once.c
Remove trailing whitespace and replace space indentation with a tab.

No functional change.
2026-11-06 03:00:27 +11:00
ShengYi Hung 7806832f23 libthr: Cache recent pshared_key
For a pshare key, we can actually cache the last one as a fast path
instead of trapping into kernel directly. It makes sense as a lock and
unlock should be a pair on the same key and at the same time. For
example, lock(A) -> unlock(A) -> lock(B) -> unlock(B). Each unlock is
a hit and refresh later (50% hit).

For a single pshare lock, it is evne a 100% hit as the key never
changed.

For nested lock lock(A) -> lock(B) -> lock(C) -> unlock(C) ->
unlock(B) -> unlock(A). It only cache the last one. However, we should
really think about rewritting this logic as it is a pshare lock shared
by many processes and nested should be uncommon.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60957
2026-11-05 10:41:05 +11:00
ShengYi Hung b138d017c7 libc/locale: Check EILSEQ return
_citrus_iconv_std_iconv_convert can return EILSEQ without setting
invlen. As a result, we should check EILSEQ in the return value or it
will incorrectly return -2

Reviewed by:    kevans
Fixes: e2030ca246 ("libc: fix c*rtomb/mbrtoc*")
MFC after:      2 days
Differential Revision: https://reviews.freebsd.org/D61151
2026-11-04 15:09:36 +11:00
ShengYi Hung 6071292d39 libthr: Return EDEADLK if it is held by ourself
Reviewed by:    kib, markj
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60959
2026-11-03 17:51:49 +11:00
ShengYi Hung 5cc08734ad __FreeBSD_version: Bump for USB 3.1 and 3.2 changes
Bump new USB changes. Also, update RELNOTE and UPDATING.

Sponsored by:   The FreeBSD Foundation
2026-11-02 14:53:34 +11:00
ShengYi Hung 20b1998254 usb: support SSP and SSPx2 xHCI
Only the default PSI IDs are supported, other controllers fall back to
USB 3.0.  Record the speed IDs the controller has: the root hub BOS
lists those, and a link without one uses the closest lower ID.

Per xHCI 6.2.2, take the parent hub slot ID and port number of SS and
SSP devices from the closest higher-rank hub.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D52347
2026-11-02 14:02:11 +11:00
ShengYi Hung fb470e8f1c usb: Add support for SSP and SSPx2 hubs
An SSP hub reports its sublink speeds in the BOS descriptor, and
Extended Port Status tells which one each port uses.  Read it based on
bcdUSB, since the ports of a hub can be faster than its upstream link.
Without it, the ports are treated as SuperSpeed.

Read the speed again in usbd_req_re_enumerate(), since a link can come
back at another speed.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57204
2026-11-02 14:02:11 +11:00
ShengYi Hung 23ef0bdb48 usb: Add SSPlus device capability descriptor
Add the SuperSpeedPlus USB Device Capability descriptor and its field
macros.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57203
2026-11-02 14:02:11 +11:00
ShengYi Hung 2f79adc289 usb: Implement usbd_req_get_bos_descriptor helper
Get the header or the complete BOS descriptor of SS+ devices.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57202
2026-11-02 14:02:11 +11:00
ShengYi Hung 1928debe1a usb: Add get_ext_port_status helper function
usbd_req_get_ext_port_status() wraps the Get Extended Port Status
request.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57201
2026-11-02 14:02:11 +11:00
ShengYi Hung 1fe552b036 usb: Add extended port status struct
Extended Port Status reports the speed and lane count of SS and SSP
links.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57200
2026-11-02 14:02:11 +11:00
ShengYi Hung ab18352d8f usb: Add usbd_bos_foreach helper
Iterate the capabilities of a BOS descriptor.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57199
2026-11-02 14:02:11 +11:00
ShengYi Hung 85c3bd4595 usb: support SSP/SSPx2 devices in all-speed consumers
Handle the new speeds wherever USB_SPEED_SUPER was checked.  Most
consumers treat them as SS.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57198
2026-11-02 14:02:11 +11:00
ShengYi Hung 65346af496 usbdump: Support SSP and SSPx2 speed display
Add the SuperSpeedPlus speed names.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57197
2026-11-02 14:02:10 +11:00
ShengYi Hung 2802f8d4a0 usbconfig: Add SSPx2 support
libusb has one speed for all SSP links, so print "SUPER+ (>=10Gbps)".

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57196
2026-11-02 14:02:10 +11:00
ShengYi Hung 1a38209136 libusb: Add SSP and SSPx2 enum support
Report the new kernel speeds as LIBUSB20_SPEED_SUPER_PLUS.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57195
2026-11-02 14:02:10 +11:00
ShengYi Hung 6e575d08a5 usb: Add SSP and SSPx2 speed and move USB_*_MAX into enum
Add the USB 3.1 and 3.2 speeds and revisions.  The speeds are in USB
3.2 rank order, so they can be compared directly.

Also, move USB_*_MAX into the enums.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D57194
2026-11-02 14:02:10 +11:00
ShengYi Hung 6a65632e1a libthr: Add missing include header
Fixes:          56a490f9c5 ("libthr: Robust tryjoin test")
MFC after:      2 weeks
2026-10-30 06:17:00 +11:00
ShengYi Hung 56a490f9c5 libthr: Robust tryjoin test
We cannot actually rely on a status (finish) before thr_exit. The
thread needs the kernel signal status=1 to userspace. Before that,
any tryjoin fails. The previous one works as we sleep 1 and should be
enough for normal case.

Reviewed by:    kib, markj
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60832
2026-10-30 04:44:15 +11:00
ShengYi Hung 8e3a6d7f5a libthr: Deduplicate some rwlock code
1. abstime calculation
2. rdlock flags judgement

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60958
2026-10-30 04:44:15 +11:00
ShengYi Hung 894f70a2bd libthr: drop use of try_gc in the end of thr_join
thr_try_gc unlock and lock again to make sure the lock order. However,
there is no reason for such roundtrip if the caller holds the correct
oder. As a result, we create a new helper function to add the thread
to gc list without unlock + lock and wire the join_common to this new helper.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60717
2026-10-19 16:23:14 +11:00
ShengYi Hung fe6aee442d vfs_subr.c: fix signature mismatch for close method
Reviewed by:    jhb
Differential Revision:  https://reviews.freebsd.org/D49166
2026-10-18 13:29:41 +11:00
ShengYi Hung 7af3fd0993 null.c: fix signature mismatch for null_read
Reviewed by:    jhb
Differential Revision: https://reviews.freebsd.org/D49168
2026-10-18 13:29:41 +11:00
ShengYi Hung a0e1529736 libthr: Remove deadcode in join_common
The while loop previous can only be break when ret == ETIMEDOUT. They
never produce EBUSY. Remove the deadcode here.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60711
2026-10-18 13:06:59 +11:00
ShengYi Hung 23626eb9e3 linux: cap mount id to INT_MAX
linux stores mount id as a int32_t, using xor would make it becomes
negative in some cases. As a result, we cap the value to INT_MAX to
prevent getting a negative value from userspace.

MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D59202
2026-10-14 06:27:46 +11:00
ShengYi Hung 5fb07bbcd5 libthr: Fix LIBPTHREAD_QUEUE_FIFO range
LIBPTHREAD_QUEUE_FIFO is used in bitwise offset, we set the limit to
0~31 so that it won't cause undefined behavior. Also, create a new
helper function to do getenv++strtol directly and check the boundary of
the valid value.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60487
2026-10-14 06:27:46 +11:00
ShengYi Hung 305c3044e0 libthr: Support disable spinloop
Like yieldloops, we shoulde be able to set _thr_spinloops to zero.
Originally, it makes us to enformce default spin time even if we try to
disable it. Make MUTEX_ADAPTIVE_SPINS a one time initialization now.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60486
2026-10-10 09:13:31 +11:00
ShengYi Hung 5b1f1fd624 hyperv: Fix single page invalidation path
A single page invalidation sets addr2 == 0. In the original code, it
falsely flush the whole address in non global pmap. However, the
kernel pmap are all PG_G, which means a single page flush will always be
staled and thus become invalid. As a result, we set parameter based on
their op in a new helper function instead of relying on args. This
affects only on AMD platform as Intel has their PTI implementation.

PR:     291577
Tested by:      [email protected]
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60380
2026-10-10 09:13:31 +11:00
ShengYi Hung de2c0f157a libthr: Fix some bugs in trylock
1. When contester > 2, a release causes kernel set CONTENTION bit but
   with no owner. In this case, the userspace should be able to try the
   lock instead of fall immediately. We copy this from trylock2.
2. A PI mutex should consult to kernel instead of decided by userspace
   itself.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60427
2026-10-08 04:14:04 +11:00
ShengYi Hung 99edcc3bd5 libthr: Reorder pthread mutex to prevent false sharing
On a 64 byte cache line CPU (amd64), m_owner is contended by all of
the shared processes. However, after finding one winner, mtx is
enqueued, which trigger a cache refresh from other processors. Reorder
mtx so that m_lock and m_qu will not be in the same cache line.

Notice that this doesn't affet arch that expose 128 bytes cache line
line aarch64 or powerpc.

Reviewed by:    kib, markj
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60434
2026-10-08 04:05:58 +11:00
ShengYi Hung 627e7d5b72 libthr: reject count < 0
This causes count == -1 spin for INT_MAX times in userspace.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60425
2026-10-08 03:59:19 +11:00
ShengYi Hung 1d21e67e72 libthr: Do not rely on UB in counter
counter + 1 > 0 is a undefined behavior and nobody guarantee that it
will be honestly perform by the compiler that counter + 1 will always be
INT_MIN. We switch to INT_MAX check instead to provide a deterministic
result.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D60426
2026-10-08 03:59:10 +11:00
ShengYi Hung 192781bf5d libthr: Consume error in check_and_init_mutex
MFC after:      2 weeks
2026-10-07 12:26:11 +11:00
ShengYi Hung 228b1a0116 uchcom: Set rate to 1 if 0
If userspace provides rate == 0, it causes kernel panic as rate is
directly used as a divident, which cannot be zero. Fix it by set the
rate to 1 if it is passed as 0.

Reviewed by:    imp, emaste
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D59111
2026-09-26 16:45:08 +10:00
ShengYi Hung 102adf88e6 linux: Exposes renderD nodes and chardev in sysfs
To allow normal users to render through the render device, we expose the
renderD node. This enables Wayland applications to use hardware
acceleration when running under the Linux emulator.

Additionally, libdrm and Mesa need to look up
/sys/dev/char/<major>:<minor> and <pcidev>/drm to identify the
corresponding renderer device (e.g., a renderD device). We expose this
path as well so that libdrm can locate the renderer.

Differential Revision: https://reviews.freebsd.org/D59190
2026-09-26 16:36:46 +10:00
ShengYi Hung ef26f64c11 amd64/pmap: Return la57 in amd nested page
AMD doesn't encode page depth in eptp. As a result, the page level is
decided by the host la57 value. Without this, it uses 4 level page and
therefore cause machine enable la57 have garbage page translation.

PR:		291768
Reviewed by:	kib
Tested by:	Antranig Vartanian <[email protected]>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D57978
2026-09-11 13:01:44 +00:00
ShengYi Hung 0f59df8386 xhci: Only reset the data toggle value when the USB stack asks for it
The previous patch assumes that we don't want to reset toggle bit in
STOPPED_STEP. However, a device can explicitly call
usbd_clear_data_toggle if necessary. As a result, instead of not
dropping the bit unconditionally, we added a field in xhci to specify
that we want to drop it, so that usbd_clear_data_toggle can handle it
correctly.

Reported by:    oh
Reviewed by:    kevans
Tested by:      oh
Fixes:		28d85db46b ("xhci: Do not drop and add bits in xhci")
MFC after:	3 days
Differential Revision:  https://reviews.freebsd.org/D59186
2026-08-26 15:52:11 -05:00
ShengYi Hung 6bda9f26d2 libusb: change callback register handler to int
libusb upstream uses int for register handler. This causes some library
user (like pyusb) to assume that we have int in all implementations and
therefore provides a 4 byte storage only. This causes Segmentation
fault as we will right the pointer.

Reviewed by:    adrian
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D54211

(cherry picked from commit ce9ced951a)
2026-08-21 10:52:56 -04:00
ShengYi Hung 89d1553608 RELNOTES: Add an entry for bumping libusb version 2026-08-14 23:20:15 +08:00
ShengYi Hung 34bb38445b libusb: Bump version to 1.0.27
PR:             296234(exp-run)
Relnotes:       yes
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57772
2026-08-14 23:18:21 +08:00
ShengYi Hung 749318f2ae libusb: capsicumize libusb
FreeBSD's libusb has three components: libusb01, libusb10, and libusb20.

libusb20 handles communication with character devices. We now requires a
backend context for libusb20. The backend context contains contains the
capsicumized usbctrl fd and usb directory (/dev/usb) fd so that the
library user can enter the capiblity mode safely while using libusb.

libusb10 is updated to support capabilities via a context option. Since
libusb allows general read/write access, we preserve all possible
capabilities when passing backend context to libusb20. It is the
responsibility of the libusb user to call cap_enter() at an appropriate
time.

All base system tools using libusb and libusb20 have been updated to
support Capsicum.

Reviewed by:    adrian, markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51865
2026-08-14 23:09:08 +08:00
ShengYi Hung 1c1bce5bbd libusb: Mark defualt smybol tag as latest stable version
As we might change the libusb ABI in 16, we should mark thje first
version as FBSD_1.8 instead of 1.9. Since versioning patch has not
landed for a long time, it makes sense to change it directly.

Discussed with: kib
Fixes: 527a82474c ("libusb: versioning symbols")
Sponsored by:   The FreeBSD Foundation
2026-08-13 23:38:08 +08:00
ShengYi Hung 527a82474c libusb: versioning symbols
Reviewed by:    bapt, kevans
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D55686
2026-08-12 22:49:35 +08:00
ShengYi Hung e3e56236bc xhci: Fix packet xfer larger than 64kb
Previously, multiple frames of xfers are split into many tds. In the
refactor process, we forget to consider this. The td builder is already
allocate with enough numbers of tds. What we need to do is to fill the
normal trbs for muiltiple tds when building trbs.

PR:             297053
Tested by:      phk, [email protected]
Fixes:  e0b235ecd4 ("xhci: Refactor xhci_generic_setup code")
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D58465
2026-07-27 13:31:12 +08:00
ShengYi Hung 5f346dba4f libusb: Sync interface for libusb_init_option
Sponsored by:   The FreeBSD Foundation
2026-07-26 00:05:40 +08:00
ShengYi Hung 340c6aff67 libusb: Add LIBUSB_DT_SUPERSPEED_HUB
Sponsored by:   The FreeBSD Foundation
2026-07-25 23:41:20 +08:00
ShengYi Hung b78f8800a7 x86/specialreg: Add MSR_AMD_CPUID01 MSR
Reviewed by:    markj
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D56311
2026-07-25 21:26:41 +08:00
ShengYi Hung 2cf2d95563 usb: preserve error when doing request
Currently, USB request not distinguished different error and always return EIO.
However, some error are recoverable or ignorable in userspace.
Therefore, we preserve the meaning of different error to userspace then
allow userspace to decide how to use the return error.

Reviewed by:    adrian
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52244
2026-07-25 11:16:59 +08:00
ShengYi Hung e0b235ecd4 xhci: Refactor xhci_generic_setup code
Our USB TRB buildup subroutines were previously difficult to follow. In
setup_generic_chain_sub(), the routine filled TRB packets based on the
characteristics passed by the caller and the current state (for example,
whether the TRB was the last in the TD).

However, most TRB types (except Normal TRBs) cannot be shared across TDs.
To simplify the logic, refactor xhci_setup_generic() so that TRBs are
constructed according to their transfer type, with dedicated helper
functions for each TRB type.

Sponsored by:   The FreeBSD Foundation
Assisted-by:    Claude Code (Opus 4.6, Opus 4.8(1M) and Sonet 5.0)
Differential Revision:  https://reviews.freebsd.org/D57130
2026-07-25 09:49:35 +08:00
ShengYi Hung b8f1972d51 hexdump: Support octal and hex for -N option
GNU hexdump supports octal and hex, we add supports for BSD style
hexdump for better compatibility.

See: https://github.com/llvm/llvm-project/pull/206581/

MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D58074
2026-07-20 16:11:54 +08:00
ShengYi Hung 7fc2c9f688 apei: Fix i386 build over bus read, write function
bus_{read,write}_8 are macro wrappers around the corresponding bus_space
functions in sys/bus.h, so implementing bus_{read,write}_8 won't work.
Implement the underlying bus_space function instead.

Reviewed by:    jrtc27, rlibby
Fixes:          9313f6b014
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D58301
2026-07-20 15:34:42 +08:00
ShengYi Hung 02c440e204 hwpstate_intel: Minimize ifdef for i386 build
Reported by:    jrtc27
Fixes:  bdc0f76782
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation
2026-07-19 22:03:48 +08:00
ShengYi Hung 86691d52a6 kvm: Support non-default CPUID leaf
KVM does not always use 0x40000000 as its CPUID base. For example, QEMU
adds a 0x100 offset when nested virtualization is detected and the host
exposes Hyper-V enlightenment hints. To accommodate this behavior,
switch the detection logic to use the CPUID leaf returned by do_cpuid(),
making the implementation more flexible.

See:
https://github.com/qemu/qemu/blob/master/target/i386/kvm/kvm.c#L2300

Reviewed by:    kib
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D58146
2026-07-11 16:39:36 +08:00
ShengYi Hung 76aa776b5f stand: Fix shadow buffer offset handling
The shadow buffer is addressed relative to `tg_origin`, which includes
the padding offset, whereas `gfxfb_blt` operates on coordinates without
that offset. To make `gfx_fb_copy_area` emulate the behavior of
`gfxfb_blt`, the source coordinates must include the padding offset,
while the destination coordinates must not. The original implementation
omitted the offset from the source coordinates; this change corrects
that.

Additionally, `gfx_fb_cons_display` already applies the padding offset,
so the redundant adjustment is removed.

PR:             296246
Reported by:    [email protected]
Reviewed by:    imp
Tested by:      [email protected], [email protected],
[email protected]
Fixes:          32da2f23ae
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57821
2026-07-01 03:52:55 +08:00
ShengYi Hung 240330a85e libusb: don't treat EINVAL from USB_FS_COMPLETE as device detach
ugen20_process() treats any non-EBUSY errno returned by USB_FS_COMPLETE
as device detach and returns LIBUSB20_ERROR_OTHER. This causes libusb10
to set device_is_gone and fail all subsequent transfer with
LIBUSB_ERROR_NO_DEVICE.

However, USB_FS_COMPLETE can also return EINVAL when a completion
references an endpoint that no longer exists, for example after
SET_INTERFACE or SET_CONFIG removes and recreates endpoints. This is a
transient condition and does not indicate device detach.

Treat EINVAL the same as EBUSY and stop draining completions. This
prevents a guest selecting an isochronous streaming altsetting from
permanently breaking the passed-through device.

Reviewed by:    bapt
Event:          Halifax Hackathon 202606
Location:       Peggy's Cove Rock
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D57542
2026-06-25 19:58:23 -03:00
ShengYi Hung 35255280e5 cpufreq: Fix the incorrect format
Event:          Halifax Hackathon 202606
Location:       jrm@'s dining room
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D57275
2026-06-24 22:17:37 -03:00
ShengYi Hung 8452afeb56 hwpstate_intel: Use 8bit scale instead of percentage scale
Reviewed by:    olce
Relnotes:       yes
Event:          Halifax Hackathon 202606
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55629
2026-06-25 02:18:20 +08:00
ShengYi Hung 29b8220b17 hwpstate_intel: Use ipi instead of thread_lock + sched_bind
Reviewed by:    olce
Event:          Halifax Hackathon 202606
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55628
2026-06-24 22:30:25 +08:00
ShengYi Hung 08dca5971b libusb: Add missing default in handling option switch
This makes GCC happy

Fixes:  2879c818e5 ("implement libusb_set_option")
Event:  Halifax Hackathon 202606
Sponsored by:   The FreeBSD Foundation
2026-06-23 22:37:53 +08:00
ShengYi Hung 25c2251064 libusb: Implement libusb_set_log_cb
Reviewed by:    adrian
Event:  Halifax Hackathon 202606
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57770
2026-06-23 22:28:49 +08:00
ShengYi Hung 1a8701e2e9 libusb: Implement libusb20_tr_get_flags
Reviewed by:    adrian, bapt
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57543
2026-06-22 21:54:31 +08:00
ShengYi Hung d928113eaa libusb: Bump manual date for multiple changes
Sponsored by:   The FreeBSD Foundation
2026-06-22 21:36:48 +08:00
ShengYi Hung d84b639a68 libusb: implement zlp flag in libusb transfer
The USB protocol defines a Zero-Length Packet (ZLP) to signal the end of
a transfer when the data size is an exact multiple of the Maximum Packet
Size (MPS). Without a ZLP in such cases, the device may not be able to
determine that the transfer has completed.

This flag is added to libusb to allow the user send a ZLP in the end
of libusb_xfer.

Reviewed by:    adrian
Sponsored by:   The FreeBSD Foundataion
Differential Revision: https://reviews.freebsd.org/D51759
2026-06-22 21:36:48 +08:00
ShengYi Hung 964823a18e libusb: implement libusb_get_max_alt_packet_size
The libusb has a function to calculate the size from given interface,
alt_setting, endpoint. Implementing it by refactoring the calculating
function for libusb_get_max_iso_packet_size.

Reviewed by:    adrian
Sponsored By:   FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51225
2026-06-22 21:36:47 +08:00
ShengYi Hung be95871347 libusb: refactor the process of setting option when init the context.
From
https://github.com/libusb/libusb/commit/6622f386f52807dac76c8a260c98aa02c311bc93#diff-c1f9bc250077d41456a3e580fca0ddf5d8c25b741bff6d9b9505990a8b70b254R2358.
We are able to set all of the option from the init_context. To address
this, we modify the process of setting option in init_context to make it be more clear and then
adapat libusb_set_option inside to all other option.

Reviewed by:    adrian
Sponsored By:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51224
2026-06-22 21:36:47 +08:00
ShengYi Hung 2879c818e5 libusb: implement libusb_set_option
Implement libusb_set_option for API compatibility of libusb upstream
The implementation status of each option is as following:

LIBUSB_OPTION_LOG_LEVEL: just like libusb_set_debug
LIBUSB_OPTION_LOG_CB: add callback support for DPRINTF
LIBUSB_OPTION_NO_DEVICE_DISCOVERY: disable initialization of devd and
netlink when register. Also, create no thread when registration of
callback happens.
LIBUSB_OPTION_USE_USBDK: no needed as USBDK is for Windows

Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50818
2026-06-22 21:36:47 +08:00
ShengYi Hung ae489991d1 libusb: implement IAD parser
libusb provide functions to parse interface association descriptor. This
descriptor indicates that a function is composed by multiple interface
and which interfaces is associate to the target function. This
descriptor is not a separate USB require, instead, it comes with the
config descriptor.

Reviewed by:    adrian
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50958
2026-06-22 21:36:47 +08:00
ShengYi Hung 32da2f23ae stand: Bulk operations on each gfxfb_blt if shadow buffer enabled
Previously, gfxfb_blt flushed the framebuffer on every call. Since a
single drawing operation may invoke gfxfb_blt multiple times, this can
result in unnecessary flushes.

Instead, write updates to the shadow buffer (when present) and mark the
affected area as dirty. Flushing is deferred so multiple gfxfb_blt calls
can be coalesced into a single update. As before, only the dirty region
is flushed.

This fixes the slow bootloader problem in some platforms.

Reviewed by:    imp, adrian, obiwac
Tested by:      obiwac, jrm
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57373
2026-06-19 04:43:24 +08:00
ShengYi Hung 61e2ffd816 libusb: Sync libusb_class_code with upstream
This reflects the difference from the upstream libusb code.
See: https://github.com/libusb/libusb/blob/master/libusb/libusb.h

Reviewed by:    adrian
Event:          BSDCan 2026
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57620
2026-06-18 04:11:13 +08:00
ShengYi Hung ff46acfd52 usb: implement attach kernel driver feature
FreeBSD's USB framework supports detaching kernel drivers to allow
user space applications to exclusively claim USB interfaces. However,
it lacked support for reattaching the kernel driver afterward.

This commit adds the missing functionality, enabling user space
to return control of the device back to the kernel.

Reviewed by:    lwhsu
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52122
2026-06-11 23:08:30 +08:00
ShengYi Hung 2934783fa8 usb: Add missing unsetup while detaching uchcom
Reviewed by:    christos
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57329
2026-06-09 19:28:27 +08:00
ShengYi Hung 9c04895086 libc: Use slow path in fenv in C++
C++ exposes cfenv functions via using ::func. Our name-mangling
mechanism rewrites all function calls causing symbols such as
std::feclearexcept to be transformed into std::__feclearexcept_int.
Since no such function exists, compilation fails.

The using ::feclearexpect declarations themselves are unaffected because
they are not function calls, which further exposes the mismatch

As a result, enable the fast path only for C and fall back to the slow
path in C++.

Reviewed by:    kib
Fixes:          5bc64b7d41
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57450
2026-06-09 19:25:30 +08:00
ShengYi Hung 7b26353a59 hwpstate_intel: Disable package control on hybrid CPU
In package control mode, the performance of all cores depends on the
most recent value written to the request field. If the last write comes
from an E-core, all cores are forced to align with the E-core
performance level, resulting in significant performance degradation.
Therefore, package control is disabled on hybrid-core systems.

Reviewed by:    olce
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Sponsored by:   Framework Computer Inc
Differential Revision: https://reviews.freebsd.org/D57377
2026-06-02 14:41:41 +08:00
ShengYi Hung 4ccbceefeb spi: Remove incorrect pci id
This id is for SPI flash instead of spi bus

Fixes: 39e297bf54 ("ig4iic: Add PantherLake IDs")
MFC after:      2 weeks
Sponsored by:  The FreeBSD Foundation
Sponsored by:  Framework Computer Inc
2026-06-01 16:45:20 +08:00
ShengYi Hung df5e9e3da5 usb: Add missing mtx lock and unlock in pushing dma queue
Accessing usb_xfer_queue requires bus lock, we added this missing lock
in here to prevent racing issue.

Reviewed by:    adrian
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57293
2026-05-28 22:36:10 +08:00
ShengYi Hung 28d85db46b xhci: Do not drop and add bits in xhci
Drop and Add bits reset the data toggle for high-speed devices in XHCI.
The toggle bit represents the sequence number in USB 2.0 transfers. However,
a device can only recognize that the toggle bit has been reset while in
the HALT state. As a result, the host and device toggle values may
become mismatched, causing xHCI to reject the packet. This issue was
observed while testing the EZ-USB FX2 device.

The transfer may then return to the original value after a
bi-directional TD because the toggle field is only one bit wide. This
explains the reson that we can only receive packets bi-transfer in some
case. Therefore, we do not reset the toggle bit here.

Reviewed by:    adrian
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57146
2026-05-22 15:41:07 +08:00
ShengYi Hung 776584319f sound: Fix lock order reversal in dsp_poll()
chn_poll() may hold both rdch and wrch channel locks while calling
chn_trigger(rdch).  chn_trigger() switches the lock order from
"channel -> dsp dev" to "dsp dev -> channel" by temporarily dropping
the channel lock before acquiring the dsp lock.

However, only rdch was unlocked during the transition while wrch
remained locked. Since wrch is also a channel lock and witness had
already established the lock order requirement:

    dsp dev -> channel

witness reports a lock order reversal when pcm_lock() is acquired while
wrch is still held.

Avoid holding rdch and wrch simultaneously during chn_trigger()
lock-order switching by only keeping the channel locks when needed.

The issue can be reliably reproduced by starting pipewire,
pipewire-pulse, and pavucontrol.

Reviewed by:    christos
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57009
2026-05-15 22:52:48 +08:00
ShengYi Hung bf2c6d23ad Revert "libusb: change callback register handler to int"
This reverts commit ce9ced951a.

We should handle backward compatibility before introducing this patch as
people may rely on old ABI.
2026-05-06 00:48:46 +08:00
ShengYi Hung 0627136698 libusb: fix incorrect status type when completion on cancel the events
Reviewed by:    lwhsu, markj
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51736
2026-05-05 23:58:49 +08:00
ShengYi Hung ce9ced951a libusb: change callback register handler to int
libusb upstream uses int for register handler. This causes some library
user (like pyusb) to assume that we have int in all implementations and
therefore provides a 4 byte storage only. This causes Segmentation
fault as we will right the pointer.

Reviewed by:    adrian
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D54211
2026-05-05 23:48:22 +08:00
ShengYi Hung efc0ced5c4 ath{10,11,12}k: Add missing header in Makefile
Reviewed by:    bz
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56693
2026-05-05 23:26:48 +08:00
ShengYi Hung 261002908f libusb: Add libusb_endpoint_transfer_type enum
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
2026-05-05 23:22:47 +08:00
ShengYi Hung e48e979458 hwpstate_amd: Cache cpuid
Reviewed by:    olce
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56305
2026-04-16 16:44:03 +08:00
ShengYi Hung 43d632779b x86: Mark LOCORE to prevent build failure on i386 platform
PR:     294468
Reported by:    [email protected]
Tested by:      [email protected]
Discussed with: kib
Fixes:  9289df1949cd ("x86: Add zen identifier helper function")
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56377
2026-04-14 12:58:39 +08:00
ShengYi Hung 2358492b03 x86: Add zen identifier helper function
Reviewed by:    kib
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56330
2026-04-10 21:51:31 +08:00
ShengYi Hung 095cbb1bb7 hwpstate_amd: Expose nodes as much as possible in legacy pstate
Reviewed by:    olce
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D55606
2026-04-08 15:48:34 +08:00
ShengYi Hung e6eba50769 vmm: Add missing AVX instructions for AVX512 in cpuid stdext
Reported by:    Tom <[email protected]>
Reviewed by:    markj
Tested by:      Tom <[email protected]>
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D56021
2026-03-30 15:19:44 +08:00
ShengYi Hung c25976f0a9 libc: Fix cxa_thread_atexit{,nothr} test.
After patch 9d26b82, we don't provide recursive call protection anymore.
Therefore, to pass the test, we adjust the testcase by protecting on
caller and the testcase is to make sure the dtors is properly handled.

Reported by:    siva
Reviewed by:    kib
Approved by:    markj (mentor)
Fixes:  9d26b82826 ("libc: Fix dtor order in __cxa_thread_atexit")
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55893
2026-03-22 10:48:24 +08:00
ShengYi Hung 191f47bcd6 hwpstate_amd: Refactor the cpufreq code by using delegation pattenr
We separate the code of CPPC and legacy pstate driver to make it easier
to read.

Reviewed by:    olce
Approved by:    markj (mentor)
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55604
2026-03-22 10:35:36 +08:00
ShengYi Hung 9d26b82826 libc: Fix dtor order in __cxa_thread_atexit
The thread_local variable may creates another thread_local variable
inside its dtor. This new object is immediately be registered in
__cxa_thread_atexit() and need to be freed before processing another
variable.

This fixes the libcxx test thread_local_destruction_order.pass.cpp.

Reported by:    kib
Approved by:    lwhsu (mentor)
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55826
2026-03-14 12:30:25 +08:00
ShengYi Hung 728ae49a6b kern_time: Honor the precise option when counting diff
When preecise option is used, the true elapsed time should also use the
precise timer.

This fixes the test case sleep_for.signals.pass.cpp in libcxx.

Reviewed by:    kib, imp
Approved by:    lwhsu (mentor)
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55824
2026-03-14 12:21:26 +08:00
ShengYi Hung 546d925cb4 ichwd: Add manual for i6300esb watchdog
Reviewed by:    ziaee, mhorne
Approved by:    lwhsu (mentor)
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D54466
2026-03-04 21:51:13 +08:00
ShengYi Hung e387d9438b smp: Use bitwise operation to count cpu number
Previously, we iterated over all CPUs using CPU_FOREACH and checked
individual bits to count valid CPUs. Refactor this to use a bitwise AND
and popcount to count the number of enabled bits directly.

Approved by:    markj (mentor)
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D54474
2026-02-18 17:40:54 +08:00
ShengYi Hung 87c4d6555b hwpstate_amd: Use ipi instead of sched_bind + thread_lock
Reviewed by:    olce
Approved by:    markj (mentor)
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D54505
2026-01-16 22:38:15 +08:00
ShengYi Hung 5b61ef94d6 smp: add smp_rendezvous_cpu helper function
Reviewed by:    olce
Approved by:    markj (mentor)
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D54551
2026-01-16 22:38:12 +08:00
ShengYi Hung 3642ba2a98 hwpstate_amd: Fix compile error
Add parentheses between OR and AND operator to pass the compiler check.

Approved by:    lwhsu (mentor)
Fixes:  3e6e4e4a0d ("hwpstate: add CPPC support for pstate driver on AMD")
MFC aftert:     2 weeks
Differential Revision: https://reviews.freebsd.org/D54465
2026-01-03 14:09:48 +08:00
ShengYi Hung 3e6e4e4a0d hwpstate: add CPPC support for pstate driver on AMD
Implement CPPC interface for AMD Pstate Driver.
This feature is only enabled when the CPUID shows it support CPPC.

The CPPC is implemneted by the following steps:

1. Write MSR to enable it.
2. Read capability registert which indicates binary value of levels
about lowest, best energy efficient, guarantee, and max performance.
3. Write request register with epp in energy balanced mode. And let
CPU and firmware to enter autonomous mode.

Also, create a sysctl handler to allow userspace to change epp value.
In intel's hwpstate, The epp value can be in package level and core level.
However, in AMD's one, there is only core level. Thus, to sync with the
intel's code, we implement package level control in software and provide
another sysctl (machdep.hwpstate_pkg_ctrl) to control it.

Reviewed by:    olce, khng
Approved by:    lwhsu (mentor)
MFC after:      2 weeks
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49587
2026-01-03 10:52:51 +08:00
ShengYi Hung 1d1a2e6932 lldb: Fix empty register set when trying to get size of register
The register set information is stored as a singleton in
GetRegisterInfo_i386. However, other functions later access this
information assuming it is stored in GetSharedRegisterInfoVector. To
resolve this inconsistency, we remove the original construction logic
and instead initialize the singleton using llvm::call_once within the
appropriate function (GetSharedRegisterInfoVector_i386).

PR:		289945
Obtained from:	llvm-project 41859c27842eeda1ef6ff18f3b2fb269388c0857
2025-11-23 12:49:51 -05:00