Commit graph

1076 commits

Author SHA1 Message Date
Elliott Mitchell
a9e0f316b3 kern/intr: redeclare intr_setaffinity()'s third arg constant
This matches reality and allows removal of a __DECONST().

Fixes: 4c72d075a5 ("LinuxKPI: const argument to irq_set_affinity_hint()")
Fixes: 9b33b154b5 ("Add support to cpuset for binding hardware interrupts")
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1126
2024-05-09 17:14:35 -06:00
Tijl Coosemans
2ae0f5a4d0 linuxkpi: Make arch_io_*_memtype_wc amd64-only
Linux only implements these functions on x86.  They return 0 on other
architectures.  The FreeBSD implementation calls PHYS_TO_DMAP but this
panics on i386 because it does not have a direct map so return 0 on i386
as well for now.  These functions are only used by graphics/drm-*-kmod
to mark the VRAM aperture write-combining but this is also accomplished
by a call to vm_phys_fictitious_reg_range so this change is sufficient
to fix drm-*-kmod on i386 for FreeBSD 14.1.

Reviewed by:	kib
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D45125
2024-05-08 20:52:37 +02:00
Emmanuel Vadot
11d79c4756 linuxkpi: Add linuxkpi_video module
This contain the hdmi code and the aperture code like in linux.

Differential Revision:	https://reviews.freebsd.org/D44925
Reviewed by:		bz
Obtained from:		drm-kmod
Sponsored by:		Beckhoff Automation GmbH & Co. KG
2024-04-30 07:42:31 +02:00
Bjoern A. Zeeb
563c72e213 LinuxKPI: utsname.h add missing SPDX-License-Identifier
Reported by:	markj (2023-05-24; sorry took me a while)
MFC after:	3 days
2024-04-19 18:23:12 +00:00
Bjoern A. Zeeb
2a8c50592f LinuxKPI: add __counted_by() and __nonstring
Add checks for __counted_by(_x) and __nonstring as and depending
on compiler support enable the attribute/feature.

This is needed to make mtk76 and ath1xk drivers compile.

Sposnored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste, dim
Differential Revision: https://reviews.freebsd.org/D44587
2024-04-15 19:31:49 +00:00
Bjoern A. Zeeb
170c2e0e2b LinuxKPI: add devm_kfree()
mt76 calls devm_kfree() directly, so alias it to our
lkpi_devm_kmalloc_release() function.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D44589
2024-04-15 16:55:59 +00:00
Bjoern A. Zeeb
21761f2ede LinuxKPI: napi_schedule() requires return value, implement napi_is_scheduled()
A newer version of iwlwifi requires a return value from napi_schedule();
unclear if the function always should have been bool. Add the bool to test
based on the napi_schedule_prep() result.

Also add napi_is_scheduled() for rtw89.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste (previous version)
Differential Revision:	https://reviews.freebsd.org/D44591
2024-04-15 16:19:47 +00:00
Bjoern A. Zeeb
3d3ec17825 LinuxKPI: sk_buff: implement skb_queue_splice_tail_init()
Implement skb_queue_splice_tail_init() and SKB_DATA_ALIGN() as
needed by the mt76 wireless driver.

Sponsord by:	The FreeBD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44590
2024-04-15 16:06:11 +00:00
Bjoern A. Zeeb
738c02ba24 LinuxKPI: add dev_alloc_pages()
Add dev_alloc_pages() though it seems a weird KPI, not passing a dev
despite its name.  Used by updated wireless driver.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44588
2024-04-12 23:15:27 +00:00
Bjoern A. Zeeb
f674f016c0 LinuxKPI: add BITS_TO_BYTES()
Just like BITS_TO_LONG() ... used in rtw89.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44603
2024-04-12 23:11:47 +00:00
Bjoern A. Zeeb
218b2ccf8c LinuxKPI: implement memzero_explicit()
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D44586
2024-04-12 23:09:19 +00:00
Bjoern A. Zeeb
a1cdddcf15 LinuxKPI: add further constants to pci.h
Updated wireless drivers require more knowledge about PCI (BAR) bits.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Reviewed by:	jhb
Differential Revision: https://reviews.freebsd.org/D44573
2024-04-12 23:08:06 +00:00
Vladimir Kondratyev
4e7aa03b70 LinuxKPI: Stub sysfs_remove_link in linux/sysfs.h
sysfs_create_link is stubbed already. Stub sysfs_remove_link too to be
feature-complete.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
56041ee817 LinuxKPI: Add want_init_on_free to linux/mm.h
want_init_on_free returns if heap memory zeroing on free is enabled.
FreeBSD does not zeroes heap memory on free().

Sponsored by:	Serenity Cyber Security
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
f7ea333e2b LinuxKPI: Add ACPI_ID_LEN const to linux/mod_devicetable.h
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
f1206503e5 LinuxKPI: Add pci_dev_id to linux/pci.h
It returns bus/device/function number for given PCI device.
Also add intermediate PCI_DEVID macro used in some drivers.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
e8f59f4d31 LinuxKPI: Add the accelerator PCIe class
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:43 +03:00
Vladimir Kondratyev
e0eeeca8b8 LinuxKPI: Add PTR_IF macro
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
06902a4479 LinuxKPI: Add vm_flags_(clear|set) functions
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
9289c1f6f1 LinuxKPI: Add get_random_u32_below function
get_random_u32_below returns a random integer in the interval [0, ceil),
with uniform distribution.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
38c276a43f LinuxKPI: Add VM_ACCESS_FLAGS define to linux/mm.h
VM_ACCESS_FLAGS is a basic access permission flags.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
3208d4ad2b LinuxKPI: Import vanilla linux/overflow.h
It is dual-licensed (GPLv2 & MIT) and self-contained header file.
No need to reimplement it.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
8cfd1dd821 LinuxKPI: Move [SU](8|16|32|64)_(MAX|MIN) defines to linux/limits.h
Some source files get them from linux/limits.h directly rather than from
linux/kernel.h.
While here replace Linux constant values with sys/stdint.h provided ones.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
1970388766 LinuxKPI: Add strnchr function
strnchr() finds a character in a length limited string.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 month
2024-04-08 09:47:42 +03:00
Vladimir Kondratyev
aafe4126f7 LinuxKPI: Add ms_to_ktime
Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	emaste
MFC after:	1 week
2024-04-08 09:47:42 +03:00
Zhenlei Huang
317cc829ee LinuxKPI: Remove the temporary variable fileid from the macro request_module
The variable fileid stores the result from kern_kldload() but never gets
used. Since the third parameter `*fileid` of kern_kldload() can be NULL,
this unused variable can be safely removed.

No functional change intended.

Reviewed by:	emaste, bz, #linuxkpi
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D44583
2024-04-06 00:26:09 +08:00
Bjoern A. Zeeb
ce707e674f LinuxKPI: add PCI_VENDOR_ID_ITTIM
Add PCI_VENDOR_ID_ITTIM as needed by mt76.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-04-02 10:03:31 +00:00
Tom Coldrick
d3befb534b LinuxKPI: Queue skbuffs at tail in __skb_queue_tail
Correct skb_queue_tail to queue the buffer at the tail of the skbuff.
The skbuff is a circular doubly-linked list, and we call with a pointer
to the head of the list.  Thus queueing before the head gives us a
queueing at the tail.

As a motivating factor, the current behaviour (queueing at the head) was
causing frequent kernel panics from my RTL8822BE wireless card, which
uses the rtw88 driver.  Interrupts can cause buffers to be added to the
rtwdev c2h_queue while the queue is being drained in rtw_c2h_work.
Queueing at the head would leave the nascent entry in the linked list
pointing to the old, now freed, memory for the buffer being processed.
When rtw_c2h_work is next called, we try reading this and so panic.

Reviewed by:	emaste, bz
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D44192
2024-03-04 09:33:12 -05:00
Bjoern A. Zeeb
7061745867 LinuxKPI: sort dev_<loglevel>() functions
Sort the dev_<loglevel> functions by loglevel order, add the dev_alert()
version and an indentation change.

No functional changes.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D43719
2024-02-14 22:05:21 +00:00
Bjoern A. Zeeb
53eb2c63c9 LinuxKPI: 802.11: correct HT protection fields
It seems during the initial buildup of the file, the defines were
either mixed or not flagged as "FIXME".
Define the values through to the net80211 definitions and also
annotate them by at least some standards reference.

MFC after:	3 days
Fixes:		6b4cac814e
Reviewed by:	cc
Differential Revision: https://reviews.freebsd.org/D43658
2024-02-14 19:36:30 +00:00
Vladimir Kondratyev
c0b8047bdc LinuxKPI: Allow kmalloc to be called when FPU protection is enabled
Amdgpu driver does a lot of memory allocations in FPU-protected sections
of code for certain display cores, e.g. for DCN30. This does not work
on FreeBSD as its malloc function can not be run within a critical
section. Check this condition and temporally exit from FPU-protected
context to workaround issue and reduce source code patching.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu (previous version)
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D42822
2024-02-11 01:01:50 +03:00
Vladimir Kondratyev
db65db64fb Revert "LinuxKPI: Add explicit software context to FPU sections"
kmalloc() support within FPU sections will be redone in other way.

This reverts commit 5a3bd28167.

Sponsored by:	Serenity Cyber Security, LLC
Requested by:	jhb
2024-02-11 01:01:50 +03:00
Vladimir Kondratyev
7f1a7506cb Revert "LinuxKPI: Do not use explicit context in FPU sections on powerpc64"
kmalloc() support within FPU sections will be redone in other way.

This reverts commit b4efc62776.

Sponsored by:	Serenity Cyber Security, LLC
Requested by:	jhb
2024-02-11 01:01:50 +03:00
Bjoern A. Zeeb
2d9d35837d LinuxKPI: implement memset_after()
memset_after() is needed by iwlwifi d3.c.

MFC after:	3 days
Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D43644
2024-02-03 13:50:32 +00:00
Bjoern A. Zeeb
2f029bf911 LinuxKPI: 802.11: extend ieee80211_key_seq and WLAN_KEY_LEN_* defines
For iwlwifi(4) d3.c we need another struct in struct ieee80211_key_seq
and related WLAN_KEY_LEN_* defines in.

MFC after:	3 days
Reviewed by:	cc, emaste
Differential Revision: https://reviews.freebsd.org/D43646
2024-02-03 13:31:50 +00:00
Gleb Smirnoff
f79a8585bb sockets: garbage collect SS_ISCONFIRMING
Fixes:	8df32b19de
2024-01-30 10:38:33 -08:00
Ed Maste
7e77089dcc linuxkpi: remove invalid KASSERT from hash_add_rcu
hash_add_rcu asserted that the node's prev pointer was NULL in an
attempt to detect addition of a node already on a list, but the caller
is not required to provide a zeroed node.

Reported in https://github.com/freebsd/drm-kmod/issues/282

Reviewed by:	bz, manu
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D43645
2024-01-29 11:40:17 -05:00
Mark Johnston
344a04ad2c linuxkpi: Annotate an unused variable as such
This addresses a -Wunused-but-set-variable warning in the gcc builds.

No functional change intended.

Reported by:	Jenkins
2023-12-27 10:11:33 -05:00
Vladimir Kondratyev
dbca442414 LinuxKPI: Constify src parameter of bitmap_copy
in bitmap_from_arr32() to fix build on 32 bit archs.

Sponsored by:	Serenity Cyber Security, LLC
Fixes:	5ae2e6f913 ("LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()")
MFC after:	1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev
73ccd188c4 LinuxKPI: Define ioread64() in linux/io.h only on 64 bit archs.
32 bit archs includes nonatomic version from linux/io-64-nonatomic-*.h

Sponsored by:   Serenity Cyber Security, LLC
Fixes:		dcfc983373 ("LinuxKPI: Implement ioread64()")
MFC after:      1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev
b4efc62776 LinuxKPI: Do not use explicit context in FPU sections on powerpc64
It is not supported yet.

Sponsored by:	Serenity Cyber Security, LLC
Fixes:	5a3bd28167 ("LinuxKPI: Add explicit software context to FPU sections")
MFC after:	1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev
5a3bd28167 LinuxKPI: Add explicit software context to FPU sections
Amdgpu driver does a lot of memory allocations in FPU-protected sections
of code for certain display cores, e.g. for DCN30. This does not work
currently on FreeBSD as its malloc function can not be run within a
critical section. Allocate memory for FPU context to overcome such
restriction.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu (previous version), markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42822
2023-12-24 11:20:01 +03:00
Vladimir Kondratyev
808ae4e29b LinuxKPI: Add pcie_capability_clear_and_set_word() function
It does a Read-Modify-Write operation using clear and set bitmasks on
PCI Express Capability Register at pos. As certain PCI Express
Capability Registers are accessed concurrently in RMW fashion, hence
require locking which is handled transparently to the caller.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	manu, bz
MFC after:	1 week
MFC TODO:	Move pcie_cap_lock to bottom to preserve KBI compatibility
Differential Revision:	https://reviews.freebsd.org/D42821
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
730387b64e LinuxKPI: Add linux/apple-gmux.h
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42819
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
c58ddc2546 LinuxKPI: Rename linux_list_add to __list_add() in linux/list.h
to match Linux

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42818
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
9903d83d67 LinuxKPI: Add linux/ioport.h header
Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42817
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
7f88d742e5 LinuxKPI: Add get_random_u64() function
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42816
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
2b037743a7 LinuxKPI: Add linux/dynamic_debug.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42815
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev
5ae2e6f913 LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()
and bitmap_shift_right() functions to linux/bitmap.h

They perform calculation of two bitmaps intersection,
copying the contents of u32 array of bits to bitmap and
logical right shifting of the bits in a bitmap.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42812
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev
1b2f43a742 LinuxKPI: Add cancel_work() function.
Cancel a work not waiting for it to finish.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42811
2023-12-24 11:19:59 +03:00