freebsd-src/sys/powerpc
Mitchell Horne b134c10d65 busdma: fix page miscount for small segment sizes
For small segments (< PAGE_SIZE) there is a mismatch between how
required bounce pages are counted in _bus_dmamap_count_pages() and
bounce_bus_dmamap_load_buffer().

This problem has been observed on the RISC-V VisionFive v2 SoC (and
earlier revisions of the hardware) which has memory physically addressed
above 4GB. This requires some bouncing for the dwmmc driver, which has
has a maximum segment size of 2048 bytes. When attempting to load a
page-aligned 4-page buffer that requires bouncing, we can end up
counting 4 bounce pages for an 8-segment transfer. These pages will be
incorrectly configured to cover only the first half of the transfer (4 x
2048 bytes).

Fix the immediate issue by adding the maxsegsz check to
_bus_dmamap_count_pages(); this is what _bus_dmamap_count_phys() does
already. The result is that we will inefficiently allocate a separate
bounce page for each segment (8 pages for the example above), but the
transfer will proceed in its entirety.

The more complete fix is to address the shortcomings in how small
segments are assigned to bounce pages, so that we opportunistically
batch multiple segments to a page whenever they fit (e.g. two 2048 bytes
segments per 4096 page). This will be addressed more holistically in the
future. For now this change will prevent the (silent) incomplete
transfers that have been observed.

PR:		273694
Reported by:	Jari Sihvola <jsihv@gmx.com>
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34118
2024-02-16 14:38:48 -04:00
..
aim pmap: Convert boolean_t to bool. 2024-01-31 14:48:26 -08:00
amigaone sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
booke pmap: Convert boolean_t to bool. 2024-01-31 14:48:26 -08:00
conf Add a COMPAT_FREEBSD14 kernel option 2023-10-10 11:48:22 +02:00
cpufreq sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
fpu sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
include pmap: Convert boolean_t to bool. 2024-01-31 14:48:26 -08:00
mambo sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
mikrotik sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
mpc85xx powerpc mpc85xx: Fix infinite recursion in bus_adjust_resource method 2024-02-16 09:40:34 -08:00
ofw sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
powermac powerpc powermac: Use bus_generic_rman_* 2024-01-23 09:36:49 -08:00
powernv sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
powerpc busdma: fix page miscount for small segment sizes 2024-02-16 14:38:48 -04:00
ps3 powerpc ps3bus: Use bus_generic_rman_* 2024-01-23 09:36:12 -08:00
pseries sys: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:00 -07:00
psim powerpc psim: Fix infinite recursion in bus_adjust_resource method 2024-02-16 09:42:30 -08:00