########################################################################### ###
#@File
#@Copyright     Copyright (c) Imagination Technologies Ltd. All Rights Reserved
#@License       Dual MIT/GPLv2
#
# The contents of this file are subject to the MIT license as set out below.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# Alternatively, the contents of this file may be used under the terms of
# the GNU General Public License Version 2 ("GPL") in which case the provisions
# of GPL are applicable instead of those above.
#
# If you wish to allow use of your version of this file only under the terms of
# GPL, and not to allow others to use your version of this file under the terms
# of the MIT license, indicate your decision by deleting the provisions above
# and replace them with the notice and other provisions required by GPL as set
# out in the file called "GPL-COPYING" included in this distribution. If you do
# not delete the provisions above, a recipient may use your version of this file
# under the terms of either the MIT license or GPL.
#
# This License is also included in this distribution in the file called
# "MIT-COPYING".
#
# EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
# PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
### ###########################################################################

LINUX_KERNEL_VERSION := $(shell uname -r)
KERNEL_MAJOR := $(word 1, $(subst ., ,$(LINUX_KERNEL_VERSION)))
KERNEL_MINOR := $(word 2, $(subst ., ,$(LINUX_KERNEL_VERSION)))
# Display
XDX_PLATEFORM_DRV := \
	pvr_device.o \
	pvr_heaps.o \
	pvr_drv.o \
	event.o \
	fwload.o \
	km_apphint.o \
	osmmap_stub.o \
	osfunc.o \
	allocmem.o \
	osconnection_server.o \
	physmem_osmem_linux.o \
	pmr_os.o \
	pvr_bridge_k.o \
	pvr_debug.o \
	physmem_dmabuf.o \
	dkf_server.o \
	pmr_env.o \
	pvr_gem.o

# Wrap ExtMem support
ifeq ($(SUPPORT_WRAP_EXTMEM),1)
	XDX_PLATEFORM_DRV += \
	physmem_extmem_linux.o
endif

ifeq ($(SUPPORT_LINUX_WRAP_EXTMEM_PAGE_TABLE_WALK),1)
	XDX_PLATEFORM_DRV += pg_walk_through.o
endif

ifeq ($(NO_HARDWARE),1)
	XDX_PLATEFORM_DRV += pvr_sysconfig_nohw.o
else
	XDX_PLATEFORM_DRV += pvr_sysconfig.o
endif

ifeq ($(SUPPORT_PHYSMEM_TEST),1)
	XDX_PLATEFORM_DRV += physmem_test.o
endif # SUPPORT_PHYSMEM_TEST

ifeq ($(PVR_LOADER),1)
	XDX_PLATEFORM_DRV += pvr_platform_drv.o
endif #PVR_LOADER

ifeq ($(SUPPORT_RGX),1)
ifeq ($(CONFIG_EVENT_TRACING),y)
	XDX_PLATEFORM_DRV += pvr_gputrace.o
endif
endif # SUPPORT_RGX

ifeq ($(PVRSRV_ANDROID_TRACE_GPU_FREQ),1)
	XDX_PLATEFORM_DRV += pvr_gpufreq.o
endif

ifeq ($(SUPPORT_SECURE_EXPORT),1)
	XDX_PLATEFORM_DRV += ossecure_export.o
	subdir-ccflags-y += -DSUPPORT_SECURE_EXPORT
endif # SUPPORT_SECURE_EXPORT

ifeq ($(PVR_HANDLE_BACKEND),idr)
	XDX_PLATEFORM_DRV += handle_idr.o
endif # PVR_HANDLE_BACKEND

ifeq ($(PVRSRV_ENABLE_LINUX_MMAP_STATS),1)
	XDX_PLATEFORM_DRV += mmap_stats.o
endif # PVRSRV_ENABLE_LINUX_MMAP_STATS

ifeq ($(SUPPORT_BUFFER_SYNC),1)
	subdir-ccflags-y += -DSUPPORT_BUFFER_SYNC

	XDX_PLATEFORM_DRV += \
		pvr_buffer_sync.o \
		pvr_fence.o
endif # SUPPORT_BUFFER_SYNC

ifeq ($(SUPPORT_NATIVE_FENCE_SYNC),1)
	XDX_PLATEFORM_DRV += \
		pvr_sync_ioctl_common.o \
		pvr_sync_file.o \
		pvr_counting_timeline.o \
		pvr_sw_fence.o \
		pvr_export_fence.o \
		pvr_fence.o
	ifeq ($(USE_PVRSYNC_DEVNODE),1)
		XDX_PLATEFORM_DRV += pvr_sync_ioctl_dev.o
	else
		XDX_PLATEFORM_DRV += pvr_sync_ioctl_drm.o
	endif # USE_PVRSYNC_DEVNODE

	ifeq ($(SUPPORT_BUFFER_SYNC),1)
		subdir-ccflags-y += -DSUPPORT_BUFFER_SYNC

		XDX_PLATEFORM_DRV += pvr_buffer_sync.o
	endif # SUPPORT_BUFFER_SYNC
else # SUPPORT_NATIVE_FENCE_SYNC
	ifeq ($(SUPPORT_FALLBACK_FENCE_SYNC),1)
		XDX_PLATEFORM_DRV += ossecure_export.o
	endif
endif # SUPPORT_NATIVE_FENCE_SYNC

ifeq ($(SUPPORT_LINUX_DVFS),1)
	XDX_PLATEFORM_DRV += \
		pvr_dvfs_device.o \
		pvr_dvfs_common.o
else
	ifeq ($(SUPPORT_PDVFS),1)
		XDX_PLATEFORM_DRV += \
			pvr_dvfs_proactive.o \
 			pvr_dvfs_common.o
	endif #SUPPORT_PDVFS
endif # SUPPORT_LINUX_DVFS

ifeq ($(PVRSRV_ENABLE_PVR_ION_STATS),1)
	XDX_PLATEFORM_DRV += pvr_ion_stats.o
endif

ifeq ($(CONFIG_X86),y)
	XDX_PLATEFORM_DRV += osfunc_x86.o
else ifeq ($(CONFIG_ARM),y)
	XDX_PLATEFORM_DRV += osfunc_arm.o
else ifeq ($(CONFIG_ARM64),y)
	XDX_PLATEFORM_DRV += osfunc_arm64.o
else ifeq ($(CONFIG_RISCV),y)
	XDX_PLATEFORM_DRV += osfunc_riscv.o
else ifeq ($(CONFIG_LOONGARCH),y)
	XDX_PLATEFORM_DRV += osfunc_loongarch.o
else ifeq ($(CONFIG_SW64),y)
	XDX_PLATEFORM_DRV += osfunc_sw64.o
endif # CONFIG_X86

ifeq ($(CONFIG_DEBUG_FS),y)
	XDX_PLATEFORM_DRV += pvr_debugfs.o
else ifeq ($(CONFIG_PROC_FS),y)
	XDX_PLATEFORM_DRV += pvr_procfs.o
endif # CONFIG_DEBUG_FS

ifeq ($(CONFIG_EVENT_TRACING),y)
	XDX_PLATEFORM_DRV += trace_events.o
endif # CONFIG_EVENT_TRACING

XDX_PLATEFORM_DRV += \
	dma_support.o \
	interrupt_support.o

ifeq ($(CONFIG_PCI), y)
XDX_PLATEFORM_DRV += pci_support.o
endif # CONFIG_PCI

ifeq ($(XDXGPU_SMMU_SUPPORT),1)
	XDX_PLATEFORM_DRV += smmu_platform.o
endif

XDX_BR_FILES = $(addprefix platform/,$(XDX_PLATEFORM_DRV))
