Skip to content

Commit

Permalink
LinuxKPI: update linuxkpi_video to Linux 6.6
Browse files Browse the repository at this point in the history
disable hdmi_audio_infoframe_pack_for_dp function for now as it depends
on not imported yet drm sources and is not used by drm-kmod.

Reviewed by:	manu
Sponsored by:	Serenity CyberSecurity, LLC
Differential Revision:	https://reviews.freebsd.org/D46224
  • Loading branch information
wulf7 committed Aug 7, 2024
1 parent a9e4753 commit c89d94a
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 59 deletions.
16 changes: 11 additions & 5 deletions sys/compat/linuxkpi/common/include/linux/aperture.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ int devm_aperture_acquire_for_platform_device(struct platform_device *pdev,
resource_size_t size);

int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
bool primary, const char *name);
const char *name);

int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev);

int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *name);
#else
Expand All @@ -28,7 +30,12 @@ static inline int devm_aperture_acquire_for_platform_device(struct platform_devi
}

static inline int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
bool primary, const char *name)
const char *name)
{
return 0;
}

static inline int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev)
{
return 0;
}
Expand All @@ -41,7 +48,6 @@ static inline int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev,

/**
* aperture_remove_all_conflicting_devices - remove all existing framebuffers
* @primary: also kick vga16fb if present; only relevant for VGA devices
* @name: a descriptive name of the requesting driver
*
* This function removes all graphics device drivers. Use this function on systems
Expand All @@ -50,9 +56,9 @@ static inline int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev,
* Returns:
* 0 on success, or a negative errno code otherwise
*/
static inline int aperture_remove_all_conflicting_devices(bool primary, const char *name)
static inline int aperture_remove_all_conflicting_devices(const char *name)
{
return aperture_remove_conflicting_devices(0, (resource_size_t)-1, primary, name);
return aperture_remove_conflicting_devices(0, (resource_size_t)-1, name);
}

#endif
13 changes: 10 additions & 3 deletions sys/compat/linuxkpi/common/include/linux/hdmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ struct hdmi_avi_infoframe {
enum hdmi_infoframe_type type;
unsigned char version;
unsigned char length;
bool itc;
unsigned char pixel_repeat;
enum hdmi_colorspace colorspace;
enum hdmi_scan_mode scan_mode;
enum hdmi_colorimetry colorimetry;
enum hdmi_picture_aspect picture_aspect;
enum hdmi_active_aspect active_aspect;
bool itc;
enum hdmi_extended_colorimetry extended_colorimetry;
enum hdmi_quantization_range quantization_range;
enum hdmi_nups nups;
unsigned char video_code;
enum hdmi_ycc_quantization_range ycc_quantization_range;
enum hdmi_content_type content_type;
unsigned char pixel_repeat;
unsigned short top_bar;
unsigned short bottom_bar;
unsigned short left_bar;
Expand Down Expand Up @@ -336,7 +336,14 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
void *buffer, size_t size);
ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,
void *buffer, size_t size);
int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe *frame);
int hdmi_audio_infoframe_check(const struct hdmi_audio_infoframe *frame);

#ifdef __linux__
struct dp_sdp;
ssize_t
hdmi_audio_infoframe_pack_for_dp(const struct hdmi_audio_infoframe *frame,
struct dp_sdp *sdp, u8 dp_version);
#endif

enum hdmi_3d_structure {
HDMI_3D_STRUCTURE_INVALID = -1,
Expand Down
44 changes: 44 additions & 0 deletions sys/compat/linuxkpi/common/include/video/cmdline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2023 Serenity Cyber Security, LLC.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#ifndef _VIDEO_CMDLINE_H_
#define _VIDEO_CMDLINE_H_

#include <linux/types.h>

#define CONFIG_VIDEO_CMDLINE

#if defined(CONFIG_VIDEO_CMDLINE)
const char *video_get_options(const char *name);
#else
static inline const char *
video_get_options(const char *name)
{
return (NULL);
}
#endif
#endif /* _VIDEO_CMDLINE_H_ */
86 changes: 54 additions & 32 deletions sys/compat/linuxkpi/common/src/linux_aperture.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* driver can be active at any given time. Many systems load a generic
* graphics drivers, such as EFI-GOP or VESA, early during the boot process.
* During later boot stages, they replace the generic driver with a dedicated,
* hardware-specific driver. To take over the device the dedicated driver
* hardware-specific driver. To take over the device, the dedicated driver
* first has to remove the generic driver. Aperture functions manage
* ownership of framebuffer memory and hand-over between drivers.
*
Expand All @@ -43,7 +43,7 @@
* base = mem->start;
* size = resource_size(mem);
*
* ret = aperture_remove_conflicting_devices(base, size, false, "example");
* ret = aperture_remove_conflicting_devices(base, size, "example");
* if (ret)
* return ret;
*
Expand Down Expand Up @@ -76,7 +76,7 @@
* generic EFI or VESA drivers, have to register themselves as owners of their
* framebuffer apertures. Ownership of the framebuffer memory is achieved
* by calling devm_aperture_acquire_for_platform_device(). If successful, the
* driveris the owner of the framebuffer range. The function fails if the
* driver is the owner of the framebuffer range. The function fails if the
* framebuffer is already owned by another driver. See below for an example.
*
* .. code-block:: c
Expand Down Expand Up @@ -126,7 +126,7 @@
* et al for the registered framebuffer range, the aperture helpers call
* platform_device_unregister() and the generic driver unloads itself. The
* generic driver also has to provide a remove function to make this work.
* Once hot unplugged fro mhardware, it may not access the device's
* Once hot unplugged from hardware, it may not access the device's
* registers, framebuffer memory, ROM, etc afterwards.
*/

Expand Down Expand Up @@ -203,7 +203,7 @@ static void aperture_detach_platform_device(struct device *dev)

/*
* Remove the device from the device hierarchy. This is the right thing
* to do for firmware-based DRM drivers, such as EFI, VESA or VGA. After
* to do for firmware-based fb drivers, such as EFI, VESA or VGA. After
* the new driver takes over the hardware, the firmware device's state
* will be lost.
*
Expand Down Expand Up @@ -274,7 +274,6 @@ static void aperture_detach_devices(resource_size_t base, resource_size_t size)
* aperture_remove_conflicting_devices - remove devices in the given range
* @base: the aperture's base address in physical memory
* @size: aperture size in bytes
* @primary: also kick vga16fb if present; only relevant for VGA devices
* @name: a descriptive name of the requesting driver
*
* This function removes devices that own apertures within @base and @size.
Expand All @@ -283,7 +282,7 @@ static void aperture_detach_devices(resource_size_t base, resource_size_t size)
* 0 on success, or a negative errno code otherwise
*/
int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
bool primary, const char *name)
const char *name)
{
/*
* If a driver asked to unregister a platform device registered by
Expand All @@ -300,18 +299,45 @@ int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t si

aperture_detach_devices(base, size);

/*
* If this is the primary adapter, there could be a VGA device
* that consumes the VGA framebuffer I/O range. Remove this device
* as well.
*/
if (primary)
aperture_detach_devices(VGA_FB_PHYS_BASE, VGA_FB_PHYS_SIZE);

return 0;
}
EXPORT_SYMBOL(aperture_remove_conflicting_devices);

/**
* __aperture_remove_legacy_vga_devices - remove legacy VGA devices of a PCI devices
* @pdev: PCI device
*
* This function removes VGA devices provided by @pdev, such as a VGA
* framebuffer or a console. This is useful if you have a VGA-compatible
* PCI graphics device with framebuffers in non-BAR locations. Drivers
* should acquire ownership of those memory areas and afterwards call
* this helper to release remaining VGA devices.
*
* If your hardware has its framebuffers accessible via PCI BARS, use
* aperture_remove_conflicting_pci_devices() instead. The function will
* release any VGA devices automatically.
*
* WARNING: Apparently we must remove graphics drivers before calling
* this helper. Otherwise the vga fbdev driver falls over if
* we have vgacon configured.
*
* Returns:
* 0 on success, or a negative errno code otherwise
*/
int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev)
{
/* VGA framebuffer */
aperture_detach_devices(VGA_FB_PHYS_BASE, VGA_FB_PHYS_SIZE);

/* VGA textmode console */
#ifdef __linux__
return vga_remove_vgacon(pdev);
#elif defined(__FreeBSD__)
return 0;
#endif
}
EXPORT_SYMBOL(__aperture_remove_legacy_vga_devices);

/**
* aperture_remove_conflicting_pci_devices - remove existing framebuffers for PCI devices
* @pdev: PCI device
Expand All @@ -328,14 +354,14 @@ int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *na
{
bool primary = false;
resource_size_t base, size;
int bar, ret;
int bar, ret = 0;

#ifdef CONFIG_X86
#ifdef __linux__
primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
#elif defined(__FreeBSD__)
primary = NULL;
#endif
if (pdev == vga_default_device())
primary = true;

if (primary)
sysfb_disable();
#endif

for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
Expand All @@ -344,22 +370,18 @@ int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *na

base = pci_resource_start(pdev, bar);
size = pci_resource_len(pdev, bar);
ret = aperture_remove_conflicting_devices(base, size, primary, name);
if (ret)
return ret;
aperture_detach_devices(base, size);
}

/*
* WARNING: Apparently we must kick fbdev drivers before vgacon,
* otherwise the vga fbdev driver falls over.
* If this is the primary adapter, there could be a VGA device
* that consumes the VGA framebuffer I/O range. Remove this
* device as well.
*/
#ifdef __linux__
ret = vga_remove_vgacon(pdev);
if (ret)
return ret;
#endif
if (primary)
ret = __aperture_remove_legacy_vga_devices(pdev);

return 0;
return ret;

}
EXPORT_SYMBOL(aperture_remove_conflicting_pci_devices);
63 changes: 63 additions & 0 deletions sys/compat/linuxkpi/common/src/linux_cmdline.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*-
* Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/

#include <sys/param.h>
#include <sys/systm.h>

#include <video/cmdline.h>

const char *
video_get_options(const char *connector_name)
{
char tunable[64];
const char *options;

/*
* A user may use loader tunables to set a specific mode for the
* console. Tunables are read in the following order:
* 1. kern.vt.fb.modes.$connector_name
* 2. kern.vt.fb.default_mode
*
* Example of a mode specific to the LVDS connector:
* kern.vt.fb.modes.LVDS="1024x768"
*
* Example of a mode applied to all connectors not having a
* connector-specific mode:
* kern.vt.fb.default_mode="640x480"
*/
snprintf(tunable, sizeof(tunable), "kern.vt.fb.modes.%s",
connector_name);
if (bootverbose) {
printf("[drm] Connector %s: get mode from tunables:\n", connector_name);
printf("[drm] - %s\n", tunable);
printf("[drm] - kern.vt.fb.default_mode\n");
}
options = kern_getenv(tunable);
if (options == NULL)
options = kern_getenv("kern.vt.fb.default_mode");

return (options);
}
Loading

0 comments on commit c89d94a

Please sign in to comment.