1.10.2359475/4.10.00.01
authorImagination Technologies/TI <imgtec>
Tue, 15 Oct 2013 22:59:10 +0000 (01:59 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Tue, 15 Oct 2013 23:00:44 +0000 (02:00 +0300)
139 files changed:
Kbuild
Makefile
eurasiacon/build/linux2/bits.mk
eurasiacon/build/linux2/buildvars.mk
eurasiacon/build/linux2/commands.mk
eurasiacon/build/linux2/common/dridrm.mk
eurasiacon/build/linux2/config/core.mk
eurasiacon/build/linux2/defs.mk
eurasiacon/build/linux2/kbuild/external_tarball.mk [deleted file]
eurasiacon/build/linux2/moduledefs.mk
eurasiacon/build/linux2/omap4430_linux/Makefile [deleted file]
eurasiacon/build/linux2/prepare_tree.mk
eurasiacon/build/linux2/toplevel.mk
include4/img_defs.h
include4/img_types.h
include4/pvr_debug.h
include4/pvrversion.h
include4/services.h
include4/servicesext.h
include4/sgx_options.h
include4/sgxapi_km.h
include4/sgxscript.h
services4/3rdparty/bufferclass_example/bufferclass_example_linux.c
services4/3rdparty/dc_omapfb3_linux/3rdparty_dc_drm_shared.h
services4/3rdparty/dc_omapfb3_linux/Kbuild.mk
services4/3rdparty/dc_omapfb3_linux/Linux.mk
services4/3rdparty/dc_omapfb3_linux/omaplfb.h
services4/3rdparty/dc_omapfb3_linux/omaplfb_displayclass.c
services4/3rdparty/dc_omapfb3_linux/omaplfb_linux.c
services4/3rdparty/dc_ti335x_linux/3rdparty_dc_drm_shared.h
services4/3rdparty/dc_ti335x_linux/Kbuild.mk
services4/3rdparty/dc_ti335x_linux/Linux.mk
services4/3rdparty/dc_ti335x_linux/omaplfb.h
services4/3rdparty/dc_ti335x_linux/omaplfb_displayclass.c
services4/3rdparty/dc_ti335x_linux/omaplfb_linux.c
services4/3rdparty/dc_ti81xx_linux/omaplfb_linux.c
services4/3rdparty/linux_drm/Kbuild
services4/3rdparty/linux_drm/Kbuild.mk
services4/3rdparty/linux_drm/pvr_drm_stubs.c
services4/include/pvr_bridge.h
services4/include/pvr_bridge_km.h
services4/include/pvrmmap.h
services4/include/servicesint.h
services4/include/sgx_bridge.h
services4/include/sgx_mkif_km.h
services4/include/sgx_ukernel_status_codes.h
services4/include/sgxinfo.h
services4/srvkm/bridged/bridged_pvr_bridge.c
services4/srvkm/bridged/bridged_pvr_bridge.h
services4/srvkm/bridged/bridged_support.c
services4/srvkm/bridged/bridged_support.h
services4/srvkm/bridged/sgx/bridged_sgx_bridge.c
services4/srvkm/common/buffer_manager.c
services4/srvkm/common/deviceclass.c
services4/srvkm/common/devicemem.c
services4/srvkm/common/handle.c
services4/srvkm/common/hash.c
services4/srvkm/common/mem_debug.c
services4/srvkm/common/pdump_common.c
services4/srvkm/common/pvrsrv.c
services4/srvkm/common/queue.c
services4/srvkm/common/ra.c
services4/srvkm/common/refcount.c
services4/srvkm/common/resman.c
services4/srvkm/common/ttrace.c [new file with mode: 0644]
services4/srvkm/devices/sgx/mmu.c
services4/srvkm/devices/sgx/sgx_bridge_km.h
services4/srvkm/devices/sgx/sgxconfig.h
services4/srvkm/devices/sgx/sgxinfokm.h
services4/srvkm/devices/sgx/sgxinit.c
services4/srvkm/devices/sgx/sgxkick.c
services4/srvkm/devices/sgx/sgxpower.c
services4/srvkm/devices/sgx/sgxreset.c
services4/srvkm/devices/sgx/sgxtransfer.c
services4/srvkm/devices/sgx/sgxutils.c
services4/srvkm/env/linux/Kbuild.mk
services4/srvkm/env/linux/env_perproc.h
services4/srvkm/env/linux/event.c
services4/srvkm/env/linux/ion.c [new file with mode: 0644]
services4/srvkm/env/linux/ion.h [new file with mode: 0644]
services4/srvkm/env/linux/mm.c
services4/srvkm/env/linux/mm.h
services4/srvkm/env/linux/mmap.c
services4/srvkm/env/linux/mmap.h
services4/srvkm/env/linux/module.c
services4/srvkm/env/linux/mutex.c
services4/srvkm/env/linux/mutex.h
services4/srvkm/env/linux/mutils.h
services4/srvkm/env/linux/osfunc.c
services4/srvkm/env/linux/osperproc.c
services4/srvkm/env/linux/pdump.c
services4/srvkm/env/linux/private_data.h
services4/srvkm/env/linux/proc.h
services4/srvkm/env/linux/pvr_bridge_k.c
services4/srvkm/env/linux/pvr_drm.c
services4/srvkm/hwdefs/sgxerrata.h
services4/srvkm/hwdefs/sgxfeaturedefs.h
services4/srvkm/include/buffer_manager.h
services4/srvkm/include/devicemem.h [new file with mode: 0644]
services4/srvkm/include/handle.h
services4/srvkm/include/osfunc.h
services4/srvkm/include/pdump_km.h
services4/srvkm/include/pdump_osfunc.h
services4/srvkm/include/perproc.h
services4/srvkm/include/queue.h
services4/srvkm/include/refcount.h
services4/system/include/syscommon.h
services4/system/omap/oemfuncs.h [moved from services4/system/omap4/oemfuncs.h with 100% similarity]
services4/system/omap/sysconfig.c [moved from services4/system/omap4/sysconfig.c with 95% similarity]
services4/system/omap/sysconfig.h [moved from services4/system/omap4/sysconfig.h with 76% similarity]
services4/system/omap/sysinfo.h [moved from services4/system/omap4/sysinfo.h with 95% similarity]
services4/system/omap/syslocal.h [moved from services4/system/omap4/syslocal.h with 98% similarity]
services4/system/omap/sysutils.c [moved from services4/system/omap4/sysutils.c with 100% similarity]
services4/system/omap/sysutils_linux.c [moved from services4/system/omap4/sysutils_linux.c with 93% similarity]
services4/system/omap3/oemfuncs.h
services4/system/omap3/sysconfig.c
services4/system/omap3/sysconfig.h
services4/system/omap3/sysinfo.h
services4/system/omap3/syslocal.h
services4/system/omap3/sysutils.c
services4/system/omap3/sysutils_linux.c
services4/system/omap3630/oemfuncs.h
services4/system/omap3630/sysconfig.c
services4/system/omap3630/sysconfig.h
services4/system/omap3630/sysinfo.h
services4/system/omap3630/syslocal.h
services4/system/omap3630/sysutils.c
services4/system/omap3630/sysutils_linux.c
services4/system/ti335x/oemfuncs.h
services4/system/ti335x/sysconfig.c
services4/system/ti335x/sysconfig.h
services4/system/ti335x/sysinfo.h
services4/system/ti335x/syslocal.h
services4/system/ti335x/sysutils.c
services4/system/ti335x/sysutils_linux.c
services4/system/ti81xx/sysconfig.h
services4/system/ti81xx/sysutils_linux.c
tools/intern/debug/dbgdriv/common/dbgdriv.c
tools/intern/debug/dbgdriv/common/dbgdriv.h

diff --git a/Kbuild b/Kbuild
index 47b38a2..1a7eb44 100644 (file)
--- a/Kbuild
+++ b/Kbuild
@@ -45,6 +45,13 @@ ifneq ($(FBDEV),no)
 EXTRA_CFLAGS += -DFBDEV_PRESENT
 endif
 
+ifeq ($(TI_PLATFORM),ti335x)
+ifneq ($(SUPPORT_XORG),1)
+ifeq ($(PM_RUNTIME),1)
+EXTRA_CFLAGS += -DPM_RUNTIME_SUPPORT
+endif
+endif
+endif
 
 ifeq ($(TI_PLATFORM),ti335x)
 DRIFILES = services4/srvkm/env/linux/pvr_drm.c services4/3rdparty/dc_ti335x_linux/omaplfb_linux.c services4/3rdparty/dc_ti335x_linux/omaplfb_displayclass.c 
@@ -66,7 +73,7 @@ EXTRA_CFLAGS += -I$(src)/services4/srvkm/env/linux
 EXTRA_CFLAGS += -I$(src)/services4/system/include
 EXTRA_CFLAGS += -I$(src)/services4/system/$(TI_PLATFORM)
 EXTRA_CFLAGS += -I$(src)/services4/srvkm/bridged/sgx
-
+EXTRA_CFLAGS += -I$(KERNELDIR)/arch/arm/mach-omap2
 
 ifeq ($(SUPPORT_XORG),1)
 EXTRA_CFLAGS += -I$(KERNELDIR)/include/drm 
index ba1ce41..77ea3d0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,14 @@ SUPPORT_DRI_DRM_NO_LIBDRM = 1
 endif
 endif
 
+ifeq ($(TI_PLATFORM),ti335x)
+ifneq ($(SUPPORT_XORG),1)
+ifeq ($(PM_RUNTIME),1)
+PM_RUNTIME_SUPPORT = 1
+endif
+endif
+endif
+
 
 # Only enable active power management if passive power management is
 # enabled, as indicated by LDM_PLATFORM being set to 1.  On OMAP,
index a1a7eef..27da720 100644 (file)
@@ -104,9 +104,11 @@ ifneq ($(filter help,$(D)),)
 empty :=
 space := $(empty) $(empty) 
 $(info Debug options)
-$(info $(space)D=modules                  dump module info)
-$(info $(space)D=freeze-config            prevent config changes)
-$(info $(space)D=config-changes           dump diffs when config changes)
-$(info Options may be combined: make D=freeze-config,config-changes)
+$(info $(space)D=modules            dump module info)
+$(info $(space)D=config             dump all config options + type and origin)
+$(info $(space)D=freeze-config      prevent config changes)
+$(info $(space)D=config-changes     dump diffs when config changes)
+$(info $(space)D=nobuild            stop before running the main build)
+$(info Options can be combined: make D=freeze-config,config-changes)
 $(error D=help given)
 endif
index 24fa829..ef37cf7 100644 (file)
@@ -176,7 +176,7 @@ ALL_CXXFLAGS := \
  $(SYS_CXXFLAGS)
 
 ALL_HOST_CXXFLAGS := \
- $(COMMON_USER_FLAGS) $(COMMON_CFLAGS) -Wall
+ $(COMMON_USER_FLAGS) $(COMMON_CFLAGS)
 
 # User C and C++
 #
index 25e5ed1..cfeb5df 100644 (file)
@@ -98,7 +98,7 @@ endef
 define target-executable-cxx-from-o
 $(if $(V),,@echo "  LD      " $(call relative-to-top,$@))
 $(CXX) \
-       $(SYS_EXE_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
+       $(SYS_EXE_LDFLAGS_CXX) $(SYS_EXE_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
        $(SYS_EXE_CRTBEGIN) $(sort $(MODULE_ALL_OBJECTS)) $(SYS_EXE_CRTEND) \
        $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS) $(LIBGCC)
 endef
@@ -116,11 +116,29 @@ endef
 define target-shared-library-cxx-from-o
 $(if $(V),,@echo "  LD      " $(call relative-to-top,$@))
 $(CXX) -shared -Wl,-Bsymbolic \
-       $(SYS_LIB_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
+       $(SYS_LIB_LDFLAGS_CXX) $(SYS_LIB_LDFLAGS) $(MODULE_LDFLAGS) -o $@ \
        $(SYS_LIB_CRTBEGIN) $(sort $(MODULE_ALL_OBJECTS)) $(SYS_LIB_CRTEND) \
        $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS) $(LIBGCC)
 endef
 
+define host-shared-library-from-o
+$(if $(V),,@echo "  HOST_LD      " $(call relative-to-top,$@))
+$(HOST_CC) -shared -Wl,-Bsymbolic \
+       $(MODULE_HOST_LDFLAGS) -o $@ \
+       $(sort $(MODULE_ALL_OBJECTS)) \
+       $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS)
+endef
+
+# If there were any C++ source files in a shared library, we use this recipe,
+# which runs the C++ compiler to link the final library
+define host-shared-library-cxx-from-o
+$(if $(V),,@echo "  HOST_LD      " $(call relative-to-top,$@))
+$(HOST_CXX) -shared -Wl,-Bsymbolic \
+       $(MODULE_HOST_LDFLAGS) -o $@ \
+       $(sort $(MODULE_ALL_OBJECTS)) \
+       $(MODULE_LIBRARY_DIR_FLAGS) $(MODULE_LIBRARY_FLAGS)
+endef
+
 define target-copy-debug-information
 $(OBJCOPY) --only-keep-debug $@ $(basename $@).dbg
 endef
index 5d0289f..4097e7a 100644 (file)
@@ -59,5 +59,3 @@ $(eval $(call TunableBothConfigMake,PVR_DRI_DRM_NOT_PCI))
 
 $(eval $(call TunableKernelConfigC,PVR_DRI_DRM_PLATFORM_DEV,))
 
-
-export EXTERNAL_3PDD_TARBALL
index 8eb0824..42df94f 100644 (file)
@@ -56,6 +56,7 @@
 #
 define KernelConfigMake
 $$(shell echo "override $(1) := $(2)" >>$(CONFIG_KERNEL_MK).new)
+$(if $(filter config,$(D)),$(info KernelConfigMake $(1) := $(2)        # $(if $($(1)),$(origin $(1)),default)))
 endef
 
 # Write out a GNU make option for both user & kernel
@@ -88,6 +89,7 @@ endef
 #
 define KernelConfigC
 $$(shell echo "#define $(1) $(2)" >>$(CONFIG_KERNEL_H).new)
+$(if $(filter config,$(D)),$(info KernelConfigC    #define $(1) $(2)   /* $(if $($(1)),$(origin $(1)),default) */),)
 endef
 
 # Write out an option for both user & kernel
@@ -184,6 +186,14 @@ CONFIG_H                   := $(OUT)/config.h
 CONFIG_KERNEL_MK       := $(OUT)/config_kernel.mk
 CONFIG_KERNEL_H                := $(OUT)/config_kernel.h
 
+# Convert commas to spaces in $(D). This is so you can say "make
+# D=config-changes,freeze-config" and have $(filter config-changes,$(D))
+# still work.
+comma := ,
+empty :=
+space := $(empty) $(empty)
+override D := $(subst $(comma),$(space),$(D))
+
 # Create the OUT directory and delete any previous intermediary files
 #
 $(shell mkdir -p $(OUT))
@@ -209,6 +219,12 @@ endif
 # require things like SGXCORE to be set
 ifneq ($(INTERNAL_CLOBBER_ONLY),true)
 
+# These are defined by the core build system, but we might need them
+# earlier to feature-check the compilers
+#
+_CC            := $(CROSS_COMPILE)$(if $(filter default,$(origin CC)),gcc,$(CC))
+HOST_CC        ?= gcc
+
 -include ../config/user-defs.mk
 
 # FIXME: Backwards compatibility remaps.
@@ -271,21 +287,10 @@ override SUPPORT_HW_RECOVERY := 0
 override SUPPORT_ACTIVE_POWER_MANAGEMENT := 0
 endif
 
-# We're bumping against USSE limits on older cores because the ukernel
-# is too large when building both SGX_DISABLE_VISTEST_SUPPORT=0 and
-# PVRSRV_USSE_EDM_STATUS_DEBUG=1.
-#
-# Automatically disable vistest support if debugging the ukernel to
-# prevent build failures.
-#
-ifneq ($(filter 520 530 531 535 540,$(SGXCORE)),)
-ifneq ($(SGX_DISABLE_VISTEST_SUPPORT),1)
-SGX_DISABLE_VISTEST_SUPPORT ?= not-overridden
-ifeq ($(SGX_DISABLE_VISTEST_SUPPORT),not-overridden)
-$(warning Setting SGX_DISABLE_VISTEST_SUPPORT=1 because PVRSRV_USSE_EDM_STATUS_DEBUG=1)
-SGX_DISABLE_VISTEST_SUPPORT := 1
-endif
-endif
+ifeq ($(SGX_FEATURE_36BIT_MMU),1)
+override IMG_ADDRSPACE_PHYSADDR_BITS := 64
+else
+override IMG_ADDRSPACE_PHYSADDR_BITS := 32
 endif
 
 ifeq ($(SGXCORE),535)
@@ -343,12 +348,12 @@ $$(warning *** Setting $(1) via $$(origin $(1)) is deprecated)
 $$(error If you are trying to disable a component, use e.g. EXCLUDED_APIS="opengles1 opengl")
 endif
 endef
-$(foreach _o,SYS_CFLAGS SYS_CXXFLAGS SYS_EXE_LDFLAGS SYS_LIB_LDFLAGS SUPPORT_EWS SUPPORT_OPENGLES1 SUPPORT_OPENGLES2 SUPPORT_OPENVG SUPPORT_OPENCL SUPPORT_OPENGL SUPPORT_UNITTESTS SUPPORT_XORG,$(eval $(call sanity-check-support-option-origin,$(_o))))
+$(foreach _o,SYS_CFLAGS SYS_CXXFLAGS SYS_EXE_LDFLAGS SYS_LIB_LDFLAGS SYS_EXE_LDFLAGS_CXX SYS_LIB_LDFLAGS_CXX SUPPORT_EWS SUPPORT_OPENGLES1 SUPPORT_OPENGLES2 SUPPORT_OPENCL SUPPORT_RSCOMPUTE SUPPORT_OPENGL SUPPORT_UNITTESTS SUPPORT_XORG,$(eval $(call sanity-check-support-option-origin,$(_o))))
 
 # Check for words in EXCLUDED_APIS that aren't understood by the
 # common/apis/*.mk files. This should be kept in sync with all the tests on
 # EXCLUDED_APIS in those files
-_excludable_apis := opencl opengl opengles1 opengles2 openvg ews unittests xorg xorg_unittests scripts
+_excludable_apis := rscompute opencl opengl opengles1 opengles2 openvg ews unittests xorg xorg_unittests scripts
 _unrecognised := $(strip $(filter-out $(_excludable_apis),$(EXCLUDED_APIS)))
 ifneq ($(_unrecognised),)
 $(warning *** Unrecognised entries in EXCLUDED_APIS: $(_unrecognised))
@@ -378,8 +383,13 @@ ifneq ($(filter pvr2d,$(COMPONENTS)),)
 COMPONENTS += null_pvr2d_remote
 endif
 COMPONENTS += pvrvncsrv
+COMPONENTS += pvrvncinput
 endif
 
+$(if $(filter config,$(D)),$(info Build configuration:))
+
+################################# CONFIG ####################################
+
 # If KERNELDIR is set, write it out to the config.mk, with
 # KERNEL_COMPONENTS and KERNEL_ID
 #
@@ -400,19 +410,54 @@ KERNEL_CROSS_COMPILE ?= $(CROSS_COMPILE)
 $(eval $(call TunableBothConfigMake,KERNEL_CROSS_COMPILE,))
 endif
 
-# Check the KERNELDIR has a kernel built and also check that it is
-# not 64-bit, which we do not support.
+# Check the KERNELDIR has a kernel built.
 VMLINUX := $(strip $(wildcard $(KERNELDIR)/vmlinux))
+LINUXCFG := $(strip $(wildcard $(KERNELDIR)/.config))
+
 ifneq ($(VMLINUX),)
-VMLINUX_IS_64BIT := $(shell file $(VMLINUX) | grep -q 64-bit || echo false)
+ifneq ($(shell file $(KERNELDIR)/vmlinux | grep 64-bit >/dev/null && echo 1),$(shell $(_CC) -dM -E - </dev/null | grep __x86_64__ >/dev/null && echo 1))
+$(error Attempting to build 64-bit DDK against 32-bit kernel, or 32-bit DDK against 64-bit kernel. This is not allowed.)
+endif
+VMLINUX_IS_64BIT := $(shell file $(VMLINUX) | grep 64-bit >/dev/null || echo false)
+VMLINUX_HAS_PAE36 := $(shell cat $(LINUXCFG) | grep CONFIG_X86_PAE=y >/dev/null || echo false)
+VMLINUX_HAS_PAE40 := $(shell cat $(LINUXCFG) | grep CONFIG_ARM_LPAE=y >/dev/null || echo false)
+VMLINUX_HAS_DMA32 := $(shell cat $(LINUXCFG) | grep CONFIG_ZONE_DMA32=y >/dev/null || echo false)
+
+# $(error 64BIT=$(VMLINUX_IS_64BIT) PAE36=$(VMLINUX_HAS_PAE36) PAE40=$(VMLINUX_HAS_PAE40) DMA32=$(VMLINUX_HAS_DMA32) MMU36=$(SGX_FEATURE_36BIT_MMU))
+
 ifneq ($(VMLINUX_IS_64BIT),false)
-$(warning $$(KERNELDIR)/vmlinux is 64-bit, which is not supported. Kbuild may fail.)
+$(warning $$(KERNELDIR)/vmlinux: Note: vmlinux is 64-bit, which is supported but currently experimental.)
 endif
 else
 $(warning $$(KERNELDIR)/vmlinux does not exist. Kbuild may fail.)
 endif
 endif
 
+ifneq ($(VMLINUX_HAS_PAE40),false)
+ifeq ($(VMLINUX_HAS_DMA32),false)
+$(warning SGX MMUs are currently supported up to only 36 bits max. Your Kernel is built with 40-bit PAE but does not have CONFIG_ZONE_DMA32.)
+$(warning This means you must ensure the runtime system has <= 4GB of RAM, or there will be BIG problems...)
+endif 
+endif
+
+ifneq ($(SGX_FEATURE_36BIT_MMU),1)
+ifneq ($(VMLINUX_IS_64BIT),false)
+# Kernel is 64-bit
+ifeq ($(VMLINUX_HAS_DMA32),false)
+$(warning SGX is configured with 32-bit MMU. Your Kernel is 64-bit but does not have CONFIG_ZONE_DMA32.)
+$(warning This means you must ensure the runtime system has <= 4GB of RAM, or there will be BIG problems...)
+endif
+else
+ # Kernel is 32-bit
+ifneq ($(VMLINUX_HAS_PAE36),false)
+ifeq ($(VMLINUX_HAS_DMA32),false)
+$(warning SGX is configured with 32-bit MMU. Your Kernel is 32-bit PAE, but does not have CONFIG_ZONE_DMA32. )
+$(warning This means you must ensure the runtime system has <= 4GB of RAM, or there will be BIG problems...)
+endif
+endif
+endif
+endif
+
 
 # Ideally configured by platform Makefiles, as necessary
 #
@@ -500,7 +545,6 @@ $(eval $(call TunableBothConfigC,PDUMP,))
 $(eval $(call TunableBothConfigC,NO_HARDWARE,))
 $(eval $(call TunableBothConfigC,PDUMP_DEBUG_OUTFILES,))
 $(eval $(call TunableBothConfigC,PVRSRV_USSE_EDM_STATUS_DEBUG,))
-$(eval $(call TunableBothConfigC,SGX_DISABLE_VISTEST_SUPPORT,))
 $(eval $(call TunableBothConfigC,PVRSRV_RESET_ON_HWTIMEOUT,))
 $(eval $(call TunableBothConfigC,SYS_USING_INTERRUPTS,1))
 $(eval $(call TunableBothConfigC,SUPPORT_EXTERNAL_SYSTEM_CACHE,))
@@ -513,6 +557,8 @@ $(eval $(call TunableBothConfigC,SUPPORT_ION,))
 $(eval $(call TunableBothConfigC,SUPPORT_HWRECOVERY_TRACE_LIMIT,))
 $(eval $(call TunableBothConfigC,SUPPORT_PVRSRV_GET_DC_SYSTEM_BUFFER,1))
 $(eval $(call TunableBothConfigC,SUPPORT_NV12_FROM_2_HWADDRS,))
+$(eval $(call TunableBothConfigC,SGX_FEATURE_36BIT_MMU,))
+$(eval $(call TunableBothConfigC,IMG_ADDRSPACE_PHYSADDR_BITS,))
 
 $(eval $(call TunableKernelConfigC,SUPPORT_LINUX_X86_WRITECOMBINE,1))
 $(eval $(call TunableKernelConfigC,SUPPORT_LINUX_X86_PAT,1))
index 621e03e..c458d99 100644 (file)
@@ -116,6 +116,10 @@ define host-cc-option
 $(call cc-check,$(patsubst @%,%,$(HOST_CC)),$(OUT),$(1))
 endef
 
+define host-cxx-option
+$(call cc-check,$(patsubst @%,%,$(HOST_CXX)),$(OUT),$(1))
+endef
+
 define kernel-cc-option
 $(call cc-check,$(KERNEL_CROSS_COMPILE)gcc,$(OUT),$(1))
 endef
diff --git a/eurasiacon/build/linux2/kbuild/external_tarball.mk b/eurasiacon/build/linux2/kbuild/external_tarball.mk
deleted file mode 100644 (file)
index d3aa147..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-########################################################################### ###
-#@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.
-### ###########################################################################
-
-ifneq ($(EXTERNAL_3PDD_TARBALL),)
-TAR_OPT_STRIP_COMPONENTS ?= --strip-components
-prepare_tree: $(OUT)/target/kbuild/external
-$(OUT)/target/kbuild/external: eurasiacon/external/$(EXTERNAL_3PDD_TARBALL)
-       @echo "Extracting $<.."
-       @mkdir -p $@
-       @tar $(TAR_OPT_STRIP_COMPONENTS) 1 --touch -jxf $< -C $@
-       @touch $(OUT)/target/kbuild/external
-endif
index 869026f..d0c4215 100644 (file)
@@ -61,7 +61,11 @@ MODULE_INTERMEDIATES_DIR := $(if $(MODULE_HOST_BUILD),$(HOST_INTERMEDIATES)/$(TH
 $(MODULE_INTERMEDIATES_DIR):
        $(make-directory)
 
+# These are used for messages and variable names where we need to say "host"
+# or "target" according to the module build type.
 Host_or_target := $(if $(MODULE_HOST_BUILD),Host,Target)
+host_or_target := $(if $(MODULE_HOST_BUILD),host,target)
+HOST_OR_TARGET := $(if $(MODULE_HOST_BUILD),HOST,TARGET)
 
 # These define the rules for finding source files.
 # - If a name begins with a slash, we strip $(TOP) off the front if it begins
diff --git a/eurasiacon/build/linux2/omap4430_linux/Makefile b/eurasiacon/build/linux2/omap4430_linux/Makefile
deleted file mode 100644 (file)
index 6d0e81a..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-########################################################################### ###
-#@Title         Root makefile for OMAP4430 Linux.  Builds everything else.
-#@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.
-### ###########################################################################
-
-PVR_SYSTEM             := omap4
-
-KERNEL_COMPONENTS := srvkm bufferclass_example
-
-include ../kernel_version.mk
-
-# Only enable active power management if passive power management is
-# enabled, as indicated by LDM_PLATFORM being set to 1.  On OMAP,
-# the system can suspend in the case where active power management is
-# enabled in the SGX driver, but passive power management isn't. As
-# passive power management isn't enabled, the driver won't see the
-# system suspend/resume events, and so won't take appropriate action.
-LDM_PLATFORM ?= 1
-
-ifeq ($(LDM_PLATFORM),1)
-SUPPORT_LINUX_USING_WORKQUEUES := 1
-DISPLAY_CONTROLLER_COMPONENT += dc_omapfb3_linux
-DISPLAY_CONTROLLER := omaplfb
-else
-SUPPORT_LINUX_USING_SHARED_WORKQUEUES := 1
-OMAP_NON_FLIP_DISPLAY := 1
-DISPLAY_CONTROLLER_COMPONENT += linux_framebuffer
-DISPLAY_CONTROLLER := pvrlfb
-endif
-
-OPTIM := -Os
-
-SYS_CFLAGS := -march=armv7-a
-
-ifneq ($(CROSS_COMPILE),)
-SYS_CFLAGS += -mtls-dialect=arm
-endif
-
-SUPPORT_OMAP4430_NEON ?= 1
-
-ifeq ($(SUPPORT_OMAP4430_NEON),1)
-SYS_CFLAGS += -ftree-vectorize -mfpu=neon -mfloat-abi=softfp
-endif
-
-LIBGCC := $(shell $(CROSS_COMPILE)gcc -print-libgcc-file-name)
-
-SGXCORE := 540
-SGX_CORE_REV := 120
-
-SGX_DYNAMIC_TIMING_INFO := 1
-SYS_CUSTOM_POWERLOCK_WRAP := 1
-
-ifeq ($(OMAP_NON_FLIP_DISPLAY),1)
-OPK_DEFAULT := libpvrPVR2D_BLITWSEGL.so
-else
-OPK_DEFAULT := libpvrPVR2D_FLIPWSEGL.so
-endif
-
-ifeq ($(call kernel-version-at-least,2,6,35),true)
-# Work around flipping problems seen with the Taal LCDs on Blaze.
-# The work around is safe to use with other types of screen on Blaze
-# (e.g. HDMI) and on other platforms (e.g. Panda board).
-PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY := 1
-ifeq ($(LDM_PLATFORM),1)
-PVR_LDM_PLATFORM_PRE_REGISTERED := 1
-ifeq ($(call kernel-version-at-least,2,6,35,7),true)
-# Not all variants of the OMAP4 kernel have a DRM based framebuffer.
-# Note that a non-X.Org version of the driver does not have to be built
-# with DRM support if the kernel has a DRM based framebuffer.
-PVR_OMAPLFB_DRM_FB ?= 1
-ifeq ($(PVR_OMAPLFB_DRM_FB),1)
-PVR_LDM_PLATFORM_PRE_REGISTERED_DEV := "\"pvrsrvkm_pvr\""
-# There is already a "pvrsrvkm" driver (part of the DRM framebuffer code),
-# so use the pre-registered device name instead.
-PVR_LDM_DRIVER_REGISTRATION_NAME := "\"pvrsrvkm_pvr"\"
-# The DRM library will not load the Services module on behalf of the X Server,
-# as a DRM module has already been loaded (the DRM based framebuffer), so
-# load the Services module before starting the X Server.
-XORG_EXPLICIT_PVR_SERVICES_LOAD := 1
-else
-PVR_LDM_PLATFORM_PRE_REGISTERED_DEV := "\"pvrsrvkm\""
-endif
-endif
-endif
-endif
-
-include ../common/xorg_test.mk
-ifeq ($(want_xorg),1)
-
-SUPPORT_DRI_DRM := 1
-
-ifeq ($(call kernel-version-at-least,2,6,35),true)
-PVR_DRI_DRM_PLATFORM_DEV := 1
-PVR_DRI_DRM_STATIC_BUS_ID := 1
-ifeq ($(call kernel-version-at-least,2,6,35,7),true)
-ifeq ($(PVR_OMAPLFB_DRM_FB),1)
-SUPPORT_DRI_DRM_PLUGIN := 1
-endif
-ifeq ($(call kernel-version-at-least,2,6,36),true)
-PVR_DRI_DRM_DEV_BUS_ID := "\"platform:pvrsrvkm"\"
-else
-PVR_DRI_DRM_DEV_BUS_ID := "\"platform:pvrsrvkm:00"\"
-endif
-# A client DRI authorisation failure, whilst switched away from the X Server
-# VT, prevents all other attempts at DRI authorisation, even after
-# switching back to the X server VT, so don't perform a DRM drop master
-# call.
-PVR_XORG_DONT_DROP_MASTER_IN_LEAVE_VT := 1
-endif
-else
-PVR_DRI_DRM_NOT_PCI := 1
-endif
-
-XORG_TOOLCHAIN ?= tarballs-omap4-ubuntu-10.10-cross
-XORG_PVR_CONF := omap4
-XORG_PVR_VIDEO := omap4
-
-OPK_FALLBACK := libpvrPVR2D_DRIWSEGL.so
-
-ifneq ($(OMAP_NON_FLIP_DISPLAY),1)
-XORG_PVR_VIDEO ?= $(PVR_SYSTEM)
-PVR_DISPLAY_CONTROLLER_DRM_IOCTL := 1
-endif
-
-else  # xorg isn't excluded
-
-OPK_FALLBACK := libpvrPVR2D_BLITWSEGL.so
-
-endif # xorg isn't excluded
-
-ifeq ($(SUPPORT_DRI_DRM),1)
-ifeq ($(PVR_DRI_DRM_NOT_PCI),1)
-KERNEL_COMPONENTS += linux_drm
-EXTRA_KBUILD_SOURCE := $(KERNELDIR)
-endif
-EXTRA_PVRSRVKM_COMPONENTS += $(DISPLAY_CONTROLLER_COMPONENT)
-else
-KERNEL_COMPONENTS += $(DISPLAY_CONTROLLER_COMPONENT)
-endif
-
-include ../config/core.mk
-include ../common/xorg.mk
-include ../common/dridrm.mk
-include ../common/opencl.mk
-include ../common/omap4.mk
-
-# We only need this for pvr_video's includes, which should
-# really be done differently, as DISPLAY_CONTROLLER_DIR is
-# now obsolete..
-#
-$(eval $(call UserConfigMake,DISPLAY_CONTROLLER_DIR,3rdparty/$(DISPLAY_CONTROLLER_COMPONENT)))
index 05e4fe3..75dcca6 100644 (file)
 
 .PHONY: prepare_tree
 
--include eurasiacon/build/linux2/kbuild/external_tarball.mk
-
-# If there's no external tarball, there's nothing to do
-#
 prepare_tree:
 
 INTERNAL_INCLUDED_PREPARE_HEADERS :=
index 26b1198..dde6b2b 100644 (file)
@@ -224,3 +224,7 @@ clobber-%:
        $(RM) -rf $(OUT)/host/intermediates/$* $(OUT)/target/intermediates/$* $(INTERNAL_TARGETS_FOR_$*)
 
 include $(MAKE_TOP)/bits.mk
+
+# D=nobuild stops the build before any recipes are run. This line should
+# come at the end of this makefile.
+$(if $(filter nobuild,$(D)),$(error D=nobuild given),)
index 375ed99..bf0c360 100644 (file)
@@ -147,6 +147,71 @@ typedef char                               TCHAR, *PTCHAR, *PTSTR;
 #define IMG_UNDEF      (~0UL)
 #endif
 
+/*
+   Do the right thing when using printf to output cpu addresses,
+   depending on architecture.
+ */
+#if defined (_WIN64)
+    #define UINTPTR_FMT "%016llX"
+#else
+    #if defined (__x86_64__)
+        #define UINTPTR_FMT "%016lX"
+    #else
+        #define UINTPTR_FMT "%08lX"
+    #endif
+#endif
+
+/* 
+   Similarly for DEV_ and SYS_ PHYSADDRs, but this is dependent on 32/36-bit MMU
+   capability, in addition to host architecture.
+ */
+#if IMG_ADDRSPACE_PHYSADDR_BITS == 32
+       #if defined(IMG_UINT32_IS_ULONG)
+               #define CPUPADDR_FMT "%08lX"
+               #define DEVPADDR_FMT "%08lX"
+               #define SYSPADDR_FMT "%08lX"
+       #else
+               #define CPUPADDR_FMT "%08X"
+               #define DEVPADDR_FMT "%08X"
+               #define SYSPADDR_FMT "%08X"
+       #endif
+#else
+       #if defined(__x86_64__)
+                       #define CPUPADDR_FMT "%016lX"
+                       #define DEVPADDR_FMT "%016lX"
+                       #define SYSPADDR_FMT "%016lX"
+       #else
+
+                       #define CPUPADDR_FMT "%016llX"
+                       #define DEVPADDR_FMT "%016llX"
+                       #define SYSPADDR_FMT "%016llX"
+       #endif
+#endif
+
+/*
+   Define a printf format macro for the length property of the format-specifier
+   for size_t, that allows avoidance of C99 dependency on compilers that don't
+   support this, while still ensuring that whatever the size of size_t (eg 32, 
+   64 bit Linux builds, or Win32/64 builds), a size_t (or IMG_SIZE_T) can be
+   passed to printf-type functions without a cast.
+*/
+#if defined LINUX
+       /* Use C99 format specifier where possible */
+       #define SIZE_T_FMT_LEN "z"
+#elif  defined _WIN64
+       #define SIZE_T_FMT_LEN "I"
+#else
+       #define SIZE_T_FMT_LEN "l" /* May need to be updated as required, for other OSs */
+#endif
+
+
+#if defined (__x86_64__)
+       #define IMG_UINT64_FMT "l"
+#else
+       #define IMG_UINT64_FMT "ll" /* May need to be updated as required, for other OSs */
+#endif
+
+
 #endif /* #if !defined (__IMG_DEFS_H__) */
 /*****************************************************************************
  End of file (IMG_DEFS.H)
index 7f5137e..3e04e4a 100644 (file)
@@ -75,17 +75,16 @@ typedef signed long         IMG_INT32,      *IMG_PINT32;
 #endif
 
 #if  defined(USE_CODE)
-
-typedef unsigned __int64       IMG_UINT64, *IMG_PUINT64;
-typedef __int64                                IMG_INT64,  *IMG_PINT64;
-
+       typedef unsigned __int64        IMG_UINT64, *IMG_PUINT64;
+       typedef __int64                         IMG_INT64,  *IMG_PINT64;
+#elif defined(LINUX) && defined (__x86_64)
+       typedef unsigned long           IMG_UINT64,     *IMG_PUINT64;
+       typedef long                            IMG_INT64,      *IMG_PINT64;
+#elif defined(LINUX) || defined(__METAG) || defined (__QNXNTO__)
+       typedef unsigned long long              IMG_UINT64,     *IMG_PUINT64;
+       typedef long long                               IMG_INT64,      *IMG_PINT64;
 #else
- #if defined(LINUX) || defined(__METAG) || defined (__QNXNTO__)
-               typedef unsigned long long              IMG_UINT64,     *IMG_PUINT64;
-               typedef long long                               IMG_INT64,      *IMG_PINT64;
-       #else
-               #error("define an OS")
-       #endif
+       #error("define an OS")
 #endif
 
 #if !(defined(LINUX) && defined (__KERNEL__))
@@ -107,11 +106,19 @@ typedef IMG_INT32       IMG_RESULT;
 
 #if defined(_WIN64)
        typedef unsigned __int64        IMG_UINTPTR_T;
+    typedef signed   __int64    IMG_INTPTR_T;
        typedef signed __int64          IMG_PTRDIFF_T;
        typedef IMG_UINT64                      IMG_SIZE_T;
 #else
-       typedef unsigned int    IMG_UINTPTR_T;
-       typedef IMG_UINT32              IMG_SIZE_T;
+    #if defined (__x86_64__)
+       typedef IMG_UINT64              IMG_SIZE_T;
+        typedef unsigned long   IMG_UINTPTR_T;
+        typedef signed long     IMG_INTPTR_T;
+    #else
+       typedef IMG_UINT32              IMG_SIZE_T;
+        typedef unsigned long  IMG_UINTPTR_T;
+        typedef signed long     IMG_INTPTR_T;
+    #endif
 #endif
 
 typedef IMG_PVOID       IMG_HANDLE;
@@ -121,9 +128,9 @@ typedef void**          IMG_HVOID,  * IMG_PHVOID;
 #define IMG_NULL        0 
 
 /* services/stream ID */
-typedef IMG_UINT32      IMG_SID;
+typedef IMG_UINTPTR_T      IMG_SID;
 
-typedef IMG_UINT32      IMG_EVENTSID;
+typedef IMG_UINTPTR_T      IMG_EVENTSID;
 
 /*
  * Address types.
@@ -184,7 +191,12 @@ typedef IMG_UINT32 IMG_DEVMEM_SIZE_T;
 typedef struct _IMG_CPU_PHYADDR
 {
        /* variable sized type (32,64) */
-       IMG_UINTPTR_T uiAddr;
+#if IMG_ADDRSPACE_PHYSADDR_BITS == 32
+       /* variable sized type (32,64) */
+       IMG_UINT32 uiAddr;
+#else
+       IMG_UINT64 uiAddr;
+#endif
 } IMG_CPU_PHYADDR;
 
 /* device physical address */
@@ -192,10 +204,9 @@ typedef struct _IMG_DEV_PHYADDR
 {
 #if IMG_ADDRSPACE_PHYSADDR_BITS == 32
        /* variable sized type (32,64) */
-       IMG_UINTPTR_T uiAddr;
-#else
        IMG_UINT32 uiAddr;
-       IMG_UINT32 uiHighAddr;
+#else
+       IMG_UINT64 uiAddr;
 #endif
 } IMG_DEV_PHYADDR;
 
@@ -203,7 +214,12 @@ typedef struct _IMG_DEV_PHYADDR
 typedef struct _IMG_SYS_PHYADDR
 {
        /* variable sized type (32,64) */
-       IMG_UINTPTR_T uiAddr;
+#if IMG_ADDRSPACE_PHYSADDR_BITS == 32
+       /* variable sized type (32,64) */
+       IMG_UINT32 uiAddr;
+#else
+       IMG_UINT64 uiAddr;
+#endif
 } IMG_SYS_PHYADDR;
 
 #include "img_defs.h"
index 7e05666..fcc0275 100644 (file)
@@ -53,16 +53,17 @@ extern "C" {
 #define PVR_MAX_DEBUG_MESSAGE_LEN      (512)
 
 /* These are privately used by pvr_debug, use the PVR_DBG_ defines instead */
-#define DBGPRIV_FATAL                  0x01UL
-#define DBGPRIV_ERROR                  0x02UL
-#define DBGPRIV_WARNING                        0x04UL
-#define DBGPRIV_MESSAGE                        0x08UL
-#define DBGPRIV_VERBOSE                        0x10UL
-#define DBGPRIV_CALLTRACE              0x20UL
-#define DBGPRIV_ALLOC                  0x40UL
-#define DBGPRIV_DBGDRV_MESSAGE 0x80UL
-
-#define DBGPRIV_DBGLEVEL_COUNT 8
+#define DBGPRIV_FATAL                  0x001UL
+#define DBGPRIV_ERROR                  0x002UL
+#define DBGPRIV_WARNING                        0x004UL
+#define DBGPRIV_MESSAGE                        0x008UL
+#define DBGPRIV_VERBOSE                        0x010UL
+#define DBGPRIV_CALLTRACE              0x020UL
+#define DBGPRIV_ALLOC                  0x040UL
+#define DBGPRIV_BUFFERED               0x080UL
+#define DBGPRIV_DBGDRV_MESSAGE 0x100UL
+
+#define DBGPRIV_DBGLEVEL_COUNT 9
 
 #if !defined(PVRSRV_NEED_PVR_ASSERT) && defined(DEBUG)
 #define PVRSRV_NEED_PVR_ASSERT
@@ -143,27 +144,29 @@ IMG_IMPORT IMG_VOID IMG_CALLCONV PVRSRVDebugAssertFail(const IMG_CHAR *pszFile,
        #define PVR_DBG_VERBOSE         DBGPRIV_VERBOSE
        #define PVR_DBG_CALLTRACE       DBGPRIV_CALLTRACE
        #define PVR_DBG_ALLOC           DBGPRIV_ALLOC
+       #define PVR_DBG_BUFFERED        DBGPRIV_BUFFERED
        #define PVR_DBGDRIV_MESSAGE     DBGPRIV_DBGDRV_MESSAGE
 
        /* These levels are always on with PVRSRV_NEED_PVR_DPF */
-       #define __PVR_DPF_0x01UL(x...) PVRSRVDebugPrintf(DBGPRIV_FATAL, x)
-       #define __PVR_DPF_0x02UL(x...) PVRSRVDebugPrintf(DBGPRIV_ERROR, x)
+       #define __PVR_DPF_0x001UL(x...) PVRSRVDebugPrintf(DBGPRIV_FATAL, x)
+       #define __PVR_DPF_0x002UL(x...) PVRSRVDebugPrintf(DBGPRIV_ERROR, x)
+       #define __PVR_DPF_0x080UL(x...) PVRSRVDebugPrintf(DBGPRIV_BUFFERED, x)
 
        /* Some are compiled out completely in release builds */
 #if defined(DEBUG)
-       #define __PVR_DPF_0x04UL(x...) PVRSRVDebugPrintf(DBGPRIV_WARNING, x)
-       #define __PVR_DPF_0x08UL(x...) PVRSRVDebugPrintf(DBGPRIV_MESSAGE, x)
-       #define __PVR_DPF_0x10UL(x...) PVRSRVDebugPrintf(DBGPRIV_VERBOSE, x)
-       #define __PVR_DPF_0x20UL(x...) PVRSRVDebugPrintf(DBGPRIV_CALLTRACE, x)
-       #define __PVR_DPF_0x40UL(x...) PVRSRVDebugPrintf(DBGPRIV_ALLOC, x)
-       #define __PVR_DPF_0x80UL(x...) PVRSRVDebugPrintf(DBGPRIV_DBGDRV_MESSAGE, x)
+       #define __PVR_DPF_0x004UL(x...) PVRSRVDebugPrintf(DBGPRIV_WARNING, x)
+       #define __PVR_DPF_0x008UL(x...) PVRSRVDebugPrintf(DBGPRIV_MESSAGE, x)
+       #define __PVR_DPF_0x010UL(x...) PVRSRVDebugPrintf(DBGPRIV_VERBOSE, x)
+       #define __PVR_DPF_0x020UL(x...) PVRSRVDebugPrintf(DBGPRIV_CALLTRACE, x)
+       #define __PVR_DPF_0x040UL(x...) PVRSRVDebugPrintf(DBGPRIV_ALLOC, x)
+       #define __PVR_DPF_0x100UL(x...) PVRSRVDebugPrintf(DBGPRIV_DBGDRV_MESSAGE, x)
 #else
-       #define __PVR_DPF_0x04UL(x...)
-       #define __PVR_DPF_0x08UL(x...)
-       #define __PVR_DPF_0x10UL(x...)
-       #define __PVR_DPF_0x20UL(x...)
-       #define __PVR_DPF_0x40UL(x...)
-       #define __PVR_DPF_0x80UL(x...)
+       #define __PVR_DPF_0x004UL(x...)
+       #define __PVR_DPF_0x008UL(x...)
+       #define __PVR_DPF_0x010UL(x...)
+       #define __PVR_DPF_0x020UL(x...)
+       #define __PVR_DPF_0x040UL(x...)
+       #define __PVR_DPF_0x100UL(x...)
 #endif
 
        /* Translate the different log levels to separate macros
@@ -188,6 +191,7 @@ IMG_IMPORT IMG_VOID IMG_CALLCONV PVRSRVDebugAssertFail(const IMG_CHAR *pszFile,
        #define PVR_DBG_VERBOSE         DBGPRIV_VERBOSE,__FILE__, __LINE__
        #define PVR_DBG_CALLTRACE       DBGPRIV_CALLTRACE,__FILE__, __LINE__
        #define PVR_DBG_ALLOC           DBGPRIV_ALLOC,__FILE__, __LINE__
+       #define PVR_DBG_BUFFERED        DBGPRIV_BUFFERED,__FILE__, __LINE__
        #define PVR_DBGDRIV_MESSAGE     DBGPRIV_DBGDRV_MESSAGE, "", 0
 
        #define PVR_DPF(X)                      PVRSRVDebugPrintf X
@@ -200,13 +204,14 @@ IMG_IMPORT IMG_VOID IMG_CALLCONV PVRSRVDebugPrintf(IMG_UINT32 ui32DebugLevel,
                                                                                                   const IMG_CHAR *pszFormat,
                                                                                                   ...) IMG_FORMAT_PRINTF(4, 5);
 
+IMG_IMPORT IMG_VOID IMG_CALLCONV PVRSRVDebugPrintfDumpCCB(void);
+
 #else  /* defined(PVRSRV_NEED_PVR_DPF) */
 
        #define PVR_DPF(X)
 
 #endif /* defined(PVRSRV_NEED_PVR_DPF) */
 
-
 /* PVR_TRACE() handling */
 
 #if defined(PVRSRV_NEED_PVR_TRACE)
index cc327ae..0e4b5c2 100644 (file)
@@ -49,21 +49,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define PVR_STR2(X) PVR_STR(X)
 
 #define PVRVERSION_MAJ               1
-#define PVRVERSION_MIN               9
-#define PVRVERSION_BRANCH            19
+#define PVRVERSION_MIN               10
 
 #define PVRVERSION_FAMILY           "sgxddk"
-#define PVRVERSION_BRANCHNAME       "1.9"
-#define PVRVERSION_BUILD             2188537
+#define PVRVERSION_BRANCHNAME       "1.10"
+#define PVRVERSION_BUILD             2359475
 #define PVRVERSION_BSCONTROL        "SGX_DDK_Linux_CustomerTI"
 
-#define PVRVERSION_STRING           "SGX_DDK_Linux_CustomerTI sgxddk 19 1.9@" PVR_STR2(PVRVERSION_BUILD)
-#define PVRVERSION_STRING_SHORT     "1.9@" PVR_STR2(PVRVERSION_BUILD)
+#define PVRVERSION_STRING           "SGX_DDK_Linux_CustomerTI sgxddk 1.10@" PVR_STR2(PVRVERSION_BUILD)
+#define PVRVERSION_STRING_SHORT     "1.10@" PVR_STR2(PVRVERSION_BUILD)
 
 #define COPYRIGHT_TXT               "Copyright (c) Imagination Technologies Ltd. All Rights Reserved."
 
-#define PVRVERSION_BUILD_HI          218
-#define PVRVERSION_BUILD_LO          8537
+#define PVRVERSION_BUILD_HI          235
+#define PVRVERSION_BUILD_LO          9475
 #define PVRVERSION_STRING_NUMERIC    PVR_STR2(PVRVERSION_MAJ) "." PVR_STR2(PVRVERSION_MIN) "." PVR_STR2(PVRVERSION_BUILD_HI) "." PVR_STR2(PVRVERSION_BUILD_LO)
 
 #endif /* _PVRVERSION_H_ */
index 5b927a7..418d7f1 100644 (file)
@@ -354,11 +354,7 @@ typedef struct _PVRSRV_CONNECTION_
 typedef struct _PVRSRV_DEV_DATA_
 {
        IMG_CONST PVRSRV_CONNECTION      *psConnection; /*!< Services connection info */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;                             /*!< Dev cookie */
-#else
        IMG_HANDLE                      hDevCookie;                             /*!< Dev cookie */
-#endif
 
 } PVRSRV_DEV_DATA;
 
@@ -427,16 +423,6 @@ typedef struct _PVRSRV_CLIENT_MEM_INFO_
        /* ptr to associated client sync info - NULL if no sync */
        struct _PVRSRV_CLIENT_SYNC_INFO_        *psClientSyncInfo;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       /* handle to client mapping data (OS specific) */
-       IMG_SID                                                         hMappingInfo;
-
-       /* handle to kernel mem info */
-       IMG_SID                                                         hKernelMemInfo;
-
-       /* resman handle for UM mapping clean-up */
-       IMG_SID                                                         hResItem;
-#else
        /* handle to client mapping data (OS specific) */
        IMG_HANDLE                                                      hMappingInfo;
 
@@ -445,7 +431,6 @@ typedef struct _PVRSRV_CLIENT_MEM_INFO_
 
        /* resman handle for UM mapping clean-up */
        IMG_HANDLE                                                      hResItem;
-#endif
 
 #if defined(SUPPORT_MEMINFO_IDS)
        #if !defined(USE_CODE)
@@ -456,6 +441,9 @@ typedef struct _PVRSRV_CLIENT_MEM_INFO_
        IMG_UINT32                                                      dummy2;
        #endif /* !defined(USE_CODE) */
 #endif /* defined(SUPPORT_MEMINFO_IDS) */
+#if defined(SUPPORT_ION)
+       IMG_SIZE_T                                                      uiIonBufferSize;
+#endif /* defined(SUPPORT_ION) */
 
        /*
                ptr to next mem info
@@ -474,11 +462,7 @@ typedef struct _PVRSRV_CLIENT_MEM_INFO_
 typedef struct _PVRSRV_HEAP_INFO_
 {
        IMG_UINT32                      ui32HeapID;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevMemHeap;
-#else
        IMG_HANDLE                      hDevMemHeap;
-#endif
        IMG_DEV_VIRTADDR        sDevVAddrBase;
        IMG_UINT32                      ui32HeapByteSize;
        IMG_UINT32                      ui32Attribs;
@@ -496,11 +480,7 @@ typedef struct _PVRSRV_EVENTOBJECT_
        /* globally unique name of the event object */
        IMG_CHAR        szName[EVENTOBJNAME_MAXLENGTH];
        /* kernel specific handle for the event object */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID     hOSEventKM;
-#else
        IMG_HANDLE      hOSEventKM;
-#endif
 
 } PVRSRV_EVENTOBJECT;
 
@@ -526,13 +506,8 @@ typedef struct _PVRSRV_MISC_INFO_
        /*!< SOC Timer register */
        IMG_VOID        *pvSOCTimerRegisterKM;
        IMG_VOID        *pvSOCTimerRegisterUM;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hSOCTimerRegisterOSMemHandle;
-       IMG_SID         hSOCTimerRegisterMappingInfo;
-#else
        IMG_HANDLE      hSOCTimerRegisterOSMemHandle;
        IMG_HANDLE      hSOCTimerRegisterMappingInfo;
-#endif
 
        /*!< SOC Clock Gating registers */
        IMG_VOID        *pvSOCClockGateRegs;
@@ -544,11 +519,7 @@ typedef struct _PVRSRV_MISC_INFO_
 
        /* global event object */
        PVRSRV_EVENTOBJECT      sGlobalEventObject;//FIXME: should be private to services
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_EVENTSID            hOSGlobalEvent;
-#else
        IMG_HANDLE                      hOSGlobalEvent;
-#endif
 
        /* Note: add misc. items as required */
        IMG_UINT32      aui32DDKVersion[4];
@@ -566,7 +537,6 @@ typedef struct _PVRSRV_MISC_INFO_
                 * directly in the srvclient PVRSRVGetMiscInfo code, and then convert it
                 * to a kernel meminfo if required. Try to not waste space.
                 */
-#if !defined (SUPPORT_SID_INTERFACE)
                union
                {
                        /*!< Input client meminfo (UM side) */
@@ -575,7 +545,6 @@ typedef struct _PVRSRV_MISC_INFO_
                        /*!< Output kernel meminfo (Bridge+KM side) */
                        struct _PVRSRV_KERNEL_MEM_INFO_ *psKernelMemInfo;
                } u;
-#endif
 
                /*!< Offset in MemInfo to start cache op */
                IMG_VOID *pvBaseVAddr;
@@ -591,7 +560,6 @@ typedef struct _PVRSRV_MISC_INFO_
                 * directly in the srvclient PVRSRVGetMiscInfo code, and then convert it
                 * to a kernel meminfo if required. Try to not waste space.
                 */
-#if !defined(SUPPORT_SID_INTERFACE)
                union
                {
                        /*!< Input client meminfo (UM side) */
@@ -600,7 +568,6 @@ typedef struct _PVRSRV_MISC_INFO_
                        /*!< Output kernel meminfo (Bridge+KM side) */
                        struct _PVRSRV_KERNEL_MEM_INFO_ *psKernelMemInfo;
                } u;
-#endif
 
                /*!< Resulting refcount */
                IMG_UINT32 ui32RefCount;
@@ -620,11 +587,7 @@ typedef struct _PVRSRV_SYNC_TOKEN_
           The fields are hidden in sPrivate in order to reinforce this. */
        struct
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID    hKernelSyncInfo;
-#else
                IMG_HANDLE hKernelSyncInfo;
-#endif
                IMG_UINT32 ui32ReadOpsPendingSnapshot;
                IMG_UINT32 ui32WriteOpsPendingSnapshot;
                IMG_UINT32 ui32ReadOps2PendingSnapshot;
@@ -673,11 +636,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVReleaseMiscInfo (IMG_CONST PVRSRV_CONNECTION *ps
 
 IMG_IMPORT
 PVRSRV_ERROR PVRSRVPollForValue ( const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                       IMG_SID    hOSEvent,
-#else
                                                        IMG_HANDLE hOSEvent,
-#endif
                                                        volatile IMG_UINT32 *pui32LinMemAddr,
                                                        IMG_UINT32 ui32Value,
                                                        IMG_UINT32 ui32Mask,
@@ -687,30 +646,18 @@ PVRSRV_ERROR PVRSRVPollForValue ( const PVRSRV_CONNECTION *psConnection,
 /* memory APIs */
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDeviceMemContext(IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID    *phDevMemContext,
-#else
                                                                                        IMG_HANDLE *phDevMemContext,
-#endif
                                                                                        IMG_UINT32 *pui32SharedHeapCount,
                                                                                        PVRSRV_HEAP_INFO *psHeapInfo);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyDeviceMemContext(IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID                         hDevMemContext
-#else
                                                                                        IMG_HANDLE                      hDevMemContext
-#endif
        );
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfo(IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID     hDevMemContext,
-#else
                                                                                        IMG_HANDLE hDevMemContext,
-#endif
                                                                                        IMG_UINT32 *pui32SharedHeapCount,
                                                                                        PVRSRV_HEAP_INFO *psHeapInfo);
 
@@ -727,11 +674,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfo(IMG_CONST PVRSRV_DEV_DATA *
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVAllocDeviceMem2(IMG_CONST PVRSRV_DEV_DATA      *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       IMG_SID                 hDevMemHeap,
-#else
                                                                        IMG_HANDLE              hDevMemHeap,
-#endif
                                                                        IMG_UINT32              ui32Attribs,
                                                                        IMG_SIZE_T              ui32Size,
                                                                        IMG_SIZE_T              ui32Alignment,
@@ -741,11 +684,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVAllocDeviceMem2(IMG_CONST PVRSRV_DEV_DATA  *psDev
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVAllocDeviceMem(IMG_CONST PVRSRV_DEV_DATA       *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       IMG_SID                 hDevMemHeap,
-#else
                                                                        IMG_HANDLE              hDevMemHeap,
-#endif
                                                                        IMG_UINT32              ui32Attribs,
                                                                        IMG_SIZE_T              ui32Size,
                                                                        IMG_SIZE_T              ui32Alignment,
@@ -758,20 +697,12 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVFreeDeviceMem(IMG_CONST PVRSRV_DEV_DATA   *psDevDa
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVExportDeviceMem(IMG_CONST PVRSRV_DEV_DATA      *psDevData,
                                                                                                PVRSRV_CLIENT_MEM_INFO          *psMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                               IMG_SID                                         *phMemInfo
-#else
                                                                                                IMG_HANDLE                                      *phMemInfo
-#endif
        );
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVReserveDeviceVirtualMem(IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID                         hDevMemHeap,
-#else
                                                                                        IMG_HANDLE                      hDevMemHeap,
-#endif
                                                                                        IMG_DEV_VIRTADDR        *psDevVAddr,
                                                                                        IMG_SIZE_T                      ui32Size,
                                                                                        IMG_SIZE_T                      ui32Alignment,
@@ -782,13 +713,8 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVFreeDeviceVirtualMem(IMG_CONST PVRSRV_DEV_DATA *
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceMemory (IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       IMG_SID hKernelMemInfo,
-                                                                       IMG_SID hDstDevMemHeap,
-#else
                                                                        IMG_HANDLE hKernelMemInfo,
                                                                        IMG_HANDLE hDstDevMemHeap,
-#endif
                                                                        PVRSRV_CLIENT_MEM_INFO **ppsDstMemInfo);
 
 IMG_IMPORT
@@ -807,11 +733,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapExtMemory (IMG_CONST PVRSRV_DEV_DATA *psDev
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemory(IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                               IMG_SID                                 hDevMemContext,
-#else
                                                                                                IMG_HANDLE                              hDevMemContext,
-#endif
                                                                                                IMG_SIZE_T                              ui32ByteSize,
                                                                                                IMG_SIZE_T                              ui32PageOffset,
                                                                                                IMG_BOOL                                bPhysContig,
@@ -829,13 +751,8 @@ PVRSRV_ERROR PVRSRVChangeDeviceMemoryAttributes(IMG_CONST PVRSRV_DEV_DATA                  *psD
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemory (IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID hDevMemContext,
-                                                                               IMG_SID hDeviceClassBuffer,
-#else
                                                                                IMG_HANDLE hDevMemContext,
                                                                                IMG_HANDLE hDeviceClassBuffer,
-#endif
                                                                                PVRSRV_CLIENT_MEM_INFO **ppsMemInfo);
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapDeviceClassMemory (IMG_CONST PVRSRV_DEV_DATA *psDevData,
@@ -863,23 +780,18 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVExportDeviceMem2(IMG_CONST PVRSRV_DEV_DATA        *psDe
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceMemory2(IMG_CONST PVRSRV_DEV_DATA     *psDevData,
                                                                                                 IMG_INT                                        iFd,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                IMG_SID                                        hDstDevMemHeap,
-#else
                                                                                                 IMG_HANDLE                                     hDstDevMemHeap,
-#endif
                                                                                                 PVRSRV_CLIENT_MEM_INFO         **ppsDstMemInfo);
 #endif /* defined(LINUX) */
 
 #if defined(SUPPORT_ION)
 PVRSRV_ERROR PVRSRVMapIonHandle(const PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                IMG_SID    hDevMemContext,
-#else
-                                                                IMG_HANDLE hDevMemContext,
-#endif
-                                                               IMG_INT32 uiFD,
-                                                               IMG_UINT32 uiSize,
+                                                               IMG_HANDLE hDevMemHeap,
+                                                               IMG_UINT32 ui32NumFDs,
+                                                               IMG_INT    *paiBufferFDs,
+                                                               IMG_UINT32 ui32ChunkCount,
+                                                               IMG_SIZE_T *pauiOffset,
+                                                               IMG_SIZE_T *pauiSize,
                                                                IMG_UINT32 ui32Attribs,
                                                                PVRSRV_CLIENT_MEM_INFO **ppsMemInfo);
 
@@ -890,11 +802,7 @@ PVRSRV_ERROR PVRSRVUnmapIonHandle(const PVRSRV_DEV_DATA *psDevData,
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVAllocDeviceMemSparse(const PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                       IMG_SID  hDevMemHeap,
-#else
                                                                                                        IMG_HANDLE hDevMemHeap,
-#endif
                                                                                                        IMG_UINT32 ui32Attribs,
                                                                                                        IMG_SIZE_T uAlignment,
                                                                                                        IMG_UINT32 ui32ChunkSize,
@@ -970,11 +878,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVEnumDCDims (IMG_HANDLE hDevice,
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDCSystemBuffer(IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID *phBuffer
-#else
                                                                                IMG_HANDLE *phBuffer
-#endif
        );
 
 IMG_IMPORT
@@ -989,117 +893,69 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDCSwapChain (IMG_HANDLE                            hDevice,
                                                                                                        IMG_UINT32                              ui32BufferCount,
                                                                                                        IMG_UINT32                              ui32OEMFlags,
                                                                                                        IMG_UINT32                              *pui32SwapChainID,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                       IMG_SID                                 *phSwapChain
-#else
                                                                                                        IMG_HANDLE                              *phSwapChain
-#endif
        );
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyDCSwapChain (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID hSwapChain
-#else
                                                                                        IMG_HANDLE              hSwapChain
-#endif
        );
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSetDCDstRect (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID         hSwapChain,
-#else
                                                                                IMG_HANDLE      hSwapChain,
-#endif
                                                                                IMG_RECT        *psDstRect);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSetDCSrcRect (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID         hSwapChain,
-#else
                                                                                IMG_HANDLE      hSwapChain,
-#endif
                                                                                IMG_RECT        *psSrcRect);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSetDCDstColourKey (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID         hSwapChain,
-#else
                                                                                        IMG_HANDLE      hSwapChain,
-#endif
                                                                                        IMG_UINT32      ui32CKColour);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSetDCSrcColourKey (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID         hSwapChain,
-#else
                                                                                        IMG_HANDLE      hSwapChain,
-#endif
                                                                                        IMG_UINT32      ui32CKColour);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDCBuffers(IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       IMG_SID     hSwapChain,
-                                                                       IMG_SID    *phBuffer
-#else
                                                                        IMG_HANDLE hSwapChain,
                                                                        IMG_HANDLE *phBuffer
-#endif
        );
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDCBuffers2(IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                         IMG_SID    hSwapChain,
-                                                                                         IMG_SID   *phBuffer,
-#else
                                                                                          IMG_HANDLE hSwapChain,
                                                                                          IMG_HANDLE *phBuffer,
-#endif
                                                                                          IMG_SYS_PHYADDR *psPhyAddr);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSwapToDCBuffer (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID    hBuffer,
-#else
                                                                                IMG_HANDLE hBuffer,
-#endif
                                                                                IMG_UINT32 ui32ClipRectCount,
                                                                                IMG_RECT  *psClipRect,
                                                                                IMG_UINT32 ui32SwapInterval,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID hPrivateTag
-#else
                                                                                IMG_HANDLE hPrivateTag
-#endif
        );
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSwapToDCBuffer2 (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID    hBuffer,
-#else
                                                                                IMG_HANDLE hBuffer,
-#endif
                                                                                IMG_UINT32 ui32SwapInterval,
                                                                                PVRSRV_CLIENT_MEM_INFO **ppsMemInfos,
-                                                                               IMG_UINT32 ui32NumMemInfos,
+                                                                               PVRSRV_CLIENT_SYNC_INFO **ppsSyncInfos,
+                                                                               IMG_UINT32 ui32NumMemSyncInfos,
                                                                                IMG_PVOID  pvPrivData,
-                                                                               IMG_UINT32 ui32PrivDataLength);
+                                                                               IMG_UINT32 ui32PrivDataLength,
+                                                                               IMG_HANDLE *phFence);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSwapToDCSystem (IMG_HANDLE hDevice,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                               IMG_SID hSwapChain
-#else
                                                                                IMG_HANDLE hSwapChain
-#endif
        );
 
 /******************************************************************************
@@ -1120,11 +976,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetBCBufferInfo(IMG_HANDLE hDevice,
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetBCBuffer(IMG_HANDLE hDevice,
                                                                                                IMG_UINT32 ui32BufferIndex,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                               IMG_SID   *phBuffer
-#else
                                                                                                IMG_HANDLE *phBuffer
-#endif
        );
 
 
@@ -1142,11 +994,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpStopInitPhase(IMG_CONST PVRSRV_CONNECTION *
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpMemPol(IMG_CONST PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                 IMG_SID    hKernelMemInfo,
-#else
                                                                                  PVRSRV_CLIENT_MEM_INFO *psMemInfo,
-#endif                                                                           
                                                                                  IMG_UINT32 ui32Offset,
                                                                                  IMG_UINT32 ui32Value,
                                                                                  IMG_UINT32 ui32Mask,
@@ -1155,22 +1003,14 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpMemPol(IMG_CONST PVRSRV_CONNECTION *psConne
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpSyncPol(IMG_CONST PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                        IMG_SID    hKernelSyncInfo,
-#else
                                                                                         PVRSRV_CLIENT_SYNC_INFO *psClientSyncInfo,
-#endif
                                                                                         IMG_BOOL   bIsRead,
                                                                                         IMG_UINT32 ui32Value,
                                                                                         IMG_UINT32 ui32Mask);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpSyncPol2(IMG_CONST PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                        IMG_SID  hKernelSyncInfo,
-#else
                                                                                         PVRSRV_CLIENT_SYNC_INFO *psClientSyncInfo,
-#endif
                                                                                         IMG_BOOL bIsRead);
 
 IMG_IMPORT
@@ -1222,11 +1062,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpPDDevPAddr(IMG_CONST PVRSRV_CONNECTION *psC
 #if !defined(USE_CODE)
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpMemPages(IMG_CONST PVRSRV_DEV_DATA *psDevData,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                                  IMG_SID                              hKernelMemInfo,
-#else
                                                                                                                   IMG_HANDLE                   hKernelMemInfo,
-#endif
                                                                                                                   IMG_DEV_PHYADDR              *pPages,
                                                                                                                   IMG_UINT32                   ui32NumPages,
                                                                                                                   IMG_DEV_VIRTADDR             sDevVAddr,
@@ -1279,11 +1115,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpBitmap(IMG_CONST PVRSRV_DEV_DATA *psDevData
                                                                                        IMG_UINT32 ui32Height,
                                                                                        IMG_UINT32 ui32StrideInBytes,
                                                                                        IMG_DEV_VIRTADDR sDevBaseAddr,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       IMG_SID    hDevMemContext,
-#else
                                                                                        IMG_HANDLE hDevMemContext,
-#endif
                                                                                        IMG_UINT32 ui32Size,
                                                                                        PDUMP_PIXEL_FORMAT ePixelFormat,
                                                                                        PDUMP_MEM_FORMAT eMemFormat,
@@ -1338,12 +1170,12 @@ IMG_IMPORT IMG_BOOL IMG_CALLCONV PVRSRVGetAppHint(IMG_VOID                      *pvHintState,
  *****************************************************************************/
 
 /* Exported APIs */
-IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVAllocUserModeMem (IMG_SIZE_T ui32Size);
-IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVCallocUserModeMem (IMG_SIZE_T ui32Size);
-IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVReallocUserModeMem (IMG_PVOID pvBase, IMG_SIZE_T uNewSize);
+IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVAllocUserModeMem (IMG_SIZE_T uiSize);
+IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVCallocUserModeMem (IMG_SIZE_T uiSize);
+IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVReallocUserModeMem (IMG_PVOID pvBase, IMG_SIZE_T uiNewSize);
 IMG_IMPORT IMG_VOID  IMG_CALLCONV PVRSRVFreeUserModeMem (IMG_PVOID pvMem);
-IMG_IMPORT IMG_VOID PVRSRVMemCopy(IMG_VOID *pvDst, const IMG_VOID *pvSrc, IMG_SIZE_T ui32Size);
-IMG_IMPORT IMG_VOID PVRSRVMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_SIZE_T ui32Size);
+IMG_IMPORT IMG_VOID PVRSRVMemCopy(IMG_VOID *pvDst, const IMG_VOID *pvSrc, IMG_SIZE_T uiSize);
+IMG_IMPORT IMG_VOID PVRSRVMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_SIZE_T uiSize);
 
 struct _PVRSRV_MUTEX_OPAQUE_STRUCT_;
 typedef        struct  _PVRSRV_MUTEX_OPAQUE_STRUCT_ *PVRSRV_MUTEX_HANDLE;
@@ -1492,11 +1324,7 @@ IMG_IMPORT IMG_PVOID IMG_CALLCONV PVRSRVReallocUserModeMemTracking(IMG_VOID *pvM
  *****************************************************************************/
 
 IMG_IMPORT PVRSRV_ERROR PVRSRVEventObjectWait(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       IMG_EVENTSID hOSEvent
-#else
                                                                        IMG_HANDLE hOSEvent
-#endif
        );
 
 /*!
@@ -1509,11 +1337,7 @@ IMG_IMPORT PVRSRV_ERROR PVRSRVEventObjectWait(const PVRSRV_CONNECTION *psConnect
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateSyncInfoModObj(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                        IMG_SID *phKernelSyncInfoModObj
-#else
                                                                                                         IMG_HANDLE *phKernelSyncInfoModObj
-#endif
        );
 
 /*!
@@ -1526,11 +1350,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateSyncInfoModObj(const PVRSRV_CONNECTION *ps
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroySyncInfoModObj(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                         IMG_SID hKernelSyncInfoModObj
-#else
                                                                                                          IMG_HANDLE hKernelSyncInfoModObj
-#endif
        );
 
 
@@ -1565,11 +1385,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroySyncInfoModObj(const PVRSRV_CONNECTION *p
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVModifyPendingSyncOps(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                         IMG_SID    hKernelSyncInfoModObj,
-#else
                                                                                                          IMG_HANDLE hKernelSyncInfoModObj,
-#endif
                                                                                                          PVRSRV_CLIENT_SYNC_INFO *psSyncInfo,
                                                                                                          IMG_UINT32 ui32ModifyFlags,
                                                                                                          IMG_UINT32 *pui32ReadOpsPending,
@@ -1590,11 +1406,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVModifyPendingSyncOps(const PVRSRV_CONNECTION *ps
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVModifyCompleteSyncOps(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                         IMG_SID hKernelSyncInfoModObj
-#else
                                                                                                          IMG_HANDLE hKernelSyncInfoModObj
-#endif
        );
 
 /*!
@@ -1620,11 +1432,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVModifyCompleteSyncOps(const PVRSRV_CONNECTION *p
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSyncOpsTakeToken(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                const IMG_SID      hKernelSyncInfo,
-#else
                                                                                                 const PVRSRV_CLIENT_SYNC_INFO *psSyncInfo,
-#endif
                                                                                                 PVRSRV_SYNC_TOKEN *psSyncToken);
 /*!
  ******************************************************************************
@@ -1644,11 +1452,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVSyncOpsTakeToken(const PVRSRV_CONNECTION *psConn
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSyncOpsFlushToToken(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                       const IMG_SID            hKernelSyncInfo,
-#else
                                                                                                        const PVRSRV_CLIENT_SYNC_INFO *psSyncInfo,
-#endif
                                                                                                        const PVRSRV_SYNC_TOKEN *psSyncToken,
                                                                                                        IMG_BOOL bWait);
 /*!
@@ -1671,11 +1475,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVSyncOpsFlushToToken(const PVRSRV_CONNECTION *psC
  ******************************************************************************/
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVSyncOpsFlushToModObj(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                        IMG_SID  hKernelSyncInfoModObj,
-#else
                                                                                                         IMG_HANDLE hKernelSyncInfoModObj,
-#endif
                                                                                                         IMG_BOOL bWait);
 
 /*!
index 80df117..2f044dd 100644 (file)
@@ -645,6 +645,9 @@ typedef enum _PVRSRV_PIXEL_FORMAT_ {
        PVRSRV_PIXEL_FORMAT_RAW512                              = 224,
        PVRSRV_PIXEL_FORMAT_RAW1024                             = 225,
 
+       /* Same as NV12 but with interleaved VU rather than interleaved UV */
+       PVRSRV_PIXEL_FORMAT_NV21                                = 226,
+
        PVRSRV_PIXEL_FORMAT_FORCE_I32                   = 0x7fffffff
 
 } PVRSRV_PIXEL_FORMAT;
@@ -744,17 +747,10 @@ typedef struct _PVRSRV_CLIENT_SYNC_INFO_
        IMG_DEV_VIRTADDR                sReadOps2CompleteDevVAddr;
 
        /* handle to client mapping data (OS specific) */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hMappingInfo;
-
-       /* handle to kernel sync info */
-       IMG_SID                                 hKernelSyncInfo;
-#else
        IMG_HANDLE                                      hMappingInfo;
 
        /* handle to kernel sync info */
        IMG_HANDLE                                      hKernelSyncInfo;
-#endif
 
 } PVRSRV_CLIENT_SYNC_INFO, *PPVRSRV_CLIENT_SYNC_INFO;
 
@@ -803,7 +799,7 @@ typedef struct _IMG_RECT_16_
 typedef PVRSRV_ERROR (*PFN_GET_BUFFER_ADDR)(IMG_HANDLE,
                                                                                        IMG_HANDLE,
                                                                                        IMG_SYS_PHYADDR**,
-                                                                                       IMG_SIZE_T*,
+                                                                                       IMG_UINT32*,
                                                                                        IMG_VOID**,
                                                                                        IMG_HANDLE*,
                                                                                        IMG_BOOL*,
index b64cd39..9a1627e 100644 (file)
@@ -87,17 +87,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 
 
-#if defined (SUPPORT_SID_INTERFACE)
-#define PVR_SECURE_HANDLES_SET_OFFSET  OPTIONS_BIT4
-#define OPTIONS_BIT4           (0x1U << 4)
-#else
 #if defined(PVR_SECURE_HANDLES) || defined (INTERNAL_TEST)
 #define PVR_SECURE_HANDLES_SET_OFFSET  OPTIONS_BIT4
 #define OPTIONS_BIT4           (0x1U << 4)
 #else
 #define OPTIONS_BIT4           0x0
 #endif /* PVR_SECURE_HANDLES */
-#endif
 
 #if defined(SGX_BYPASS_SYSTEM_CACHE) || defined (INTERNAL_TEST)
 #define SGX_BYPASS_SYSTEM_CACHE_SET_OFFSET     OPTIONS_BIT5
index bb8776a..05bb624 100644 (file)
@@ -83,11 +83,8 @@ extern "C" {
 #if defined(SUPPORT_MEMORY_TILING)
 #define SGX_VPB_TILED_HEAP_ID                  14
 #endif
-#if defined(SUPPORT_ION)
-#define SGX_ION_HEAP_ID                                                        15
-#endif
 
-#define SGX_MAX_HEAP_ID                                                        16
+#define SGX_MAX_HEAP_ID                                                        15
 
 /*
  * Keep SGX_3DPARAMETERS_HEAP_ID as TQ full custom
@@ -120,8 +117,14 @@ extern "C" {
 #define SGX_MAX_SRC_SYNCS_TA                           32
 #define SGX_MAX_DST_SYNCS_TA                           1
 /* note: there is implicitly 1 3D Dst Sync */
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+/* note: only one dst sync is supported by the 2D paths */
+#define SGX_MAX_SRC_SYNCS_TQ                           6
+#define SGX_MAX_DST_SYNCS_TQ                           2
+#else /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
 #define SGX_MAX_SRC_SYNCS_TQ                           8
 #define SGX_MAX_DST_SYNCS_TQ                           1
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
 #endif
 
 
@@ -236,6 +239,7 @@ typedef struct _CTL_STATUS_
 typedef enum _SGX_MISC_INFO_REQUEST_
 {
        SGX_MISC_INFO_REQUEST_CLOCKSPEED = 0,
+       SGX_MISC_INFO_REQUEST_CLOCKSPEED_SLCSIZE,
        SGX_MISC_INFO_REQUEST_SGXREV,
        SGX_MISC_INFO_REQUEST_DRIVER_SGXREV,
 #if defined(SUPPORT_SGX_EDM_MEMORY_DEBUG)
@@ -254,6 +258,9 @@ typedef enum _SGX_MISC_INFO_REQUEST_
        SGX_MISC_INFO_REQUEST_SPM,
        SGX_MISC_INFO_REQUEST_ACTIVEPOWER,
        SGX_MISC_INFO_REQUEST_LOCKUPS,
+#if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
+       SGX_MISC_INFO_REQUEST_EDM_STATUS_BUFFER_INFO,
+#endif
        SGX_MISC_INFO_REQUEST_FORCE_I16                                 =  0x7fff
 } SGX_MISC_INFO_REQUEST;
 
@@ -275,11 +282,24 @@ typedef struct _PVRSRV_SGX_MISCINFO_FEATURES
 #if defined(SUPPORT_SGX_EDM_MEMORY_DEBUG)
        IMG_UINT32                      ui32DeviceMemValue;             /*!< device mem value read from ukernel */
 #endif
+} PVRSRV_SGX_MISCINFO_FEATURES;
+
+typedef struct _PVRSRV_SGX_MISCINFO_QUERY_CLOCKSPEED_SLCSIZE
+{
+       IMG_UINT32                      ui32SGXClockSpeed;
+       IMG_UINT32                      ui32SGXSLCSize;
+} PVRSRV_SGX_MISCINFO_QUERY_CLOCKSPEED_SLCSIZE;
+
 #if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
+/******************************************************************************
+ * Struct for getting access to the EDM Status Buffer
+ ******************************************************************************/
+typedef struct _PVRSRV_SGX_MISCINFO_EDM_STATUS_BUFFER_INFO
+{
        IMG_DEV_VIRTADDR        sDevVAEDMStatusBuffer;  /*!< DevVAddr of the EDM status buffer */
        IMG_PVOID                       pvEDMStatusBuffer;              /*!< CPUVAddr of the EDM status buffer */
+} PVRSRV_SGX_MISCINFO_EDM_STATUS_BUFFER_INFO;
 #endif
-} PVRSRV_SGX_MISCINFO_FEATURES;
 
 
 /******************************************************************************
@@ -389,6 +409,7 @@ typedef struct _SGX_MISC_INFO_
                IMG_UINT32      reserved;       /*!< Unused: ensures valid code in the case everything else is compiled out */
                PVRSRV_SGX_MISCINFO_FEATURES                                            sSGXFeatures;
                IMG_UINT32                                                                                      ui32SGXClockSpeed;
+               PVRSRV_SGX_MISCINFO_QUERY_CLOCKSPEED_SLCSIZE                            sQueryClockSpeedSLCSize;
                PVRSRV_SGX_MISCINFO_ACTIVEPOWER                                         sActivePower;
                PVRSRV_SGX_MISCINFO_LOCKUPS                                                     sLockups;
                PVRSRV_SGX_MISCINFO_SPM                                                         sSPM;
@@ -396,6 +417,10 @@ typedef struct _SGX_MISC_INFO_
                SGX_BREAKPOINT_INFO                                                                     sSGXBreakpointInfo;
 #endif
                PVRSRV_SGX_MISCINFO_SET_HWPERF_STATUS                           sSetHWPerfStatus;
+
+#if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
+               PVRSRV_SGX_MISCINFO_EDM_STATUS_BUFFER_INFO                      sEDMStatusBufferInfo;
+#endif
        } uData;
 } SGX_MISC_INFO;
 
@@ -439,7 +464,6 @@ typedef struct _PVRSRV_SGX_PDUMP_CONTEXT_
 } PVRSRV_SGX_PDUMP_CONTEXT;
 
 
-#if !defined (SUPPORT_SID_INTERFACE)
 typedef struct _SGX_KICKTA_DUMP_ROFF_
 {
        IMG_HANDLE                      hKernelMemInfo;                                         /*< Buffer handle */
@@ -448,13 +472,8 @@ typedef struct _SGX_KICKTA_DUMP_ROFF_
        IMG_UINT32                      ui32Value;                                                      /*< Actual value to dump */
        IMG_PCHAR                       pszName;                                                        /*< Name of buffer */
 } SGX_KICKTA_DUMP_ROFF, *PSGX_KICKTA_DUMP_ROFF;
-#endif
 
-#if defined (SUPPORT_SID_INTERFACE)
-typedef struct _SGX_KICKTA_DUMP_BUFFER_KM_
-#else
 typedef struct _SGX_KICKTA_DUMP_BUFFER_
-#endif
 {
        IMG_UINT32                      ui32SpaceUsed;
        IMG_UINT32                      ui32Start;                                                      /*< Byte offset of start to dump */
@@ -475,13 +494,8 @@ typedef struct _SGX_KICKTA_DUMP_BUFFER_
 #if defined (__QNXNTO__)
        IMG_UINT32          ui32NameLength;                     /*< Number of characters in buffer name */
 #endif
-#if defined (SUPPORT_SID_INTERFACE)
-} SGX_KICKTA_DUMP_BUFFER_KM, *PSGX_KICKTA_DUMP_BUFFER_KM;
-#else
 } SGX_KICKTA_DUMP_BUFFER, *PSGX_KICKTA_DUMP_BUFFER;
-#endif
 
-#if !defined (SUPPORT_SID_INTERFACE)
 #ifdef PDUMP
 /*
        PDUMP version of above kick structure
@@ -501,7 +515,6 @@ typedef struct _SGX_KICKTA_PDUMP_
        IMG_UINT32                                              ui32ROffArraySize;
 } SGX_KICKTA_PDUMP, *PSGX_KICKTA_PDUMP;
 #endif /* PDUMP */
-#endif /* #if !defined (SUPPORT_SID_INTERFACE) */
 
 #if defined(TRANSFER_QUEUE)
 #if defined(SGX_FEATURE_2D_HARDWARE)
index 46b89d2..2a3a846 100644 (file)
@@ -42,11 +42,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __SGXSCRIPT_H__
 #define __SGXSCRIPT_H__
 
+#include "sgxfeaturedefs.h"
 #if defined (__cplusplus)
 extern "C" {
 #endif
 
 #define        SGX_MAX_INIT_COMMANDS   64
+#define        SGX_MAX_PRINT_COMMANDS  96
 #define        SGX_MAX_DEINIT_COMMANDS 16
 
 typedef        enum _SGX_INIT_OPERATION
@@ -54,6 +56,7 @@ typedef       enum _SGX_INIT_OPERATION
        SGX_INIT_OP_ILLEGAL = 0,
        SGX_INIT_OP_WRITE_HW_REG,
        SGX_INIT_OP_READ_HW_REG,
+       SGX_INIT_OP_PRINT_HW_REG,
 #if defined(PDUMP)
        SGX_INIT_OP_PDUMP_HW_REG,
 #endif
@@ -86,6 +89,10 @@ typedef struct _SGX_INIT_SCRIPTS_
        SGX_INIT_COMMAND asInitCommandsPart1[SGX_MAX_INIT_COMMANDS];
        SGX_INIT_COMMAND asInitCommandsPart2[SGX_MAX_INIT_COMMANDS];
        SGX_INIT_COMMAND asDeinitCommands[SGX_MAX_DEINIT_COMMANDS];
+#if defined(SGX_FEATURE_MP)
+       SGX_INIT_COMMAND asSGXREGDebugCommandsPart1[SGX_MAX_PRINT_COMMANDS];
+#endif
+       SGX_INIT_COMMAND *apsSGXREGDebugCommandsPart2[SGX_FEATURE_MP_CORE_COUNT_3D];
 } SGX_INIT_SCRIPTS;
 
 #if defined(__cplusplus)
index 90d25c8..fdb8ce3 100644 (file)
@@ -101,7 +101,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #undef BCE_USE_SET_MEMORY
 #endif
 
-#if defined(__i386__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) && defined(SUPPORT_LINUX_X86_PAT) && defined(SUPPORT_LINUX_X86_WRITECOMBINE)
+#if (defined(__i386__) || defined(__x86_64__)) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)) && defined(SUPPORT_LINUX_X86_PAT) && defined(SUPPORT_LINUX_X86_WRITECOMBINE)
 #include <asm/cacheflush.h>
 #define        BCE_USE_SET_MEMORY
 #endif
index addbfc2..b522c41 100644 (file)
@@ -39,7 +39,6 @@ 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.
-  
 */ /**************************************************************************/
 #ifndef __3RDPARTY_DC_DRM_SHARED_H__
 #define __3RDPARTY_DC_DRM_SHARED_H__
index eca9351..d442f79 100644 (file)
 # 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.
-#   
 ### ###########################################################################
 
 ccflags-y += \
        -I$(TOP)/services4/3rdparty/dc_omapfb3_linux \
-       -I$(KERNELDIR)/drivers/video/omap2 \
-       -I$(KERNELDIR)/arch/arm/plat-omap/include
+       -Idrivers/video/omap2 \
+       -Iarch/arm/plat-omap/include
 
 omaplfb-y += \
        services4/3rdparty/dc_omapfb3_linux/omaplfb_displayclass.o \
index 7574073..75d11a9 100644 (file)
@@ -36,7 +36,6 @@
 # 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.
-#   
 ### ###########################################################################
 
 modules := dc_omapfb3_linux
index c69640d..0e5b8fb 100644 (file)
@@ -37,7 +37,6 @@ 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.
-  
 */ /**************************************************************************/
 #ifndef __OMAPLFB_H__
 #define __OMAPLFB_H__
@@ -66,6 +65,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define        OMAPLFB_CONSOLE_UNLOCK()        release_console_sem()
 #endif
 
+#if defined(CONFIG_ION_OMAP)
+#include <linux/ion.h>
+#include <linux/omap_ion.h>
+#endif /* defined(CONFIG_ION_OMAP) */
+
 #define unref__ __attribute__ ((unused))
 
 typedef void *       OMAPLFB_HANDLE;
@@ -227,6 +231,10 @@ typedef struct OMAPLFB_DEVINFO_TAG
        OMAPLFB_ATOMIC_BOOL     sLeaveVT;
 #endif
 
+#if defined(CONFIG_ION_OMAP)
+       struct ion_client      *psIONClient;
+#endif
+
 }  OMAPLFB_DEVINFO;
 
 #define        OMAPLFB_PAGE_SIZE 4096
index 0c77e94..c2e87e4 100644 (file)
@@ -37,7 +37,6 @@ 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.
-  
 */ /**************************************************************************/
 
 /**************************************************************************
@@ -88,20 +87,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "omaplfb.h"
 
 #if defined(CONFIG_DSSCOMP)
-
-#if !defined(CONFIG_ION_OMAP)
+#if defined(CONFIG_ION_OMAP)
+extern struct ion_device *omap_ion_device;
+#else /* defined(CONFIG_ION_OMAP) */
 #error CONFIG_DSSCOMP support requires CONFIG_ION_OMAP
-#endif
-
-#include <linux/ion.h>
-#include <linux/omap_ion.h>
-
-extern struct ion_client *gpsIONClient;
-
+#endif /* defined(CONFIG_ION_OMAP) */
+#if defined(CONFIG_DRM_OMAP_DMM_TILER)
+#include <../drivers/staging/omapdrm/omap_dmm_tiler.h>
+#include <../drivers/video/omap2/dsscomp/tiler-utils.h>
+#elif defined(CONFIG_TI_TILER)
 #include <mach/tiler.h>
+#else /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
+#error CONFIG_DSSCOMP support requires either \
+       CONFIG_DRM_OMAP_DMM_TILER or CONFIG_TI_TILER
+#endif /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
 #include <video/dsscomp.h>
 #include <plat/dsscomp.h>
-
 #endif /* defined(CONFIG_DSSCOMP) */
 
 #define OMAPLFB_COMMAND_COUNT          1
@@ -109,7 +110,7 @@ extern struct ion_client *gpsIONClient;
 #define        OMAPLFB_VSYNC_SETTLE_COUNT      5
 
 //#define      OMAPLFB_MAX_NUM_DEVICES         FB_MAX
-#define        OMAPLFB_MAX_NUM_DEVICES         1
+#define OMAPLFB_MAX_NUM_DEVICES         1
 #if (OMAPLFB_MAX_NUM_DEVICES > FB_MAX)
 #error "OMAPLFB_MAX_NUM_DEVICES must not be greater than FB_MAX"
 #endif
@@ -119,6 +120,7 @@ static OMAPLFB_DEVINFO *gapsDevInfo[OMAPLFB_MAX_NUM_DEVICES];
 /* Top level 'hook ptr' */
 static PFN_DC_GET_PVRJTABLE gpfnGetPVRJTable = NULL;
 
+#if !defined(CONFIG_DSSCOMP)
 /* Round x up to a multiple of y */
 static inline unsigned long RoundUpToMultiple(unsigned long x, unsigned long y)
 {
@@ -148,6 +150,7 @@ static unsigned long LCM(unsigned long x, unsigned long y)
 
        return (gcd == 0) ? 0 : ((x / gcd) * y);
 }
+#endif
 
 unsigned OMAPLFBMaxFBDevIDPlusOne(void)
 {
@@ -479,15 +482,14 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                                       IMG_HANDLE *phSwapChain,
                                       IMG_UINT32 *pui32SwapChainID)
 {
-       OMAPLFB_DEVINFO *psDevInfo;
        OMAPLFB_SWAPCHAIN *psSwapChain;
-       OMAPLFB_BUFFER *psBuffer;
-       IMG_UINT32 i;
+       OMAPLFB_DEVINFO *psDevInfo;
        PVRSRV_ERROR eError;
-       IMG_UINT32 ui32BuffersToSkip;
+       IMG_UINT32 i;
 
        UNREFERENCED_PARAMETER(ui32OEMFlags);
-       
+       UNREFERENCED_PARAMETER(ui32Flags);
+
        /* Check parameters */
        if(!hDevice
        || !psDstSurfAttrib
@@ -514,60 +516,7 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                eError = PVRSRV_ERROR_FLIP_CHAIN_EXISTS;
                goto ExitUnLock;
        }
-       
-       /* Check the buffer count */
-       if(ui32BufferCount > psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers)
-       {
-               eError = PVRSRV_ERROR_TOOMANYBUFFERS;
-               goto ExitUnLock;
-       }
-       
-       if ((psDevInfo->sFBInfo.ulRoundedBufferSize * (unsigned long)ui32BufferCount) > psDevInfo->sFBInfo.ulFBSize)
-       {
-               eError = PVRSRV_ERROR_TOOMANYBUFFERS;
-               goto ExitUnLock;
-       }
-
-       /*
-        * We will allocate the swap chain buffers at the back of the frame
-        * buffer area.  This preserves the front portion, which may be being
-        * used by other Linux Framebuffer based applications.
-        */
-       ui32BuffersToSkip = psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers - ui32BufferCount;
-
-       /* 
-        *      Verify the DST/SRC attributes,
-        *      SRC/DST must match the current display mode config
-       */
-       if(psDstSurfAttrib->pixelformat != psDevInfo->sDisplayFormat.pixelformat
-       || psDstSurfAttrib->sDims.ui32ByteStride != psDevInfo->sDisplayDim.ui32ByteStride
-       || psDstSurfAttrib->sDims.ui32Width != psDevInfo->sDisplayDim.ui32Width
-       || psDstSurfAttrib->sDims.ui32Height != psDevInfo->sDisplayDim.ui32Height)
-       {
-               /* DST doesn't match the current mode */
-               eError = PVRSRV_ERROR_INVALID_PARAMS;
-               goto ExitUnLock;
-       }               
-
-       if(psDstSurfAttrib->pixelformat != psSrcSurfAttrib->pixelformat
-       || psDstSurfAttrib->sDims.ui32ByteStride != psSrcSurfAttrib->sDims.ui32ByteStride
-       || psDstSurfAttrib->sDims.ui32Width != psSrcSurfAttrib->sDims.ui32Width
-       || psDstSurfAttrib->sDims.ui32Height != psSrcSurfAttrib->sDims.ui32Height)
-       {
-               /* DST doesn't match the SRC */
-               eError = PVRSRV_ERROR_INVALID_PARAMS;
-               goto ExitUnLock;
-       }               
 
-       /* check flags if implementation requires them */
-       UNREFERENCED_PARAMETER(ui32Flags);
-       
-#if defined(PVR_OMAPFB3_UPDATE_MODE)
-       if (!OMAPLFBSetUpdateMode(psDevInfo, PVR_OMAPFB3_UPDATE_MODE))
-       {
-               printk(KERN_WARNING DRIVER_PREFIX ": %s: Device %u: Couldn't set frame buffer update mode %d\n", __FUNCTION__, psDevInfo->uiFBDevID, PVR_OMAPFB3_UPDATE_MODE);
-       }
-#endif
        /* create a swapchain structure */
        psSwapChain = (OMAPLFB_SWAPCHAIN*)OMAPLFBAllocKernelMem(sizeof(OMAPLFB_SWAPCHAIN));
        if(!psSwapChain)
@@ -576,56 +525,121 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                goto ExitUnLock;
        }
 
-       psBuffer = (OMAPLFB_BUFFER*)OMAPLFBAllocKernelMem(sizeof(OMAPLFB_BUFFER) * ui32BufferCount);
-       if(!psBuffer)
+       /* If services asks for a 0-length swap chain, it's probably Android.
+        *
+        * This will use only non-display memory posting via PVRSRVSwapToDCBuffers2(),
+        * and we can skip some useless sanity checking.
+        */
+       if(ui32BufferCount > 0)
        {
-               eError = PVRSRV_ERROR_OUT_OF_MEMORY;
-               goto ErrorFreeSwapChain;
-       }
+               IMG_UINT32 ui32BuffersToSkip;
 
-       psSwapChain->ulBufferCount = (unsigned long)ui32BufferCount;
-       psSwapChain->psBuffer = psBuffer;
-       psSwapChain->bNotVSynced = OMAPLFB_TRUE;
-       psSwapChain->uiFBDevID = psDevInfo->uiFBDevID;
+               /* Check the buffer count */
+               if(ui32BufferCount > psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers)
+               {
+                       eError = PVRSRV_ERROR_TOOMANYBUFFERS;
+                       goto ErrorFreeSwapChain;
+               }
+       
+               if ((psDevInfo->sFBInfo.ulRoundedBufferSize * (unsigned long)ui32BufferCount) > psDevInfo->sFBInfo.ulFBSize)
+               {
+                       eError = PVRSRV_ERROR_TOOMANYBUFFERS;
+                       goto ErrorFreeSwapChain;
+               }
 
-       /* Link the buffers */
-       for(i=0; i<ui32BufferCount-1; i++)
-       {
-               psBuffer[i].psNext = &psBuffer[i+1];
-       }
-       /* and link last to first */
-       psBuffer[i].psNext = &psBuffer[0];
+               /*
+                * We will allocate the swap chain buffers at the back of the frame
+                * buffer area.  This preserves the front portion, which may be being
+                * used by other Linux Framebuffer based applications.
+                */
+               ui32BuffersToSkip = psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers - ui32BufferCount;
 
-       /* Configure the swapchain buffers */
-       for(i=0; i<ui32BufferCount; i++)
-       {
-               IMG_UINT32 ui32SwapBuffer = i + ui32BuffersToSkip;
-               IMG_UINT32 ui32BufferOffset = ui32SwapBuffer * (IMG_UINT32)psDevInfo->sFBInfo.ulRoundedBufferSize;
+               /* 
+                *      Verify the DST/SRC attributes,
+                *      SRC/DST must match the current display mode config
+                */
+               if(psDstSurfAttrib->pixelformat != psDevInfo->sDisplayFormat.pixelformat
+               || psDstSurfAttrib->sDims.ui32ByteStride != psDevInfo->sDisplayDim.ui32ByteStride
+               || psDstSurfAttrib->sDims.ui32Width != psDevInfo->sDisplayDim.ui32Width
+               || psDstSurfAttrib->sDims.ui32Height != psDevInfo->sDisplayDim.ui32Height)
+               {
+                       /* DST doesn't match the current mode */
+                       eError = PVRSRV_ERROR_INVALID_PARAMS;
+                       goto ErrorFreeSwapChain;
+               }
 
-#if defined(CONFIG_DSSCOMP)
-               if (psDevInfo->sFBInfo.bIs2D)
+               if(psDstSurfAttrib->pixelformat != psSrcSurfAttrib->pixelformat
+               || psDstSurfAttrib->sDims.ui32ByteStride != psSrcSurfAttrib->sDims.ui32ByteStride
+               || psDstSurfAttrib->sDims.ui32Width != psSrcSurfAttrib->sDims.ui32Width
+               || psDstSurfAttrib->sDims.ui32Height != psSrcSurfAttrib->sDims.ui32Height)
                {
-                       ui32BufferOffset = 0;
+                       /* DST doesn't match the SRC */
+                       eError = PVRSRV_ERROR_INVALID_PARAMS;
+                       goto ErrorFreeSwapChain;
                }
+
+               psSwapChain->psBuffer = (OMAPLFB_BUFFER*)OMAPLFBAllocKernelMem(sizeof(OMAPLFB_BUFFER) * ui32BufferCount);
+               if(!psSwapChain->psBuffer)
+               {
+                       eError = PVRSRV_ERROR_OUT_OF_MEMORY;
+                       goto ErrorFreeSwapChain;
+               }
+
+               /* Link the buffers */
+               for(i = 0; i < ui32BufferCount - 1; i++)
+               {
+                       psSwapChain->psBuffer[i].psNext = &psSwapChain->psBuffer[i + 1];
+               }
+
+               /* and link last to first */
+               psSwapChain->psBuffer[i].psNext = &psSwapChain->psBuffer[0];
+
+               /* Configure the swapchain buffers */
+               for(i = 0; i < ui32BufferCount; i++)
+               {
+                       IMG_UINT32 ui32SwapBuffer = i + ui32BuffersToSkip;
+                       IMG_UINT32 ui32BufferOffset = ui32SwapBuffer * (IMG_UINT32)psDevInfo->sFBInfo.ulRoundedBufferSize;
+
+#if defined(CONFIG_DSSCOMP)
+                       if (psDevInfo->sFBInfo.bIs2D)
+                       {
+                               ui32BufferOffset = 0;
+                       }
 #endif /* defined(CONFIG_DSSCOMP) */
 
-               psBuffer[i].psSyncData = ppsSyncData[i];
+                       psSwapChain->psBuffer[i].psSyncData = ppsSyncData[i];
 
-               psBuffer[i].sSysAddr.uiAddr = psDevInfo->sFBInfo.sSysAddr.uiAddr + ui32BufferOffset;
-               psBuffer[i].sCPUVAddr = psDevInfo->sFBInfo.sCPUVAddr + ui32BufferOffset;
-               psBuffer[i].ulYOffset = ui32BufferOffset / psDevInfo->sFBInfo.ulByteStride;
-               psBuffer[i].psDevInfo = psDevInfo;
+                       psSwapChain->psBuffer[i].sSysAddr.uiAddr = psDevInfo->sFBInfo.sSysAddr.uiAddr + ui32BufferOffset;
+                       psSwapChain->psBuffer[i].sCPUVAddr = psDevInfo->sFBInfo.sCPUVAddr + ui32BufferOffset;
+                       psSwapChain->psBuffer[i].ulYOffset = ui32BufferOffset / psDevInfo->sFBInfo.ulByteStride;
+                       psSwapChain->psBuffer[i].psDevInfo = psDevInfo;
 
 #if defined(CONFIG_DSSCOMP)
-               if (psDevInfo->sFBInfo.bIs2D)
-               {
-                       psBuffer[i].sSysAddr.uiAddr += ui32SwapBuffer *
-                               ALIGN((IMG_UINT32)psDevInfo->sFBInfo.ulWidth * psDevInfo->sFBInfo.uiBytesPerPixel, PAGE_SIZE);
-               }
+                       if (psDevInfo->sFBInfo.bIs2D)
+                       {
+                               psSwapChain->psBuffer[i].sSysAddr.uiAddr += ui32SwapBuffer *
+                                       ALIGN((IMG_UINT32)psDevInfo->sFBInfo.ulWidth * psDevInfo->sFBInfo.uiBytesPerPixel, PAGE_SIZE);
+                       }
 #endif /* defined(CONFIG_DSSCOMP) */
 
-               OMAPLFBInitBufferForSwap(&psBuffer[i]);
+                       OMAPLFBInitBufferForSwap(&psSwapChain->psBuffer[i]);
+               }
+       }
+       else
+       {
+               psSwapChain->psBuffer = NULL;
+       }
+
+#if defined(PVR_OMAPFB3_UPDATE_MODE)
+       if (!OMAPLFBSetUpdateMode(psDevInfo, PVR_OMAPFB3_UPDATE_MODE))
+       {
+               printk(KERN_WARNING DRIVER_PREFIX ": %s: Device %u: Couldn't set frame buffer update mode %d\n", __FUNCTION__, psDevInfo->uiFBDevID, PVR_OMAPFB3_UPDATE_MODE);
        }
+#endif /* defined(PVR_OMAPFB3_UPDATE_MODE) */
+
+       psSwapChain->ulBufferCount = (unsigned long)ui32BufferCount;
+       psSwapChain->bNotVSynced = OMAPLFB_TRUE;
+       psSwapChain->uiFBDevID = psDevInfo->uiFBDevID;
 
        if (OMAPLFBCreateSwapQueue(psSwapChain) != OMAPLFB_OK)
        { 
@@ -661,7 +675,10 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
 ErrorDestroySwapQueue:
        OMAPLFBDestroySwapQueue(psSwapChain);
 ErrorFreeBuffers:
-       OMAPLFBFreeKernelMem(psBuffer);
+       if(psSwapChain->psBuffer)
+       {
+               OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
+       }
 ErrorFreeSwapChain:
        OMAPLFBFreeKernelMem(psSwapChain);
 ExitUnLock:
@@ -710,7 +727,10 @@ static PVRSRV_ERROR DestroyDCSwapChain(IMG_HANDLE hDevice,
        }
 
        /* Free resources */
-       OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
+       if (psSwapChain->psBuffer)
+       {
+               OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
+       }
        OMAPLFBFreeKernelMem(psSwapChain);
 
        psDevInfo->psSwapChain = NULL;
@@ -974,6 +994,7 @@ static IMG_BOOL ProcessFlipV1(IMG_HANDLE hCmdCookie,
 #if defined(CONFIG_DSSCOMP)
                if (is_tiler_addr(psBuffer->sSysAddr.uiAddr))
                {
+                       int res;
                        IMG_UINT32 w = psBuffer->psDevInfo->sDisplayDim.ui32Width;
                        IMG_UINT32 h = psBuffer->psDevInfo->sDisplayDim.ui32Height;
                        struct dsscomp_setup_dispc_data comp = {
@@ -997,9 +1018,13 @@ static IMG_BOOL ProcessFlipV1(IMG_HANDLE hCmdCookie,
                        };
                        struct tiler_pa_info *pas[1] = { NULL };
                        comp.ovls[0].ba = (u32) psBuffer->sSysAddr.uiAddr;
-                       dsscomp_gralloc_queue(&comp, pas, true,
+                       res = dsscomp_gralloc_queue(&comp, pas, true,
                                                                  (void *) psDevInfo->sPVRJTable.pfnPVRSRVCmdComplete,
                                                                  (void *) psBuffer->hCmdComplete);
+                       if (res != 0)
+                       {
+                               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: dsscomp_gralloc_queue failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res));
+                       }
                }
                else
 #endif /* defined(CONFIG_DSSCOMP) */
@@ -1025,6 +1050,14 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
 {
        struct tiler_pa_info *apsTilerPAs[5];
        IMG_UINT32 i, k;
+       struct
+       {
+               IMG_UINTPTR_T uiAddr;
+               IMG_UINTPTR_T uiUVAddr;
+               struct tiler_pa_info *psTilerInfo;
+       }
+       asMemInfo[5] = {};
+       int res;
 
        if(ui32DssDataLength != sizeof(*psDssData))
        {
@@ -1039,7 +1072,7 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
                return IMG_FALSE;
        }
 
-       for(i = k = 0; i < ui32NumMemInfos && k < ARRAY_SIZE(apsTilerPAs); i++, k++)
+       for(i = k = 0; i < ui32NumMemInfos && k < ARRAY_SIZE(asMemInfo); i++, k++)
        {
                struct tiler_pa_info *psTilerInfo;
                IMG_CPU_VIRTADDR virtAddr;
@@ -1051,27 +1084,28 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
                psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetByteSize(ppsMemInfos[i], &uByteSize);
                ui32NumPages = (uByteSize + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-               apsTilerPAs[k] = NULL;
-
                psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], 0, &phyAddr);
 
-               /* NV12 buffers are already mapped to tiler */
-               if(psDssData->ovls[k].cfg.color_mode == OMAP_DSS_COLOR_NV12)
-               {
-                       psDssData->ovls[k].ba = (u32)phyAddr.uiAddr;
-
-                       psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], (uByteSize * 2) / 3, &phyAddr);
-                       psDssData->ovls[k].uv = (u32)phyAddr.uiAddr;
-                       continue;
-               }
-
-               /* Other kinds of buffer may also already be mapped to tiler */
+               /* TILER buffers do not need meminfos */
                if(is_tiler_addr((u32)phyAddr.uiAddr))
                {
-                       psDssData->ovls[k].ba = (u32)phyAddr.uiAddr;
+#ifdef CONFIG_DRM_OMAP_DMM_TILER
+                       enum tiler_fmt fmt;
+#endif
+                       asMemInfo[k].uiAddr = phyAddr.uiAddr;
+#ifdef CONFIG_DRM_OMAP_DMM_TILER
+                       if(tiler_get_fmt((u32)phyAddr.uiAddr, &fmt) && fmt == TILFMT_8BIT)
+#else
+                       if(tiler_fmt((u32)phyAddr.uiAddr) == TILFMT_8BIT)
+#endif
+                       {
+                               psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], (uByteSize * 2) / 3, &phyAddr);
+                               asMemInfo[k].uiUVAddr = phyAddr.uiAddr;
+                       }
                        continue;
                }
 
+               /* normal gralloc layer */
                psTilerInfo = kzalloc(sizeof(*psTilerInfo), GFP_KERNEL);
                if(!psTilerInfo)
                {
@@ -1087,37 +1121,58 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
 
                psTilerInfo->num_pg = ui32NumPages;
                psTilerInfo->memtype = TILER_MEM_USING;
-
                for(j = 0; j < ui32NumPages; j++)
                {
                        psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], j << PAGE_SHIFT, &phyAddr);
                        psTilerInfo->mem[j] = (u32)phyAddr.uiAddr;
                }
 
-               /* Need base address for in-page offset */
+               /* need base address for in-page offset */
                psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuVAddr(ppsMemInfos[i], &virtAddr);
-               psDssData->ovls[k].ba = (u32)virtAddr;
-               apsTilerPAs[k] = psTilerInfo;
+               asMemInfo[k].uiAddr = (IMG_UINTPTR_T) virtAddr;
+               asMemInfo[k].psTilerInfo = psTilerInfo;
        }
 
-       /* Set up cloned layer addresses (but don't duplicate tiler_pas) */
-       for(i = k; i < psDssData->num_ovls && i < ARRAY_SIZE(apsTilerPAs); i++)
+       for(i = 0; i < psDssData->num_ovls; i++)
        {
-               unsigned int ix = psDssData->ovls[i].ba;
-               if(ix >= ARRAY_SIZE(apsTilerPAs))
+               unsigned int ix;
+               apsTilerPAs[i] = NULL;
+
+               /* only supporting Post2, cloned and fbmem layers */
+               if (psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_LAYER_IX &&
+                   psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_OVL_IX &&
+                   psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_FB)
                {
-                       WARN(1, "Invalid clone layer (%u); skipping all cloned layers", ix);
-                       psDssData->num_ovls = k;
-                       break;
+                       psDssData->ovls[i].cfg.enabled = false;
+               }
+
+               if (psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_LAYER_IX)
+               {
+                       continue;
                }
-               apsTilerPAs[i] = apsTilerPAs[ix];
-               psDssData->ovls[i].ba = psDssData->ovls[ix].ba;
-               psDssData->ovls[i].uv = psDssData->ovls[ix].uv;
+
+               /* Post2 layers */
+               ix = psDssData->ovls[i].ba;
+               if (ix >= k)
+               {
+                       WARN(1, "Invalid Post2 layer (%u)", ix);
+                       psDssData->ovls[i].cfg.enabled = false;
+                       continue;
+               }
+
+               psDssData->ovls[i].addressing = OMAP_DSS_BUFADDR_DIRECT;
+               psDssData->ovls[i].ba = (u32) asMemInfo[ix].uiAddr;
+               psDssData->ovls[i].uv = (u32) asMemInfo[ix].uiUVAddr;
+               apsTilerPAs[i] = asMemInfo[ix].psTilerInfo;
        }
 
-       dsscomp_gralloc_queue(psDssData, apsTilerPAs, false,
+       res = dsscomp_gralloc_queue(psDssData, apsTilerPAs, false,
                                                  (void *)psDevInfo->sPVRJTable.pfnPVRSRVCmdComplete,
                                                  (void *)hCmdCookie);
+       if (res != 0)
+       {
+               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: dsscomp_gralloc_queue failed (%d)\n", __FUNCTION__, psDevInfo->uiFBDevID, res));
+       }
 
        for(i = 0; i < k; i++)
        {
@@ -1196,8 +1251,6 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
        struct module *psLINFBOwner;
        OMAPLFB_FBINFO *psPVRFBInfo = &psDevInfo->sFBInfo;
        OMAPLFB_ERROR eError = OMAPLFB_ERROR_GENERIC;
-       unsigned long FBSize;
-       unsigned long ulLCM;
        unsigned uiFBDevID = psDevInfo->uiFBDevID;
 
        OMAPLFB_CONSOLE_LOCK();
@@ -1209,20 +1262,6 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                goto ErrorRelSem;
        }
 
-       FBSize = (psLINFBInfo->screen_size) != 0 ?
-                                       psLINFBInfo->screen_size :
-                                       psLINFBInfo->fix.smem_len;
-
-       /*
-        * Try and filter out invalid FB info structures (a problem
-        * seen on some OMAP3 systems).
-        */
-       if (FBSize == 0 || psLINFBInfo->fix.line_length == 0)
-       {
-               eError = OMAPLFB_ERROR_INVALID_DEVICE;
-               goto ErrorRelSem;
-       }
-
        psLINFBOwner = psLINFBInfo->fbops->owner;
        if (!try_module_get(psLINFBOwner))
        {
@@ -1248,43 +1287,62 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
 
        psDevInfo->psLINFBInfo = psLINFBInfo;
 
-       ulLCM = LCM(psLINFBInfo->fix.line_length, OMAPLFB_PAGE_SIZE);
+       psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
+       psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
+
+       if (psPVRFBInfo->ulWidth == 0 || psPVRFBInfo->ulHeight == 0)
+       {
+               eError = OMAPLFB_ERROR_INVALID_DEVICE;
+               goto ErrorFBRel;
+       }
+
+#if !defined(CONFIG_DSSCOMP)
+       psPVRFBInfo->ulFBSize = (psLINFBInfo->screen_size) != 0 ?
+                                       psLINFBInfo->screen_size :
+                                       psLINFBInfo->fix.smem_len;
+
+       /*
+        * Try and filter out invalid FB info structures (a problem
+        * seen on some OMAP3 systems).
+        */
+       if (psPVRFBInfo->ulFBSize == 0 || psLINFBInfo->fix.line_length == 0)
+       {
+               eError = OMAPLFB_ERROR_INVALID_DEVICE;
+               goto ErrorFBRel;
+       }
 
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer physical address: 0x%lx\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->fix.smem_start));
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer virtual address: 0x%lx\n",
-                       psDevInfo->uiFBDevID, (unsigned long)psLINFBInfo->screen_base));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
                        ": Device %u: Framebuffer size: %lu\n",
-                       psDevInfo->uiFBDevID, FBSize));
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulFBSize));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
                        ": Device %u: Framebuffer virtual width: %u\n",
                        psDevInfo->uiFBDevID, psLINFBInfo->var.xres_virtual));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
                        ": Device %u: Framebuffer virtual height: %u\n",
                        psDevInfo->uiFBDevID, psLINFBInfo->var.yres_virtual));
+#endif
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer width: %u\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->var.xres));
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer height: %u\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->var.yres));
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer stride: %u\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->fix.line_length));
+                       ": Device %u: Framebuffer width: %lu\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulWidth));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: LCM of stride and page size: %lu\n",
-                       psDevInfo->uiFBDevID, ulLCM));
-
-       /* Additional implementation specific information */
-       OMAPLFBPrintInfo(psDevInfo);
+                       ": Device %u: Framebuffer height: %lu\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulHeight));
 
 #if defined(CONFIG_DSSCOMP)
        {
-               /* for some reason we need at least 3 buffers in the swap chain */
-               int n = FBSize / RoundUpToMultiple(psLINFBInfo->fix.line_length * psLINFBInfo->var.yres, ulLCM);
+#if defined(SUPPORT_PVRSRV_GET_DC_SYSTEM_BUFFER)
+               /*
+                * Assume we need 3 swap buffers, and a separate system
+                * buffer.
+                */
+               int n = 4;
+#else
+               /*
+                * Assume we need just 3 swap buffers, and no separate
+                * system buffer.
+                */
+               int n = 3;
+#endif
                int res;
                int i, x, y, w;
                ion_phys_addr_t phys;
@@ -1295,8 +1353,8 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                {
                        /* TILER will align width to 128-bytes */
                        /* however, SGX must have full page width */
-                       .w = ALIGN(psLINFBInfo->var.xres, PAGE_SIZE / (psLINFBInfo->var.bits_per_pixel / 8)),
-                       .h = psLINFBInfo->var.yres,
+                       .w = ALIGN(psPVRFBInfo->ulWidth, PAGE_SIZE / (psLINFBInfo->var.bits_per_pixel / 8)),
+                       .h = psPVRFBInfo->ulHeight,
                        .fmt = psLINFBInfo->var.bits_per_pixel == 16 ? TILER_PIXEL_FMT_16BIT : TILER_PIXEL_FMT_32BIT,
                        .flags = 0,
                };
@@ -1305,43 +1363,43 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                           " %s: Device %u: Requesting %d TILER 2D framebuffers\n",
                           __FUNCTION__, uiFBDevID, n);
 
-               /* INTEGRATION_POINT: limit to MAX 3 FBs to save TILER container space */
-               if (n != 3)
-                       n = 3;
-
                sAllocData.w *= n;
 
                psPVRFBInfo->uiBytesPerPixel = psLINFBInfo->var.bits_per_pixel >> 3;
                psPVRFBInfo->bIs2D = OMAPLFB_TRUE;
 
-               res = omap_ion_tiler_alloc(gpsIONClient, &sAllocData);
+               res = omap_ion_tiler_alloc(psDevInfo->psIONClient, &sAllocData);
                psPVRFBInfo->psIONHandle = sAllocData.handle;
                if (res < 0)
                {
                        printk(KERN_ERR DRIVER_PREFIX
                                   " %s: Device %u: Could not allocate 2D framebuffer(%d)\n",
                                   __FUNCTION__, uiFBDevID, res);
-                       goto ErrorModPut;
+                       goto ErrorFBRel;
                }
 
-               psLINFBInfo->fix.smem_start = ion_phys(gpsIONClient, sAllocData.handle, &phys, &size);
+               res = ion_phys(psDevInfo->psIONClient, sAllocData.handle, &phys, &size);
+               if (res < 0)
+               {
+                       printk(KERN_ERR DRIVER_PREFIX
+                                  " %s: Device %u: Could not get 2D framebufferphysical address (%d)\n",
+                                  __FUNCTION__, uiFBDevID, res);
+                       goto ErrorFBRel;
+               }
 
                psPVRFBInfo->sSysAddr.uiAddr = phys;
                psPVRFBInfo->sCPUVAddr = 0;
-               psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
-               psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
 
                psPVRFBInfo->ulByteStride = PAGE_ALIGN(psPVRFBInfo->ulWidth * psPVRFBInfo->uiBytesPerPixel);
                w = psPVRFBInfo->ulByteStride >> PAGE_SHIFT;
  
-               /* this is an "effective" FB size to get correct number of buffers */
                psPVRFBInfo->ulFBSize = sAllocData.h * n * psPVRFBInfo->ulByteStride;
                psPVRFBInfo->psPageList = kzalloc(w * n * psPVRFBInfo->ulHeight * sizeof(*psPVRFBInfo->psPageList), GFP_KERNEL);
                if (!psPVRFBInfo->psPageList)
                {
                        printk(KERN_WARNING DRIVER_PREFIX ": %s: Device %u: Could not allocate page list\n", __FUNCTION__, psDevInfo->uiFBDevID);
-                       ion_free(gpsIONClient, sAllocData.handle);
-                       goto ErrorModPut;
+                       ion_free(psDevInfo->psIONClient, sAllocData.handle);
+                       goto ErrorFBRel;
                }
 
                tilview_create(&view, phys, psDevInfo->sFBInfo.ulWidth, psDevInfo->sFBInfo.ulHeight);
@@ -1362,21 +1420,48 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
        psPVRFBInfo->sSysAddr.uiAddr = psLINFBInfo->fix.smem_start;
        psPVRFBInfo->sCPUVAddr = psLINFBInfo->screen_base;
 
-       psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
-       psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
        psPVRFBInfo->ulByteStride =  psLINFBInfo->fix.line_length;
-       psPVRFBInfo->ulFBSize = FBSize;
 #endif /* defined(CONFIG_DSSCOMP) */
 
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: Framebuffer physical address: 0x%x\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->sSysAddr.uiAddr));
+
+       if (psPVRFBInfo->sCPUVAddr != NULL)
+       {
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: Framebuffer virtual address: %p\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->sCPUVAddr));
+       }
+
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: Framebuffer stride: %lu\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulByteStride));
+
+       /* Additional implementation specific information */
+       OMAPLFBPrintInfo(psDevInfo);
+
        psPVRFBInfo->ulBufferSize = psPVRFBInfo->ulHeight * psPVRFBInfo->ulByteStride;
 
-       /* Round the buffer size up to a multiple of the number of pages
-        * and the byte stride.
-        * This is used internally, to ensure buffers start on page
-        * boundaries, for the benefit of PVR Services.
-        */
-       psPVRFBInfo->ulRoundedBufferSize = RoundUpToMultiple(psPVRFBInfo->ulBufferSize, ulLCM);
+#if defined(CONFIG_DSSCOMP)
+       psPVRFBInfo->ulRoundedBufferSize = psPVRFBInfo->ulBufferSize;
+#else
+       {
+               unsigned long ulLCM;
+               ulLCM = LCM(psPVRFBInfo->ulByteStride, OMAPLFB_PAGE_SIZE);
+
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: LCM of stride and page size: %lu\n",
+                       psDevInfo->uiFBDevID, ulLCM));
 
+               /* Round the buffer size up to a multiple of the number of pages
+                * and the byte stride.
+                * This is used internally, to ensure buffers start on page
+                * boundaries, for the benefit of PVR Services.
+                */
+               psPVRFBInfo->ulRoundedBufferSize = RoundUpToMultiple(psPVRFBInfo->ulBufferSize, ulLCM);
+       }
+#endif
        if(psLINFBInfo->var.bits_per_pixel == 16)
        {
                if((psLINFBInfo->var.red.length == 5) &&
@@ -1429,6 +1514,11 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
        eError = OMAPLFB_OK;
        goto ErrorRelSem;
 
+ErrorFBRel:
+       if (psLINFBInfo->fbops->fb_release != NULL) 
+       {
+               (void) psLINFBInfo->fbops->fb_release(psLINFBInfo, 0);
+       }
 ErrorModPut:
        module_put(psLINFBOwner);
 ErrorRelSem:
@@ -1450,7 +1540,7 @@ static void OMAPLFBDeInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                kfree(psPVRFBInfo->psPageList);
                if (psPVRFBInfo->psIONHandle)
                {
-                       ion_free(gpsIONClient, psPVRFBInfo->psIONHandle);
+                       ion_free(psDevInfo->psIONClient, psPVRFBInfo->psIONHandle);
                }
        }
 #endif /* defined(CONFIG_DSSCOMP) */
@@ -1495,6 +1585,22 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
                goto ErrorFreeDevInfo;
        }
 
+#if defined(CONFIG_ION_OMAP)
+       psDevInfo->psIONClient =
+               ion_client_create(omap_ion_device,
+                                                 1 << ION_HEAP_TYPE_CARVEOUT |
+                                                 1 << OMAP_ION_HEAP_TYPE_TILER,
+                                                 "dc_omapfb3_linux");
+       if (IS_ERR_OR_NULL(psDevInfo->psIONClient))
+       {
+               printk(KERN_ERR DRIVER_PREFIX
+                       ": %s: Device %u: Failed to create ion client\n", __FUNCTION__, uiFBDevID);
+
+               goto ErrorFreeDevInfo;
+       }
+#endif /* defined(CONFIG_ION_OMAP) */
+
+#ifdef FBDEV_PRESENT
        /* Save private fbdev information structure in the dev. info. */
        if(OMAPLFBInitFBDev(psDevInfo) != OMAPLFB_OK)
        {
@@ -1504,7 +1610,7 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
                 * there is no Linux framebuffer device corresponding
                 * to the device ID.
                 */
-               goto ErrorFreeDevInfo;
+               goto ErrorIonClientDestroy;
        }
 
        psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers = (IMG_UINT32)(psDevInfo->sFBInfo.ulFBSize / psDevInfo->sFBInfo.ulRoundedBufferSize);
@@ -1512,6 +1618,9 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
        {
                psDevInfo->sDisplayInfo.ui32MaxSwapChains = 1;
                psDevInfo->sDisplayInfo.ui32MaxSwapInterval = 1;
+#if defined(CONFIG_DSSCOMP)
+               psDevInfo->sDisplayInfo.ui32MinSwapInterval = 1;
+#endif
        }
 
        psDevInfo->sDisplayInfo.ui32PhysicalWidthmm = psDevInfo->sFBInfo.ulPhysicalWidthmm;
@@ -1534,6 +1643,21 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
        psDevInfo->sSystemBuffer.psDevInfo = psDevInfo;
 
        OMAPLFBInitBufferForSwap(&psDevInfo->sSystemBuffer);
+#else
+psDevInfo->sSystemBuffer.sCPUVAddr = 0x100;
+//                psDevInfo->sSystemBuffer.ulBufferSize = 600*3200;
+
+                psDevInfo->sDisplayFormat.pixelformat = 20;
+                psDevInfo->sFBInfo.ulWidth      =  800;
+                psDevInfo->sFBInfo.ulHeight     =  600;
+                psDevInfo->sFBInfo.ulByteStride =  3200;
+                psDevInfo->sFBInfo.ulFBSize     =  8388608;
+                psDevInfo->sFBInfo.ulBufferSize = 600*3200;
+#endif
+
+#if defined(CONFIG_DSSCOMP) && defined(SUPPORT_PVRSRV_GET_DC_SYSTEM_BUFFER)
+       OMAPLFBFlip(psDevInfo, &psDevInfo->sSystemBuffer);
+#endif
 
        /*
                Setup the DC Jtable so SRVKM can call into this driver
@@ -1603,12 +1727,17 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
 #if defined(SUPPORT_DRI_DRM)
        OMAPLFBAtomicBoolInit(&psDevInfo->sLeaveVT, OMAPLFB_FALSE);
 #endif
+
        return psDevInfo;
 
 ErrorUnregisterDevice:
        (void)psDevInfo->sPVRJTable.pfnPVRSRVRemoveDCDevice(psDevInfo->uiPVRDevID);
 ErrorDeInitFBDev:
        OMAPLFBDeInitFBDev(psDevInfo);
+ErrorIonClientDestroy:
+#if defined(CONFIG_ION_OMAP)
+       ion_client_destroy(psDevInfo->psIONClient);
+#endif /* defined(CONFIG_ION_OMAP) */
 ErrorFreeDevInfo:
        OMAPLFBFreeKernelMem(psDevInfo);
 ErrorExit:
@@ -1654,19 +1783,6 @@ static OMAPLFB_BOOL OMAPLFBDeInitDev(OMAPLFB_DEVINFO *psDevInfo)
 {
        PVRSRV_DC_DISP2SRV_KMJTABLE *psPVRJTable = &psDevInfo->sPVRJTable;
 
-       OMAPLFBCreateSwapChainLockDeInit(psDevInfo);
-
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sBlanked);
-       OMAPLFBAtomicIntDeInit(&psDevInfo->sBlankEvents);
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sFlushCommands);
-#if defined(CONFIG_HAS_EARLYSUSPEND)
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sEarlySuspendFlag);
-#endif
-#if defined(SUPPORT_DRI_DRM)
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sLeaveVT);
-#endif
-       psPVRJTable = &psDevInfo->sPVRJTable;
-
        if (psPVRJTable->pfnPVRSRVRemoveCmdProcList (psDevInfo->uiPVRDevID, OMAPLFB_COMMAND_COUNT) != PVRSRV_OK)
        {
                printk(KERN_ERR DRIVER_PREFIX
@@ -1684,8 +1800,31 @@ static OMAPLFB_BOOL OMAPLFBDeInitDev(OMAPLFB_DEVINFO *psDevInfo)
                        ": %s: Device %u: PVR Device %u: Couldn't remove device from PVR Services\n", __FUNCTION__, psDevInfo->uiFBDevID, psDevInfo->uiPVRDevID);
                return OMAPLFB_FALSE;
        }
-       
+
+#if defined(CONFIG_DSSCOMP)
+       /* Disable the overlay, as we will be freeing the display buffers */
+       psDevInfo->sSystemBuffer.sSysAddr.uiAddr = 0;
+       OMAPLFBFlip(psDevInfo, &psDevInfo->sSystemBuffer);
+#endif /* defined(CONFIG_DSSCOMP) */
+
+       OMAPLFBCreateSwapChainLockDeInit(psDevInfo);
+
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sBlanked);
+       OMAPLFBAtomicIntDeInit(&psDevInfo->sBlankEvents);
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sFlushCommands);
+#if defined(CONFIG_HAS_EARLYSUSPEND)
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sEarlySuspendFlag);
+#endif
+#if defined(SUPPORT_DRI_DRM)
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sLeaveVT);
+#endif
+
+#ifdef FBDEV_PRESENT
        OMAPLFBDeInitFBDev(psDevInfo);
+#endif
+#if defined(CONFIG_ION_OMAP)
+       ion_client_destroy(psDevInfo->psIONClient);
+#endif
 
        OMAPLFBSetDevInfoPtr(psDevInfo->uiFBDevID, NULL);
 
index 08d8277..54b5d50 100644 (file)
@@ -37,7 +37,6 @@ 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.
-  
 */ /**************************************************************************/
 
 /**************************************************************************
@@ -94,7 +93,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <linux/mutex.h>
 
 #if defined(PVR_OMAPLFB_DRM_FB)
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
 #include <plat/display.h>
+#else
+#include <video/omapdss.h>
+#endif
 #include <linux/omap_gpu.h>
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
 /* OmapZoom.org OMAP3 2.6.29 kernel tree       - Needs mach/vrfb.h
@@ -108,7 +111,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #if defined(PVR_OMAPFB3_NEEDS_PLAT_VRFB_H)
+#ifdef FBDEV_PRESENT
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
 #include <plat/vrfb.h>
+#else
+#include <video/omapvrfb.h>
+#endif
+#endif
+
 #else
 #if defined(PVR_OMAPFB3_NEEDS_MACH_VRFB_H)
 #include <mach/vrfb.h>
@@ -119,7 +129,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define        PVR_DEBUG DEBUG
 #undef DEBUG
 #endif
+#ifdef FBDEV_PRESENT
 #include <omapfb/omapfb.h>
+#endif
 #if defined(DEBUG)
 #undef DEBUG
 #endif
@@ -130,7 +142,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif /* defined(PVR_OMAPLFB_DRM_FB) */
 
 #if defined(CONFIG_DSSCOMP)
+#if defined(CONFIG_DRM_OMAP_DMM_TILER)
+#include <../drivers/staging/omapdrm/omap_dmm_tiler.h>
+#include <../drivers/video/omap2/dsscomp/tiler-utils.h>
+#elif defined(CONFIG_TI_TILER)
 #include <mach/tiler.h>
+#else /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
+#error CONFIG_DSSCOMP support requires either \
+       CONFIG_DRM_OMAP_DMM_TILER or CONFIG_TI_TILER
+#endif /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
 #include <video/dsscomp.h>
 #include <plat/dsscomp.h>
 #endif /* defined(CONFIG_DSSCOMP) */
@@ -154,7 +174,12 @@ MODULE_SUPPORTED_DEVICE(DEVNAME);
 #if !defined(PVR_OMAPLFB_DRM_FB)
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
 #define OMAP_DSS_DRIVER(drv, dev) struct omap_dss_driver *drv = (dev) != NULL ? (dev)->driver : NULL
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
 #define OMAP_DSS_MANAGER(man, dev) struct omap_overlay_manager *man = (dev) != NULL ? (dev)->manager : NULL
+#else
+#define OMAP_DSS_MANAGER(man, dev) struct omap_overlay_manager *man = (dev) != NULL ? (dev)->output->manager : NULL
+#endif
+
 #define        WAIT_FOR_VSYNC(man)     ((man)->wait_for_vsync)
 #else
 #define OMAP_DSS_DRIVER(drv, dev) struct omap_dss_device *drv = (dev)
@@ -272,6 +297,9 @@ static void WorkQueueHandler(struct work_struct *psWork)
 OMAPLFB_ERROR OMAPLFBCreateSwapQueue(OMAPLFB_SWAPCHAIN *psSwapChain)
 {
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
+#if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,37))
+#define WQ_FREEZABLE WQ_FREEZEABLE
+#endif
        /*
         * Calling alloc_ordered_workqueue with the WQ_FREEZABLE and
         * WQ_MEM_RECLAIM flags set, (currently) has the same effect as
@@ -281,12 +309,7 @@ OMAPLFB_ERROR OMAPLFBCreateSwapQueue(OMAPLFB_SWAPCHAIN *psSwapChain)
         * conditions, preventing the driver from holding on to
         * resources longer than it needs to.
         */
-#if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,37))
-        psSwapChain->psWorkQueue = alloc_ordered_workqueue(DEVNAME, WQ_FREEZEABLE | WQ_MEM_RECLAIM);
-#else
-        psSwapChain->psWorkQueue = alloc_ordered_workqueue(DEVNAME, WQ_FREEZABLE | WQ_MEM_RECLAIM);
-#endif
-
+       psSwapChain->psWorkQueue = alloc_ordered_workqueue(DEVNAME, WQ_FREEZABLE | WQ_MEM_RECLAIM);
 #else
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
        psSwapChain->psWorkQueue = create_freezable_workqueue(DEVNAME);
@@ -328,7 +351,6 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
 {
        struct fb_var_screeninfo sFBVar;
        int res;
-       unsigned long ulYResVirtual;
 
        OMAPLFB_CONSOLE_LOCK();
 
@@ -337,9 +359,26 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
        sFBVar.xoffset = 0;
        sFBVar.yoffset = psBuffer->ulYOffset;
 
-       ulYResVirtual = psBuffer->ulYOffset + sFBVar.yres;
-
 #if defined(CONFIG_DSSCOMP)
+       /*
+        * If flipping to a NULL buffer, blank the screen to prevent
+        * warnings/errors from the display subsystem.
+        */
+       if (psBuffer->sSysAddr.uiAddr == 0)
+       {
+               struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
+               OMAP_DSS_MANAGER(psDSSMan, psDSSDev);
+
+               if (psDSSMan != NULL && psDSSMan->blank != NULL)
+               {
+                       res = psDSSMan->blank(psDSSMan, false);
+                       if (res != 0)
+                       {
+                               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: DSS manager blank call failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res));
+                       }
+               }
+       }
+
        {
                /*
                 * If using DSSCOMP, we need to use dsscomp queuing for normal
@@ -367,7 +406,7 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
                                        .width = sFBVar.xres_virtual,
                                        .height = sFBVar.yres_virtual,
                                        .stride = sFBFix.line_length,
-                                       .enabled = 1,
+                                       .enabled = (psBuffer->sSysAddr.uiAddr != 0),
                                        .global_alpha = 255,
                                },
                        },
@@ -376,51 +415,70 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
                /* do not map buffer into TILER1D as it is contiguous */
                struct tiler_pa_info *pas[] = { NULL };
 
-               d.ovls[0].ba = sFBFix.smem_start;
+               d.ovls[0].ba = (u32) psBuffer->sSysAddr.uiAddr;
+
                omapfb_mode_to_dss_mode(&sFBVar, &d.ovls[0].cfg.color_mode);
 
                res = dsscomp_gralloc_queue(&d, pas, true, NULL, NULL);
+               if (res != 0)
+               {
+                       DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: dsscomp_gralloc_queue failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res));
+               }
        }
 #else /* defined(CONFIG_DSSCOMP) */
-       /*
-        * PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY should be defined to work
-        * around flipping problems seen with the Taal LCDs on Blaze.
-        * The work around is safe to use with other types of screen on Blaze
-        * (e.g. HDMI) and on other platforms (e.g. Panda board).
-        */
+       {
+               unsigned long ulYResVirtual = psBuffer->ulYOffset + sFBVar.yres;
+
+               /*
+                * PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY should be defined to 
+                * work around flipping problems seen with the Taal LCDs on
+                * Blaze.
+                * The work around is safe to use with other types of screen
+                * on Blaze (e.g. HDMI) and on other platforms (e.g. Panda
+                * board).
+                */
 #if !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY)
-       /*
-        * Attempt to change the virtual screen resolution if it is too
-        * small.  Note that fb_set_var also pans the display.
-        */
-       if (sFBVar.xres_virtual != sFBVar.xres || sFBVar.yres_virtual < ulYResVirtual)
+               /*
+                * Attempt to change the virtual screen resolution if it is too
+                * small.  Note that fb_set_var also pans the display.
+                */
+               if (sFBVar.xres_virtual != sFBVar.xres || sFBVar.yres_virtual < ulYResVirtual)
 #endif /* !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY) */
-       {
-               sFBVar.xres_virtual = sFBVar.xres;
-               sFBVar.yres_virtual = ulYResVirtual;
+               {
+                       sFBVar.xres_virtual = sFBVar.xres;
+                       sFBVar.yres_virtual = ulYResVirtual;
 
-               sFBVar.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
+                       sFBVar.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
 
-               res = fb_set_var(psDevInfo->psLINFBInfo, &sFBVar);
-               if (res != 0)
-               {
-                       printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_set_var failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       res = fb_set_var(psDevInfo->psLINFBInfo, &sFBVar);
+                       if (res != 0)
+                       {
+                               printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_set_var failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       }
                }
-       }
 #if !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY)
-       else
-       {
-               res = fb_pan_display(psDevInfo->psLINFBInfo, &sFBVar);
-               if (res != 0)
+               else
                {
-                       printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_pan_display failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       res = fb_pan_display(psDevInfo->psLINFBInfo, &sFBVar);
+                       if (res != 0)
+                       {
+                               printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_pan_display failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       }
                }
-       }
 #endif /* !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY) */
+       }
 #endif /* defined(CONFIG_DSSCOMP) */
 
        OMAPLFB_CONSOLE_UNLOCK();
 }
+
+/* Newer kernels don't have any update mode capability */
+
+//#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
+//#define      PVR_OMAPLFB_HAS_UPDATE_MODE
+//#endif
+
+//#if defined(PVR_OMAPLFB_HAS_UPDATE_MODE)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 #if !defined(PVR_OMAPLFB_DRM_FB) || defined(DEBUG)
 static OMAPLFB_BOOL OMAPLFBValidateDSSUpdateMode(enum omap_dss_update_mode eMode)
@@ -487,7 +545,6 @@ static enum omap_dss_update_mode OMAPLFBToDSSUpdateMode(OMAPLFB_UPDATE_MODE eMod
 
        return -1;
 }
-
 #endif
 #if defined(DEBUG)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
@@ -520,45 +577,7 @@ static const char *OMAPLFBDSSUpdateModeToString(enum omap_dss_update_mode eMode)
        return OMAPLFBUpdateModeToString(OMAPLFBFromDSSUpdateMode(eMode));
 }
 #endif
-void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
-{
-#if defined(PVR_OMAPLFB_DRM_FB)
-       struct drm_connector *psConnector;
-       unsigned uConnectors;
-       unsigned uConnector;
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: DRM framebuffer\n", psDevInfo->uiFBDevID));
-
-       for (psConnector = NULL, uConnectors = 0;
-               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL;)
-       {
-               uConnectors++;
-       }
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Number of screens (DRM connectors): %u\n", psDevInfo->uiFBDevID, uConnectors));
-
-       if (uConnectors == 0)
-       {
-               return;
-       }
-
-       for (psConnector = NULL, uConnector = 0;
-               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL; uConnector++)
-       {
-               enum omap_dss_update_mode eMode = omap_connector_get_update_mode(psConnector);
-
-               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Screen %u: %s (%d)\n", psDevInfo->uiFBDevID, uConnector, OMAPLFBDSSUpdateModeToString(eMode), (int)eMode));
-
-       }
-#else  /* defined(PVR_OMAPLFB_DRM_FB) */
-       OMAPLFB_UPDATE_MODE eMode = OMAPLFBGetUpdateMode(psDevInfo);
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: non-DRM framebuffer\n", psDevInfo->uiFBDevID));
-
-//     DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: %s\n", psDevInfo->uiFBDevID, OMAPLFBUpdateModeToString(eMode)));
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
-}
-#endif /* defined(DEBUG) */
+#endif /* defined(DEBUG) */
 
 /* 
  * Get display update mode.
@@ -566,7 +585,6 @@ void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
  */
 OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
 {
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
        OMAPLFB_UPDATE_MODE eMode = OMAPLFB_UPDATE_MODE_UNDEFINED;
@@ -604,6 +622,7 @@ OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
 
        return eMode;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_DRIVER(psDSSDrv, psDSSDev);
 
@@ -633,16 +652,15 @@ OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
        }
 
        return OMAPLFBFromDSSUpdateMode(eMode);
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #else
-       return OMAPLFB_UPDATE_MODE_AUTO;
+        return OMAPLFB_UPDATE_MODE_AUTO;
 #endif
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
 
 /* Set display update mode */
 OMAPLFB_BOOL OMAPLFBSetUpdateMode(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_UPDATE_MODE eMode)
 {
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
        enum omap_dss_update_mode eDSSMode;
@@ -693,6 +711,7 @@ OMAPLFB_BOOL OMAPLFBSetUpdateMode(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_UPDATE_MOD
 
        return OMAPLFB_TRUE;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_DRIVER(psDSSDrv, psDSSDev);
        enum omap_dss_update_mode eDSSMode;
@@ -718,11 +737,63 @@ OMAPLFB_BOOL OMAPLFBSetUpdateMode(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_UPDATE_MOD
        }
 
        return (res == 0);
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #else
 return 1;
 #endif
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
+
+}
+//#else /* defined(PVR_OMAPLFB_HAS_UPDATE_MODE) */
+
+//OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
+//{
+//     return OMAPLFB_UPDATE_MODE_UNDEFINED;
+//}
+
+//#endif /* defined(PVR_OMAPLFB_HAS_UPDATE_MODE) */
+
+#if defined(DEBUG)
+void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
+{
+#if defined(PVR_OMAPLFB_DRM_FB)
+       struct drm_connector *psConnector;
+       unsigned uConnectors;
+       unsigned uConnector;
+
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: DRM framebuffer\n", psDevInfo->uiFBDevID));
+
+       for (psConnector = NULL, uConnectors = 0;
+               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL;)
+       {
+               uConnectors++;
+       }
+
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Number of screens (DRM connectors): %u\n", psDevInfo->uiFBDevID, uConnectors));
+
+       if (uConnectors == 0)
+       {
+               return;
+       }
+
+       for (psConnector = NULL, uConnector = 0;
+               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL; uConnector++)
+       {
+               enum omap_dss_update_mode eMode = omap_connector_get_update_mode(psConnector);
+
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Screen %u: %s (%d)\n", psDevInfo->uiFBDevID, uConnector, OMAPLFBDSSUpdateModeToString(eMode), (int)eMode));
+
+       }
+#else  /* defined(PVR_OMAPLFB_DRM_FB) */
+//#if defined(PVR_OMAPLFB_HAS_UPDATE_MODE)
+       OMAPLFB_UPDATE_MODE eMode = OMAPLFBGetUpdateMode(psDevInfo);
+
+       //DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: %s\n", psDevInfo->uiFBDevID, OMAPLFBUpdateModeToString(eMode)));
+//#endif
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: non-DRM framebuffer\n", psDevInfo->uiFBDevID));
+
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
+#endif /* defined(DEBUG) */
 
 /* Wait for VSync */
 OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
@@ -738,6 +809,7 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
 
        return OMAPLFB_TRUE;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+#if FBDEV_PRESENT
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_MANAGER(psDSSMan, psDSSDev);
 
@@ -750,7 +822,7 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
                        return OMAPLFB_FALSE;
                }
        }
-
+#endif
        return OMAPLFB_TRUE;
 #endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
@@ -761,7 +833,6 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
  */
 OMAPLFB_BOOL OMAPLFBManualSync(OMAPLFB_DEVINFO *psDevInfo)
 {
-#if 0
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
 
@@ -777,6 +848,8 @@ OMAPLFB_BOOL OMAPLFBManualSync(OMAPLFB_DEVINFO *psDevInfo)
 
        return OMAPLFB_TRUE;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+
+#if 0
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_DRIVER(psDSSDrv, psDSSDev);
 
@@ -789,11 +862,9 @@ OMAPLFB_BOOL OMAPLFBManualSync(OMAPLFB_DEVINFO *psDevInfo)
                        return OMAPLFB_FALSE;
                }
        }
-
-       return OMAPLFB_TRUE;
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #endif
        return OMAPLFB_TRUE;
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
 
 /*
@@ -865,6 +936,7 @@ static int OMAPLFBFrameBufferEvents(struct notifier_block *psNotif,
 /* Unblank the screen */
 OMAPLFB_ERROR OMAPLFBUnblankDisplay(OMAPLFB_DEVINFO *psDevInfo)
 {
+#ifdef FBDEV_PRESENT
        int res;
 
        OMAPLFB_CONSOLE_LOCK();
@@ -876,7 +948,7 @@ OMAPLFB_ERROR OMAPLFBUnblankDisplay(OMAPLFB_DEVINFO *psDevInfo)
                        ": %s: Device %u: fb_blank failed (%d)\n", __FUNCTION__, psDevInfo->uiFBDevID, res);
                return (OMAPLFB_ERROR_GENERIC);
        }
-
+#endif
        return (OMAPLFB_OK);
 }
 
index addbfc2..b522c41 100644 (file)
@@ -39,7 +39,6 @@ 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.
-  
 */ /**************************************************************************/
 #ifndef __3RDPARTY_DC_DRM_SHARED_H__
 #define __3RDPARTY_DC_DRM_SHARED_H__
index eca9351..d442f79 100644 (file)
 # 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.
-#   
 ### ###########################################################################
 
 ccflags-y += \
        -I$(TOP)/services4/3rdparty/dc_omapfb3_linux \
-       -I$(KERNELDIR)/drivers/video/omap2 \
-       -I$(KERNELDIR)/arch/arm/plat-omap/include
+       -Idrivers/video/omap2 \
+       -Iarch/arm/plat-omap/include
 
 omaplfb-y += \
        services4/3rdparty/dc_omapfb3_linux/omaplfb_displayclass.o \
index 7574073..75d11a9 100644 (file)
@@ -36,7 +36,6 @@
 # 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.
-#   
 ### ###########################################################################
 
 modules := dc_omapfb3_linux
index c69640d..0e5b8fb 100644 (file)
@@ -37,7 +37,6 @@ 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.
-  
 */ /**************************************************************************/
 #ifndef __OMAPLFB_H__
 #define __OMAPLFB_H__
@@ -66,6 +65,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define        OMAPLFB_CONSOLE_UNLOCK()        release_console_sem()
 #endif
 
+#if defined(CONFIG_ION_OMAP)
+#include <linux/ion.h>
+#include <linux/omap_ion.h>
+#endif /* defined(CONFIG_ION_OMAP) */
+
 #define unref__ __attribute__ ((unused))
 
 typedef void *       OMAPLFB_HANDLE;
@@ -227,6 +231,10 @@ typedef struct OMAPLFB_DEVINFO_TAG
        OMAPLFB_ATOMIC_BOOL     sLeaveVT;
 #endif
 
+#if defined(CONFIG_ION_OMAP)
+       struct ion_client      *psIONClient;
+#endif
+
 }  OMAPLFB_DEVINFO;
 
 #define        OMAPLFB_PAGE_SIZE 4096
index de04272..313ca96 100644 (file)
@@ -37,7 +37,6 @@ 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.
-  
 */ /**************************************************************************/
 
 /**************************************************************************
@@ -88,20 +87,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "omaplfb.h"
 
 #if defined(CONFIG_DSSCOMP)
-
-#if !defined(CONFIG_ION_OMAP)
+#if defined(CONFIG_ION_OMAP)
+extern struct ion_device *omap_ion_device;
+#else /* defined(CONFIG_ION_OMAP) */
 #error CONFIG_DSSCOMP support requires CONFIG_ION_OMAP
-#endif
-
-#include <linux/ion.h>
-#include <linux/omap_ion.h>
-
-extern struct ion_client *gpsIONClient;
-
+#endif /* defined(CONFIG_ION_OMAP) */
+#if defined(CONFIG_DRM_OMAP_DMM_TILER)
+#include <../drivers/staging/omapdrm/omap_dmm_tiler.h>
+#include <../drivers/video/omap2/dsscomp/tiler-utils.h>
+#elif defined(CONFIG_TI_TILER)
 #include <mach/tiler.h>
+#else /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
+#error CONFIG_DSSCOMP support requires either \
+       CONFIG_DRM_OMAP_DMM_TILER or CONFIG_TI_TILER
+#endif /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
 #include <video/dsscomp.h>
 #include <plat/dsscomp.h>
-
 #endif /* defined(CONFIG_DSSCOMP) */
 
 #define OMAPLFB_COMMAND_COUNT          1
@@ -119,6 +120,7 @@ static OMAPLFB_DEVINFO *gapsDevInfo[OMAPLFB_MAX_NUM_DEVICES];
 /* Top level 'hook ptr' */
 static PFN_DC_GET_PVRJTABLE gpfnGetPVRJTable = NULL;
 
+#if !defined(CONFIG_DSSCOMP)
 /* Round x up to a multiple of y */
 static inline unsigned long RoundUpToMultiple(unsigned long x, unsigned long y)
 {
@@ -148,6 +150,7 @@ static unsigned long LCM(unsigned long x, unsigned long y)
 
        return (gcd == 0) ? 0 : ((x / gcd) * y);
 }
+#endif
 
 unsigned OMAPLFBMaxFBDevIDPlusOne(void)
 {
@@ -479,15 +482,14 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                                       IMG_HANDLE *phSwapChain,
                                       IMG_UINT32 *pui32SwapChainID)
 {
-       OMAPLFB_DEVINFO *psDevInfo;
        OMAPLFB_SWAPCHAIN *psSwapChain;
-       OMAPLFB_BUFFER *psBuffer;
-       IMG_UINT32 i;
+       OMAPLFB_DEVINFO *psDevInfo;
        PVRSRV_ERROR eError;
-       IMG_UINT32 ui32BuffersToSkip;
+       IMG_UINT32 i;
 
        UNREFERENCED_PARAMETER(ui32OEMFlags);
-       
+       UNREFERENCED_PARAMETER(ui32Flags);
+
        /* Check parameters */
        if(!hDevice
        || !psDstSurfAttrib
@@ -514,60 +516,7 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                eError = PVRSRV_ERROR_FLIP_CHAIN_EXISTS;
                goto ExitUnLock;
        }
-       
-       /* Check the buffer count */
-       if(ui32BufferCount > psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers)
-       {
-               eError = PVRSRV_ERROR_TOOMANYBUFFERS;
-               goto ExitUnLock;
-       }
-       
-       if ((psDevInfo->sFBInfo.ulRoundedBufferSize * (unsigned long)ui32BufferCount) > psDevInfo->sFBInfo.ulFBSize)
-       {
-               eError = PVRSRV_ERROR_TOOMANYBUFFERS;
-               goto ExitUnLock;
-       }
-
-       /*
-        * We will allocate the swap chain buffers at the back of the frame
-        * buffer area.  This preserves the front portion, which may be being
-        * used by other Linux Framebuffer based applications.
-        */
-       ui32BuffersToSkip = psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers - ui32BufferCount;
-
-       /* 
-        *      Verify the DST/SRC attributes,
-        *      SRC/DST must match the current display mode config
-       */
-       if(psDstSurfAttrib->pixelformat != psDevInfo->sDisplayFormat.pixelformat
-       || psDstSurfAttrib->sDims.ui32ByteStride != psDevInfo->sDisplayDim.ui32ByteStride
-       || psDstSurfAttrib->sDims.ui32Width != psDevInfo->sDisplayDim.ui32Width
-       || psDstSurfAttrib->sDims.ui32Height != psDevInfo->sDisplayDim.ui32Height)
-       {
-               /* DST doesn't match the current mode */
-               eError = PVRSRV_ERROR_INVALID_PARAMS;
-               goto ExitUnLock;
-       }               
-
-       if(psDstSurfAttrib->pixelformat != psSrcSurfAttrib->pixelformat
-       || psDstSurfAttrib->sDims.ui32ByteStride != psSrcSurfAttrib->sDims.ui32ByteStride
-       || psDstSurfAttrib->sDims.ui32Width != psSrcSurfAttrib->sDims.ui32Width
-       || psDstSurfAttrib->sDims.ui32Height != psSrcSurfAttrib->sDims.ui32Height)
-       {
-               /* DST doesn't match the SRC */
-               eError = PVRSRV_ERROR_INVALID_PARAMS;
-               goto ExitUnLock;
-       }               
 
-       /* check flags if implementation requires them */
-       UNREFERENCED_PARAMETER(ui32Flags);
-       
-#if defined(PVR_OMAPFB3_UPDATE_MODE)
-       if (!OMAPLFBSetUpdateMode(psDevInfo, PVR_OMAPFB3_UPDATE_MODE))
-       {
-               printk(KERN_WARNING DRIVER_PREFIX ": %s: Device %u: Couldn't set frame buffer update mode %d\n", __FUNCTION__, psDevInfo->uiFBDevID, PVR_OMAPFB3_UPDATE_MODE);
-       }
-#endif
        /* create a swapchain structure */
        psSwapChain = (OMAPLFB_SWAPCHAIN*)OMAPLFBAllocKernelMem(sizeof(OMAPLFB_SWAPCHAIN));
        if(!psSwapChain)
@@ -576,56 +525,121 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
                goto ExitUnLock;
        }
 
-       psBuffer = (OMAPLFB_BUFFER*)OMAPLFBAllocKernelMem(sizeof(OMAPLFB_BUFFER) * ui32BufferCount);
-       if(!psBuffer)
+       /* If services asks for a 0-length swap chain, it's probably Android.
+        *
+        * This will use only non-display memory posting via PVRSRVSwapToDCBuffers2(),
+        * and we can skip some useless sanity checking.
+        */
+       if(ui32BufferCount > 0)
        {
-               eError = PVRSRV_ERROR_OUT_OF_MEMORY;
-               goto ErrorFreeSwapChain;
-       }
+               IMG_UINT32 ui32BuffersToSkip;
 
-       psSwapChain->ulBufferCount = (unsigned long)ui32BufferCount;
-       psSwapChain->psBuffer = psBuffer;
-       psSwapChain->bNotVSynced = OMAPLFB_TRUE;
-       psSwapChain->uiFBDevID = psDevInfo->uiFBDevID;
+               /* Check the buffer count */
+               if(ui32BufferCount > psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers)
+               {
+                       eError = PVRSRV_ERROR_TOOMANYBUFFERS;
+                       goto ErrorFreeSwapChain;
+               }
+       
+               if ((psDevInfo->sFBInfo.ulRoundedBufferSize * (unsigned long)ui32BufferCount) > psDevInfo->sFBInfo.ulFBSize)
+               {
+                       eError = PVRSRV_ERROR_TOOMANYBUFFERS;
+                       goto ErrorFreeSwapChain;
+               }
 
-       /* Link the buffers */
-       for(i=0; i<ui32BufferCount-1; i++)
-       {
-               psBuffer[i].psNext = &psBuffer[i+1];
-       }
-       /* and link last to first */
-       psBuffer[i].psNext = &psBuffer[0];
+               /*
+                * We will allocate the swap chain buffers at the back of the frame
+                * buffer area.  This preserves the front portion, which may be being
+                * used by other Linux Framebuffer based applications.
+                */
+               ui32BuffersToSkip = psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers - ui32BufferCount;
 
-       /* Configure the swapchain buffers */
-       for(i=0; i<ui32BufferCount; i++)
-       {
-               IMG_UINT32 ui32SwapBuffer = i + ui32BuffersToSkip;
-               IMG_UINT32 ui32BufferOffset = ui32SwapBuffer * (IMG_UINT32)psDevInfo->sFBInfo.ulRoundedBufferSize;
+               /* 
+                *      Verify the DST/SRC attributes,
+                *      SRC/DST must match the current display mode config
+                */
+               if(psDstSurfAttrib->pixelformat != psDevInfo->sDisplayFormat.pixelformat
+               || psDstSurfAttrib->sDims.ui32ByteStride != psDevInfo->sDisplayDim.ui32ByteStride
+               || psDstSurfAttrib->sDims.ui32Width != psDevInfo->sDisplayDim.ui32Width
+               || psDstSurfAttrib->sDims.ui32Height != psDevInfo->sDisplayDim.ui32Height)
+               {
+                       /* DST doesn't match the current mode */
+                       eError = PVRSRV_ERROR_INVALID_PARAMS;
+                       goto ErrorFreeSwapChain;
+               }
 
-#if defined(CONFIG_DSSCOMP)
-               if (psDevInfo->sFBInfo.bIs2D)
+               if(psDstSurfAttrib->pixelformat != psSrcSurfAttrib->pixelformat
+               || psDstSurfAttrib->sDims.ui32ByteStride != psSrcSurfAttrib->sDims.ui32ByteStride
+               || psDstSurfAttrib->sDims.ui32Width != psSrcSurfAttrib->sDims.ui32Width
+               || psDstSurfAttrib->sDims.ui32Height != psSrcSurfAttrib->sDims.ui32Height)
                {
-                       ui32BufferOffset = 0;
+                       /* DST doesn't match the SRC */
+                       eError = PVRSRV_ERROR_INVALID_PARAMS;
+                       goto ErrorFreeSwapChain;
                }
+
+               psSwapChain->psBuffer = (OMAPLFB_BUFFER*)OMAPLFBAllocKernelMem(sizeof(OMAPLFB_BUFFER) * ui32BufferCount);
+               if(!psSwapChain->psBuffer)
+               {
+                       eError = PVRSRV_ERROR_OUT_OF_MEMORY;
+                       goto ErrorFreeSwapChain;
+               }
+
+               /* Link the buffers */
+               for(i = 0; i < ui32BufferCount - 1; i++)
+               {
+                       psSwapChain->psBuffer[i].psNext = &psSwapChain->psBuffer[i + 1];
+               }
+
+               /* and link last to first */
+               psSwapChain->psBuffer[i].psNext = &psSwapChain->psBuffer[0];
+
+               /* Configure the swapchain buffers */
+               for(i = 0; i < ui32BufferCount; i++)
+               {
+                       IMG_UINT32 ui32SwapBuffer = i + ui32BuffersToSkip;
+                       IMG_UINT32 ui32BufferOffset = ui32SwapBuffer * (IMG_UINT32)psDevInfo->sFBInfo.ulRoundedBufferSize;
+
+#if defined(CONFIG_DSSCOMP)
+                       if (psDevInfo->sFBInfo.bIs2D)
+                       {
+                               ui32BufferOffset = 0;
+                       }
 #endif /* defined(CONFIG_DSSCOMP) */
 
-               psBuffer[i].psSyncData = ppsSyncData[i];
+                       psSwapChain->psBuffer[i].psSyncData = ppsSyncData[i];
 
-               psBuffer[i].sSysAddr.uiAddr = psDevInfo->sFBInfo.sSysAddr.uiAddr + ui32BufferOffset;
-               psBuffer[i].sCPUVAddr = psDevInfo->sFBInfo.sCPUVAddr + ui32BufferOffset;
-               psBuffer[i].ulYOffset = ui32BufferOffset / psDevInfo->sFBInfo.ulByteStride;
-               psBuffer[i].psDevInfo = psDevInfo;
+                       psSwapChain->psBuffer[i].sSysAddr.uiAddr = psDevInfo->sFBInfo.sSysAddr.uiAddr + ui32BufferOffset;
+                       psSwapChain->psBuffer[i].sCPUVAddr = psDevInfo->sFBInfo.sCPUVAddr + ui32BufferOffset;
+                       psSwapChain->psBuffer[i].ulYOffset = ui32BufferOffset / psDevInfo->sFBInfo.ulByteStride;
+                       psSwapChain->psBuffer[i].psDevInfo = psDevInfo;
 
 #if defined(CONFIG_DSSCOMP)
-               if (psDevInfo->sFBInfo.bIs2D)
-               {
-                       psBuffer[i].sSysAddr.uiAddr += ui32SwapBuffer *
-                               ALIGN((IMG_UINT32)psDevInfo->sFBInfo.ulWidth * psDevInfo->sFBInfo.uiBytesPerPixel, PAGE_SIZE);
-               }
+                       if (psDevInfo->sFBInfo.bIs2D)
+                       {
+                               psSwapChain->psBuffer[i].sSysAddr.uiAddr += ui32SwapBuffer *
+                                       ALIGN((IMG_UINT32)psDevInfo->sFBInfo.ulWidth * psDevInfo->sFBInfo.uiBytesPerPixel, PAGE_SIZE);
+                       }
 #endif /* defined(CONFIG_DSSCOMP) */
 
-               OMAPLFBInitBufferForSwap(&psBuffer[i]);
+                       OMAPLFBInitBufferForSwap(&psSwapChain->psBuffer[i]);
+               }
+       }
+       else
+       {
+               psSwapChain->psBuffer = NULL;
+       }
+
+#if defined(PVR_OMAPFB3_UPDATE_MODE)
+       if (!OMAPLFBSetUpdateMode(psDevInfo, PVR_OMAPFB3_UPDATE_MODE))
+       {
+               printk(KERN_WARNING DRIVER_PREFIX ": %s: Device %u: Couldn't set frame buffer update mode %d\n", __FUNCTION__, psDevInfo->uiFBDevID, PVR_OMAPFB3_UPDATE_MODE);
        }
+#endif /* defined(PVR_OMAPFB3_UPDATE_MODE) */
+
+       psSwapChain->ulBufferCount = (unsigned long)ui32BufferCount;
+       psSwapChain->bNotVSynced = OMAPLFB_TRUE;
+       psSwapChain->uiFBDevID = psDevInfo->uiFBDevID;
 
        if (OMAPLFBCreateSwapQueue(psSwapChain) != OMAPLFB_OK)
        { 
@@ -661,7 +675,10 @@ static PVRSRV_ERROR CreateDCSwapChain(IMG_HANDLE hDevice,
 ErrorDestroySwapQueue:
        OMAPLFBDestroySwapQueue(psSwapChain);
 ErrorFreeBuffers:
-       OMAPLFBFreeKernelMem(psBuffer);
+       if(psSwapChain->psBuffer)
+       {
+               OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
+       }
 ErrorFreeSwapChain:
        OMAPLFBFreeKernelMem(psSwapChain);
 ExitUnLock:
@@ -710,7 +727,10 @@ static PVRSRV_ERROR DestroyDCSwapChain(IMG_HANDLE hDevice,
        }
 
        /* Free resources */
-       OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
+       if (psSwapChain->psBuffer)
+       {
+               OMAPLFBFreeKernelMem(psSwapChain->psBuffer);
+       }
        OMAPLFBFreeKernelMem(psSwapChain);
 
        psDevInfo->psSwapChain = NULL;
@@ -974,6 +994,7 @@ static IMG_BOOL ProcessFlipV1(IMG_HANDLE hCmdCookie,
 #if defined(CONFIG_DSSCOMP)
                if (is_tiler_addr(psBuffer->sSysAddr.uiAddr))
                {
+                       int res;
                        IMG_UINT32 w = psBuffer->psDevInfo->sDisplayDim.ui32Width;
                        IMG_UINT32 h = psBuffer->psDevInfo->sDisplayDim.ui32Height;
                        struct dsscomp_setup_dispc_data comp = {
@@ -997,9 +1018,13 @@ static IMG_BOOL ProcessFlipV1(IMG_HANDLE hCmdCookie,
                        };
                        struct tiler_pa_info *pas[1] = { NULL };
                        comp.ovls[0].ba = (u32) psBuffer->sSysAddr.uiAddr;
-                       dsscomp_gralloc_queue(&comp, pas, true,
+                       res = dsscomp_gralloc_queue(&comp, pas, true,
                                                                  (void *) psDevInfo->sPVRJTable.pfnPVRSRVCmdComplete,
                                                                  (void *) psBuffer->hCmdComplete);
+                       if (res != 0)
+                       {
+                               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: dsscomp_gralloc_queue failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res));
+                       }
                }
                else
 #endif /* defined(CONFIG_DSSCOMP) */
@@ -1025,6 +1050,14 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
 {
        struct tiler_pa_info *apsTilerPAs[5];
        IMG_UINT32 i, k;
+       struct
+       {
+               IMG_UINTPTR_T uiAddr;
+               IMG_UINTPTR_T uiUVAddr;
+               struct tiler_pa_info *psTilerInfo;
+       }
+       asMemInfo[5] = {};
+       int res;
 
        if(ui32DssDataLength != sizeof(*psDssData))
        {
@@ -1039,7 +1072,7 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
                return IMG_FALSE;
        }
 
-       for(i = k = 0; i < ui32NumMemInfos && k < ARRAY_SIZE(apsTilerPAs); i++, k++)
+       for(i = k = 0; i < ui32NumMemInfos && k < ARRAY_SIZE(asMemInfo); i++, k++)
        {
                struct tiler_pa_info *psTilerInfo;
                IMG_CPU_VIRTADDR virtAddr;
@@ -1051,27 +1084,28 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
                psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetByteSize(ppsMemInfos[i], &uByteSize);
                ui32NumPages = (uByteSize + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-               apsTilerPAs[k] = NULL;
-
                psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], 0, &phyAddr);
 
-               /* NV12 buffers are already mapped to tiler */
-               if(psDssData->ovls[k].cfg.color_mode == OMAP_DSS_COLOR_NV12)
-               {
-                       psDssData->ovls[k].ba = (u32)phyAddr.uiAddr;
-
-                       psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], (uByteSize * 2) / 3, &phyAddr);
-                       psDssData->ovls[k].uv = (u32)phyAddr.uiAddr;
-                       continue;
-               }
-
-               /* Other kinds of buffer may also already be mapped to tiler */
+               /* TILER buffers do not need meminfos */
                if(is_tiler_addr((u32)phyAddr.uiAddr))
                {
-                       psDssData->ovls[k].ba = (u32)phyAddr.uiAddr;
+#ifdef CONFIG_DRM_OMAP_DMM_TILER
+                       enum tiler_fmt fmt;
+#endif
+                       asMemInfo[k].uiAddr = phyAddr.uiAddr;
+#ifdef CONFIG_DRM_OMAP_DMM_TILER
+                       if(tiler_get_fmt((u32)phyAddr.uiAddr, &fmt) && fmt == TILFMT_8BIT)
+#else
+                       if(tiler_fmt((u32)phyAddr.uiAddr) == TILFMT_8BIT)
+#endif
+                       {
+                               psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], (uByteSize * 2) / 3, &phyAddr);
+                               asMemInfo[k].uiUVAddr = phyAddr.uiAddr;
+                       }
                        continue;
                }
 
+               /* normal gralloc layer */
                psTilerInfo = kzalloc(sizeof(*psTilerInfo), GFP_KERNEL);
                if(!psTilerInfo)
                {
@@ -1087,37 +1121,58 @@ static IMG_BOOL ProcessFlipV2(IMG_HANDLE hCmdCookie,
 
                psTilerInfo->num_pg = ui32NumPages;
                psTilerInfo->memtype = TILER_MEM_USING;
-
                for(j = 0; j < ui32NumPages; j++)
                {
                        psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuPAddr(ppsMemInfos[i], j << PAGE_SHIFT, &phyAddr);
                        psTilerInfo->mem[j] = (u32)phyAddr.uiAddr;
                }
 
-               /* Need base address for in-page offset */
+               /* need base address for in-page offset */
                psDevInfo->sPVRJTable.pfnPVRSRVDCMemInfoGetCpuVAddr(ppsMemInfos[i], &virtAddr);
-               psDssData->ovls[k].ba = (u32)virtAddr;
-               apsTilerPAs[k] = psTilerInfo;
+               asMemInfo[k].uiAddr = (IMG_UINTPTR_T) virtAddr;
+               asMemInfo[k].psTilerInfo = psTilerInfo;
        }
 
-       /* Set up cloned layer addresses (but don't duplicate tiler_pas) */
-       for(i = k; i < psDssData->num_ovls && i < ARRAY_SIZE(apsTilerPAs); i++)
+       for(i = 0; i < psDssData->num_ovls; i++)
        {
-               unsigned int ix = psDssData->ovls[i].ba;
-               if(ix >= ARRAY_SIZE(apsTilerPAs))
+               unsigned int ix;
+               apsTilerPAs[i] = NULL;
+
+               /* only supporting Post2, cloned and fbmem layers */
+               if (psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_LAYER_IX &&
+                   psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_OVL_IX &&
+                   psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_FB)
                {
-                       WARN(1, "Invalid clone layer (%u); skipping all cloned layers", ix);
-                       psDssData->num_ovls = k;
-                       break;
+                       psDssData->ovls[i].cfg.enabled = false;
+               }
+
+               if (psDssData->ovls[i].addressing != OMAP_DSS_BUFADDR_LAYER_IX)
+               {
+                       continue;
                }
-               apsTilerPAs[i] = apsTilerPAs[ix];
-               psDssData->ovls[i].ba = psDssData->ovls[ix].ba;
-               psDssData->ovls[i].uv = psDssData->ovls[ix].uv;
+
+               /* Post2 layers */
+               ix = psDssData->ovls[i].ba;
+               if (ix >= k)
+               {
+                       WARN(1, "Invalid Post2 layer (%u)", ix);
+                       psDssData->ovls[i].cfg.enabled = false;
+                       continue;
+               }
+
+               psDssData->ovls[i].addressing = OMAP_DSS_BUFADDR_DIRECT;
+               psDssData->ovls[i].ba = (u32) asMemInfo[ix].uiAddr;
+               psDssData->ovls[i].uv = (u32) asMemInfo[ix].uiUVAddr;
+               apsTilerPAs[i] = asMemInfo[ix].psTilerInfo;
        }
 
-       dsscomp_gralloc_queue(psDssData, apsTilerPAs, false,
+       res = dsscomp_gralloc_queue(psDssData, apsTilerPAs, false,
                                                  (void *)psDevInfo->sPVRJTable.pfnPVRSRVCmdComplete,
                                                  (void *)hCmdCookie);
+       if (res != 0)
+       {
+               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: dsscomp_gralloc_queue failed (%d)\n", __FUNCTION__, psDevInfo->uiFBDevID, res));
+       }
 
        for(i = 0; i < k; i++)
        {
@@ -1196,8 +1251,6 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
        struct module *psLINFBOwner;
        OMAPLFB_FBINFO *psPVRFBInfo = &psDevInfo->sFBInfo;
        OMAPLFB_ERROR eError = OMAPLFB_ERROR_GENERIC;
-       unsigned long FBSize;
-       unsigned long ulLCM;
        unsigned uiFBDevID = psDevInfo->uiFBDevID;
 
        OMAPLFB_CONSOLE_LOCK();
@@ -1209,20 +1262,6 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                goto ErrorRelSem;
        }
 
-       FBSize = (psLINFBInfo->screen_size) != 0 ?
-                                       psLINFBInfo->screen_size :
-                                       psLINFBInfo->fix.smem_len;
-
-       /*
-        * Try and filter out invalid FB info structures (a problem
-        * seen on some OMAP3 systems).
-        */
-       if (FBSize == 0 || psLINFBInfo->fix.line_length == 0)
-       {
-               eError = OMAPLFB_ERROR_INVALID_DEVICE;
-               goto ErrorRelSem;
-       }
-
        psLINFBOwner = psLINFBInfo->fbops->owner;
        if (!try_module_get(psLINFBOwner))
        {
@@ -1248,43 +1287,62 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
 
        psDevInfo->psLINFBInfo = psLINFBInfo;
 
-       ulLCM = LCM(psLINFBInfo->fix.line_length, OMAPLFB_PAGE_SIZE);
+       psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
+       psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
+
+       if (psPVRFBInfo->ulWidth == 0 || psPVRFBInfo->ulHeight == 0)
+       {
+               eError = OMAPLFB_ERROR_INVALID_DEVICE;
+               goto ErrorFBRel;
+       }
+
+#if !defined(CONFIG_DSSCOMP)
+       psPVRFBInfo->ulFBSize = (psLINFBInfo->screen_size) != 0 ?
+                                       psLINFBInfo->screen_size :
+                                       psLINFBInfo->fix.smem_len;
+
+       /*
+        * Try and filter out invalid FB info structures (a problem
+        * seen on some OMAP3 systems).
+        */
+       if (psPVRFBInfo->ulFBSize == 0 || psLINFBInfo->fix.line_length == 0)
+       {
+               eError = OMAPLFB_ERROR_INVALID_DEVICE;
+               goto ErrorFBRel;
+       }
 
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer physical address: 0x%lx\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->fix.smem_start));
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer virtual address: 0x%lx\n",
-                       psDevInfo->uiFBDevID, (unsigned long)psLINFBInfo->screen_base));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
                        ": Device %u: Framebuffer size: %lu\n",
-                       psDevInfo->uiFBDevID, FBSize));
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulFBSize));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
                        ": Device %u: Framebuffer virtual width: %u\n",
                        psDevInfo->uiFBDevID, psLINFBInfo->var.xres_virtual));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
                        ": Device %u: Framebuffer virtual height: %u\n",
                        psDevInfo->uiFBDevID, psLINFBInfo->var.yres_virtual));
+#endif
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer width: %u\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->var.xres));
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer height: %u\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->var.yres));
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: Framebuffer stride: %u\n",
-                       psDevInfo->uiFBDevID, psLINFBInfo->fix.line_length));
+                       ": Device %u: Framebuffer width: %lu\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulWidth));
        DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
-                       ": Device %u: LCM of stride and page size: %lu\n",
-                       psDevInfo->uiFBDevID, ulLCM));
-
-       /* Additional implementation specific information */
-       OMAPLFBPrintInfo(psDevInfo);
+                       ": Device %u: Framebuffer height: %lu\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulHeight));
 
 #if defined(CONFIG_DSSCOMP)
        {
-               /* for some reason we need at least 3 buffers in the swap chain */
-               int n = FBSize / RoundUpToMultiple(psLINFBInfo->fix.line_length * psLINFBInfo->var.yres, ulLCM);
+#if defined(SUPPORT_PVRSRV_GET_DC_SYSTEM_BUFFER)
+               /*
+                * Assume we need 3 swap buffers, and a separate system
+                * buffer.
+                */
+               int n = 4;
+#else
+               /*
+                * Assume we need just 3 swap buffers, and no separate
+                * system buffer.
+                */
+               int n = 3;
+#endif
                int res;
                int i, x, y, w;
                ion_phys_addr_t phys;
@@ -1295,8 +1353,8 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                {
                        /* TILER will align width to 128-bytes */
                        /* however, SGX must have full page width */
-                       .w = ALIGN(psLINFBInfo->var.xres, PAGE_SIZE / (psLINFBInfo->var.bits_per_pixel / 8)),
-                       .h = psLINFBInfo->var.yres,
+                       .w = ALIGN(psPVRFBInfo->ulWidth, PAGE_SIZE / (psLINFBInfo->var.bits_per_pixel / 8)),
+                       .h = psPVRFBInfo->ulHeight,
                        .fmt = psLINFBInfo->var.bits_per_pixel == 16 ? TILER_PIXEL_FMT_16BIT : TILER_PIXEL_FMT_32BIT,
                        .flags = 0,
                };
@@ -1305,43 +1363,43 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                           " %s: Device %u: Requesting %d TILER 2D framebuffers\n",
                           __FUNCTION__, uiFBDevID, n);
 
-               /* INTEGRATION_POINT: limit to MAX 3 FBs to save TILER container space */
-               if (n != 3)
-                       n = 3;
-
                sAllocData.w *= n;
 
                psPVRFBInfo->uiBytesPerPixel = psLINFBInfo->var.bits_per_pixel >> 3;
                psPVRFBInfo->bIs2D = OMAPLFB_TRUE;
 
-               res = omap_ion_tiler_alloc(gpsIONClient, &sAllocData);
+               res = omap_ion_tiler_alloc(psDevInfo->psIONClient, &sAllocData);
                psPVRFBInfo->psIONHandle = sAllocData.handle;
                if (res < 0)
                {
                        printk(KERN_ERR DRIVER_PREFIX
                                   " %s: Device %u: Could not allocate 2D framebuffer(%d)\n",
                                   __FUNCTION__, uiFBDevID, res);
-                       goto ErrorModPut;
+                       goto ErrorFBRel;
                }
 
-               psLINFBInfo->fix.smem_start = ion_phys(gpsIONClient, sAllocData.handle, &phys, &size);
+               res = ion_phys(psDevInfo->psIONClient, sAllocData.handle, &phys, &size);
+               if (res < 0)
+               {
+                       printk(KERN_ERR DRIVER_PREFIX
+                                  " %s: Device %u: Could not get 2D framebufferphysical address (%d)\n",
+                                  __FUNCTION__, uiFBDevID, res);
+                       goto ErrorFBRel;
+               }
 
                psPVRFBInfo->sSysAddr.uiAddr = phys;
                psPVRFBInfo->sCPUVAddr = 0;
-               psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
-               psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
 
                psPVRFBInfo->ulByteStride = PAGE_ALIGN(psPVRFBInfo->ulWidth * psPVRFBInfo->uiBytesPerPixel);
                w = psPVRFBInfo->ulByteStride >> PAGE_SHIFT;
  
-               /* this is an "effective" FB size to get correct number of buffers */
                psPVRFBInfo->ulFBSize = sAllocData.h * n * psPVRFBInfo->ulByteStride;
                psPVRFBInfo->psPageList = kzalloc(w * n * psPVRFBInfo->ulHeight * sizeof(*psPVRFBInfo->psPageList), GFP_KERNEL);
                if (!psPVRFBInfo->psPageList)
                {
                        printk(KERN_WARNING DRIVER_PREFIX ": %s: Device %u: Could not allocate page list\n", __FUNCTION__, psDevInfo->uiFBDevID);
-                       ion_free(gpsIONClient, sAllocData.handle);
-                       goto ErrorModPut;
+                       ion_free(psDevInfo->psIONClient, sAllocData.handle);
+                       goto ErrorFBRel;
                }
 
                tilview_create(&view, phys, psDevInfo->sFBInfo.ulWidth, psDevInfo->sFBInfo.ulHeight);
@@ -1362,21 +1420,48 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
        psPVRFBInfo->sSysAddr.uiAddr = psLINFBInfo->fix.smem_start;
        psPVRFBInfo->sCPUVAddr = psLINFBInfo->screen_base;
 
-       psPVRFBInfo->ulWidth = psLINFBInfo->var.xres;
-       psPVRFBInfo->ulHeight = psLINFBInfo->var.yres;
        psPVRFBInfo->ulByteStride =  psLINFBInfo->fix.line_length;
-       psPVRFBInfo->ulFBSize = FBSize;
 #endif /* defined(CONFIG_DSSCOMP) */
 
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: Framebuffer physical address: 0x%x\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->sSysAddr.uiAddr));
+
+       if (psPVRFBInfo->sCPUVAddr != NULL)
+       {
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: Framebuffer virtual address: %p\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->sCPUVAddr));
+       }
+
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: Framebuffer stride: %lu\n",
+                       psDevInfo->uiFBDevID, psPVRFBInfo->ulByteStride));
+
+       /* Additional implementation specific information */
+       OMAPLFBPrintInfo(psDevInfo);
+
        psPVRFBInfo->ulBufferSize = psPVRFBInfo->ulHeight * psPVRFBInfo->ulByteStride;
 
-       /* Round the buffer size up to a multiple of the number of pages
-        * and the byte stride.
-        * This is used internally, to ensure buffers start on page
-        * boundaries, for the benefit of PVR Services.
-        */
-       psPVRFBInfo->ulRoundedBufferSize = RoundUpToMultiple(psPVRFBInfo->ulBufferSize, ulLCM);
+#if defined(CONFIG_DSSCOMP)
+       psPVRFBInfo->ulRoundedBufferSize = psPVRFBInfo->ulBufferSize;
+#else
+       {
+               unsigned long ulLCM;
+               ulLCM = LCM(psPVRFBInfo->ulByteStride, OMAPLFB_PAGE_SIZE);
+
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX
+                       ": Device %u: LCM of stride and page size: %lu\n",
+                       psDevInfo->uiFBDevID, ulLCM));
 
+               /* Round the buffer size up to a multiple of the number of pages
+                * and the byte stride.
+                * This is used internally, to ensure buffers start on page
+                * boundaries, for the benefit of PVR Services.
+                */
+               psPVRFBInfo->ulRoundedBufferSize = RoundUpToMultiple(psPVRFBInfo->ulBufferSize, ulLCM);
+       }
+#endif
        if(psLINFBInfo->var.bits_per_pixel == 16)
        {
                if((psLINFBInfo->var.red.length == 5) &&
@@ -1429,6 +1514,11 @@ static OMAPLFB_ERROR OMAPLFBInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
        eError = OMAPLFB_OK;
        goto ErrorRelSem;
 
+ErrorFBRel:
+       if (psLINFBInfo->fbops->fb_release != NULL) 
+       {
+               (void) psLINFBInfo->fbops->fb_release(psLINFBInfo, 0);
+       }
 ErrorModPut:
        module_put(psLINFBOwner);
 ErrorRelSem:
@@ -1450,7 +1540,7 @@ static void OMAPLFBDeInitFBDev(OMAPLFB_DEVINFO *psDevInfo)
                kfree(psPVRFBInfo->psPageList);
                if (psPVRFBInfo->psIONHandle)
                {
-                       ion_free(gpsIONClient, psPVRFBInfo->psIONHandle);
+                       ion_free(psDevInfo->psIONClient, psPVRFBInfo->psIONHandle);
                }
        }
 #endif /* defined(CONFIG_DSSCOMP) */
@@ -1494,6 +1584,21 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
        {
                goto ErrorFreeDevInfo;
        }
+
+#if defined(CONFIG_ION_OMAP)
+       psDevInfo->psIONClient =
+               ion_client_create(omap_ion_device,
+                                                 1 << ION_HEAP_TYPE_CARVEOUT |
+                                                 1 << OMAP_ION_HEAP_TYPE_TILER,
+                                                 "dc_omapfb3_linux");
+       if (IS_ERR_OR_NULL(psDevInfo->psIONClient))
+       {
+               printk(KERN_ERR DRIVER_PREFIX
+                       ": %s: Device %u: Failed to create ion client\n", __FUNCTION__, uiFBDevID);
+
+               goto ErrorFreeDevInfo;
+       }
+#endif /* defined(CONFIG_ION_OMAP) */
 #ifdef FBDEV_PRESENT
        /* Save private fbdev information structure in the dev. info. */
        if(OMAPLFBInitFBDev(psDevInfo) != OMAPLFB_OK)
@@ -1504,7 +1609,7 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
                 * there is no Linux framebuffer device corresponding
                 * to the device ID.
                 */
-               goto ErrorFreeDevInfo;
+               goto ErrorIonClientDestroy;
        }
 
        psDevInfo->sDisplayInfo.ui32MaxSwapChainBuffers = (IMG_UINT32)(psDevInfo->sFBInfo.ulFBSize / psDevInfo->sFBInfo.ulRoundedBufferSize);
@@ -1512,6 +1617,9 @@ static OMAPLFB_DEVINFO *OMAPLFBInitDev(unsigned uiFBDevID)
        {
                psDevInfo->sDisplayInfo.ui32MaxSwapChains = 1;
                psDevInfo->sDisplayInfo.ui32MaxSwapInterval = 1;
+#if defined(CONFIG_DSSCOMP)
+               psDevInfo->sDisplayInfo.ui32MinSwapInterval = 1;
+#endif
        }
 
        psDevInfo->sDisplayInfo.ui32PhysicalWidthmm = psDevInfo->sFBInfo.ulPhysicalWidthmm;
@@ -1547,6 +1655,10 @@ psDevInfo->sSystemBuffer.sCPUVAddr = 0x100;
 #endif
 
 
+#if defined(CONFIG_DSSCOMP) && defined(SUPPORT_PVRSRV_GET_DC_SYSTEM_BUFFER)
+       OMAPLFBFlip(psDevInfo, &psDevInfo->sSystemBuffer);
+#endif
+
        /*
                Setup the DC Jtable so SRVKM can call into this driver
        */
@@ -1615,12 +1727,17 @@ psDevInfo->sSystemBuffer.sCPUVAddr = 0x100;
 #if defined(SUPPORT_DRI_DRM)
        OMAPLFBAtomicBoolInit(&psDevInfo->sLeaveVT, OMAPLFB_FALSE);
 #endif
+
        return psDevInfo;
 
 ErrorUnregisterDevice:
        (void)psDevInfo->sPVRJTable.pfnPVRSRVRemoveDCDevice(psDevInfo->uiPVRDevID);
 ErrorDeInitFBDev:
        OMAPLFBDeInitFBDev(psDevInfo);
+ErrorIonClientDestroy:
+#if defined(CONFIG_ION_OMAP)
+       ion_client_destroy(psDevInfo->psIONClient);
+#endif /* defined(CONFIG_ION_OMAP) */
 ErrorFreeDevInfo:
        OMAPLFBFreeKernelMem(psDevInfo);
 ErrorExit:
@@ -1666,19 +1783,6 @@ static OMAPLFB_BOOL OMAPLFBDeInitDev(OMAPLFB_DEVINFO *psDevInfo)
 {
        PVRSRV_DC_DISP2SRV_KMJTABLE *psPVRJTable = &psDevInfo->sPVRJTable;
 
-       OMAPLFBCreateSwapChainLockDeInit(psDevInfo);
-
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sBlanked);
-       OMAPLFBAtomicIntDeInit(&psDevInfo->sBlankEvents);
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sFlushCommands);
-#if defined(CONFIG_HAS_EARLYSUSPEND)
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sEarlySuspendFlag);
-#endif
-#if defined(SUPPORT_DRI_DRM)
-       OMAPLFBAtomicBoolDeInit(&psDevInfo->sLeaveVT);
-#endif
-       psPVRJTable = &psDevInfo->sPVRJTable;
-
        if (psPVRJTable->pfnPVRSRVRemoveCmdProcList (psDevInfo->uiPVRDevID, OMAPLFB_COMMAND_COUNT) != PVRSRV_OK)
        {
                printk(KERN_ERR DRIVER_PREFIX
@@ -1696,8 +1800,32 @@ static OMAPLFB_BOOL OMAPLFBDeInitDev(OMAPLFB_DEVINFO *psDevInfo)
                        ": %s: Device %u: PVR Device %u: Couldn't remove device from PVR Services\n", __FUNCTION__, psDevInfo->uiFBDevID, psDevInfo->uiPVRDevID);
                return OMAPLFB_FALSE;
        }
-       
+
+#if defined(CONFIG_DSSCOMP)
+       /* Disable the overlay, as we will be freeing the display buffers */
+       psDevInfo->sSystemBuffer.sSysAddr.uiAddr = 0;
+       OMAPLFBFlip(psDevInfo, &psDevInfo->sSystemBuffer);
+#endif /* defined(CONFIG_DSSCOMP) */
+
+       OMAPLFBCreateSwapChainLockDeInit(psDevInfo);
+
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sBlanked);
+       OMAPLFBAtomicIntDeInit(&psDevInfo->sBlankEvents);
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sFlushCommands);
+#if defined(CONFIG_HAS_EARLYSUSPEND)
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sEarlySuspendFlag);
+#endif
+#if defined(SUPPORT_DRI_DRM)
+       OMAPLFBAtomicBoolDeInit(&psDevInfo->sLeaveVT);
+#endif
+
+#ifdef FBDEV_PRESENT
        OMAPLFBDeInitFBDev(psDevInfo);
+#endif
+
+#if defined(CONFIG_ION_OMAP)
+       ion_client_destroy(psDevInfo->psIONClient);
+#endif
 
        OMAPLFBSetDevInfoPtr(psDevInfo->uiFBDevID, NULL);
 
index af2f73b..861873b 100644 (file)
@@ -37,7 +37,6 @@ 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.
-  
 */ /**************************************************************************/
 
 /**************************************************************************
@@ -95,7 +94,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <video/da8xx-fb.h>
 #if defined(PVR_OMAPLFB_DRM_FB)
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0))
 #include <plat/display.h>
+#else
+#include <video/omapdss.h>
+#endif
 #include <linux/omap_gpu.h>
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
 /* OmapZoom.org OMAP3 2.6.29 kernel tree       - Needs mach/vrfb.h
@@ -109,7 +112,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #if defined(PVR_OMAPFB3_NEEDS_PLAT_VRFB_H)
+#ifdef FBDEV_PRESENT
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
 #include <plat/vrfb.h>
+#else
+#include <video/omapvrfb.h>
+#endif
+#endif
+
 #else
 #if defined(PVR_OMAPFB3_NEEDS_MACH_VRFB_H)
 #include <mach/vrfb.h>
@@ -120,7 +130,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define        PVR_DEBUG DEBUG
 #undef DEBUG
 #endif
+#ifdef FBDEV_PRESENT
 #include <omapfb/omapfb.h>
+#endif
 #if defined(DEBUG)
 #undef DEBUG
 #endif
@@ -131,7 +143,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif /* defined(PVR_OMAPLFB_DRM_FB) */
 
 #if defined(CONFIG_DSSCOMP)
+#if defined(CONFIG_DRM_OMAP_DMM_TILER)
+#include <../drivers/staging/omapdrm/omap_dmm_tiler.h>
+#include <../drivers/video/omap2/dsscomp/tiler-utils.h>
+#elif defined(CONFIG_TI_TILER)
 #include <mach/tiler.h>
+#else /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
+#error CONFIG_DSSCOMP support requires either \
+       CONFIG_DRM_OMAP_DMM_TILER or CONFIG_TI_TILER
+#endif /* defined(CONFIG_DRM_OMAP_DMM_TILER) */
 #include <video/dsscomp.h>
 #include <plat/dsscomp.h>
 #endif /* defined(CONFIG_DSSCOMP) */
@@ -155,7 +175,12 @@ MODULE_SUPPORTED_DEVICE(DEVNAME);
 #if !defined(PVR_OMAPLFB_DRM_FB)
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
 #define OMAP_DSS_DRIVER(drv, dev) struct omap_dss_driver *drv = (dev) != NULL ? (dev)->driver : NULL
+//#define OMAP_DSS_MANAGER(man, dev) struct omap_overlay_manager *man = (dev) != NULL ? (dev)->manager : NULL
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
 #define OMAP_DSS_MANAGER(man, dev) struct omap_overlay_manager *man = (dev) != NULL ? (dev)->manager : NULL
+#else
+#define OMAP_DSS_MANAGER(man, dev) struct omap_overlay_manager *man = (dev) != NULL ? (dev)->output->manager : NULL
+#endif
 #define        WAIT_FOR_VSYNC(man)     ((man)->wait_for_vsync)
 #else
 #define OMAP_DSS_DRIVER(drv, dev) struct omap_dss_device *drv = (dev)
@@ -273,6 +298,9 @@ static void WorkQueueHandler(struct work_struct *psWork)
 OMAPLFB_ERROR OMAPLFBCreateSwapQueue(OMAPLFB_SWAPCHAIN *psSwapChain)
 {
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
+#if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,37))
+#define WQ_FREEZABLE WQ_FREEZEABLE
+#endif
        /*
         * Calling alloc_ordered_workqueue with the WQ_FREEZABLE and
         * WQ_MEM_RECLAIM flags set, (currently) has the same effect as
@@ -282,12 +310,7 @@ OMAPLFB_ERROR OMAPLFBCreateSwapQueue(OMAPLFB_SWAPCHAIN *psSwapChain)
         * conditions, preventing the driver from holding on to
         * resources longer than it needs to.
         */
-#if (LINUX_VERSION_CODE == KERNEL_VERSION(2,6,37))
-       psSwapChain->psWorkQueue = alloc_ordered_workqueue(DEVNAME, WQ_FREEZEABLE | WQ_MEM_RECLAIM);
-#else
        psSwapChain->psWorkQueue = alloc_ordered_workqueue(DEVNAME, WQ_FREEZABLE | WQ_MEM_RECLAIM);
-#endif
-
 #else
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
        psSwapChain->psWorkQueue = create_freezable_workqueue(DEVNAME);
@@ -329,7 +352,6 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
 {
        struct fb_var_screeninfo sFBVar;
        int res;
-       unsigned long ulYResVirtual;
 
        OMAPLFB_CONSOLE_LOCK();
 
@@ -338,9 +360,26 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
        sFBVar.xoffset = 0;
        sFBVar.yoffset = psBuffer->ulYOffset;
 
-       ulYResVirtual = psBuffer->ulYOffset + sFBVar.yres;
-
 #if defined(CONFIG_DSSCOMP)
+       /*
+        * If flipping to a NULL buffer, blank the screen to prevent
+        * warnings/errors from the display subsystem.
+        */
+       if (psBuffer->sSysAddr.uiAddr == 0)
+       {
+               struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
+               OMAP_DSS_MANAGER(psDSSMan, psDSSDev);
+
+               if (psDSSMan != NULL && psDSSMan->blank != NULL)
+               {
+                       res = psDSSMan->blank(psDSSMan, false);
+                       if (res != 0)
+                       {
+                               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: DSS manager blank call failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res));
+                       }
+               }
+       }
+
        {
                /*
                 * If using DSSCOMP, we need to use dsscomp queuing for normal
@@ -368,7 +407,7 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
                                        .width = sFBVar.xres_virtual,
                                        .height = sFBVar.yres_virtual,
                                        .stride = sFBFix.line_length,
-                                       .enabled = 1,
+                                       .enabled = (psBuffer->sSysAddr.uiAddr != 0),
                                        .global_alpha = 255,
                                },
                        },
@@ -377,54 +416,72 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
                /* do not map buffer into TILER1D as it is contiguous */
                struct tiler_pa_info *pas[] = { NULL };
 
-               d.ovls[0].ba = sFBFix.smem_start;
+               d.ovls[0].ba = (u32) psBuffer->sSysAddr.uiAddr;
+
                omapfb_mode_to_dss_mode(&sFBVar, &d.ovls[0].cfg.color_mode);
 
                res = dsscomp_gralloc_queue(&d, pas, true, NULL, NULL);
+               if (res != 0)
+               {
+                       DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: dsscomp_gralloc_queue failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res));
+               }
        }
 #else /* defined(CONFIG_DSSCOMP) */
-       /*
-        * PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY should be defined to work
-        * around flipping problems seen with the Taal LCDs on Blaze.
-        * The work around is safe to use with other types of screen on Blaze
-        * (e.g. HDMI) and on other platforms (e.g. Panda board).
-        */
+       {
+               unsigned long ulYResVirtual = psBuffer->ulYOffset + sFBVar.yres;
+
+               /*
+                * PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY should be defined to 
+                * work around flipping problems seen with the Taal LCDs on
+                * Blaze.
+                * The work around is safe to use with other types of screen
+                * on Blaze (e.g. HDMI) and on other platforms (e.g. Panda
+                * board).
+                */
 #if !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY)
-       /*
-        * Attempt to change the virtual screen resolution if it is too
-        * small.  Note that fb_set_var also pans the display.
-        */
-       if (sFBVar.xres_virtual != sFBVar.xres || sFBVar.yres_virtual < ulYResVirtual)
+               /*
+                * Attempt to change the virtual screen resolution if it is too
+                * small.  Note that fb_set_var also pans the display.
+                */
+               if (sFBVar.xres_virtual != sFBVar.xres || sFBVar.yres_virtual < ulYResVirtual)
 #endif /* !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY) */
-       {
-               sFBVar.xres_virtual = sFBVar.xres;
-               sFBVar.yres_virtual = ulYResVirtual;
+               {
+                       sFBVar.xres_virtual = sFBVar.xres;
+                       sFBVar.yres_virtual = ulYResVirtual;
 
-               sFBVar.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
+                       sFBVar.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
 
-               res = fb_set_var(psDevInfo->psLINFBInfo, &sFBVar);
-               if (res != 0)
-               {
-                       printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_set_var failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       res = fb_set_var(psDevInfo->psLINFBInfo, &sFBVar);
+                       if (res != 0)
+                       {
+                               printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_set_var failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       }
                }
-       }
 #if !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY)
-       else
-       {
-               res = fb_pan_display(psDevInfo->psLINFBInfo, &sFBVar);
-               if (res != 0)
+               else
                {
-                       printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_pan_display failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       res = fb_pan_display(psDevInfo->psLINFBInfo, &sFBVar);
+                       if (res != 0)
+                       {
+                               printk(KERN_ERR DRIVER_PREFIX ": %s: Device %u: fb_pan_display failed (Y Offset: %lu, Error: %d)\n", __FUNCTION__, psDevInfo->uiFBDevID, psBuffer->ulYOffset, res);
+                       }
                }
-       }
 #endif /* !defined(PVR_OMAPLFB_DONT_USE_FB_PAN_DISPLAY) */
+       }
 #endif /* defined(CONFIG_DSSCOMP) */
 
        OMAPLFB_CONSOLE_UNLOCK();
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
+/* Newer kernels don't have any update mode capability */
+
+//#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
+//#define      PVR_OMAPLFB_HAS_UPDATE_MODE
+//#endif
+
+//#if defined(PVR_OMAPLFB_HAS_UPDATE_MODE)
 #if !defined(PVR_OMAPLFB_DRM_FB) || defined(DEBUG)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 static OMAPLFB_BOOL OMAPLFBValidateDSSUpdateMode(enum omap_dss_update_mode eMode)
 {
        switch (eMode)
@@ -458,7 +515,6 @@ static OMAPLFB_UPDATE_MODE OMAPLFBFromDSSUpdateMode(enum omap_dss_update_mode eM
 }
 #endif
 #endif
-
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 static OMAPLFB_BOOL OMAPLFBValidateUpdateMode(OMAPLFB_UPDATE_MODE eMode)
 {
@@ -475,6 +531,7 @@ static OMAPLFB_BOOL OMAPLFBValidateUpdateMode(OMAPLFB_UPDATE_MODE eMode)
        return OMAPLFB_FALSE;
 }
 #endif
+
 #if 0
 static enum omap_dss_update_mode OMAPLFBToDSSUpdateMode(OMAPLFB_UPDATE_MODE eMode)
 {
@@ -515,7 +572,6 @@ static const char *OMAPLFBUpdateModeToString(OMAPLFB_UPDATE_MODE eMode)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 static const char *OMAPLFBDSSUpdateModeToString(enum omap_dss_update_mode eMode)
 {
-
        if (!OMAPLFBValidateDSSUpdateMode(eMode))
        {
                return "Unknown Update Mode";
@@ -524,45 +580,7 @@ static const char *OMAPLFBDSSUpdateModeToString(enum omap_dss_update_mode eMode)
        return OMAPLFBUpdateModeToString(OMAPLFBFromDSSUpdateMode(eMode));
 }
 #endif
-void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
-{
-#if defined(PVR_OMAPLFB_DRM_FB)
-       struct drm_connector *psConnector;
-       unsigned uConnectors;
-       unsigned uConnector;
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: DRM framebuffer\n", psDevInfo->uiFBDevID));
-
-       for (psConnector = NULL, uConnectors = 0;
-               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL;)
-       {
-               uConnectors++;
-       }
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Number of screens (DRM connectors): %u\n", psDevInfo->uiFBDevID, uConnectors));
-
-       if (uConnectors == 0)
-       {
-               return;
-       }
-
-       for (psConnector = NULL, uConnector = 0;
-               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL; uConnector++)
-       {
-               enum omap_dss_update_mode eMode = omap_connector_get_update_mode(psConnector);
-
-               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Screen %u: %s (%d)\n", psDevInfo->uiFBDevID, uConnector, OMAPLFBDSSUpdateModeToString(eMode), (int)eMode));
-
-       }
-#else  /* defined(PVR_OMAPLFB_DRM_FB) */
-       OMAPLFB_UPDATE_MODE eMode = OMAPLFBGetUpdateMode(psDevInfo);
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: non-DRM framebuffer\n", psDevInfo->uiFBDevID));
-
-       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: %s\n", psDevInfo->uiFBDevID, OMAPLFBUpdateModeToString(eMode)));
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
-}
-#endif /* defined(DEBUG) */
+#endif /* defined(DEBUG) */
 
 /* 
  * Get display update mode.
@@ -570,7 +588,6 @@ void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
  */
 OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
 {
-#if 0
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
        OMAPLFB_UPDATE_MODE eMode = OMAPLFB_UPDATE_MODE_UNDEFINED;
@@ -608,7 +625,7 @@ OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
 
        return eMode;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
-
+#if 0
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_DRIVER(psDSSDrv, psDSSDev);
 
@@ -626,9 +643,8 @@ OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
                {
                        return OMAPLFB_UPDATE_MODE_AUTO;
                }
-//             DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: No get_update_mode function\n", __FUNCTION__, psDevInfo->uiFBDevID));
-//             return OMAPLFB_UPDATE_MODE_UNDEFINED;
-                       return OMAPLFB_UPDATE_MODE_AUTO;
+               DEBUG_PRINTK((KERN_WARNING DRIVER_PREFIX ": %s: Device %u: No get_update_mode function\n", __FUNCTION__, psDevInfo->uiFBDevID));
+               return OMAPLFB_UPDATE_MODE_UNDEFINED;
        }
 
        eMode = psDSSDrv->get_update_mode(psDSSDev);
@@ -638,15 +654,14 @@ OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
        }
 
        return OMAPLFBFromDSSUpdateMode(eMode);
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #endif
 return OMAPLFB_UPDATE_MODE_AUTO;
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
 
 /* Set display update mode */
 OMAPLFB_BOOL OMAPLFBSetUpdateMode(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_UPDATE_MODE eMode)
 {
-#if 0
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
        enum omap_dss_update_mode eDSSMode;
@@ -697,6 +712,7 @@ OMAPLFB_BOOL OMAPLFBSetUpdateMode(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_UPDATE_MOD
 
        return OMAPLFB_TRUE;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+#if 0
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_DRIVER(psDSSDrv, psDSSDev);
        enum omap_dss_update_mode eDSSMode;
@@ -722,15 +738,65 @@ OMAPLFB_BOOL OMAPLFBSetUpdateMode(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_UPDATE_MOD
        }
 
        return (res == 0);
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #endif
 return 1;
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
+//#else /* defined(PVR_OMAPLFB_HAS_UPDATE_MODE) */
+
+//OMAPLFB_UPDATE_MODE OMAPLFBGetUpdateMode(OMAPLFB_DEVINFO *psDevInfo)
+//{
+//     return OMAPLFB_UPDATE_MODE_UNDEFINED;
+//}
+
+//#endif /* defined(PVR_OMAPLFB_HAS_UPDATE_MODE) */
+
+#if defined(DEBUG)
+void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
+{
+#if defined(PVR_OMAPLFB_DRM_FB)
+       struct drm_connector *psConnector;
+       unsigned uConnectors;
+       unsigned uConnector;
+
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: DRM framebuffer\n", psDevInfo->uiFBDevID));
+
+       for (psConnector = NULL, uConnectors = 0;
+               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL;)
+       {
+               uConnectors++;
+       }
+
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Number of screens (DRM connectors): %u\n", psDevInfo->uiFBDevID, uConnectors));
+
+       if (uConnectors == 0)
+       {
+               return;
+       }
+
+       for (psConnector = NULL, uConnector = 0;
+               (psConnector = omap_fbdev_get_next_connector(psDevInfo->psLINFBInfo, psConnector)) != NULL; uConnector++)
+       {
+               enum omap_dss_update_mode eMode = omap_connector_get_update_mode(psConnector);
+
+               DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: Screen %u: %s (%d)\n", psDevInfo->uiFBDevID, uConnector, OMAPLFBDSSUpdateModeToString(eMode), (int)eMode));
+
+       }
+#else  /* defined(PVR_OMAPLFB_DRM_FB) */
+//#if defined(PVR_OMAPLFB_HAS_UPDATE_MODE)
+       OMAPLFB_UPDATE_MODE eMode = OMAPLFBGetUpdateMode(psDevInfo);
+
+//     DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: %s\n", psDevInfo->uiFBDevID, OMAPLFBUpdateModeToString(eMode)));
+//#endif
+       DEBUG_PRINTK((KERN_INFO DRIVER_PREFIX ": Device %u: non-DRM framebuffer\n", psDevInfo->uiFBDevID));
+
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
+}
+#endif /* defined(DEBUG) */
 
 /* Wait for VSync */
 OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
 {
-#if 0
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
 
@@ -742,6 +808,7 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
 
        return OMAPLFB_TRUE;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+#if 0
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_MANAGER(psDSSMan, psDSSDev);
 
@@ -756,15 +823,16 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
        }
 
        return OMAPLFB_TRUE;
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #endif
-
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #if FBDEV_PRESENT
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
       int r;
 
       void grpx_irq_wait_handler(void *data)
       {
-          complete((struct completion *)data);
+        if (data != NULL)
+        complete((struct completion *)data);
 //      do_gettimeofday(&tv);
   //      curtime=tv.tv_usec;
 //printk("The time in handler is %ld\n",curtime);
@@ -786,9 +854,11 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
           printk (KERN_WARNING DRIVER_PREFIX ": Failed to un-register for vsync call back\n");
           return OMAPLFB_FALSE;
       }
+#endif
 #endif
       return OMAPLFB_TRUE;
 
+
 }
 
 /*
@@ -797,7 +867,6 @@ OMAPLFB_BOOL OMAPLFBWaitForVSync(OMAPLFB_DEVINFO *psDevInfo)
  */
 OMAPLFB_BOOL OMAPLFBManualSync(OMAPLFB_DEVINFO *psDevInfo)
 {
-#if 0
 #if defined(PVR_OMAPLFB_DRM_FB)
        struct drm_connector *psConnector;
 
@@ -813,6 +882,7 @@ OMAPLFB_BOOL OMAPLFBManualSync(OMAPLFB_DEVINFO *psDevInfo)
 
        return OMAPLFB_TRUE;
 #else  /* defined(PVR_OMAPLFB_DRM_FB) */
+#if 0
        struct omap_dss_device *psDSSDev = fb2display(psDevInfo->psLINFBInfo);
        OMAP_DSS_DRIVER(psDSSDrv, psDSSDev);
 
@@ -827,9 +897,9 @@ OMAPLFB_BOOL OMAPLFBManualSync(OMAPLFB_DEVINFO *psDevInfo)
        }
 
        return OMAPLFB_TRUE;
-#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 #endif
-return OMAPLFB_TRUE;
+       return OMAPLFB_TRUE;
+#endif /* defined(PVR_OMAPLFB_DRM_FB) */
 }
 
 /*
index 34669e1..3ce0060 100644 (file)
@@ -423,6 +423,7 @@ void OMAPLFBFlip(OMAPLFB_DEVINFO *psDevInfo, OMAPLFB_BUFFER *psBuffer)
        OMAPLFB_CONSOLE_UNLOCK();
 }
 
+#if 0
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 #if !defined(PVR_OMAPLFB_DRM_FB) || defined(DEBUG)
 static OMAPLFB_BOOL OMAPLFBValidateDSSUpdateMode(enum omap_dss_update_mode eMode)
@@ -473,7 +474,6 @@ static OMAPLFB_BOOL OMAPLFBValidateUpdateMode(OMAPLFB_UPDATE_MODE eMode)
 
        return OMAPLFB_FALSE;
 }
-#if 0
 static enum omap_dss_update_mode OMAPLFBToDSSUpdateMode(OMAPLFB_UPDATE_MODE eMode)
 {
        switch(eMode)
@@ -510,6 +510,7 @@ static const char *OMAPLFBUpdateModeToString(OMAPLFB_UPDATE_MODE eMode)
 
        return "Unknown Update Mode";
 }
+#if 0
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
 static const char *OMAPLFBDSSUpdateModeToString(enum omap_dss_update_mode eMode)
 {
@@ -522,6 +523,7 @@ static const char *OMAPLFBDSSUpdateModeToString(enum omap_dss_update_mode eMode)
        return OMAPLFBUpdateModeToString(OMAPLFBFromDSSUpdateMode(eMode));
 }
 #endif
+#endif
 void OMAPLFBPrintInfo(OMAPLFB_DEVINFO *psDevInfo)
 {
 #if defined(PVR_OMAPLFB_DRM_FB)
index aededed..d01ef39 100644 (file)
@@ -34,6 +34,7 @@ drm-y := pvr_drm_stubs.o drm_auth.o drm_bufs.o drm_cache.o drm_context.o drm_dma
        drm_crtc.o drm_modes.o drm_edid.o \
        drm_info.o drm_debugfs.o drm_encoder_slave.o
 else
+# Works for 2.6.37 till 3.2 kernel
 drm-y := pvr_drm_stubs.o drm_auth.o drm_bufs.o drm_cache.o drm_context.o drm_dma.o drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
        drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
        drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
@@ -41,6 +42,23 @@ drm-y := pvr_drm_stubs.o drm_auth.o drm_bufs.o drm_cache.o drm_context.o drm_dma
        drm_crtc.o drm_modes.o drm_edid.o \
        drm_info.o drm_debugfs.o drm_encoder_slave.o drm_global.o drm_platform.o drm_trace_points.o
 endif
+
+# For 3.3 kernel only
+#drm-y := pvr_drm_stubs.o drm_auth.o drm_bufs.o drm_cache.o drm_context.o drm_dma.o drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
+#      drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
+#      drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
+#      drm_sysfs.o drm_hashtab.o drm_mm.o \
+#      drm_crtc.o drm_modes.o drm_edid.o \
+#      drm_info.o drm_debugfs.o drm_encoder_slave.o drm_global.o drm_platform.o drm_trace_points.o
+
+# For greater than/equal to 3.4 till 3.8 kernel
+#drm-y := pvr_drm_stubs.o drm_auth.o drm_bufs.o drm_cache.o drm_context.o drm_dma.o drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
+#      drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
+#      drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
+#      drm_sysfs.o drm_hashtab.o drm_mm.o \
+#      drm_crtc.o drm_modes.o drm_edid.o \
+#      drm_info.o drm_debugfs.o drm_encoder_slave.o drm_global.o drm_platform.o drm_trace_points.o drm_prime.o
+
 # less than 2.6.32 kernel
 
 #drm-y := pvr_drm_stubs.o drm_auth.o drm_bufs.o drm_cache.o drm_context.o drm_dma.o drm_drawable.o drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
index 8c62f44..adee440 100644 (file)
@@ -43,7 +43,7 @@ $(call must-be-defined,$(SUPPORT_DRI_DRM))
 DRM_SOURCE_DIR := drivers/gpu/drm
 
 ccflags-y += \
-        -I$(KERNELDIR)/include/drm \
+        -Iinclude/drm \
         -I$(DRM_SOURCE_DIR)
 
 drm-y += \
index ddbee9b..b78fd18 100644 (file)
@@ -84,6 +84,14 @@ release_device(struct device *dev)
 {
 }
 
+int pci_bus_read_config_dword(struct pci_bus *bus, unsigned int devfn,int where, u32 *val) 
+{ 
+       return 0;
+}
+
+
+
 int
 drm_pvr_dev_add(void)
 {
index 5a25467..6bec2b5 100644 (file)
@@ -304,11 +304,7 @@ typedef struct PVRSRV_BRIDGE_PACKAGE_TAG
        IMG_VOID                                *pvParamOut;                    /*!< output data buffer */
        IMG_UINT32                              ui32OutBufferSize;              /*!< size of output data buffer */
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hKernelServices;                /*!< kernel servcies handle */
-#else
        IMG_HANDLE                              hKernelServices;                /*!< kernel servcies handle */
-#endif
 }PVRSRV_BRIDGE_PACKAGE;
 
 
@@ -354,11 +350,7 @@ typedef struct PVRSRV_BRIDGE_IN_ENUMCLASS_TAG
 typedef struct PVRSRV_BRIDGE_IN_CLOSE_DISPCLASS_DEVICE_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 } PVRSRV_BRIDGE_IN_CLOSE_DISPCLASS_DEVICE;
 
 
@@ -368,11 +360,7 @@ typedef struct PVRSRV_BRIDGE_IN_CLOSE_DISPCLASS_DEVICE_TAG
 typedef struct PVRSRV_BRIDGE_IN_ENUM_DISPCLASS_FORMATS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 } PVRSRV_BRIDGE_IN_ENUM_DISPCLASS_FORMATS;
 
 
@@ -382,11 +370,7 @@ typedef struct PVRSRV_BRIDGE_IN_ENUM_DISPCLASS_FORMATS_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_DISPCLASS_SYSBUFFER_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 } PVRSRV_BRIDGE_IN_GET_DISPCLASS_SYSBUFFER;
 
 
@@ -396,11 +380,7 @@ typedef struct PVRSRV_BRIDGE_IN_GET_DISPCLASS_SYSBUFFER_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_DISPCLASS_INFO_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 } PVRSRV_BRIDGE_IN_GET_DISPCLASS_INFO;
 
 
@@ -410,11 +390,7 @@ typedef struct PVRSRV_BRIDGE_IN_GET_DISPCLASS_INFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_CLOSE_BUFFERCLASS_DEVICE_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 } PVRSRV_BRIDGE_IN_CLOSE_BUFFERCLASS_DEVICE;
 
 
@@ -424,11 +400,7 @@ typedef struct PVRSRV_BRIDGE_IN_CLOSE_BUFFERCLASS_DEVICE_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_BUFFERCLASS_INFO_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 } PVRSRV_BRIDGE_IN_GET_BUFFERCLASS_INFO;
 
 
@@ -438,11 +410,7 @@ typedef struct PVRSRV_BRIDGE_IN_GET_BUFFERCLASS_INFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_RELEASE_DEVICEINFO_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
 
 } PVRSRV_BRIDGE_IN_RELEASE_DEVICEINFO;
 
@@ -465,13 +433,8 @@ typedef struct PVRSRV_BRIDGE_IN_FREE_CLASSDEVICEINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_DEVMEM_HEAPINFO_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hDevMemContext;
-#else
        IMG_HANDLE                      hDevCookie;
        IMG_HANDLE                      hDevMemContext;
-#endif
 
 }PVRSRV_BRIDGE_IN_GET_DEVMEM_HEAPINFO;
 
@@ -482,11 +445,7 @@ typedef struct PVRSRV_BRIDGE_IN_GET_DEVMEM_HEAPINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_CREATE_DEVMEMCONTEXT_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
 
 }PVRSRV_BRIDGE_IN_CREATE_DEVMEMCONTEXT;
 
@@ -497,13 +456,8 @@ typedef struct PVRSRV_BRIDGE_IN_CREATE_DEVMEMCONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_IN_DESTROY_DEVMEMCONTEXT_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hDevMemContext;
-#else
        IMG_HANDLE                      hDevCookie;
        IMG_HANDLE                      hDevMemContext;
-#endif
 
 }PVRSRV_BRIDGE_IN_DESTROY_DEVMEMCONTEXT;
 
@@ -514,16 +468,11 @@ typedef struct PVRSRV_BRIDGE_IN_DESTROY_DEVMEMCONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hDevMemHeap;
-#else
        IMG_HANDLE                      hDevCookie;
        IMG_HANDLE                      hDevMemHeap;
-#endif
        IMG_UINT32                      ui32Attribs;
-       IMG_SIZE_T                      ui32Size;
-       IMG_SIZE_T                      ui32Alignment;
+       IMG_SIZE_T                      uSize;
+       IMG_SIZE_T                      uAlignment;
        IMG_PVOID                       pvPrivData;
        IMG_UINT32                      ui32PrivDataLength;
 
@@ -539,11 +488,7 @@ typedef struct PVRSRV_BRIDGE_IN_ALLOCDEVICEMEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_MAPMEMINFOTOUSER_TAG
 {
        IMG_UINT32  ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID     hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
 
 }PVRSRV_BRIDGE_IN_MAPMEMINFOTOUSER;
 
@@ -553,17 +498,9 @@ typedef struct PVRSRV_BRIDGE_IN_MAPMEMINFOTOUSER_TAG
 typedef struct PVRSRV_BRIDGE_IN_UNMAPMEMINFOFROMUSER_TAG
 {
        IMG_UINT32      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        IMG_PVOID                                pvLinAddr;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hMappingInfo;
-#else
        IMG_HANDLE                               hMappingInfo;
-#endif
 
 }PVRSRV_BRIDGE_IN_UNMAPMEMINFOFROMUSER;
 
@@ -573,13 +510,8 @@ typedef struct PVRSRV_BRIDGE_IN_UNMAPMEMINFOFROMUSER_TAG
 typedef struct PVRSRV_BRIDGE_IN_FREEDEVICEMEM_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-       IMG_SID                 hKernelMemInfo;
-#else
        IMG_HANDLE                              hDevCookie;
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
 
 }PVRSRV_BRIDGE_IN_FREEDEVICEMEM;
@@ -590,32 +522,27 @@ typedef struct PVRSRV_BRIDGE_IN_FREEDEVICEMEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_EXPORTDEVICEMEM_TAG
 {
        IMG_UINT32      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hDevCookie;
-       IMG_SID         hKernelMemInfo;
-#else
        IMG_HANDLE                              hDevCookie;
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
 
 }PVRSRV_BRIDGE_IN_EXPORTDEVICEMEM;
 
 /******************************************************************************
  *     'bridge in' map ion handle
  *****************************************************************************/
+#define ION_IMPORT_MAX_FDS 3
+#define ION_IMPORT_MAX_CHUNK_COUNT 3
 typedef struct _PVRSRV_BRIDGE_IN_MAP_ION_HANDLE_
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-       IMG_HANDLE                      handle;
+       IMG_UINT32                      ui32NumFDs;
+       IMG_INT32                       ai32BufferFDs[ION_IMPORT_MAX_FDS];
        IMG_UINT32                      ui32Attribs;
-       IMG_SIZE_T                      ui32Size;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hDevMemContext;
-#else
+       IMG_UINT32                      ui32ChunkCount;
+       IMG_SIZE_T                      auiOffset[ION_IMPORT_MAX_CHUNK_COUNT];
+       IMG_SIZE_T                      auiSize[ION_IMPORT_MAX_CHUNK_COUNT];
        IMG_HANDLE                      hDevCookie;
-       IMG_HANDLE                      hDevMemContext;
-#endif
+       IMG_HANDLE                      hDevMemHeap;
 } PVRSRV_BRIDGE_IN_MAP_ION_HANDLE;
 
 /******************************************************************************
@@ -624,11 +551,7 @@ typedef struct _PVRSRV_BRIDGE_IN_MAP_ION_HANDLE_
 typedef struct PVRSRV_BRIDGE_IN_UNMAP_ION_HANDLE_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
 }PVRSRV_BRIDGE_IN_UNMAP_ION_HANDLE;
 
 /******************************************************************************
@@ -647,12 +570,8 @@ typedef struct PVRSRV_BRIDGE_IN_GETFREEDEVICEMEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_CREATECOMMANDQUEUE_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
-       IMG_SIZE_T                      ui32QueueSize;
+       IMG_SIZE_T                      uQueueSize;
 
 }PVRSRV_BRIDGE_IN_CREATECOMMANDQUEUE;
 
@@ -663,11 +582,7 @@ typedef struct PVRSRV_BRIDGE_IN_CREATECOMMANDQUEUE_TAG
 typedef struct PVRSRV_BRIDGE_IN_DESTROYCOMMANDQUEUE_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
        PVRSRV_QUEUE_INFO       *psQueueInfo;
 
 }PVRSRV_BRIDGE_IN_DESTROYCOMMANDQUEUE;
@@ -679,11 +594,7 @@ typedef struct PVRSRV_BRIDGE_IN_DESTROYCOMMANDQUEUE_TAG
 typedef struct PVRSRV_BRIDGE_IN_MHANDLE_TO_MMAP_DATA_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hMHandle;        /* Handle associated with the memory that needs to be mapped */
-#else
        IMG_HANDLE                      hMHandle;        /* Handle associated with the memory that needs to be mapped */
-#endif
 } PVRSRV_BRIDGE_IN_MHANDLE_TO_MMAP_DATA;
 
 
@@ -693,11 +604,7 @@ typedef struct PVRSRV_BRIDGE_IN_MHANDLE_TO_MMAP_DATA_TAG
 typedef struct PVRSRV_BRIDGE_IN_RELEASE_MMAP_DATA_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hMHandle;        /* Handle associated with the memory that needs to be mapped */
-#else
        IMG_HANDLE                      hMHandle;        /* Handle associated with the memory that needs to be mapped */
-#endif
 } PVRSRV_BRIDGE_IN_RELEASE_MMAP_DATA;
 
 
@@ -707,14 +614,10 @@ typedef struct PVRSRV_BRIDGE_IN_RELEASE_MMAP_DATA_TAG
 typedef struct PVRSRV_BRIDGE_IN_RESERVE_DEV_VIRTMEM_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevMemHeap;
-#else
        IMG_HANDLE                      hDevMemHeap;
-#endif
        IMG_DEV_VIRTADDR        *psDevVAddr;
-       IMG_SIZE_T                      ui32Size;
-       IMG_SIZE_T                      ui32Alignment;
+       IMG_SIZE_T                      uSize;
+       IMG_SIZE_T                      uAlignment;
 
 }PVRSRV_BRIDGE_IN_RESERVE_DEV_VIRTMEM;
 
@@ -724,11 +627,7 @@ typedef struct PVRSRV_BRIDGE_IN_RESERVE_DEV_VIRTMEM_TAG
 typedef struct PVRSRV_BRIDGE_OUT_CONNECT_SERVICES_TAG
 {
        PVRSRV_ERROR    eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelServices;
-#else
        IMG_HANDLE              hKernelServices;
-#endif
 }PVRSRV_BRIDGE_OUT_CONNECT_SERVICES;
 
 /******************************************************************************
@@ -737,13 +636,8 @@ typedef struct PVRSRV_BRIDGE_OUT_CONNECT_SERVICES_TAG
 typedef struct PVRSRV_BRIDGE_OUT_RESERVE_DEV_VIRTMEM_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-       IMG_SID                 hKernelSyncInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
        PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
 
@@ -756,11 +650,7 @@ typedef struct PVRSRV_BRIDGE_OUT_RESERVE_DEV_VIRTMEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_FREE_DEV_VIRTMEM_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
 
@@ -773,13 +663,8 @@ typedef struct PVRSRV_BRIDGE_IN_FREE_DEV_VIRTMEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hKernelMemInfo;
-       IMG_SID                                 hDstDevMemHeap;
-#else
        IMG_HANDLE                              hKernelMemInfo;
        IMG_HANDLE                              hDstDevMemHeap;
-#endif
 
 }PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY;
 
@@ -790,11 +675,7 @@ typedef struct PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_OUT_MAP_DEV_MEMORY_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDstKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psDstKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sDstClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sDstClientSyncInfo;
 
@@ -807,11 +688,7 @@ typedef struct PVRSRV_BRIDGE_OUT_MAP_DEV_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_IN_UNMAP_DEV_MEMORY_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO          *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
 
@@ -824,11 +701,7 @@ typedef struct PVRSRV_BRIDGE_IN_UNMAP_DEV_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_IN_MAP_EXT_MEMORY_TAG
 {
        IMG_UINT32       ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID          hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        IMG_SYS_PHYADDR *psSysPAddr;
        IMG_UINT32       ui32Flags;
 
@@ -852,13 +725,8 @@ typedef struct PVRSRV_BRIDGE_IN_UNMAP_EXT_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_IN_MAP_DEVICECLASS_MEMORY_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDeviceClassBuffer;
-       IMG_SID                 hDevMemContext;
-#else
        IMG_HANDLE              hDeviceClassBuffer;
        IMG_HANDLE              hDevMemContext;
-#endif
 
 }PVRSRV_BRIDGE_IN_MAP_DEVICECLASS_MEMORY;
 
@@ -871,13 +739,8 @@ typedef struct PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY_TAG
        PVRSRV_ERROR            eError;
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-       IMG_SID                 hMappingInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
        IMG_HANDLE                              hMappingInfo;
-#endif
 
 }PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY;
 
@@ -888,11 +751,7 @@ typedef struct PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_IN_UNMAP_DEVICECLASS_MEMORY_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
 
@@ -905,11 +764,7 @@ typedef struct PVRSRV_BRIDGE_IN_UNMAP_DEVICECLASS_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_MEMPOL_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        IMG_UINT32 ui32Offset;
        IMG_UINT32 ui32Value;
        IMG_UINT32 ui32Mask;
@@ -924,11 +779,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_MEMPOL_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_SYNCPOL_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo;
-#endif
        IMG_BOOL   bIsRead;
        IMG_BOOL   bUseLastOpDumpVal;
        IMG_UINT32 ui32Value;
@@ -945,11 +796,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPMEM_TAG
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
        IMG_PVOID  pvLinAddr;
        IMG_PVOID  pvAltLinAddr;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        IMG_UINT32 ui32Offset;
        IMG_UINT32 ui32Bytes;
        IMG_UINT32 ui32Flags;
@@ -964,11 +811,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPSYNC_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
        IMG_PVOID  pvAltLinAddr;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo;
-#endif
        IMG_UINT32 ui32Offset;
        IMG_UINT32 ui32Bytes;
 
@@ -981,11 +824,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPSYNC_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPREG_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-#else
        IMG_HANDLE              hDevCookie;
-#endif
        PVRSRV_HWREG    sHWReg;
        IMG_UINT32              ui32Flags;
        IMG_CHAR                szRegRegion[32];
@@ -998,11 +837,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPREG_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_REGPOL_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        PVRSRV_HWREG sHWReg;
        IMG_UINT32 ui32Mask;
        IMG_UINT32 ui32Flags;
@@ -1026,13 +861,8 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPPDREG_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_MEMPAGES_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hKernelMemInfo;
-#else
        IMG_HANDLE                      hDevCookie;
        IMG_HANDLE                      hKernelMemInfo;
-#endif
        IMG_DEV_PHYADDR         *pPages;
        IMG_UINT32                      ui32NumPages;
        IMG_DEV_VIRTADDR        sDevVAddr;
@@ -1072,22 +902,14 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_SETFRAME_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_BITMAP_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_CHAR   szFileName[PVRSRV_PDUMP_MAX_FILENAME_SIZE];
        IMG_UINT32 ui32FileOffset;
        IMG_UINT32 ui32Width;
        IMG_UINT32 ui32Height;
        IMG_UINT32 ui32StrideInBytes;
        IMG_DEV_VIRTADDR sDevBaseAddr;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevMemContext;
-#else
        IMG_HANDLE hDevMemContext;
-#endif
        IMG_UINT32 ui32Size;
        PDUMP_PIXEL_FORMAT ePixelFormat;
        PDUMP_MEM_FORMAT eMemFormat;
@@ -1102,11 +924,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_BITMAP_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_READREG_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_CHAR   szFileName[PVRSRV_PDUMP_MAX_FILENAME_SIZE];
        IMG_UINT32 ui32FileOffset;
        IMG_UINT32 ui32Address;
@@ -1130,11 +948,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DRIVERINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPPDDEVPADDR_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelMemInfo;
-#else
        IMG_HANDLE hKernelMemInfo;
-#endif
        IMG_UINT32 ui32Offset;
        IMG_DEV_PHYADDR sPDDevPAddr;
 }PVRSRV_BRIDGE_IN_PDUMP_DUMPPDDEVPADDR;
@@ -1145,11 +959,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_DUMPPDDEVPADDR_TAG
 typedef struct PVRSRV_BRIDGE_PDUM_IN_CYCLE_COUNT_REG_READ_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_UINT32 ui32RegOffset;
        IMG_BOOL bLastFrame;
 }PVRSRV_BRIDGE_IN_PDUMP_CYCLE_COUNT_REG_READ;
@@ -1177,11 +987,7 @@ typedef struct PVRSRV_BRIDGE_OUT_ACQUIRE_DEVICEINFO_TAG
 {
 
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
 
 } PVRSRV_BRIDGE_OUT_ACQUIRE_DEVICEINFO;
 
@@ -1205,11 +1011,7 @@ typedef struct PVRSRV_BRIDGE_IN_OPEN_DISPCLASS_DEVICE_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
        IMG_UINT32              ui32DeviceID;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-#else
        IMG_HANDLE              hDevCookie;
-#endif
 
 }PVRSRV_BRIDGE_IN_OPEN_DISPCLASS_DEVICE;
 
@@ -1219,11 +1021,7 @@ typedef struct PVRSRV_BRIDGE_IN_OPEN_DISPCLASS_DEVICE_TAG
 typedef struct PVRSRV_BRIDGE_OUT_OPEN_DISPCLASS_DEVICE_TAG
 {
        PVRSRV_ERROR    eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDeviceKM;
-#else
        IMG_HANDLE              hDeviceKM;
-#endif
 
 }PVRSRV_BRIDGE_OUT_OPEN_DISPCLASS_DEVICE;
 
@@ -1234,16 +1032,11 @@ typedef struct PVRSRV_BRIDGE_OUT_OPEN_DISPCLASS_DEVICE_TAG
 typedef struct PVRSRV_BRIDGE_IN_WRAP_EXT_MEMORY_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-       IMG_SID                                 hDevMemContext;
-#else
        IMG_HANDLE              hDevCookie;
        IMG_HANDLE                              hDevMemContext;
-#endif
        IMG_VOID                                *pvLinAddr;
-       IMG_SIZE_T              ui32ByteSize;
-       IMG_SIZE_T              ui32PageOffset;
+       IMG_SIZE_T              uByteSize;
+       IMG_SIZE_T              uPageOffset;
        IMG_BOOL                bPhysContig;
        IMG_UINT32                              ui32NumPageTableEntries;
        IMG_SYS_PHYADDR         *psSysPAddr;
@@ -1268,11 +1061,7 @@ typedef struct PVRSRV_BRIDGE_OUT_WRAP_EXT_MEMORY_TAG
 typedef struct PVRSRV_BRIDGE_IN_UNWRAP_EXT_MEMORY_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelMemInfo;
-#else
        IMG_HANDLE hKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
 
@@ -1302,11 +1091,7 @@ typedef struct PVRSRV_BRIDGE_OUT_ENUM_DISPCLASS_FORMATS_TAG
 typedef struct PVRSRV_BRIDGE_IN_ENUM_DISPCLASS_DIMS_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDeviceKM;
-#else
        IMG_HANDLE              hDeviceKM;
-#endif
        DISPLAY_FORMAT  sFormat;
 
 }PVRSRV_BRIDGE_IN_ENUM_DISPCLASS_DIMS;
@@ -1341,11 +1126,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GET_DISPCLASS_INFO_TAG
 typedef struct PVRSRV_BRIDGE_OUT_GET_DISPCLASS_SYSBUFFER_TAG
 {
        PVRSRV_ERROR    eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hBuffer;
-#else
        IMG_HANDLE              hBuffer;
-#endif
 
 }PVRSRV_BRIDGE_OUT_GET_DISPCLASS_SYSBUFFER;
 
@@ -1356,11 +1137,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GET_DISPCLASS_SYSBUFFER_TAG
 typedef struct PVRSRV_BRIDGE_IN_CREATE_DISPCLASS_SWAPCHAIN_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDeviceKM;
-#else
        IMG_HANDLE                              hDeviceKM;
-#endif
        IMG_UINT32                              ui32Flags;
        DISPLAY_SURF_ATTRIBUTES sDstSurfAttrib;
        DISPLAY_SURF_ATTRIBUTES sSrcSurfAttrib;
@@ -1377,11 +1154,7 @@ typedef struct PVRSRV_BRIDGE_IN_CREATE_DISPCLASS_SWAPCHAIN_TAG
 typedef struct PVRSRV_BRIDGE_OUT_CREATE_DISPCLASS_SWAPCHAIN_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hSwapChain;
-#endif
        IMG_UINT32                      ui32SwapChainID;
 
 } PVRSRV_BRIDGE_OUT_CREATE_DISPCLASS_SWAPCHAIN;
@@ -1393,13 +1166,8 @@ typedef struct PVRSRV_BRIDGE_OUT_CREATE_DISPCLASS_SWAPCHAIN_TAG
 typedef struct PVRSRV_BRIDGE_IN_DESTROY_DISPCLASS_SWAPCHAIN_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hSwapChain;
-#endif
 
 } PVRSRV_BRIDGE_IN_DESTROY_DISPCLASS_SWAPCHAIN;
 
@@ -1410,13 +1178,8 @@ typedef struct PVRSRV_BRIDGE_IN_DESTROY_DISPCLASS_SWAPCHAIN_TAG
 typedef struct PVRSRV_BRIDGE_IN_SET_DISPCLASS_RECT_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hSwapChain;
-#endif
        IMG_RECT                        sRect;
 
 } PVRSRV_BRIDGE_IN_SET_DISPCLASS_RECT;
@@ -1428,13 +1191,8 @@ typedef struct PVRSRV_BRIDGE_IN_SET_DISPCLASS_RECT_TAG
 typedef struct PVRSRV_BRIDGE_IN_SET_DISPCLASS_COLOURKEY_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hSwapChain;
-#endif
        IMG_UINT32                      ui32CKColour;
 
 } PVRSRV_BRIDGE_IN_SET_DISPCLASS_COLOURKEY;
@@ -1446,13 +1204,8 @@ typedef struct PVRSRV_BRIDGE_IN_SET_DISPCLASS_COLOURKEY_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_DISPCLASS_BUFFERS_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hSwapChain;
-#endif
 
 } PVRSRV_BRIDGE_IN_GET_DISPCLASS_BUFFERS;
 
@@ -1464,11 +1217,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GET_DISPCLASS_BUFFERS_TAG
 {
        PVRSRV_ERROR            eError;
        IMG_UINT32                      ui32BufferCount;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         ahBuffer[PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS];
-#else
        IMG_HANDLE                      ahBuffer[PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS];
-#endif
        IMG_SYS_PHYADDR         asPhyAddr[PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS];
 } PVRSRV_BRIDGE_OUT_GET_DISPCLASS_BUFFERS;
 
@@ -1479,37 +1228,24 @@ typedef struct PVRSRV_BRIDGE_OUT_GET_DISPCLASS_BUFFERS_TAG
 typedef struct PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_BUFFER_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hBuffer;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hBuffer;
-#endif
        IMG_UINT32                      ui32SwapInterval;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hPrivateTag;
-#else
        IMG_HANDLE                      hPrivateTag;
-#endif
        IMG_UINT32                      ui32ClipRectCount;
        IMG_RECT                        sClipRect[PVRSRV_MAX_DC_CLIP_RECTS];
 
 } PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_BUFFER;
 
+
 /******************************************************************************
- *     'bridge in' swap to buffer
+ *     'bridge in' swap to buffer 2
  *****************************************************************************/
 typedef struct PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_BUFFER2_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hSwapChain;
-#endif
        IMG_UINT32                      ui32SwapInterval;
 
        IMG_UINT32                      ui32NumMemInfos;
@@ -1521,19 +1257,26 @@ typedef struct PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_BUFFER2_TAG
 
 } PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_BUFFER2;
 
+
+/******************************************************************************
+ *     'bridge out' swap to buffer 2
+ *****************************************************************************/
+typedef struct PVRSRV_BRIDGE_OUT_SWAP_DISPCLASS_TO_BUFFER2_TAG
+{
+       PVRSRV_ERROR            eError;
+       IMG_HANDLE                      hFence;
+
+} PVRSRV_BRIDGE_OUT_SWAP_DISPCLASS_TO_BUFFER2;
+
+
 /******************************************************************************
  *     'bridge in' swap to system buffer (primary)
  *****************************************************************************/
 typedef struct PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_SYSTEM_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDeviceKM;
-       IMG_SID                         hSwapChain;
-#else
        IMG_HANDLE                      hDeviceKM;
        IMG_HANDLE                      hSwapChain;
-#endif
 
 } PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_SYSTEM;
 
@@ -1545,11 +1288,7 @@ typedef struct PVRSRV_BRIDGE_IN_OPEN_BUFFERCLASS_DEVICE_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
        IMG_UINT32                      ui32DeviceID;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
 
 } PVRSRV_BRIDGE_IN_OPEN_BUFFERCLASS_DEVICE;
 
@@ -1560,11 +1299,7 @@ typedef struct PVRSRV_BRIDGE_IN_OPEN_BUFFERCLASS_DEVICE_TAG
 typedef struct PVRSRV_BRIDGE_OUT_OPEN_BUFFERCLASS_DEVICE_TAG
 {
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID      hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
 
 } PVRSRV_BRIDGE_OUT_OPEN_BUFFERCLASS_DEVICE;
 
@@ -1586,11 +1321,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GET_BUFFERCLASS_INFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_BUFFERCLASS_BUFFER_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDeviceKM;
-#else
        IMG_HANDLE                      hDeviceKM;
-#endif
        IMG_UINT32 ui32BufferIndex;
 
 } PVRSRV_BRIDGE_IN_GET_BUFFERCLASS_BUFFER;
@@ -1602,11 +1333,7 @@ typedef struct PVRSRV_BRIDGE_IN_GET_BUFFERCLASS_BUFFER_TAG
 typedef struct PVRSRV_BRIDGE_OUT_GET_BUFFERCLASS_BUFFER_TAG
 {
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID      hBuffer;
-#else
        IMG_HANDLE                      hBuffer;
-#endif
 
 } PVRSRV_BRIDGE_OUT_GET_BUFFERCLASS_BUFFER;
 
@@ -1629,11 +1356,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GET_DEVMEM_HEAPINFO_TAG
 typedef struct PVRSRV_BRIDGE_OUT_CREATE_DEVMEMCONTEXT_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevMemContext;
-#else
        IMG_HANDLE                      hDevMemContext;
-#endif
        IMG_UINT32                      ui32ClientHeapCount;
        PVRSRV_HEAP_INFO        sHeapInfo[PVRSRV_MAX_CLIENT_HEAPS];
 
@@ -1646,11 +1369,7 @@ typedef struct PVRSRV_BRIDGE_OUT_CREATE_DEVMEMCONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_OUT_CREATE_DEVMEMHEAP_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevMemHeap;
-#else
        IMG_HANDLE                      hDevMemHeap;
-#endif
 
 } PVRSRV_BRIDGE_OUT_CREATE_DEVMEMHEAP;
 
@@ -1661,11 +1380,7 @@ typedef struct PVRSRV_BRIDGE_OUT_CREATE_DEVMEMHEAP_TAG
 typedef struct PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
 
@@ -1678,11 +1393,7 @@ typedef struct PVRSRV_BRIDGE_OUT_ALLOCDEVICEMEM_TAG
 typedef struct PVRSRV_BRIDGE_OUT_EXPORTDEVICEMEM_TAG
 {
        PVRSRV_ERROR                    eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hMemInfo;
-#else
        IMG_HANDLE                              hMemInfo;
-#endif
 #if defined(SUPPORT_MEMINFO_IDS)
        IMG_UINT64                              ui64Stamp;
 #endif
@@ -1696,13 +1407,10 @@ typedef struct PVRSRV_BRIDGE_OUT_EXPORTDEVICEMEM_TAG
 typedef struct _PVRSRV_BRIDGE_OUT_MAP_ION_HANDLE_
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
+       IMG_SIZE_T                              uiIonBufferSize;
 
 } PVRSRV_BRIDGE_OUT_MAP_ION_HANDLE;
 
@@ -1714,11 +1422,7 @@ typedef struct PVRSRV_BRIDGE_OUT_MAPMEMINFOTOUSER_TAG
 {
        PVRSRV_ERROR                    eError;
        IMG_PVOID                               pvLinAddr;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hMappingInfo;
-#else
        IMG_HANDLE                              hMappingInfo;
-#endif
 
 }PVRSRV_BRIDGE_OUT_MAPMEMINFOTOUSER;
 
@@ -1729,9 +1433,9 @@ typedef struct PVRSRV_BRIDGE_OUT_MAPMEMINFOTOUSER_TAG
 typedef struct PVRSRV_BRIDGE_OUT_GETFREEDEVICEMEM_TAG
 {
        PVRSRV_ERROR eError;
-       IMG_SIZE_T ui32Total;
-       IMG_SIZE_T ui32Free;
-       IMG_SIZE_T ui32LargestBlock;
+       IMG_SIZE_T uTotal;
+       IMG_SIZE_T uFree;
+       IMG_SIZE_T uLargestBlock;
 
 } PVRSRV_BRIDGE_OUT_GETFREEDEVICEMEM;
 
@@ -1748,18 +1452,18 @@ typedef struct PVRSRV_BRIDGE_OUT_MHANDLE_TO_MMAP_DATA_TAG
     /* This is a the offset you should pass to mmap(2) so that
      * the driver can look up the full details for the mapping
      * request. */
-     IMG_UINT32                        ui32MMapOffset;
+     IMG_UINTPTR_T             uiMMapOffset;
 
     /* This is the byte offset you should add to the mapping you
      * get from mmap */
-    IMG_UINT32                 ui32ByteOffset;
+    IMG_UINTPTR_T              uiByteOffset;
 
     /* This is the real size of the mapping that will be created
      * which should be passed to mmap _and_ munmap. */
-    IMG_UINT32                         ui32RealByteSize;
+    IMG_SIZE_T                         uiRealByteSize;
 
     /* User mode address associated with mapping */
-    IMG_UINT32                 ui32UserVAddr;
+    IMG_UINTPTR_T       uiUserVAddr;
 
 } PVRSRV_BRIDGE_OUT_MHANDLE_TO_MMAP_DATA;
 
@@ -1771,10 +1475,10 @@ typedef struct PVRSRV_BRIDGE_OUT_RELEASE_MMAP_DATA_TAG
     IMG_BOOL                   bMUnmap;
 
     /* User mode address associated with mapping */
-    IMG_UINT32                 ui32UserVAddr;
+    IMG_UINTPTR_T              uiUserVAddr;
 
     /* Size of mapping */
-    IMG_UINT32                 ui32RealByteSize;
+    IMG_SIZE_T                 uiRealByteSize;
 } PVRSRV_BRIDGE_OUT_RELEASE_MMAP_DATA;
 //#endif
 
@@ -1840,8 +1544,8 @@ typedef struct PVRSRV_BRIDGE_OUT_PDUMP_ISCAPTURING_TAG
 typedef struct PVRSRV_BRIDGE_IN_GET_FB_STATS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-       IMG_SIZE_T ui32Total;
-       IMG_SIZE_T ui32Available;
+       IMG_SIZE_T uTotal;
+       IMG_SIZE_T uAvailable;
 
 } PVRSRV_BRIDGE_IN_GET_FB_STATS;
 
@@ -1852,11 +1556,7 @@ typedef struct PVRSRV_BRIDGE_IN_GET_FB_STATS_TAG
 typedef struct PVRSRV_BRIDGE_IN_MAPPHYSTOUSERSPACE_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
        IMG_SYS_PHYADDR         sSysPhysAddr;
        IMG_UINT32                      uiSizeInBytes;
 
@@ -1881,11 +1581,7 @@ typedef struct PVRSRV_BRIDGE_OUT_MAPPHYSTOUSERSPACE_TAG
 typedef struct PVRSRV_BRIDGE_IN_UNMAPPHYSTOUSERSPACE_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
        IMG_PVOID                       pvUserAddr;
        IMG_PVOID                       pvProcess;
 
@@ -1903,7 +1599,6 @@ typedef struct PVRSRV_BRIDGE_OUT_GETPHYSTOUSERSPACEMAP_TAG
 } PVRSRV_BRIDGE_OUT_GETPHYSTOUSERSPACEMAP;
 
 
-#if !defined (SUPPORT_SID_INTERFACE)
 /******************************************************************************
  *     'bridge in' Register RTSIM process thread
  *****************************************************************************/
@@ -1953,7 +1648,6 @@ typedef struct PVRSRV_BRIDGE_IN_PROCESS_SIMISR_EVENT_TAG
        PVRSRV_ERROR            eError;
 
 } PVRSRV_BRIDGE_IN_PROCESS_SIMISR_EVENT;
-#endif /* #if !defined (SUPPORT_SID_INTERFACE) */
 
 /******************************************************************************
  *     'bridge in' initialisation server disconnect
@@ -1969,28 +1663,20 @@ typedef struct PVRSRV_BRIDGE_IN_ALLOC_SHARED_SYS_MEM_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
     IMG_UINT32 ui32Flags;
-    IMG_SIZE_T ui32Size;
+    IMG_SIZE_T uSize;
 }PVRSRV_BRIDGE_IN_ALLOC_SHARED_SYS_MEM;
 
 typedef struct PVRSRV_BRIDGE_OUT_ALLOC_SHARED_SYS_MEM_TAG
 {
        PVRSRV_ERROR            eError;
-#if defined (SUPPORT_SID_INTERFACE)
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
 }PVRSRV_BRIDGE_OUT_ALLOC_SHARED_SYS_MEM;
 
 typedef struct PVRSRV_BRIDGE_IN_FREE_SHARED_SYS_MEM_TAG
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-       IMG_SID                 hMappingInfo;
-#else
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
 }PVRSRV_BRIDGE_IN_FREE_SHARED_SYS_MEM;
 
@@ -2002,22 +1688,14 @@ typedef struct PVRSRV_BRIDGE_OUT_FREE_SHARED_SYS_MEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_MAP_MEMINFO_MEM_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelMemInfo;
-#else
        IMG_HANDLE hKernelMemInfo;
-#endif
 }PVRSRV_BRIDGE_IN_MAP_MEMINFO_MEM;
 
 typedef struct PVRSRV_BRIDGE_OUT_MAP_MEMINFO_MEM_TAG
 {
        PVRSRV_CLIENT_MEM_INFO  sClientMemInfo;
        PVRSRV_CLIENT_SYNC_INFO sClientSyncInfo;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hKernelMemInfo;
-#else
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
-#endif
        PVRSRV_ERROR eError;
 }PVRSRV_BRIDGE_OUT_MAP_MEMINFO_MEM;
 
@@ -2035,11 +1713,7 @@ typedef struct PVRSRV_BRIDGE_OUT_UNMAP_MEMINFO_MEM_TAG
 typedef struct PVRSRV_BRIDGE_IN_EVENT_OBJECT_WAI_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hOSEventKM;
-#else
        IMG_HANDLE      hOSEventKM;
-#endif
 } PVRSRV_BRIDGE_IN_EVENT_OBJECT_WAIT;
 
 typedef struct PVRSRV_BRIDGE_IN_EVENT_OBJECT_OPEN_TAG
@@ -2049,56 +1723,35 @@ typedef struct PVRSRV_BRIDGE_IN_EVENT_OBJECT_OPEN_TAG
 
 typedef struct PVRSRV_BRIDGE_OUT_EVENT_OBJECT_OPEN_TAG
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_UINT32   hOSEvent;
-#else
        IMG_HANDLE hOSEvent;
-#endif
        PVRSRV_ERROR eError;
 } PVRSRV_BRIDGE_OUT_EVENT_OBJECT_OPEN;
 
 typedef struct PVRSRV_BRIDGE_IN_EVENT_OBJECT_CLOSE_TAG
 {
        PVRSRV_EVENTOBJECT sEventObject;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hOSEventKM;
-#else
        IMG_HANDLE hOSEventKM;
-#endif
 } PVRSRV_BRIDGE_IN_EVENT_OBJECT_CLOSE;
 
 typedef struct PVRSRV_BRIDGE_OUT_CREATE_SYNC_INFO_MOD_OBJ_TAG
 {
        PVRSRV_ERROR eError;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfoModObj;
-#else
        IMG_HANDLE hKernelSyncInfoModObj;
-#endif
 
 } PVRSRV_BRIDGE_OUT_CREATE_SYNC_INFO_MOD_OBJ;
 
 typedef struct PVRSRV_BRIDGE_IN_DESTROY_SYNC_INFO_MOD_OBJ
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfoModObj;
-#else
        IMG_HANDLE hKernelSyncInfoModObj;
-#endif
 } PVRSRV_BRIDGE_IN_DESTROY_SYNC_INFO_MOD_OBJ;
 
 typedef struct PVRSRV_BRIDGE_IN_MODIFY_PENDING_SYNC_OPS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfoModObj;
-       IMG_SID    hKernelSyncInfo;
-#else
        IMG_HANDLE hKernelSyncInfoModObj;
        IMG_HANDLE hKernelSyncInfo;
-#endif
        IMG_UINT32 ui32ModifyFlags;
 
 } PVRSRV_BRIDGE_IN_MODIFY_PENDING_SYNC_OPS;
@@ -2106,11 +1759,7 @@ typedef struct PVRSRV_BRIDGE_IN_MODIFY_PENDING_SYNC_OPS_TAG
 typedef struct PVRSRV_BRIDGE_IN_MODIFY_COMPLETE_SYNC_OPS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfoModObj;
-#else
        IMG_HANDLE hKernelSyncInfoModObj;
-#endif
 } PVRSRV_BRIDGE_IN_MODIFY_COMPLETE_SYNC_OPS;
 
 typedef struct PVRSRV_BRIDGE_OUT_MODIFY_PENDING_SYNC_OPS_TAG
@@ -2127,11 +1776,7 @@ typedef struct PVRSRV_BRIDGE_OUT_MODIFY_PENDING_SYNC_OPS_TAG
 typedef struct PVRSRV_BRIDGE_IN_SYNC_OPS_TAKE_TOKEN_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        IMG_HANDLE hKernelSyncInfo;
-#endif
 
 } PVRSRV_BRIDGE_IN_SYNC_OPS_TAKE_TOKEN;
 
@@ -2148,11 +1793,7 @@ typedef struct PVRSRV_BRIDGE_OUT_SYNC_OPS_TAKE_TOKEN_TAG
 typedef struct PVRSRV_BRIDGE_IN_SYNC_OPS_FLUSH_TO_TOKEN_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        IMG_HANDLE hKernelSyncInfo;
-#endif
        IMG_UINT32 ui32ReadOpsPendingSnapshot;
        IMG_UINT32 ui32WriteOpsPendingSnapshot;
        IMG_UINT32 ui32ReadOps2PendingSnapshot;
@@ -2161,21 +1802,13 @@ typedef struct PVRSRV_BRIDGE_IN_SYNC_OPS_FLUSH_TO_TOKEN_TAG
 typedef struct PVRSRV_BRIDGE_IN_SYNC_OPS_FLUSH_TO_MOD_OBJ_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfoModObj;
-#else
        IMG_HANDLE hKernelSyncInfoModObj;
-#endif
 } PVRSRV_BRIDGE_IN_SYNC_OPS_FLUSH_TO_MOD_OBJ;
 
 typedef struct PVRSRV_BRIDGE_IN_SYNC_OPS_FLUSH_TO_DELTA_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        IMG_HANDLE hKernelSyncInfo;
-#endif
        IMG_UINT32 ui32Delta;
 } PVRSRV_BRIDGE_IN_SYNC_OPS_FLUSH_TO_DELTA;
 
@@ -2183,33 +1816,21 @@ typedef struct PVRSRV_BRIDGE_IN_ALLOC_SYNC_INFO_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
 } PVRSRV_BRIDGE_IN_ALLOC_SYNC_INFO;
 
 typedef struct PVRSRV_BRIDGE_OUT_ALLOC_SYNC_INFO_TAG
 {
        PVRSRV_ERROR eError;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        IMG_HANDLE hKernelSyncInfo;
-#endif
 } PVRSRV_BRIDGE_OUT_ALLOC_SYNC_INFO;
 
 typedef struct PVRSRV_BRIDGE_IN_FREE_SYNC_INFO_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hKernelSyncInfo;
-#else
        IMG_HANDLE hKernelSyncInfo;
-#endif
 } PVRSRV_BRIDGE_IN_FREE_SYNC_INFO;
 
 typedef struct PVRSRV_BRIDGE_IN_CHG_DEV_MEM_ATTRIBS_TAG
index 3a1cac8..351c939 100644 (file)
@@ -56,6 +56,11 @@ extern "C" {
 #if defined(__linux__)
 PVRSRV_ERROR LinuxBridgeInit(IMG_VOID);
 IMG_VOID LinuxBridgeDeInit(IMG_VOID);
+
+#if defined(SUPPORT_MEMINFO_IDS)
+extern IMG_UINT64 g_ui64MemInfoID;
+#endif
+
 #endif
 
 IMG_IMPORT
@@ -68,7 +73,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVAcquireDeviceDataKM(IMG_UINT32                        uiDevIndex,
                                                                                                        IMG_HANDLE                      *phDevCookie);
                                                        
 IMG_IMPORT
-PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T ui32QueueSize,
+PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T uQueueSize,
                                                                                                         PVRSRV_QUEUE_INFO **ppsQueueInfo);
 
 IMG_IMPORT
@@ -76,22 +81,14 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyCommandQueueKM(PVRSRV_QUEUE_INFO *psQueue
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapsKM(IMG_HANDLE hDevCookie,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                       PVRSRV_HEAP_INFO_KM *psHeapInfo);
-#else
                                                                                                        PVRSRV_HEAP_INFO *psHeapInfo);
-#endif
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDeviceMemContextKM(IMG_HANDLE                                    hDevCookie,
                                                                                                                 PVRSRV_PER_PROCESS_DATA        *psPerProc,
                                                                                                                 IMG_HANDLE                                     *phDevMemContext,
                                                                                                                 IMG_UINT32                                     *pui32ClientHeapCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                                PVRSRV_HEAP_INFO_KM            *psHeapInfo,
-#else
                                                                                                                 PVRSRV_HEAP_INFO                       *psHeapInfo,
-#endif
                                                                                                                 IMG_BOOL                                       *pbCreated,
                                                                                                                 IMG_BOOL                                       *pbShared);
 
@@ -106,11 +103,7 @@ IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfoKM(IMG_HANDLE                              hDevCookie,
                                                                                                                        IMG_HANDLE                      hDevMemContext,
                                                                                                                        IMG_UINT32                      *pui32ClientHeapCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                                       PVRSRV_HEAP_INFO_KM     *psHeapInfo,
-#else
                                                                                                                        PVRSRV_HEAP_INFO        *psHeapInfo,
-#endif
                                                                                                                        IMG_BOOL                        *pbShared
                                        );
 
@@ -154,11 +147,16 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVFreeDeviceMemKM(IMG_HANDLE                        hDevCookie,
 IMG_IMPORT
 PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
                                                                  IMG_HANDLE hDevCookie,
-                                                                 IMG_HANDLE hDevMemContext,
-                                                                 IMG_HANDLE hIon,
+                                                                 IMG_HANDLE hDevMemHeap,
+                                                                 IMG_UINT32 ui32NumFDs,
+                                                                 IMG_INT32  *pai32BufferFDs,
                                                                  IMG_UINT32 ui32Flags,
-                                                                 IMG_UINT32 ui32Size,
-                                                                 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo);
+                                                                 IMG_UINT32 ui32ChunkCount,
+                                                                 IMG_SIZE_T *pauiOffset,
+                                                                 IMG_SIZE_T *pauiSize,
+                                                                 IMG_SIZE_T *puiIonBufferSize,
+                                                                 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo,
+                                                                 IMG_UINT64 *pui64Stamp);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapIonHandleKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo);
@@ -283,7 +281,8 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE     hDeviceKM,
                                                                         PVRSRV_KERNEL_SYNC_INFO **ppsSyncInfos,
                                                                         IMG_UINT32     ui32NumMemSyncInfos,
                                                                         IMG_PVOID      pvPrivData,
-                                                                        IMG_UINT32     ui32PrivDataLength);
+                                                                        IMG_UINT32     ui32PrivDataLength,
+                                                                        IMG_HANDLE     *phFence);
 IMG_IMPORT
 PVRSRV_ERROR PVRSRVSwapToDCSystemKM(IMG_HANDLE hDeviceKM,
                                                                        IMG_HANDLE      hSwapChain);
@@ -334,11 +333,7 @@ IMG_IMPORT
 IMG_VOID IMG_CALLCONV PVRSRVReleaseSyncInfoKM(PVRSRV_KERNEL_SYNC_INFO  *psKernelSyncInfo);
 
 IMG_IMPORT
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO_KM *psMiscInfo);
-#else
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo);
-#endif
 
 /*!
  * *****************************************************************************
index 1a3930c..c18c872 100644 (file)
@@ -54,11 +54,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  @return               PVRSRV_OK, or error code.
  ***************************************************************************/
 
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRPMapKMem(IMG_HANDLE hModule, IMG_VOID **ppvLinAddr, IMG_VOID *pvLinAddrKM, IMG_SID *phMappingInfo, IMG_SID hMHandle);
-#else
 PVRSRV_ERROR PVRPMapKMem(IMG_HANDLE hModule, IMG_VOID **ppvLinAddr, IMG_VOID *pvLinAddrKM, IMG_HANDLE *phMappingInfo, IMG_HANDLE hMHandle);
-#endif
 
 
 /*!
@@ -71,11 +67,7 @@ PVRSRV_ERROR PVRPMapKMem(IMG_HANDLE hModule, IMG_VOID **ppvLinAddr, IMG_VOID *pv
 
  @return       IMG_BOOL indicating success or otherwise.
  ***************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_BOOL PVRUnMapKMem(IMG_HANDLE hModule, IMG_SID hMappingInfo, IMG_SID hMHandle);
-#else
 IMG_BOOL PVRUnMapKMem(IMG_HANDLE hModule, IMG_HANDLE hMappingInfo, IMG_HANDLE hMHandle);
-#endif
 
 #endif /* _PVRMMAP_H_ */
 
index cce0199..9ff980f 100644 (file)
@@ -131,6 +131,8 @@ typedef struct _PVRSRV_KERNEL_MEM_INFO_
        /* ptr to associated kernel sync info - NULL if no sync */
        struct _PVRSRV_KERNEL_SYNC_INFO_        *psKernelSyncInfo;
 
+       IMG_HANDLE                              hIonSyncInfo;
+
        PVRSRV_MEMTYPE                          memType;
 
     /*
@@ -247,6 +249,11 @@ typedef struct _PVRSRV_COMMAND
                                                        allocated on back of this structure, i.e. is resident in Q */
        PFN_QUEUE_COMMAND_COMPLETE  pfnCommandComplete; /*!< Command complete callback */
        IMG_HANDLE                                      hCallbackData;          /*!< Command complete callback data */
+
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       IMG_VOID                        *pvCleanupFence;        /*!< Sync fence to 'put' after timeline inc() */
+       IMG_VOID                        *pvTimeline;            /*!< Android sync timeline to inc() */
+#endif
 }PVRSRV_COMMAND, *PPVRSRV_COMMAND;
 
 
@@ -282,10 +289,10 @@ typedef struct _PVRSRV_QUEUE_INFO_
        IMG_VOID                        *pvLinQueueUM;                  /*!< Pointer to the command buffer in the user's
                                                                                                 address space */
 
-       volatile IMG_SIZE_T     ui32ReadOffset;                 /*!< Index into the buffer at which commands are being
+       volatile IMG_SIZE_T     uReadOffset;                    /*!< Index into the buffer at which commands are being
                                                                                                         consumed */
 
-       volatile IMG_SIZE_T     ui32WriteOffset;                /*!< Index into the buffer at which commands are being
+       volatile IMG_SIZE_T     uWriteOffset;                   /*!< Index into the buffer at which commands are being
                                                                                                         added */
 
        IMG_UINT32                      *pui32KickerAddrKM;             /*!< kicker address in the kernel's
@@ -294,12 +301,17 @@ typedef struct _PVRSRV_QUEUE_INFO_
        IMG_UINT32                      *pui32KickerAddrUM;             /*!< kicker address in the user's
                                                                                                 address space */
 
-       IMG_SIZE_T                      ui32QueueSize;                  /*!< Size in bytes of the buffer - excluding the safety allocation */
+       IMG_SIZE_T                      uQueueSize;                             /*!< Size in bytes of the buffer - excluding the safety allocation */
 
        IMG_UINT32                      ui32ProcessID;                  /*!< Process ID required by resource locking */
 
        IMG_HANDLE                      hMemBlock[2];
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       IMG_UINT32                      ui32FenceValue;                 /*!< 'Target' timeline value when fence signals */
+       IMG_VOID                        *pvTimeline;                    /*!< Android struct sync_timeline object */
+#endif
+
        struct _PVRSRV_QUEUE_INFO_ *psNextKM;           /*!< The next queue in the system */
 }PVRSRV_QUEUE_INFO;
 
@@ -428,11 +440,7 @@ typedef struct PVRSRV_DEVICECLASS_BUFFER_TAG
 */
 typedef struct PVRSRV_CLIENT_DEVICECLASS_INFO_TAG
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID     hDeviceKM;
-#else
        IMG_HANDLE hDeviceKM;
-#endif
        IMG_HANDLE      hServices;
 } PVRSRV_CLIENT_DEVICECLASS_INFO;
 
@@ -476,7 +484,7 @@ PVRSRV_ERROR PVRSRVQueueCommand(IMG_HANDLE hQueueInfo,
 IMG_IMPORT PVRSRV_ERROR IMG_CALLCONV
 PVRSRVAllocSharedSysMem(const PVRSRV_CONNECTION *psConnection,
                                                IMG_UINT32 ui32Flags,
-                                               IMG_SIZE_T ui32Size,
+                                               IMG_SIZE_T uSize,
                                                PVRSRV_CLIENT_MEM_INFO **ppsClientMemInfo);
 
 /*!
@@ -532,11 +540,7 @@ PVRSRVUnrefSharedSysMem(const PVRSRV_CONNECTION *psConnection,
  ********************************************************************************/
 IMG_IMPORT PVRSRV_ERROR IMG_CALLCONV
 PVRSRVMapMemInfoMem(const PVRSRV_CONNECTION *psConnection,
-#if defined (SUPPORT_SID_INTERFACE)
-                    IMG_SID hKernelMemInfo,
-#else
                     IMG_HANDLE hKernelMemInfo,
-#endif
                     PVRSRV_CLIENT_MEM_INFO **ppsClientMemInfo);
 
 
index 33b27e3..ab1593f 100644 (file)
@@ -43,11 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #if !defined(__SGX_BRIDGE_H__)
 #define __SGX_BRIDGE_H__
 
-#if defined (SUPPORT_SID_INTERFACE)
-#include "sgxapi.h"
-#else
 #include "sgxapi_km.h"
-#endif
 #include "sgxinfo.h"
 #include "pvr_bridge.h"
 
@@ -150,13 +146,8 @@ typedef struct PVRSRV_BRIDGE_OUT_GETPHYSPAGEADDR
 typedef struct PVRSRV_BRIDGE_IN_SGX_SET_TRANSFER_CONTEXT_PRIORITY_TAG
  {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
- #if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-       IMG_SID                                 hHWTransferContext;
- #else
        IMG_HANDLE                              hDevCookie;
        IMG_HANDLE                              hHWTransferContext;
- #endif
     IMG_UINT32              ui32Priority;
     IMG_UINT32              ui32OffsetOfPriorityField;
 }PVRSRV_BRIDGE_IN_SGX_SET_TRANSFER_CONTEXT_PRIORITY;
@@ -168,13 +159,8 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_SET_TRANSFER_CONTEXT_PRIORITY_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGX_SET_RENDER_CONTEXT_PRIORITY_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-       IMG_SID                                 hHWRenderContext;
-#else
        IMG_HANDLE                              hDevCookie;
        IMG_HANDLE                              hHWRenderContext;
-#endif
     IMG_UINT32              ui32Priority;
     IMG_UINT32              ui32OffsetOfPriorityField;
 }PVRSRV_BRIDGE_IN_SGX_SET_RENDER_CONTEXT_PRIORITY;
@@ -186,11 +172,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_SET_RENDER_CONTEXT_PRIORITY_TAG
 typedef struct PVRSRV_BRIDGE_IN_GETCLIENTINFO_TAG
 {
        IMG_UINT32                                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                         hDevCookie;
-#else
        IMG_HANDLE                                      hDevCookie;
-#endif
 }PVRSRV_BRIDGE_IN_GETCLIENTINFO;
 
 /*!
@@ -210,11 +192,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GETINTERNALDEVINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_GETINTERNALDEVINFO_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
 }PVRSRV_BRIDGE_IN_GETINTERNALDEVINFO;
 
 /*!
@@ -234,11 +212,7 @@ typedef struct PVRSRV_BRIDGE_OUT_GETCLIENTINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_RELEASECLIENTINFO_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
        SGX_CLIENT_INFO         sClientInfo;
 }PVRSRV_BRIDGE_IN_RELEASECLIENTINFO;
 
@@ -249,11 +223,7 @@ typedef struct PVRSRV_BRIDGE_IN_RELEASECLIENTINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_ISPBREAKPOLL_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
 }PVRSRV_BRIDGE_IN_ISPBREAKPOLL;
 
 /*!
@@ -263,11 +233,7 @@ typedef struct PVRSRV_BRIDGE_IN_ISPBREAKPOLL_TAG
 typedef struct PVRSRV_BRIDGE_IN_DOKICK_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
        SGX_CCB_KICK                    sCCBKick;
 }PVRSRV_BRIDGE_IN_DOKICK;
 
@@ -278,11 +244,7 @@ typedef struct PVRSRV_BRIDGE_IN_DOKICK_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGX_SCHEDULE_PROCESS_QUEUES_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
 }PVRSRV_BRIDGE_IN_SGX_SCHEDULE_PROCESS_QUEUES;
 
 
@@ -294,11 +256,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_SCHEDULE_PROCESS_QUEUES_TAG
 typedef struct PVRSRV_BRIDGE_IN_SUBMITTRANSFER_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
        PVRSRV_TRANSFER_SGX_KICK                        sKick;
 }PVRSRV_BRIDGE_IN_SUBMITTRANSFER;
 
@@ -310,11 +268,7 @@ typedef struct PVRSRV_BRIDGE_IN_SUBMITTRANSFER_TAG
 typedef struct PVRSRV_BRIDGE_IN_SUBMIT2D_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
        PVRSRV_2D_SGX_KICK              sKick;
 } PVRSRV_BRIDGE_IN_SUBMIT2D;
 #endif
@@ -327,11 +281,7 @@ typedef struct PVRSRV_BRIDGE_IN_SUBMIT2D_TAG
 typedef struct PVRSRV_BRIDGE_IN_READREGDWORD_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-#else
        IMG_HANDLE                              hDevCookie;
-#endif
     IMG_PCHAR                          pszKey;
     IMG_PCHAR                          pszValue;
 }PVRSRV_BRIDGE_IN_READREGDWORD;
@@ -354,11 +304,7 @@ typedef struct PVRSRV_BRIDGE_OUT_READREGDWORD_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGXGETMISCINFO_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-#else
        IMG_HANDLE              hDevCookie;
-#endif
        SGX_MISC_INFO   *psMiscInfo;
 }PVRSRV_BRIDGE_IN_SGXGETMISCINFO;
 
@@ -369,11 +315,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGXGETMISCINFO_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGXINFO_FOR_SRVINIT_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-#else
        IMG_HANDLE              hDevCookie;
-#endif
 }PVRSRV_BRIDGE_IN_SGXINFO_FOR_SRVINIT;
 
 /*!
@@ -393,11 +335,7 @@ typedef struct PVRSRV_BRIDGE_OUT_SGXINFO_FOR_SRVINIT_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGXDEVINITPART2_TAG
 {
        IMG_UINT32              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hDevCookie;
-#else
        IMG_HANDLE              hDevCookie;
-#endif
        SGX_BRIDGE_INIT_INFO    sInitInfo;
 }PVRSRV_BRIDGE_IN_SGXDEVINITPART2;
 
@@ -419,13 +357,8 @@ typedef struct PVRSRV_BRIDGE_OUT_SGXDEVINITPART2_TAG
 typedef struct PVRSRV_BRIDGE_IN_2DQUERYBLTSCOMPLETE_TAG
 {
        IMG_UINT32                              ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hDevCookie;
-       IMG_SID                                 hKernSyncInfo;
-#else
        IMG_HANDLE                              hDevCookie;
        IMG_HANDLE                              hKernSyncInfo;
-#endif
        IMG_BOOL                                bWaitForComplete;
 }PVRSRV_BRIDGE_IN_2DQUERYBLTSCOMPLETE;
 
@@ -435,26 +368,13 @@ typedef struct PVRSRV_BRIDGE_IN_2DQUERYBLTSCOMPLETE_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGXFINDSHAREDPBDESC_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_BOOL   bLockOnFailure;
        IMG_UINT32 ui32TotalPBSize;
 }PVRSRV_BRIDGE_IN_SGXFINDSHAREDPBDESC;
 
 typedef struct PVRSRV_BRIDGE_OUT_SGXFINDSHAREDPBDESC_TAG
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hKernelMemInfo;
-       IMG_SID hSharedPBDesc;
-       IMG_SID hSharedPBDescKernelMemInfoHandle;
-       IMG_SID hHWPBDescKernelMemInfoHandle;
-       IMG_SID hBlockKernelMemInfoHandle;
-       IMG_SID hHWBlockKernelMemInfoHandle;
-       IMG_SID ahSharedPBDescSubKernelMemInfoHandles[PVRSRV_BRIDGE_SGX_SHAREDPBDESC_MAX_SUBMEMINFOS];
-#else
        IMG_HANDLE hKernelMemInfo;
        IMG_HANDLE hSharedPBDesc;
        IMG_HANDLE hSharedPBDescKernelMemInfoHandle;
@@ -462,7 +382,6 @@ typedef struct PVRSRV_BRIDGE_OUT_SGXFINDSHAREDPBDESC_TAG
        IMG_HANDLE hBlockKernelMemInfoHandle;
        IMG_HANDLE hHWBlockKernelMemInfoHandle;
        IMG_HANDLE ahSharedPBDescSubKernelMemInfoHandles[PVRSRV_BRIDGE_SGX_SHAREDPBDESC_MAX_SUBMEMINFOS];
-#endif
        IMG_UINT32 ui32SharedPBDescSubKernelMemInfoHandlesCount;
        PVRSRV_ERROR eError;
 }PVRSRV_BRIDGE_OUT_SGXFINDSHAREDPBDESC;
@@ -470,11 +389,7 @@ typedef struct PVRSRV_BRIDGE_OUT_SGXFINDSHAREDPBDESC_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGXUNREFSHAREDPBDESC_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hSharedPBDesc;
-#else
        IMG_HANDLE hSharedPBDesc;
-#endif
 }PVRSRV_BRIDGE_IN_SGXUNREFSHAREDPBDESC;
 
 typedef struct PVRSRV_BRIDGE_OUT_SGXUNREFSHAREDPBDESC_TAG
@@ -487,21 +402,12 @@ typedef struct PVRSRV_BRIDGE_IN_SGXADDSHAREDPBDESC_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
        IMG_UINT32 ui32TotalPBSize;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-       IMG_SID    hSharedPBDescKernelMemInfo;
-       IMG_SID    hHWPBDescKernelMemInfo;
-       IMG_SID    hBlockKernelMemInfo;
-       IMG_SID    hHWBlockKernelMemInfo;
-       IMG_SID    *phKernelMemInfoHandles;
-#else
        IMG_HANDLE hDevCookie;
        IMG_HANDLE hSharedPBDescKernelMemInfo;
        IMG_HANDLE hHWPBDescKernelMemInfo;
        IMG_HANDLE hBlockKernelMemInfo;
        IMG_HANDLE hHWBlockKernelMemInfo;
        IMG_HANDLE *phKernelMemInfoHandles;
-#endif
        IMG_UINT32 ui32KernelMemInfoHandlesCount;
        IMG_DEV_VIRTADDR sHWPBDescDevVAddr;
 }PVRSRV_BRIDGE_IN_SGXADDSHAREDPBDESC;
@@ -509,11 +415,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGXADDSHAREDPBDESC_TAG
 typedef struct PVRSRV_BRIDGE_OUT_SGXADDSHAREDPBDESC_TAG
 {
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID      hSharedPBDesc;
-#else
        IMG_HANDLE hSharedPBDesc;
-#endif
 }PVRSRV_BRIDGE_OUT_SGXADDSHAREDPBDESC;
 
 
@@ -529,13 +431,8 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_BUFFER_ARRAY_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_3D_SIGNATURE_REGISTERS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-       IMG_SID    hDevMemContext;
-#else
        IMG_HANDLE hDevCookie;
        IMG_HANDLE hDevMemContext;
-#endif
        IMG_UINT32 ui32DumpFrameNum;
        IMG_BOOL   bLastFrame;
        IMG_UINT32 *pui32Registers;
@@ -545,11 +442,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_3D_SIGNATURE_REGISTERS_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMPCOUNTER_REGISTERS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_UINT32 ui32DumpFrameNum;
        IMG_BOOL bLastFrame;
        IMG_UINT32 *pui32Registers;
@@ -559,11 +452,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMPCOUNTER_REGISTERS_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_TA_SIGNATURE_REGISTERS_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_UINT32 ui32DumpFrameNum;
        IMG_UINT32 ui32TAKickCount;
        IMG_BOOL bLastFrame;
@@ -574,13 +463,8 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_TA_SIGNATURE_REGISTERS_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_HWPERFCB_TAG
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hDevMemContext;
-#else
        IMG_HANDLE                      hDevCookie;
        IMG_HANDLE                      hDevMemContext;
-#endif
        IMG_CHAR                        szFileName[PVRSRV_PDUMP_MAX_FILENAME_SIZE];
        IMG_UINT32                      ui32FileOffset;
        IMG_UINT32                      ui32PDumpFlags;
@@ -590,19 +474,12 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_HWPERFCB_TAG
 typedef struct PVRSRV_BRIDGE_IN_PDUMP_SAVEMEM
 {
        IMG_UINT32                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hDevCookie;
-       IMG_SID                         hDevMemContext;
-#else
        IMG_HANDLE                      hDevCookie;
-#endif
        IMG_CHAR                        szFileName[PVRSRV_PDUMP_MAX_FILENAME_SIZE];
        IMG_UINT32                      ui32FileOffset;
        IMG_DEV_VIRTADDR        sDevVAddr;
        IMG_UINT32                      ui32Size;
-#if !defined (SUPPORT_SID_INTERFACE)
        IMG_HANDLE                      hDevMemContext;
-#endif
        IMG_UINT32                      ui32PDumpFlags;
 
 }PVRSRV_BRIDGE_IN_PDUMP_SAVEMEM;
@@ -612,11 +489,7 @@ typedef struct PVRSRV_BRIDGE_IN_PDUMP_SAVEMEM
 typedef struct PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_RENDER_CONTEXT_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
     IMG_CPU_VIRTADDR pHWRenderContextCpuVAddr;
     IMG_UINT32       ui32HWRenderContextSize;
     IMG_UINT32       ui32OffsetToPDDevPAddr;
@@ -626,11 +499,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_RENDER_CONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_RENDER_CONTEXT_TAG
 {
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hHWRenderContext;
-#else
        IMG_HANDLE hHWRenderContext;
-#endif
     IMG_DEV_VIRTADDR sHWRenderContextDevVAddr;
 }PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_RENDER_CONTEXT;
 
@@ -638,23 +507,14 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_RENDER_CONTEXT_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
        IMG_BOOL   bForceCleanup;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-       IMG_SID    hHWRenderContext;
-#else
        IMG_HANDLE hDevCookie;
        IMG_HANDLE hHWRenderContext;
-#endif
 }PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_RENDER_CONTEXT;
 
 typedef struct PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_TRANSFER_CONTEXT_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
     IMG_CPU_VIRTADDR pHWTransferContextCpuVAddr;
     IMG_UINT32       ui32HWTransferContextSize;
     IMG_UINT32       ui32OffsetToPDDevPAddr;
@@ -664,11 +524,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_TRANSFER_CONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_TRANSFER_CONTEXT_TAG
 {
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID      hHWTransferContext;
-#else
        IMG_HANDLE hHWTransferContext;
-#endif
     IMG_DEV_VIRTADDR sHWTransferContextDevVAddr;
 }PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_TRANSFER_CONTEXT;
 
@@ -676,23 +532,14 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_TRANSFER_CONTEXT_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
        IMG_BOOL   bForceCleanup;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-       IMG_SID    hHWTransferContext;
-#else
        IMG_HANDLE hDevCookie;
        IMG_HANDLE hHWTransferContext;
-#endif
 }PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_TRANSFER_CONTEXT;
 
 typedef struct PVRSRV_BRIDGE_IN_SGX_FLUSH_HW_RENDER_TARGET_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
        IMG_DEV_VIRTADDR sHWRTDataSetDevVAddr;
 }PVRSRV_BRIDGE_IN_SGX_FLUSH_HW_RENDER_TARGET;
 
@@ -704,11 +551,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_FLUSH_HW_RENDER_TARGET_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_2D_CONTEXT_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-#else
        IMG_HANDLE hDevCookie;
-#endif
     IMG_CPU_VIRTADDR pHW2DContextCpuVAddr;
     IMG_UINT32       ui32HW2DContextSize;
     IMG_UINT32       ui32OffsetToPDDevPAddr;
@@ -718,11 +561,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_REGISTER_HW_2D_CONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_2D_CONTEXT_TAG
 {
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hHW2DContext;
-#else
        IMG_HANDLE hHW2DContext;
-#endif
     IMG_DEV_VIRTADDR sHW2DContextDevVAddr;
 }PVRSRV_BRIDGE_OUT_SGX_REGISTER_HW_2D_CONTEXT;
 
@@ -730,13 +569,8 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_2D_CONTEXT_TAG
 {
        IMG_UINT32 ui32BridgeFlags; /* Must be first member of structure */
        IMG_BOOL   bForceCleanup;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID    hDevCookie;
-       IMG_SID    hHW2DContext;
-#else
        IMG_HANDLE hDevCookie;
        IMG_HANDLE hHW2DContext;
-#endif
 }PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_2D_CONTEXT;
 
 #define        SGX2D_MAX_BLT_CMD_SIZ           256     /* Maximum size of a blit command, in bytes */
@@ -750,11 +584,7 @@ typedef struct PVRSRV_BRIDGE_IN_SGX_UNREGISTER_HW_2D_CONTEXT_TAG
 typedef struct PVRSRV_BRIDGE_IN_SGX_READ_HWPERF_CB_TAG
 {
        IMG_UINT32                                      ui32BridgeFlags; /* Must be first member of structure */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                         hDevCookie;
-#else
        IMG_HANDLE                                      hDevCookie;
-#endif
        IMG_UINT32                                      ui32ArraySize;
        PVRSRV_SGX_HWPERF_CB_ENTRY      *psHWPerfCBData;
 } PVRSRV_BRIDGE_IN_SGX_READ_HWPERF_CB;
index 3a9866f..baab80d 100644 (file)
@@ -139,11 +139,8 @@ typedef struct _SGXMKIF_HOST_CTL_
        IMG_UINT32                              ui32PerfGroup;                                                                  /*!< Specifies the HW's active group */
 #endif /* SGX_FEATURE_EXTENDED_PERF_COUNTERS */
 
-#if defined(FIX_HW_BRN_31939)
-       IMG_UINT32                              ui32BRN31939Mem;
-#endif
-
        IMG_UINT32                              ui32OpenCLDelayCount;                   /* Counter to keep track OpenCL task completion time in units of regular task time out events */
+       IMG_UINT32                              ui32InterruptCount;
 } SGXMKIF_HOST_CTL;
 
 /*
@@ -268,6 +265,9 @@ typedef struct _SGXMKIF_2DCMD_SHARED_ {
 
        /* need to be able to check reads and writes on 2D ops, and update writes */
        PVRSRV_DEVICE_SYNC_OBJECT       s3DSyncData;
+
+       IMG_UINT32              ui32NumStatusVals;
+       CTL_STATUS      sCtlStatusInfo[SGXTQ_MAX_STATUS];
 } SGXMKIF_2DCMD_SHARED, *PSGXMKIF_2DCMD_SHARED;
 #endif /* SGX_FEATURE_2D_HARDWARE */
 
index dc8f2f3..141a917 100644 (file)
@@ -239,6 +239,14 @@ MKTC_ST(MKTC_KICKTA_TACMD_DEBUG)
 MKTC_ST(MKTC_KICKTA_FREECONTEXT)
 #define MKTC_KICKTA_PIM_PATCHING                               0xAD00080C
 MKTC_ST(MKTC_KICKTA_PIM_PATCHING)
+#define MKTC_KICKTA_TPC_CHECK_START                            0xAD00080D
+MKTC_ST(MKTC_KICKTA_TPC_CHECK_START)
+#define MKTC_KICKTA_TPC_CHECK_END                              0xAD00080E
+MKTC_ST(MKTC_KICKTA_TPC_CHECK_END)
+#define MKTC_KICKTA_TPC_CHECK_CORE                             0xAD00080F
+MKTC_ST(MKTC_KICKTA_TPC_CHECK_CORE)
+#define MKTC_KICKTA_TPC_CHECK_FAIL                             0xAD000810
+MKTC_ST(MKTC_KICKTA_TPC_CHECK_FAIL)
 
 #define MKTC_KICKTA_CHKPT_START_DUMMY_CS               0xAD0008A1
 MKTC_ST(MKTC_KICKTA_CHKPT_START_DUMMY_CS)
@@ -659,7 +667,7 @@ MKTC_ST(MKTC_TAFINISHED_TERM_COMPLETE_START)
 #define MKTC_TAFINISHED_TERM_COMPLETE_END              0xAD001711
 MKTC_ST(MKTC_TAFINISHED_TERM_COMPLETE_END)
 
-#define MKTC_TAFINISHED_DPMPAGERECYCLING               0xAD001720
+#define MKTC_TAFINISHED_DPMPAGERECYCLING                       0xAD001720
 MKTC_ST(MKTC_TAFINISHED_DPMPAGERECYCLING)
 
 #define MKTC_2DEVENT_2DCOMPLETE                                        0xAD001800
@@ -712,11 +720,21 @@ MKTC_ST(MKTC_FIND2D_ADDR_SPACE_DIFFERENT)
 MKTC_ST(MKTC_FTD_3DOPSBLOCKED)
 #define MKTC_FTD_DSTREADOPS2BLOCKED                            0xAD001818
 MKTC_ST(MKTC_FTD_DSTREADOPS2BLOCKED)
+#define MKTC_U2DSO_UPDATESTATUSVALS                            0xAD001819
+MKTC_ST(MKTC_U2DSO_UPDATESTATUSVALS)
+#define MKTC_U2DSO_UPDATESTATUSVALS_DONE               0xAD00181A
+MKTC_ST(MKTC_U2DSO_UPDATESTATUSVALS_DONE)
 
 #define MKTC_FCM_START                                                 0xAD001900
 MKTC_ST(MKTC_FCM_START)
 #define MKTC_FCM_END                                                   0xAD001901
 MKTC_ST(MKTC_FCM_END)
+#define MKTC_FCM_PB_SAME                                               0xAD001902
+MKTC_ST(MKTC_FCM_PB_SAME)
+#define MKTC_FCM_TQ_IN_PROGESS                                 0xAD001903
+MKTC_ST(MKTC_FCM_TQ_IN_PROGESS)
+#define MKTC_FCM_TQ_MEMCONTEXT_DIFFERENT               0xAD001904
+MKTC_ST(MKTC_FCM_TQ_MEMCONTEXT_DIFFERENT)
 
 #define MKTC_TIMER_ACTIVE_POWER                                        0xAD001A00
 MKTC_ST(MKTC_TIMER_ACTIVE_POWER)
index 17f6d95..66352dc 100644 (file)
@@ -45,9 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sgxscript.h"
 #include "servicesint.h"
 #include "services.h"
-#if !defined (SUPPORT_SID_INTERFACE)
 #include "sgxapi_km.h"
-#endif
 #include "sgx_mkif_km.h"
 
 
@@ -84,17 +82,6 @@ typedef enum _SGXMKIF_CMD_TYPE_
 
 typedef struct _SGX_BRIDGE_INIT_INFO_
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelCCBMemInfo;
-       IMG_SID         hKernelCCBCtlMemInfo;
-       IMG_SID         hKernelCCBEventKickerMemInfo;
-       IMG_SID         hKernelSGXHostCtlMemInfo;
-       IMG_SID         hKernelSGXTA3DCtlMemInfo;
-#if defined(FIX_HW_BRN_31272) || defined(FIX_HW_BRN_31780) || defined(FIX_HW_BRN_33920)
-       IMG_SID         hKernelSGXPTLAWriteBackMemInfo;
-#endif
-       IMG_SID         hKernelSGXMiscMemInfo;
-#else
        IMG_HANDLE      hKernelCCBMemInfo;
        IMG_HANDLE      hKernelCCBCtlMemInfo;
        IMG_HANDLE      hKernelCCBEventKickerMemInfo;
@@ -104,7 +91,6 @@ typedef struct _SGX_BRIDGE_INIT_INFO_
        IMG_HANDLE      hKernelSGXPTLAWriteBackMemInfo;
 #endif
        IMG_HANDLE      hKernelSGXMiscMemInfo;
-#endif
 
        IMG_UINT32      aui32HostKickAddr[SGXMKIF_CMD_MAX];
 
@@ -114,53 +100,16 @@ typedef struct _SGX_BRIDGE_INIT_INFO_
        SGX_MISCINFO_STRUCT_SIZES       sSGXStructSizes;
 
 #if defined(SGX_SUPPORT_HWPROFILING)
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelHWProfilingMemInfo;
-#else
        IMG_HANDLE      hKernelHWProfilingMemInfo;
 #endif
-#endif
 #if defined(SUPPORT_SGX_HWPERF)
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelHWPerfCBMemInfo;
-#else
        IMG_HANDLE      hKernelHWPerfCBMemInfo;
 #endif
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelTASigBufferMemInfo;
-       IMG_SID         hKernel3DSigBufferMemInfo;
-#else
        IMG_HANDLE      hKernelTASigBufferMemInfo;
        IMG_HANDLE      hKernel3DSigBufferMemInfo;
-#endif
 
-#if defined(FIX_HW_BRN_29702)
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelCFIMemInfo;
-#else
-       IMG_HANDLE      hKernelCFIMemInfo;
-#endif
-#endif
-#if defined(FIX_HW_BRN_29823)
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelDummyTermStreamMemInfo;
-#else
-       IMG_HANDLE      hKernelDummyTermStreamMemInfo;
-#endif
-#endif
 
 #if defined(FIX_HW_BRN_31542) || defined(FIX_HW_BRN_36513)
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hKernelClearClipWAVDMStreamMemInfo;
-       IMG_SID hKernelClearClipWAIndexStreamMemInfo;
-       IMG_SID hKernelClearClipWAPDSMemInfo;
-       IMG_SID hKernelClearClipWAUSEMemInfo;
-       IMG_SID hKernelClearClipWAParamMemInfo;
-       IMG_SID hKernelClearClipWAPMPTMemInfo;
-       IMG_SID hKernelClearClipWATPCMemInfo;
-       IMG_SID hKernelClearClipWAPSGRgnHdrMemInfo;
-#else
        IMG_HANDLE hKernelClearClipWAVDMStreamMemInfo;
        IMG_HANDLE hKernelClearClipWAIndexStreamMemInfo;
        IMG_HANDLE hKernelClearClipWAPDSMemInfo;
@@ -170,22 +119,13 @@ typedef struct _SGX_BRIDGE_INIT_INFO_
        IMG_HANDLE hKernelClearClipWATPCMemInfo;
        IMG_HANDLE hKernelClearClipWAPSGRgnHdrMemInfo;
 #endif
-#endif
 
-#if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && defined(FIX_HW_BRN_31559)
-       IMG_HANDLE      hKernelVDMSnapShotBufferMemInfo;
-       IMG_HANDLE      hKernelVDMCtrlStreamBufferMemInfo;
-#endif
 #if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && \
        defined(FIX_HW_BRN_33657) && defined(SUPPORT_SECURE_33657_FIX)
        IMG_HANDLE      hKernelVDMStateUpdateBufferMemInfo;
 #endif
 #if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelEDMStatusBufferMemInfo;
-#else
        IMG_HANDLE      hKernelEDMStatusBufferMemInfo;
-#endif
 #endif
 
        IMG_UINT32 ui32EDMTaskReg0;
@@ -205,11 +145,7 @@ typedef struct _SGX_BRIDGE_INIT_INFO_
        IMG_UINT32 ui32CacheControl;
 
        IMG_UINT32      asInitDevData[SGX_MAX_DEV_DATA];
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         asInitMemHandles[SGX_MAX_INIT_MEM_HANDLES];
-#else
        IMG_HANDLE      asInitMemHandles[SGX_MAX_INIT_MEM_HANDLES];
-#endif
 
 } SGX_BRIDGE_INIT_INFO;
 
@@ -218,11 +154,7 @@ typedef struct _SGX_DEVICE_SYNC_LIST_
 {
        PSGXMKIF_HWDEVICE_SYNC_LIST     psHWDeviceSyncList;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hKernelHWSyncListMemInfo;
-#else
        IMG_HANDLE                              hKernelHWSyncListMemInfo;
-#endif
        PVRSRV_CLIENT_MEM_INFO  *psHWDeviceSyncListClientMemInfo;
        PVRSRV_CLIENT_MEM_INFO  *psAccessResourceClientMemInfo;
 
@@ -232,47 +164,27 @@ typedef struct _SGX_DEVICE_SYNC_LIST_
 
        /* Must be the last variable in the structure */
        IMG_UINT32                      ui32NumSyncObjects;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         ahSyncHandles[1];
-#else
        IMG_HANDLE                      ahSyncHandles[1];
-#endif
 } SGX_DEVICE_SYNC_LIST, *PSGX_DEVICE_SYNC_LIST;
 
 
 typedef struct _SGX_INTERNEL_STATUS_UPDATE_
 {
        CTL_STATUS                              sCtlStatus;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                                 hKernelMemInfo;
-#else
        IMG_HANDLE                              hKernelMemInfo;
-#endif
 } SGX_INTERNEL_STATUS_UPDATE;
 
 
 typedef struct _SGX_CCB_KICK_
 {
        SGXMKIF_COMMAND         sCommand;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hCCBKernelMemInfo;
-#else
        IMG_HANDLE      hCCBKernelMemInfo;
-#endif
 
        IMG_UINT32      ui32NumDstSyncObjects;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hKernelHWSyncListMemInfo;
-#else
        IMG_HANDLE      hKernelHWSyncListMemInfo;
-#endif
 
        /* DST syncs */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         *pahDstSyncHandles;
-#else
        IMG_HANDLE      *pahDstSyncHandles;
-#endif
 
        IMG_UINT32      ui32NumTAStatusVals;
        IMG_UINT32      ui32Num3DStatusVals;
@@ -280,14 +192,9 @@ typedef struct _SGX_CCB_KICK_
 #if defined(SUPPORT_SGX_NEW_STATUS_VALS)
        SGX_INTERNEL_STATUS_UPDATE      asTAStatusUpdate[SGX_MAX_TA_STATUS_VALS];
        SGX_INTERNEL_STATUS_UPDATE      as3DStatusUpdate[SGX_MAX_3D_STATUS_VALS];
-#else
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         ahTAStatusSyncInfo[SGX_MAX_TA_STATUS_VALS];
-       IMG_SID         ah3DStatusSyncInfo[SGX_MAX_3D_STATUS_VALS];
 #else
        IMG_HANDLE      ahTAStatusSyncInfo[SGX_MAX_TA_STATUS_VALS];
        IMG_HANDLE      ah3DStatusSyncInfo[SGX_MAX_3D_STATUS_VALS];
-#endif
 #endif
 
        IMG_BOOL        bFirstKickOrResume;
@@ -302,46 +209,23 @@ typedef struct _SGX_CCB_KICK_
 #if defined(SUPPORT_SGX_GENERALISED_SYNCOBJECTS)
        /* SRC and DST syncs */
        IMG_UINT32      ui32NumTASrcSyncs;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         ahTASrcKernelSyncInfo[SGX_MAX_TA_SRC_SYNCS];
-#else
        IMG_HANDLE      ahTASrcKernelSyncInfo[SGX_MAX_TA_SRC_SYNCS];
-#endif
        IMG_UINT32      ui32NumTADstSyncs;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         ahTADstKernelSyncInfo[SGX_MAX_TA_DST_SYNCS];
-#else
        IMG_HANDLE      ahTADstKernelSyncInfo[SGX_MAX_TA_DST_SYNCS];
-#endif
        IMG_UINT32      ui32Num3DSrcSyncs;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         ah3DSrcKernelSyncInfo[SGX_MAX_3D_SRC_SYNCS];
-#else
        IMG_HANDLE      ah3DSrcKernelSyncInfo[SGX_MAX_3D_SRC_SYNCS];
-#endif
 #else
        /* SRC syncs */
        IMG_UINT32      ui32NumSrcSyncs;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         ahSrcKernelSyncInfo[SGX_MAX_SRC_SYNCS_TA];
-#else
        IMG_HANDLE      ahSrcKernelSyncInfo[SGX_MAX_SRC_SYNCS_TA];
-#endif
 #endif
 
        /* TA/3D dependency data */
        IMG_BOOL        bTADependency;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID         hTA3DSyncInfo;
-
-       IMG_SID         hTASyncInfo;
-       IMG_SID         h3DSyncInfo;
-#else
        IMG_HANDLE      hTA3DSyncInfo;
 
        IMG_HANDLE      hTASyncInfo;
        IMG_HANDLE      h3DSyncInfo;
-#endif
 #if defined(PDUMP)
        IMG_UINT32      ui32CCBDumpWOff;
 #endif
@@ -380,11 +264,7 @@ typedef struct _SGX_CLIENT_INFO_
 typedef struct _SGX_INTERNAL_DEVINFO_
 {
        IMG_UINT32                      ui32Flags;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                         hHostCtlKernelMemInfoHandle;
-#else
        IMG_HANDLE                      hHostCtlKernelMemInfoHandle;
-#endif
        IMG_BOOL                        bForcePTOff;
 } SGX_INTERNAL_DEVINFO;
 
@@ -400,36 +280,19 @@ typedef struct _SGX_INTERNAL_DEVINFO_KM_
 #if defined(TRANSFER_QUEUE)
 typedef struct _PVRSRV_TRANSFER_SGX_KICK_
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hCCBMemInfo;
-#else
        IMG_HANDLE              hCCBMemInfo;
-#endif
        IMG_UINT32              ui32SharedCmdCCBOffset;
 
        IMG_DEV_VIRTADDR        sHWTransferContextDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hTASyncInfo;
-       IMG_SID                 h3DSyncInfo;
-#else
        IMG_HANDLE              hTASyncInfo;
        IMG_HANDLE              h3DSyncInfo;
-#endif
 
        IMG_UINT32              ui32NumSrcSync;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 ahSrcSyncInfo[SGX_MAX_TRANSFER_SYNC_OPS];
-#else
        IMG_HANDLE              ahSrcSyncInfo[SGX_MAX_TRANSFER_SYNC_OPS];
-#endif
 
        IMG_UINT32              ui32NumDstSync;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 ahDstSyncInfo[SGX_MAX_TRANSFER_SYNC_OPS];
-#else
        IMG_HANDLE              ahDstSyncInfo[SGX_MAX_TRANSFER_SYNC_OPS];
-#endif
 
        IMG_UINT32              ui32Flags;
 
@@ -438,33 +301,21 @@ typedef struct _PVRSRV_TRANSFER_SGX_KICK_
        IMG_UINT32              ui32CCBDumpWOff;
 #endif
        IMG_HANDLE              hDevMemContext;
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       /* Android >JB MR1 doesn't use ahSrcSyncInfo for synchronization */
+       IMG_INT                 iFenceFd;
+#endif
 } PVRSRV_TRANSFER_SGX_KICK, *PPVRSRV_TRANSFER_SGX_KICK;
 
 #if defined(SGX_FEATURE_2D_HARDWARE)
 typedef struct _PVRSRV_2D_SGX_KICK_
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hCCBMemInfo;
-#else
        IMG_HANDLE              hCCBMemInfo;
-#endif
        IMG_UINT32              ui32SharedCmdCCBOffset;
 
        IMG_DEV_VIRTADDR        sHW2DContextDevVAddr;
 
        IMG_UINT32              ui32NumSrcSync;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 ahSrcSyncInfo[SGX_MAX_2D_SRC_SYNC_OPS];
-
-       /* need to be able to check reads and writes on dest, and update writes */
-       IMG_SID                 hDstSyncInfo;
-
-       /* need to be able to check reads and writes on TA ops, and update writes */
-       IMG_SID                 hTASyncInfo;
-
-       /* need to be able to check reads and writes on 2D ops, and update writes */
-       IMG_SID                 h3DSyncInfo;
-#else
        IMG_HANDLE              ahSrcSyncInfo[SGX_MAX_2D_SRC_SYNC_OPS];
 
        /* need to be able to check reads and writes on dest, and update writes */
@@ -475,13 +326,16 @@ typedef struct _PVRSRV_2D_SGX_KICK_
 
        /* need to be able to check reads and writes on 2D ops, and update writes */
        IMG_HANDLE              h3DSyncInfo;
-#endif
 
        IMG_UINT32              ui32PDumpFlags;
 #if defined(PDUMP)
        IMG_UINT32              ui32CCBDumpWOff;
 #endif
        IMG_HANDLE              hDevMemContext;
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       /* Android >JB MR1 doesn't use ahSrcSyncInfo for synchronization */
+       IMG_INT                 iFenceFd;
+#endif
 } PVRSRV_2D_SGX_KICK, *PPVRSRV_2D_SGX_KICK;
 #endif /* defined(SGX_FEATURE_2D_HARDWARE) */
 #endif /* defined(TRANSFER_QUEUE) */
index 9b38583..cba9f18 100644 (file)
@@ -86,6 +86,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include <linux/file.h>
+#include <linux/sync.h>
+#endif
+
 #include "srvkm.h"
 
 /* FIXME: we should include an OS specific header here to allow configuration of
@@ -106,7 +111,7 @@ PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY g_BridgeDispatchTable[BRIDGE_DISPATCH_TABLE_E
 PVRSRV_BRIDGE_GLOBAL_STATS g_BridgeGlobalStats;
 #endif
 
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
 static IMG_BOOL abSharedDeviceMemHeap[PVRSRV_MAX_CLIENT_HEAPS];
 static IMG_BOOL *pbSharedDeviceMemHeap = abSharedDeviceMemHeap;
 #else
@@ -202,9 +207,6 @@ PVRSRVCreateDeviceMemContextBW(IMG_UINT32 ui32BridgeID,
        IMG_HANDLE hDevMemContextInt;
        IMG_UINT32 i;
        IMG_BOOL bCreated;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_HEAP_INFO_KM asHeapInfo[PVRSRV_MAX_CLIENT_HEAPS];
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_CREATE_DEVMEMCONTEXT);
 
@@ -229,11 +231,7 @@ PVRSRVCreateDeviceMemContextBW(IMG_UINT32 ui32BridgeID,
                                                                           psPerProc,
                                                                           &hDevMemContextInt,
                                                                           &psCreateDevMemContextOUT->ui32ClientHeapCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                          &asHeapInfo[0],
-#else
                                                                           &psCreateDevMemContextOUT->sHeapInfo[0],
-#endif
                                                                           &bCreated,
                                                                           pbSharedDeviceMemHeap);
 
@@ -270,13 +268,9 @@ PVRSRVCreateDeviceMemContextBW(IMG_UINT32 ui32BridgeID,
 
        for(i = 0; i < psCreateDevMemContextOUT->ui32ClientHeapCount; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID hDevMemHeapExt;
-#else
                IMG_HANDLE hDevMemHeapExt;
-#endif
 
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                if(abSharedDeviceMemHeap[i])
 #endif
                {
@@ -287,20 +281,12 @@ PVRSRVCreateDeviceMemContextBW(IMG_UINT32 ui32BridgeID,
                         * driver, hence, we use shared handles for these
                         * heaps.
                         */
-#if defined (SUPPORT_SID_INTERFACE)
-                       PVRSRVAllocHandleNR(psPerProc->psHandleBase,
-                                                               &hDevMemHeapExt,
-                                                               asHeapInfo[i].hDevMemHeap,
-                                                               PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
-                                                               PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
-#else
                        PVRSRVAllocHandleNR(psPerProc->psHandleBase, &hDevMemHeapExt,
                                                                psCreateDevMemContextOUT->sHeapInfo[i].hDevMemHeap,
                                                                PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
                                                                PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
-#endif
                }
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                else
                {
                        /*
@@ -311,31 +297,18 @@ PVRSRVCreateDeviceMemContextBW(IMG_UINT32 ui32BridgeID,
                         */
                        if(bCreated)
                        {
-#if defined (SUPPORT_SID_INTERFACE)
-                               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                                          &hDevMemHeapExt,
-                                                                          asHeapInfo[i].hDevMemHeap,
-                                                                          PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
-                                                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                                                          psCreateDevMemContextOUT->hDevMemContext);
-#else
                                PVRSRVAllocSubHandleNR(psPerProc->psHandleBase, &hDevMemHeapExt,
                                                                         psCreateDevMemContextOUT->sHeapInfo[i].hDevMemHeap,
                                                                         PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
                                                                         PVRSRV_HANDLE_ALLOC_FLAG_NONE,
                                                                         psCreateDevMemContextOUT->hDevMemContext);
-#endif
                        }
                        else
                        {
                                psCreateDevMemContextOUT->eError =
                                        PVRSRVFindHandle(psPerProc->psHandleBase,
                                                                         &hDevMemHeapExt,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                        asHeapInfo[i].hDevMemHeap,
-#else
                                                                         psCreateDevMemContextOUT->sHeapInfo[i].hDevMemHeap,
-#endif
                                                                         PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP);
                                if(psCreateDevMemContextOUT->eError != PVRSRV_OK)
                                {
@@ -345,13 +318,6 @@ PVRSRVCreateDeviceMemContextBW(IMG_UINT32 ui32BridgeID,
                }
 #endif
                psCreateDevMemContextOUT->sHeapInfo[i].hDevMemHeap = hDevMemHeapExt;
-#if defined (SUPPORT_SID_INTERFACE)
-               psCreateDevMemContextOUT->sHeapInfo[i].ui32HeapID       = asHeapInfo[i].ui32HeapID;
-               psCreateDevMemContextOUT->sHeapInfo[i].sDevVAddrBase    = asHeapInfo[i].sDevVAddrBase;
-               psCreateDevMemContextOUT->sHeapInfo[i].ui32HeapByteSize = asHeapInfo[i].ui32HeapByteSize;
-               psCreateDevMemContextOUT->sHeapInfo[i].ui32Attribs      = asHeapInfo[i].ui32Attribs;
-               psCreateDevMemContextOUT->sHeapInfo[i].ui32XTileStride  = asHeapInfo[i].ui32XTileStride;
-#endif
        }
 
        COMMIT_HANDLE_BATCH_OR_ERROR(psCreateDevMemContextOUT->eError, psPerProc)
@@ -420,9 +386,6 @@ PVRSRVGetDeviceMemHeapInfoBW(IMG_UINT32 ui32BridgeID,
        IMG_HANDLE hDevCookieInt;
        IMG_HANDLE hDevMemContextInt;
        IMG_UINT32 i;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_HEAP_INFO_KM asHeapInfo[PVRSRV_MAX_CLIENT_HEAPS];
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_GET_DEVMEM_HEAPINFO);
 
@@ -452,11 +415,7 @@ PVRSRVGetDeviceMemHeapInfoBW(IMG_UINT32 ui32BridgeID,
                PVRSRVGetDeviceMemHeapInfoKM(hDevCookieInt,
                                                                           hDevMemContextInt,
                                                                           &psGetDevMemHeapInfoOUT->ui32ClientHeapCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                       &asHeapInfo[0],
-#else
                                                                           &psGetDevMemHeapInfoOUT->sHeapInfo[0],
-#endif
                                                                           pbSharedDeviceMemHeap);
 
        if(psGetDevMemHeapInfoOUT->eError != PVRSRV_OK)
@@ -466,13 +425,9 @@ PVRSRVGetDeviceMemHeapInfoBW(IMG_UINT32 ui32BridgeID,
 
        for(i = 0; i < psGetDevMemHeapInfoOUT->ui32ClientHeapCount; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID hDevMemHeapExt;
-#else
                IMG_HANDLE hDevMemHeapExt;
-#endif
 
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                if(abSharedDeviceMemHeap[i])
 #endif
                {
@@ -483,20 +438,12 @@ PVRSRVGetDeviceMemHeapInfoBW(IMG_UINT32 ui32BridgeID,
                         * driver, hence, we use shared handles for these
                         * heaps.
                         */
-#if defined (SUPPORT_SID_INTERFACE)
-                       PVRSRVAllocHandleNR(psPerProc->psHandleBase,
-                                                               &hDevMemHeapExt,
-                                                               asHeapInfo[i].hDevMemHeap,
-                                                               PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
-                                                               PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
-#else
                        PVRSRVAllocHandleNR(psPerProc->psHandleBase, &hDevMemHeapExt,
                                                          psGetDevMemHeapInfoOUT->sHeapInfo[i].hDevMemHeap,
                                                          PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
                                                          PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
-#endif
                }
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                else
                {
                        /*
@@ -508,11 +455,7 @@ PVRSRVGetDeviceMemHeapInfoBW(IMG_UINT32 ui32BridgeID,
                        psGetDevMemHeapInfoOUT->eError =
                                PVRSRVFindHandle(psPerProc->psHandleBase,
                                                                 &hDevMemHeapExt,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                asHeapInfo[i].hDevMemHeap,
-#else
                                                                 psGetDevMemHeapInfoOUT->sHeapInfo[i].hDevMemHeap,
-#endif
                                                                 PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP);
                        if(psGetDevMemHeapInfoOUT->eError != PVRSRV_OK)
                        {
@@ -521,13 +464,6 @@ PVRSRVGetDeviceMemHeapInfoBW(IMG_UINT32 ui32BridgeID,
                }
 #endif
                psGetDevMemHeapInfoOUT->sHeapInfo[i].hDevMemHeap = hDevMemHeapExt;
-#if defined (SUPPORT_SID_INTERFACE)
-               psGetDevMemHeapInfoOUT->sHeapInfo[i].ui32HeapID       = asHeapInfo[i].ui32HeapID;
-               psGetDevMemHeapInfoOUT->sHeapInfo[i].sDevVAddrBase    = asHeapInfo[i].sDevVAddrBase;
-               psGetDevMemHeapInfoOUT->sHeapInfo[i].ui32HeapByteSize = asHeapInfo[i].ui32HeapByteSize;
-               psGetDevMemHeapInfoOUT->sHeapInfo[i].ui32Attribs      = asHeapInfo[i].ui32Attribs;
-               psGetDevMemHeapInfoOUT->sHeapInfo[i].ui32XTileStride  = asHeapInfo[i].ui32XTileStride;
-#endif
        }
 
        COMMIT_HANDLE_BATCH_OR_ERROR(psGetDevMemHeapInfoOUT->eError, psPerProc)
@@ -672,8 +608,8 @@ PVRSRVAllocDeviceMemBW(IMG_UINT32 ui32BridgeID,
                                                           psPerProc,
                                                           hDevMemHeapInt,
                                                           psAllocDeviceMemIN->ui32Attribs,
-                                                          psAllocDeviceMemIN->ui32Size,
-                                                          psAllocDeviceMemIN->ui32Alignment,
+                                                          psAllocDeviceMemIN->uSize,
+                                                          psAllocDeviceMemIN->uAlignment,
                                                           psAllocDeviceMemIN->pvPrivData,
                                                           psAllocDeviceMemIN->ui32PrivDataLength,
                                                           psAllocDeviceMemIN->ui32ChunkSize,
@@ -701,8 +637,8 @@ PVRSRVAllocDeviceMemBW(IMG_UINT32 ui32BridgeID,
                psMemInfo->sShareMemWorkaround.ui32ShareIndex = ui32ShareIndex;
                psMemInfo->sShareMemWorkaround.hDevCookieInt = hDevCookieInt;
                psMemInfo->sShareMemWorkaround.ui32OrigReqAttribs = psAllocDeviceMemIN->ui32Attribs;
-               psMemInfo->sShareMemWorkaround.ui32OrigReqSize = (IMG_UINT32)psAllocDeviceMemIN->ui32Size;
-               psMemInfo->sShareMemWorkaround.ui32OrigReqAlignment = (IMG_UINT32)psAllocDeviceMemIN->ui32Alignment;
+               psMemInfo->sShareMemWorkaround.ui32OrigReqSize = (IMG_UINT32)psAllocDeviceMemIN->uSize;
+               psMemInfo->sShareMemWorkaround.ui32OrigReqAlignment = (IMG_UINT32)psAllocDeviceMemIN->uAlignment;
        }
 
        OSMemSet(&psAllocDeviceMemOUT->sClientMemInfo,
@@ -720,11 +656,7 @@ PVRSRVAllocDeviceMemBW(IMG_UINT32 ui32BridgeID,
        psAllocDeviceMemOUT->sClientMemInfo.sDevVAddr = psMemInfo->sDevVAddr;
        psAllocDeviceMemOUT->sClientMemInfo.ui32Flags = psMemInfo->ui32Flags;
        psAllocDeviceMemOUT->sClientMemInfo.uAllocSize = psMemInfo->uAllocSize;
-#if defined (SUPPORT_SID_INTERFACE)
-       /* see below */
-#else
        psAllocDeviceMemOUT->sClientMemInfo.hMappingInfo = psMemInfo->sMemBlk.hOSMemHandle;
-#endif
 
        PVRSRVAllocHandleNR(psPerProc->psHandleBase,
                                          &psAllocDeviceMemOUT->sClientMemInfo.hKernelMemInfo,
@@ -732,23 +664,6 @@ PVRSRVAllocDeviceMemBW(IMG_UINT32 ui32BridgeID,
                                          PVRSRV_HANDLE_TYPE_MEM_INFO,
                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE);
 
-#if defined (SUPPORT_SID_INTERFACE)
-       PVR_ASSERT(psAllocDeviceMemOUT->sClientMemInfo.hKernelMemInfo != 0);
-
-       if (psMemInfo->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                          &psAllocDeviceMemOUT->sClientMemInfo.hMappingInfo,
-                                                          psMemInfo->sMemBlk.hOSMemHandle,
-                                                          PVRSRV_HANDLE_TYPE_MEM_INFO,
-                                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                                          psAllocDeviceMemOUT->sClientMemInfo.hKernelMemInfo);
-       }
-       else
-       {
-               psAllocDeviceMemOUT->sClientMemInfo.hMappingInfo = 0;
-       }
-#endif
 
        if(psAllocDeviceMemIN->ui32Attribs & PVRSRV_MEM_NO_SYNCOBJ)
        {
@@ -772,24 +687,8 @@ PVRSRVAllocDeviceMemBW(IMG_UINT32 ui32BridgeID,
                psAllocDeviceMemOUT->sClientSyncInfo.sReadOps2CompleteDevVAddr =
                        psMemInfo->psKernelSyncInfo->sReadOps2CompleteDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-               if (psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle != IMG_NULL)
-               {
-                               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                                          &psAllocDeviceMemOUT->sClientSyncInfo.hMappingInfo,
-                                                                          psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle,
-                                                                          PVRSRV_HANDLE_TYPE_SYNC_INFO,
-                                                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                                                          psAllocDeviceMemOUT->sClientMemInfo.hKernelMemInfo);
-               }
-               else
-               {
-                       psAllocDeviceMemOUT->sClientSyncInfo.hMappingInfo = 0;
-               }
-#else
                psAllocDeviceMemOUT->sClientSyncInfo.hMappingInfo =
                        psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle;
-#endif
 #endif
 
                PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
@@ -834,11 +733,7 @@ PVRSRVFreeDeviceMemBW(IMG_UINT32 ui32BridgeID,
        psRetOUT->eError =
         PVRSRVLookupHandle(psPerProc->psHandleBase,
                            &pvKernelMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psFreeDeviceMemIN->hKernelMemInfo,
-#else
                                                   psFreeDeviceMemIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        if(psRetOUT->eError != PVRSRV_OK)
@@ -855,11 +750,7 @@ PVRSRVFreeDeviceMemBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                       psFreeDeviceMemIN->hKernelMemInfo,
-#else
                                                        psFreeDeviceMemIN->psKernelMemInfo,
-#endif
                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        return 0;
@@ -873,11 +764,7 @@ PVRSRVExportDeviceMemBW(IMG_UINT32 ui32BridgeID,
                                          PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        IMG_HANDLE hDevCookieInt;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo = IMG_NULL;
-#else
        PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
-#endif
 
        PVR_ASSERT(ui32BridgeID == PVRSRV_GET_BRIDGE_ID(PVRSRV_BRIDGE_EXPORT_DEVICEMEM) ||
                           ui32BridgeID == PVRSRV_GET_BRIDGE_ID(PVRSRV_BRIDGE_EXPORT_DEVICEMEM_2));
@@ -900,11 +787,7 @@ PVRSRVExportDeviceMemBW(IMG_UINT32 ui32BridgeID,
        psExportDeviceMemOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                   (IMG_PVOID *)&psKernelMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psExportDeviceMemIN->hKernelMemInfo,
-#else
                                                   psExportDeviceMemIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        if(psExportDeviceMemOUT->eError != PVRSRV_OK)
@@ -1062,11 +945,7 @@ PVRSRVMapDeviceMemoryBW(IMG_UINT32 ui32BridgeID,
        psMapDevMemOUT->sDstClientMemInfo.sDevVAddr = psDstKernelMemInfo->sDevVAddr;
        psMapDevMemOUT->sDstClientMemInfo.ui32Flags = psDstKernelMemInfo->ui32Flags;
     psMapDevMemOUT->sDstClientMemInfo.uAllocSize = psDstKernelMemInfo->uAllocSize;
-#if defined (SUPPORT_SID_INTERFACE)
-       /* see below */
-#else
        psMapDevMemOUT->sDstClientMemInfo.hMappingInfo = psDstKernelMemInfo->sMemBlk.hOSMemHandle;
-#endif
 
        /* allocate handle to the DST kernel meminfo */
        PVRSRVAllocHandleNR(psPerProc->psHandleBase,
@@ -1076,22 +955,6 @@ PVRSRVMapDeviceMemoryBW(IMG_UINT32 ui32BridgeID,
                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE);
        psMapDevMemOUT->sDstClientSyncInfo.hKernelSyncInfo = IMG_NULL;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       /* alloc subhandle for the mapping info */
-       if (psDstKernelMemInfo->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                               &psMapDevMemOUT->sDstClientMemInfo.hMappingInfo,
-                                               psDstKernelMemInfo->sMemBlk.hOSMemHandle,
-                                               PVRSRV_HANDLE_TYPE_MEM_INFO,
-                                               PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                               psMapDevMemOUT->sDstClientMemInfo.hKernelMemInfo);
-       }
-       else
-       {
-               psMapDevMemOUT->sDstClientMemInfo.hMappingInfo = 0;
-       }
-#endif
 
        /* and setup the sync info */
        if(psDstKernelMemInfo->psKernelSyncInfo)
@@ -1106,25 +969,8 @@ PVRSRVMapDeviceMemoryBW(IMG_UINT32 ui32BridgeID,
                psMapDevMemOUT->sDstClientSyncInfo.sReadOps2CompleteDevVAddr =
                        psDstKernelMemInfo->psKernelSyncInfo->sReadOps2CompleteDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-               /* alloc subhandle for the mapping info */
-               if (psDstKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle != IMG_NULL)
-               {
-                       PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                       &psMapDevMemOUT->sDstClientSyncInfo.hMappingInfo,
-                                                       psDstKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle,
-                                                       PVRSRV_HANDLE_TYPE_MEM_INFO,
-                                                       PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                                       psMapDevMemOUT->sDstClientMemInfo.hKernelMemInfo);
-               }
-               else
-               {
-                       psMapDevMemOUT->sDstClientSyncInfo.hMappingInfo = 0;
-               }
-#else
                psMapDevMemOUT->sDstClientSyncInfo.hMappingInfo =
                        psDstKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle;
-#endif
 #endif
 
                psMapDevMemOUT->sDstClientMemInfo.psClientSyncInfo = &psMapDevMemOUT->sDstClientSyncInfo;
@@ -1159,11 +1005,7 @@ PVRSRVUnmapDeviceMemoryBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                                                        (IMG_VOID**)&psKernelMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                       psUnmapDevMemIN->hKernelMemInfo,
-#else
                                                                                        psUnmapDevMemIN->psKernelMemInfo,
-#endif
                                                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
        {
@@ -1189,11 +1031,7 @@ PVRSRVUnmapDeviceMemoryBW(IMG_UINT32 ui32BridgeID,
        }
 
        psRetOUT->eError = PVRSRVReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                       psUnmapDevMemIN->hKernelMemInfo,
-#else
                                                        psUnmapDevMemIN->psKernelMemInfo,
-#endif
                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        return 0;
@@ -1248,7 +1086,7 @@ PVRSRVMapDeviceClassMemoryBW(IMG_UINT32 ui32BridgeID,
        /* Having looked up the handle, now check its type */
        switch(eHandleType)
        {
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                case PVRSRV_HANDLE_TYPE_DISP_BUFFER:
                case PVRSRV_HANDLE_TYPE_BUF_BUFFER:
 #else
@@ -1285,23 +1123,7 @@ PVRSRVMapDeviceClassMemoryBW(IMG_UINT32 ui32BridgeID,
        psMapDevClassMemOUT->sClientMemInfo.sDevVAddr = psMemInfo->sDevVAddr;
        psMapDevClassMemOUT->sClientMemInfo.ui32Flags = psMemInfo->ui32Flags;
     psMapDevClassMemOUT->sClientMemInfo.uAllocSize = psMemInfo->uAllocSize;
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psMemInfo->sMemBlk.hOSMemHandle != 0)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                       &psMapDevClassMemOUT->sClientMemInfo.hMappingInfo,
-                                       psMemInfo->sMemBlk.hOSMemHandle,
-                                       PVRSRV_HANDLE_TYPE_MEM_INFO,
-                                       PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                       psMapDevClassMemIN->hDeviceClassBuffer);
-       }
-       else
-       {
-               psMapDevClassMemOUT->sClientMemInfo.hMappingInfo = 0;
-       }
-#else
        psMapDevClassMemOUT->sClientMemInfo.hMappingInfo = psMemInfo->sMemBlk.hOSMemHandle;
-#endif
 
        PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
                                          &psMapDevClassMemOUT->sClientMemInfo.hKernelMemInfo,
@@ -1325,24 +1147,8 @@ PVRSRVMapDeviceClassMemoryBW(IMG_UINT32 ui32BridgeID,
                psMapDevClassMemOUT->sClientSyncInfo.sReadOps2CompleteDevVAddr =
                        psMemInfo->psKernelSyncInfo->sReadOps2CompleteDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-               if (psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle != 0)
-               {
-                       PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                               &psMapDevClassMemOUT->sClientSyncInfo.hMappingInfo,
-                                                               psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle,
-                                                               PVRSRV_HANDLE_TYPE_SYNC_INFO,
-                                                               PVRSRV_HANDLE_ALLOC_FLAG_MULTI,
-                                                               psMapDevClassMemOUT->sClientMemInfo.hKernelMemInfo);
-               }
-               else
-               {
-                       psMapDevClassMemOUT->sClientSyncInfo.hMappingInfo = 0;
-               }
-#else
                psMapDevClassMemOUT->sClientSyncInfo.hMappingInfo =
                        psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle;
-#endif
 #endif
 
                psMapDevClassMemOUT->sClientMemInfo.psClientSyncInfo = &psMapDevClassMemOUT->sClientSyncInfo;
@@ -1377,11 +1183,7 @@ PVRSRVUnmapDeviceClassMemoryBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase, &pvKernelMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psUnmapDevClassMemIN->hKernelMemInfo,
-#else
                                                   psUnmapDevClassMemIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
        {
@@ -1397,11 +1199,7 @@ PVRSRVUnmapDeviceClassMemoryBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                       psUnmapDevClassMemIN->hKernelMemInfo,
-#else
                                                        psUnmapDevClassMemIN->psKernelMemInfo,
-#endif
                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        return 0;
@@ -1482,8 +1280,8 @@ PVRSRVWrapExtMemoryBW(IMG_UINT32 ui32BridgeID,
                PVRSRVWrapExtMemoryKM(hDevCookieInt,
                                                          psPerProc,
                                                          hDevMemContextInt,
-                                                         psWrapExtMemIN->ui32ByteSize,
-                                                         psWrapExtMemIN->ui32PageOffset,
+                                                         psWrapExtMemIN->uByteSize,
+                                                         psWrapExtMemIN->uPageOffset,
                                                          psWrapExtMemIN->bPhysContig,
                                                          psSysPAddr,
                                                          psWrapExtMemIN->pvLinAddr,
@@ -1511,11 +1309,7 @@ PVRSRVWrapExtMemoryBW(IMG_UINT32 ui32BridgeID,
        psWrapExtMemOUT->sClientMemInfo.sDevVAddr = psMemInfo->sDevVAddr;
        psWrapExtMemOUT->sClientMemInfo.ui32Flags = psMemInfo->ui32Flags;
     psWrapExtMemOUT->sClientMemInfo.uAllocSize = psMemInfo->uAllocSize;
-#if defined (SUPPORT_SID_INTERFACE)
-/* see below */
-#else
        psWrapExtMemOUT->sClientMemInfo.hMappingInfo = psMemInfo->sMemBlk.hOSMemHandle;
-#endif
 
        PVRSRVAllocHandleNR(psPerProc->psHandleBase,
                                          &psWrapExtMemOUT->sClientMemInfo.hKernelMemInfo,
@@ -1523,22 +1317,6 @@ PVRSRVWrapExtMemoryBW(IMG_UINT32 ui32BridgeID,
                                          PVRSRV_HANDLE_TYPE_MEM_INFO,
                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE);
 
-#if defined (SUPPORT_SID_INTERFACE)
-       /* alloc subhandle for the mapping info */
-       if (psMemInfo->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                               &psWrapExtMemOUT->sClientMemInfo.hMappingInfo,
-                                               psMemInfo->sMemBlk.hOSMemHandle,
-                                               PVRSRV_HANDLE_TYPE_MEM_INFO,
-                                               PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                               psWrapExtMemOUT->sClientMemInfo.hKernelMemInfo);
-       }
-       else
-       {
-               psWrapExtMemOUT->sClientMemInfo.hMappingInfo = 0;
-       }
-#endif
 
        /* setup the sync info */
 #if !defined(PVRSRV_DISABLE_UM_SYNCOBJ_MAPPINGS)
@@ -1551,25 +1329,8 @@ PVRSRVWrapExtMemoryBW(IMG_UINT32 ui32BridgeID,
        psWrapExtMemOUT->sClientSyncInfo.sReadOps2CompleteDevVAddr =
                psMemInfo->psKernelSyncInfo->sReadOps2CompleteDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       /* alloc subhandle for the mapping info */
-       if (psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                               &psWrapExtMemOUT->sClientSyncInfo.hMappingInfo,
-                                               psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle,
-                                               PVRSRV_HANDLE_TYPE_MEM_INFO,
-                                               PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                               psWrapExtMemOUT->sClientMemInfo.hKernelMemInfo);
-       }
-       else
-       {
-               psWrapExtMemOUT->sClientSyncInfo.hMappingInfo = 0;
-       }
-#else
        psWrapExtMemOUT->sClientSyncInfo.hMappingInfo =
                psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle;
-#endif
 #endif
 
        psWrapExtMemOUT->sClientMemInfo.psClientSyncInfo = &psWrapExtMemOUT->sClientSyncInfo;
@@ -1630,6 +1391,7 @@ PVRSRVMapIonHandleBW(IMG_UINT32 ui32BridgeID,
                                           PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        PVRSRV_KERNEL_MEM_INFO  *psKernelMemInfo;
+       IMG_UINT64 ui64Stamp;
 
        psMapIonOUT->eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                                                         &psMapIonIN->hDevCookie,
@@ -1642,9 +1404,9 @@ PVRSRVMapIonHandleBW(IMG_UINT32 ui32BridgeID,
        }
 
        psMapIonOUT->eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                                                        &psMapIonIN->hDevMemContext,
-                                                                                        psMapIonIN->hDevMemContext,
-                                                                                        PVRSRV_HANDLE_TYPE_DEV_MEM_CONTEXT);
+                                                                                        &psMapIonIN->hDevMemHeap,
+                                                                                        psMapIonIN->hDevMemHeap,
+                                                                                        PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP);
        if (psMapIonOUT->eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "%s: Failed to lookup memory context handle", __FUNCTION__));
@@ -1653,11 +1415,16 @@ PVRSRVMapIonHandleBW(IMG_UINT32 ui32BridgeID,
 
        psMapIonOUT->eError = PVRSRVMapIonHandleKM(psPerProc,
                                                                                           psMapIonIN->hDevCookie,
-                                                                                          psMapIonIN->hDevMemContext,
-                                                                                          psMapIonIN->handle,
+                                                                                          psMapIonIN->hDevMemHeap,
+                                                                                          psMapIonIN->ui32NumFDs,
+                                                                                          psMapIonIN->ai32BufferFDs,
                                                                                           psMapIonIN->ui32Attribs,
-                                                                                          psMapIonIN->ui32Size,
-                                                                                          &psKernelMemInfo);
+                                                                                          psMapIonIN->ui32ChunkCount,
+                                                                                          psMapIonIN->auiOffset,
+                                                                                          psMapIonIN->auiSize,
+                                                                                          &psMapIonOUT->uiIonBufferSize,
+                                                                                          &psKernelMemInfo,
+                                                                                          &ui64Stamp);
        if (psMapIonOUT->eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "%s: Failed to map ion handle", __FUNCTION__));
@@ -1679,6 +1446,9 @@ PVRSRVMapIonHandleBW(IMG_UINT32 ui32BridgeID,
        /* No mapping info, we map through ion */
        psMapIonOUT->sClientMemInfo.hMappingInfo = IMG_NULL;
 
+#if defined(SUPPORT_MEMINFO_IDS)
+       psMapIonOUT->sClientMemInfo.ui64Stamp = ui64Stamp;
+#endif
 
        PVRSRVAllocHandleNR(psPerProc->psHandleBase,
                                                &psMapIonOUT->sClientMemInfo.hKernelMemInfo,
@@ -1707,24 +1477,8 @@ PVRSRVMapIonHandleBW(IMG_UINT32 ui32BridgeID,
                psMapIonOUT->sClientSyncInfo.sReadOps2CompleteDevVAddr =
                        psKernelMemInfo->psKernelSyncInfo->sReadOps2CompleteDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-               if (psKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle != IMG_NULL)
-               {
-                               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                                          &psMapIonOUT->sClientSyncInfo.hMappingInfo,
-                                                                          psMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle,
-                                                                          PVRSRV_HANDLE_TYPE_SYNC_INFO,
-                                                                          PVRSRV_HANDLE_ALLOC_FLAG_NONE,
-                                                                          psMapIonOUT->sClientMemInfo.hKernelMemInfo);
-               }
-               else
-               {
-                       psMapIonOUT->sClientSyncInfo.hMappingInfo = 0;
-               }
-#else
                psMapIonOUT->sClientSyncInfo.hMappingInfo =
                        psKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle;
-#endif
 #endif
 
                PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
@@ -1753,11 +1507,7 @@ PVRSRVUnmapIonHandleBW(IMG_UINT32 ui32BridgeID,
        psUnmapIonOUT->eError =
         PVRSRVLookupHandle(psPerProc->psHandleBase,
                            &pvKernelMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psUnmapIonIN->hKernelMemInfo,
-#else
                                                   psUnmapIonIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        if(psUnmapIonOUT->eError != PVRSRV_OK)
@@ -1774,11 +1524,7 @@ PVRSRVUnmapIonHandleBW(IMG_UINT32 ui32BridgeID,
 
        psUnmapIonOUT->eError =
                PVRSRVReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                       psUnmapIonIN->hKernelMemInfo,
-#else
                                                        psUnmapIonIN->psKernelMemInfo,
-#endif
                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
 
        return 0;
@@ -1797,9 +1543,9 @@ PVRSRVGetFreeDeviceMemBW(IMG_UINT32 ui32BridgeID,
 
        psGetFreeDeviceMemOUT->eError =
                PVRSRVGetFreeDeviceMemKM(psGetFreeDeviceMemIN->ui32Flags,
-                                                                &psGetFreeDeviceMemOUT->ui32Total,
-                                                                &psGetFreeDeviceMemOUT->ui32Free,
-                                                                &psGetFreeDeviceMemOUT->ui32LargestBlock);
+                                                                &psGetFreeDeviceMemOUT->uTotal,
+                                                                &psGetFreeDeviceMemOUT->uFree,
+                                                                &psGetFreeDeviceMemOUT->uLargestBlock);
 
        return 0;
 }
@@ -1816,10 +1562,10 @@ PVRMMapOSMemHandleToMMapDataBW(IMG_UINT32 ui32BridgeID,
        psMMapDataOUT->eError =
                PVRMMapOSMemHandleToMMapData(psPerProc,
                                                                                psMMapDataIN->hMHandle,
-                                                                               &psMMapDataOUT->ui32MMapOffset,
-                                                                               &psMMapDataOUT->ui32ByteOffset,
-                                                                               &psMMapDataOUT->ui32RealByteSize,
-                                                                               &psMMapDataOUT->ui32UserVAddr);
+                                                                               &psMMapDataOUT->uiMMapOffset,
+                                                                               &psMMapDataOUT->uiByteOffset,
+                                                                               &psMMapDataOUT->uiRealByteSize,
+                                                                               &psMMapDataOUT->uiUserVAddr);
 #else
        PVR_UNREFERENCED_PARAMETER(psPerProc);
        PVR_UNREFERENCED_PARAMETER(psMMapDataIN);
@@ -1843,8 +1589,8 @@ PVRMMapReleaseMMapDataBW(IMG_UINT32 ui32BridgeID,
                PVRMMapReleaseMMapData(psPerProc,
                                                                                psMMapDataIN->hMHandle,
                                                                                &psMMapDataOUT->bMUnmap,
-                                                                               &psMMapDataOUT->ui32RealByteSize,
-                                                                               &psMMapDataOUT->ui32UserVAddr);
+                                                                               &psMMapDataOUT->uiRealByteSize,
+                                                                               &psMMapDataOUT->uiUserVAddr);
 #else
 
        PVR_UNREFERENCED_PARAMETER(psPerProc);
@@ -1856,34 +1602,6 @@ PVRMMapReleaseMMapDataBW(IMG_UINT32 ui32BridgeID,
 }
 
 
-#if defined (SUPPORT_SID_INTERFACE)
-static IMG_INT
-PVRSRVChangeDeviceMemoryAttributesBW(IMG_UINT32 ui32BridgeID,
-                                     PVRSRV_BRIDGE_IN_CHG_DEV_MEM_ATTRIBS *psChgMemAttribIN,
-                                     PVRSRV_BRIDGE_RETURN *psRetOUT,
-                                     PVRSRV_PER_PROCESS_DATA *psPerProc)
-{
-       IMG_HANDLE hKernelMemInfo;
-
-       PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_CHG_DEV_MEM_ATTRIBS);
-
-       psRetOUT->eError =
-               PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                       &hKernelMemInfo,
-                                                       psChgMemAttribIN->hKernelMemInfo,
-                                                       PVRSRV_HANDLE_TYPE_MEM_INFO);
-
-       if(psRetOUT->eError != PVRSRV_OK)
-       {
-               return 0;
-       }
-
-       psRetOUT->eError =
-               PVRSRVChangeDeviceMemoryAttributesKM(hKernelMemInfo, psChgMemAttribIN->ui32Attribs);
-
-       return 0;
-}
-#else
 static IMG_INT
 PVRSRVChangeDeviceMemoryAttributesBW(IMG_UINT32 ui32BridgeID,
                                      PVRSRV_BRIDGE_IN_CHG_DEV_MEM_ATTRIBS *psChgMemAttribIN,
@@ -1897,7 +1615,6 @@ PVRSRVChangeDeviceMemoryAttributesBW(IMG_UINT32 ui32BridgeID,
 
        return 0;
 }
-#endif
 
 #ifdef PDUMP
 static IMG_INT
@@ -2017,11 +1734,7 @@ PDumpMemPolBW(IMG_UINT32 ui32BridgeID,
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                   &pvMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                           psPDumpMemPolIN->hKernelMemInfo,
-#else
                                                   psPDumpMemPolIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
        {
@@ -2053,11 +1766,7 @@ PDumpMemBW(IMG_UINT32 ui32BridgeID,
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                   &pvMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psPDumpMemDumpIN->hKernelMemInfo,
-#else
                                                   psPDumpMemDumpIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
        {
@@ -2208,11 +1917,7 @@ PDumpSyncDumpBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase, &pvSyncInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                           psPDumpSyncDumpIN->hKernelSyncInfo,
-#else
                                                   psPDumpSyncDumpIN->psKernelSyncInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_SYNC_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
        {
@@ -2248,11 +1953,7 @@ PDumpSyncPolBW(IMG_UINT32 ui32BridgeID,
        psRetOUT->eError =
         PVRSRVLookupHandle(psPerProc->psHandleBase,
                            &pvSyncInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psPDumpSyncPolIN->hKernelSyncInfo,
-#else
                                                   psPDumpSyncPolIN->psKernelSyncInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_SYNC_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
        {
@@ -2396,30 +2097,13 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
                                        PVRSRV_BRIDGE_OUT_GET_MISC_INFO *psGetMiscInfoOUT,
                                        PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
-#if defined (SUPPORT_SID_INTERFACE)
-    PVRSRV_MISC_INFO_KM sMiscInfo = {0};
-#endif
        PVRSRV_ERROR eError;
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_GET_MISC_INFO);
 
-#if defined (SUPPORT_SID_INTERFACE)
-       sMiscInfo.ui32StateRequest = psGetMiscInfoIN->sMiscInfo.ui32StateRequest;
-       sMiscInfo.ui32StatePresent = psGetMiscInfoIN->sMiscInfo.ui32StatePresent;
-       sMiscInfo.ui32MemoryStrLen = psGetMiscInfoIN->sMiscInfo.ui32MemoryStrLen;
-       sMiscInfo.pszMemoryStr     = psGetMiscInfoIN->sMiscInfo.pszMemoryStr;
-
-       OSMemCopy(&sMiscInfo.sCacheOpCtl,
-                         &psGetMiscInfoIN->sMiscInfo.sCacheOpCtl,
-                         sizeof(sMiscInfo.sCacheOpCtl));
-       OSMemCopy(&sMiscInfo.sGetRefCountCtl,
-                         &psGetMiscInfoIN->sMiscInfo.sGetRefCountCtl,
-                         sizeof(sMiscInfo.sGetRefCountCtl));
-#else
        OSMemCopy(&psGetMiscInfoOUT->sMiscInfo,
                          &psGetMiscInfoIN->sMiscInfo,
                          sizeof(PVRSRV_MISC_INFO));
-#endif
 
        if (((psGetMiscInfoIN->sMiscInfo.ui32StateRequest & PVRSRV_MISC_INFO_MEMSTATS_PRESENT) != 0) &&
            ((psGetMiscInfoIN->sMiscInfo.ui32StateRequest & PVRSRV_MISC_INFO_DDKVERSION_PRESENT) != 0) &&
@@ -2436,20 +2120,6 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
            ((psGetMiscInfoIN->sMiscInfo.ui32StateRequest & PVRSRV_MISC_INFO_FREEMEM_PRESENT) != 0))
        {
                /* Alloc kernel side buffer to write into */
-#if defined (SUPPORT_SID_INTERFACE)
-               ASSIGN_AND_EXIT_ON_ERROR(psGetMiscInfoOUT->eError,
-                                       OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
-                                                       psGetMiscInfoOUT->sMiscInfo.ui32MemoryStrLen,
-                                                       (IMG_VOID **)&sMiscInfo.pszMemoryStr, 0,
-                                                       "Output string buffer"));
-               psGetMiscInfoOUT->eError = PVRSRVGetMiscInfoKM(&sMiscInfo);
-
-               /* Copy result to user */
-               eError = CopyToUserWrapper(psPerProc, ui32BridgeID,
-                                                                       psGetMiscInfoIN->sMiscInfo.pszMemoryStr,
-                                                                       sMiscInfo.pszMemoryStr,
-                                                                       sMiscInfo.ui32MemoryStrLen);
-#else
                ASSIGN_AND_EXIT_ON_ERROR(psGetMiscInfoOUT->eError,
                                    OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
                                    psGetMiscInfoOUT->sMiscInfo.ui32MemoryStrLen,
@@ -2463,18 +2133,11 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
                                           psGetMiscInfoIN->sMiscInfo.pszMemoryStr,
                                           psGetMiscInfoOUT->sMiscInfo.pszMemoryStr,
                                           psGetMiscInfoOUT->sMiscInfo.ui32MemoryStrLen);
-#endif
 
                /* Free kernel side buffer again */
-#if defined (SUPPORT_SID_INTERFACE)
-               OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
-                                       sMiscInfo.ui32MemoryStrLen,
-                                       (IMG_VOID *)sMiscInfo.pszMemoryStr, 0);
-#else
                OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
                          psGetMiscInfoOUT->sMiscInfo.ui32MemoryStrLen,
                         (IMG_VOID *)psGetMiscInfoOUT->sMiscInfo.pszMemoryStr, 0);
-#endif
 
                /* Replace output buffer pointer with input pointer, as both are expected
                 * to point to the same userspace memory.
@@ -2492,11 +2155,7 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
        }
        else
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               psGetMiscInfoOUT->eError = PVRSRVGetMiscInfoKM(&sMiscInfo);
-#else
                psGetMiscInfoOUT->eError = PVRSRVGetMiscInfoKM(&psGetMiscInfoOUT->sMiscInfo);
-#endif
        }
 
        /* Return on error so exit status of PVRSRVGetMiscInfoKM is propagated to client.
@@ -2512,19 +2171,11 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
         * (a shared handle is allocated at most once), and there is no
         * resource allocation to undo if the handle allocation fails.
         */
-#if defined (SUPPORT_SID_INTERFACE)
-       if (sMiscInfo.ui32StateRequest & PVRSRV_MISC_INFO_GLOBALEVENTOBJECT_PRESENT)
-#else
        if (psGetMiscInfoIN->sMiscInfo.ui32StateRequest & PVRSRV_MISC_INFO_GLOBALEVENTOBJECT_PRESENT)
-#endif
        {
                psGetMiscInfoOUT->eError = PVRSRVAllocHandle(psPerProc->psHandleBase,
                                                                                                        &psGetMiscInfoOUT->sMiscInfo.sGlobalEventObject.hOSEventKM,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                    sMiscInfo.sGlobalEventObject.hOSEventKM,
-#else
                                                                                                        psGetMiscInfoOUT->sMiscInfo.sGlobalEventObject.hOSEventKM,
-#endif
                                                                                                        PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT,
                                                                                                        PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
 
@@ -2533,27 +2184,14 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
 
-#if defined (SUPPORT_SID_INTERFACE)
-               OSMemCopy(&psGetMiscInfoOUT->sMiscInfo.sGlobalEventObject.szName,
-                                                       sMiscInfo.sGlobalEventObject.szName,
-                                                       EVENTOBJNAME_MAXLENGTH);
-#endif
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if (sMiscInfo.hSOCTimerRegisterOSMemHandle)
-#else
        if (psGetMiscInfoOUT->sMiscInfo.hSOCTimerRegisterOSMemHandle)
-#endif
        {
                /* Allocate handle for SOC OSMemHandle */
                psGetMiscInfoOUT->eError = PVRSRVAllocHandle(psPerProc->psHandleBase,
                                                  &psGetMiscInfoOUT->sMiscInfo.hSOCTimerRegisterOSMemHandle,
-#if defined (SUPPORT_SID_INTERFACE)
-                          sMiscInfo.hSOCTimerRegisterOSMemHandle,
-#else
                                                  psGetMiscInfoOUT->sMiscInfo.hSOCTimerRegisterOSMemHandle,
-#endif
                                                  PVRSRV_HANDLE_TYPE_SOC_TIMER,
                                                  PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
 
@@ -2562,32 +2200,6 @@ PVRSRVGetMiscInfoBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
        }
-#if defined (SUPPORT_SID_INTERFACE)
-       else
-       {
-               psGetMiscInfoOUT->sMiscInfo.hSOCTimerRegisterOSMemHandle = 0;
-       }
-
-       /* copy data from local sMiscInfo to OUT */
-       psGetMiscInfoOUT->sMiscInfo.ui32StateRequest = sMiscInfo.ui32StateRequest;
-       psGetMiscInfoOUT->sMiscInfo.ui32StatePresent = sMiscInfo.ui32StatePresent;
-
-       psGetMiscInfoOUT->sMiscInfo.pvSOCTimerRegisterKM = sMiscInfo.pvSOCTimerRegisterKM;
-       psGetMiscInfoOUT->sMiscInfo.pvSOCTimerRegisterUM = sMiscInfo.pvSOCTimerRegisterUM;
-       psGetMiscInfoOUT->sMiscInfo.pvSOCClockGateRegs   = sMiscInfo.pvSOCClockGateRegs;
-
-       psGetMiscInfoOUT->sMiscInfo.ui32SOCClockGateRegsSize = sMiscInfo.ui32SOCClockGateRegsSize;
-
-       OSMemCopy(&psGetMiscInfoOUT->sMiscInfo.aui32DDKVersion,
-                               &sMiscInfo.aui32DDKVersion,
-                               sizeof(psGetMiscInfoOUT->sMiscInfo.aui32DDKVersion));
-       OSMemCopy(&psGetMiscInfoOUT->sMiscInfo.sCacheOpCtl,
-                               &sMiscInfo.sCacheOpCtl,
-                               sizeof(psGetMiscInfoOUT->sMiscInfo.sCacheOpCtl));
-       OSMemCopy(&psGetMiscInfoOUT->sMiscInfo.sGetRefCountCtl,
-                               &sMiscInfo.sGetRefCountCtl,
-                               sizeof(psGetMiscInfoOUT->sMiscInfo.sGetRefCountCtl));
-#endif
 
        return 0;
 }
@@ -3135,9 +2747,6 @@ PVRSRVGetDCBuffersBW(IMG_UINT32 ui32BridgeID,
        IMG_VOID *pvDispClassInfo;
        IMG_VOID *pvSwapChain;
        IMG_UINT32 i;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_HANDLE  *pahBuffer;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_GET_DISPCLASS_BUFFERS);
 
@@ -3163,27 +2772,12 @@ PVRSRVGetDCBuffersBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       psGetDispClassBuffersOUT->eError = OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
-                                                                                                       sizeof(IMG_HANDLE) * PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS,
-                                                                                                       (IMG_PVOID *)&pahBuffer, 0,
-                                                                                                       "Temp Swapchain Buffers");
-
-       if (psGetDispClassBuffersOUT->eError != PVRSRV_OK)
-       {
-               return 0;
-       }
-#endif
 
        psGetDispClassBuffersOUT->eError =
                PVRSRVGetDCBuffersKM(pvDispClassInfo,
                                                         pvSwapChain,
                                                         &psGetDispClassBuffersOUT->ui32BufferCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                        pahBuffer,
-#else
                                                         psGetDispClassBuffersOUT->ahBuffer,
-#endif
                                                         psGetDispClassBuffersOUT->asPhyAddr);
        if (psGetDispClassBuffersOUT->eError != PVRSRV_OK)
        {
@@ -3194,37 +2788,19 @@ PVRSRVGetDCBuffersBW(IMG_UINT32 ui32BridgeID,
 
        for(i = 0; i < psGetDispClassBuffersOUT->ui32BufferCount; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID hBufferExt;
-#else
                IMG_HANDLE hBufferExt;
-#endif
 
        /* PRQA S 1461 15 */ /* ignore warning about enum type being converted */
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                       &hBufferExt,
-                                                       pahBuffer[i],
-                                                       PVRSRV_HANDLE_TYPE_DISP_BUFFER,
-                                                       (PVRSRV_HANDLE_ALLOC_FLAG)(PVRSRV_HANDLE_ALLOC_FLAG_PRIVATE | PVRSRV_HANDLE_ALLOC_FLAG_SHARED),
-                                                       psGetDispClassBuffersIN->hSwapChain);
-#else
                PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
                                                         &hBufferExt,
                                                         psGetDispClassBuffersOUT->ahBuffer[i],
                                                         PVRSRV_HANDLE_TYPE_DISP_BUFFER,
                                                         (PVRSRV_HANDLE_ALLOC_FLAG)(PVRSRV_HANDLE_ALLOC_FLAG_PRIVATE | PVRSRV_HANDLE_ALLOC_FLAG_SHARED),
                                                         psGetDispClassBuffersIN->hSwapChain);
-#endif
 
                psGetDispClassBuffersOUT->ahBuffer[i] = hBufferExt;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
-                               sizeof(IMG_HANDLE) * PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS,
-                               (IMG_PVOID)pahBuffer, 0);
-#endif
 
        COMMIT_HANDLE_BATCH_OR_ERROR(psGetDispClassBuffersOUT->eError, psPerProc)
 
@@ -3239,9 +2815,6 @@ PVRSRVSwapToDCBufferBW(IMG_UINT32 ui32BridgeID,
 {
        IMG_VOID *pvDispClassInfo;
        IMG_VOID *pvSwapChainBuf;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_HANDLE hPrivateTag;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SWAP_DISPCLASS_TO_BUFFER);
 
@@ -3266,35 +2839,12 @@ PVRSRVSwapToDCBufferBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psSwapDispClassBufferIN->hPrivateTag != 0)
-       {
-               psRetOUT->eError =
-                       PVRSRVLookupSubHandle(psPerProc->psHandleBase,
-                                                               &hPrivateTag,
-                                                               psSwapDispClassBufferIN->hPrivateTag,
-                                                               PVRSRV_HANDLE_TYPE_DISP_BUFFER,
-                                                               psSwapDispClassBufferIN->hDeviceKM);
-               if(psRetOUT->eError != PVRSRV_OK)
-               {
-                       return 0;
-               }
-       }
-       else
-       {
-               hPrivateTag = IMG_NULL;
-       }
-#endif
 
        psRetOUT->eError =
                PVRSRVSwapToDCBufferKM(pvDispClassInfo,
                                                           pvSwapChainBuf,
                                                           psSwapDispClassBufferIN->ui32SwapInterval,
-#if defined (SUPPORT_SID_INTERFACE)
-                               hPrivateTag,
-#else
                                                           psSwapDispClassBufferIN->hPrivateTag,
-#endif
                                                           psSwapDispClassBufferIN->ui32ClipRectCount,
                                                           psSwapDispClassBufferIN->sClipRect);
 
@@ -3304,34 +2854,35 @@ PVRSRVSwapToDCBufferBW(IMG_UINT32 ui32BridgeID,
 static IMG_INT
 PVRSRVSwapToDCBuffer2BW(IMG_UINT32 ui32BridgeID,
                                                PVRSRV_BRIDGE_IN_SWAP_DISPCLASS_TO_BUFFER2 *psSwapDispClassBufferIN,
-                                               PVRSRV_BRIDGE_RETURN *psRetOUT,
+                                               PVRSRV_BRIDGE_OUT_SWAP_DISPCLASS_TO_BUFFER2 *psSwapDispClassBufferOUT,
                                                PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        IMG_VOID *pvPrivData = IMG_NULL;
+       IMG_HANDLE hFence = IMG_NULL;
        IMG_VOID *pvDispClassInfo;
        IMG_VOID *pvSwapChain;
        IMG_UINT32 i;
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SWAP_DISPCLASS_TO_BUFFER2);
 
-       psRetOUT->eError =
+       psSwapDispClassBufferOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                   &pvDispClassInfo,
                                                   psSwapDispClassBufferIN->hDeviceKM,
                                                   PVRSRV_HANDLE_TYPE_DISP_INFO);
-       if(psRetOUT->eError != PVRSRV_OK)
+       if(psSwapDispClassBufferOUT->eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVSwapToDCBuffer2BW: Failed to look up DISP_INFO handle"));
                return 0;
        }
 
-       psRetOUT->eError =
+       psSwapDispClassBufferOUT->eError =
                PVRSRVLookupSubHandle(psPerProc->psHandleBase,
                                                          &pvSwapChain,
                                                          psSwapDispClassBufferIN->hSwapChain,
                                                          PVRSRV_HANDLE_TYPE_DISP_SWAP_CHAIN,
                                                          psSwapDispClassBufferIN->hDeviceKM);
-       if(psRetOUT->eError != PVRSRV_OK)
+       if(psSwapDispClassBufferOUT->eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVSwapToDCBuffer2BW: Failed to look up DISP_BUFFER handle"));
                return 0;
@@ -3355,33 +2906,37 @@ PVRSRVSwapToDCBuffer2BW(IMG_UINT32 ui32BridgeID,
 
        for (i = 0; i < psSwapDispClassBufferIN->ui32NumMemInfos; i++)
        {
-               PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo;
                PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
 
-               psRetOUT->eError =
+               psSwapDispClassBufferOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                           (IMG_PVOID *)&psKernelMemInfo,
                                                           psSwapDispClassBufferIN->ppsKernelMemInfos[i],
                                                           PVRSRV_HANDLE_TYPE_MEM_INFO);
-               if(psRetOUT->eError != PVRSRV_OK)
+               if(psSwapDispClassBufferOUT->eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR, "PVRSRVSwapToDCBuffer2BW: Failed to look up MEM_INFO handle"));
                        return 0;
                }
+               psSwapDispClassBufferIN->ppsKernelMemInfos[i] = psKernelMemInfo;
 
-               psRetOUT->eError =
-                       PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                          (IMG_PVOID *)&psKernelSyncInfo,
-                                                          psSwapDispClassBufferIN->ppsKernelSyncInfos[i],
-                                                          PVRSRV_HANDLE_TYPE_SYNC_INFO);
-               if(psRetOUT->eError != PVRSRV_OK)
+#if !defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
                {
-                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVSwapToDCBuffer2BW: Failed to look up SYNC_INFO handle"));
-                       return 0;
+                       PVRSRV_KERNEL_SYNC_INFO *psKernelSyncInfo;
+
+                       psSwapDispClassBufferOUT->eError =
+                               PVRSRVLookupHandle(psPerProc->psHandleBase,
+                                                                  (IMG_PVOID *)&psKernelSyncInfo,
+                                                                  psSwapDispClassBufferIN->ppsKernelSyncInfos[i],
+                                                                  PVRSRV_HANDLE_TYPE_SYNC_INFO);
+                       if(psSwapDispClassBufferOUT->eError != PVRSRV_OK)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "PVRSRVSwapToDCBuffer2BW: Failed to look up SYNC_INFO handle"));
+                               return 0;
+                       }
+                       psSwapDispClassBufferIN->ppsKernelSyncInfos[i] = psKernelSyncInfo;
                }
-
-               psSwapDispClassBufferIN->ppsKernelMemInfos[i] = psKernelMemInfo;
-               psSwapDispClassBufferIN->ppsKernelSyncInfos[i] = psKernelSyncInfo;
+#endif /* !defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
        }
 
        if(psSwapDispClassBufferIN->ui32PrivDataLength > 0)
@@ -3409,7 +2964,7 @@ PVRSRVSwapToDCBuffer2BW(IMG_UINT32 ui32BridgeID,
                }
        }
 
-       psRetOUT->eError =
+       psSwapDispClassBufferOUT->eError =
                PVRSRVSwapToDCBuffer2KM(pvDispClassInfo,
                                                                pvSwapChain,
                                                                psSwapDispClassBufferIN->ui32SwapInterval,
@@ -3417,15 +2972,31 @@ PVRSRVSwapToDCBuffer2BW(IMG_UINT32 ui32BridgeID,
                                                                psSwapDispClassBufferIN->ppsKernelSyncInfos,
                                                                psSwapDispClassBufferIN->ui32NumMemInfos,
                                                                pvPrivData,
-                                                               psSwapDispClassBufferIN->ui32PrivDataLength);
+                                                               psSwapDispClassBufferIN->ui32PrivDataLength,
+                                                               &hFence);
 
-       if(psRetOUT->eError != PVRSRV_OK)
+       if(psSwapDispClassBufferOUT->eError != PVRSRV_OK)
        {
                OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
                                  psSwapDispClassBufferIN->ui32PrivDataLength,
                                  pvPrivData, IMG_NULL);
        }
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       if(hFence)
+       {
+               struct sync_fence *psFence = hFence;
+               int fd = get_unused_fd();
+
+               sync_fence_install(psFence, fd);
+               psSwapDispClassBufferOUT->hFence = (IMG_HANDLE)fd;
+       }
+       else
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+       {
+               psSwapDispClassBufferOUT->hFence = (IMG_HANDLE)-1;
+       }
+
     return 0;
 }
 
@@ -3636,7 +3207,7 @@ PVRSRVAllocSharedSysMemoryBW(IMG_UINT32 ui32BridgeID,
        psAllocSharedSysMemOUT->eError =
                PVRSRVAllocSharedSysMemoryKM(psPerProc,
                                                                         psAllocSharedSysMemIN->ui32Flags,
-                                                                        psAllocSharedSysMemIN->ui32Size,
+                                                                        psAllocSharedSysMemIN->uSize,
                                                                         &psKernelMemInfo);
        if(psAllocSharedSysMemOUT->eError != PVRSRV_OK)
        {
@@ -3655,22 +3226,7 @@ PVRSRVAllocSharedSysMemoryBW(IMG_UINT32 ui32BridgeID,
                psKernelMemInfo->ui32Flags;
     psAllocSharedSysMemOUT->sClientMemInfo.uAllocSize =
         psKernelMemInfo->uAllocSize;
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psKernelMemInfo->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocHandleNR(psPerProc->psHandleBase,
-                                                       &psAllocSharedSysMemOUT->sClientMemInfo.hMappingInfo,
-                                                       psKernelMemInfo->sMemBlk.hOSMemHandle,
-                                                       PVRSRV_HANDLE_TYPE_SHARED_SYS_MEM_INFO,
-                                                       PVRSRV_HANDLE_ALLOC_FLAG_NONE);
-       }
-       else
-       {
-               psAllocSharedSysMemOUT->sClientMemInfo.hMappingInfo = 0;
-       }
-#else
        psAllocSharedSysMemOUT->sClientMemInfo.hMappingInfo = psKernelMemInfo->sMemBlk.hOSMemHandle;
-#endif
 
        PVRSRVAllocHandleNR(psPerProc->psHandleBase,
                                          &psAllocSharedSysMemOUT->sClientMemInfo.hKernelMemInfo,
@@ -3696,11 +3252,7 @@ PVRSRVFreeSharedSysMemoryBW(IMG_UINT32 ui32BridgeID,
        psFreeSharedSysMemOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                   (IMG_VOID **)&psKernelMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  psFreeSharedSysMemIN->hKernelMemInfo,
-#else
                                                   psFreeSharedSysMemIN->psKernelMemInfo,
-#endif
                                                   PVRSRV_HANDLE_TYPE_SHARED_SYS_MEM_INFO);
 
        if(psFreeSharedSysMemOUT->eError != PVRSRV_OK)
@@ -3710,27 +3262,10 @@ PVRSRVFreeSharedSysMemoryBW(IMG_UINT32 ui32BridgeID,
                PVRSRVFreeSharedSysMemoryKM(psKernelMemInfo);
        if(psFreeSharedSysMemOUT->eError != PVRSRV_OK)
                return 0;
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psFreeSharedSysMemIN->hMappingInfo != 0)
-       {
-               psFreeSharedSysMemOUT->eError =
-                       PVRSRVReleaseHandle(psPerProc->psHandleBase,
-                                                               psFreeSharedSysMemIN->hMappingInfo,
-                                                               PVRSRV_HANDLE_TYPE_SHARED_SYS_MEM_INFO);
-               if(psFreeSharedSysMemOUT->eError != PVRSRV_OK)
-               {
-                       return 0;
-               }
-       }
-#endif
 
        psFreeSharedSysMemOUT->eError =
                PVRSRVReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                       psFreeSharedSysMemIN->hKernelMemInfo,
-#else
                                                        psFreeSharedSysMemIN->psKernelMemInfo,
-#endif
                                                        PVRSRV_HANDLE_TYPE_SHARED_SYS_MEM_INFO);
        return 0;
 }
@@ -3743,11 +3278,7 @@ PVRSRVMapMemInfoMemBW(IMG_UINT32 ui32BridgeID,
 {
        PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
        PVRSRV_HANDLE_TYPE eHandleType;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID     hParent;
-#else
        IMG_HANDLE      hParent;
-#endif
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_MAP_MEMINFO_MEM);
 
        NEW_HANDLE_BATCH_OR_ERROR(psMapMemInfoMemOUT->eError, psPerProc, 2)
@@ -3764,7 +3295,7 @@ PVRSRVMapMemInfoMemBW(IMG_UINT32 ui32BridgeID,
 
        switch (eHandleType)
        {
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                case PVRSRV_HANDLE_TYPE_MEM_INFO:
                case PVRSRV_HANDLE_TYPE_MEM_INFO_REF:
                case PVRSRV_HANDLE_TYPE_SHARED_SYS_MEM_INFO:
@@ -3791,11 +3322,7 @@ PVRSRVMapMemInfoMemBW(IMG_UINT32 ui32BridgeID,
        {
                return 0;
        }
-#if defined (SUPPORT_SID_INTERFACE)
-       if (hParent == 0)
-#else
        if (hParent == IMG_NULL)
-#endif
        {
                hParent = psMapMemInfoMemIN->hKernelMemInfo;
        }
@@ -3814,23 +3341,7 @@ PVRSRVMapMemInfoMemBW(IMG_UINT32 ui32BridgeID,
                psKernelMemInfo->ui32Flags;
     psMapMemInfoMemOUT->sClientMemInfo.uAllocSize =
         psKernelMemInfo->uAllocSize;
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psKernelMemInfo->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                               &psMapMemInfoMemOUT->sClientMemInfo.hMappingInfo,
-                                               psKernelMemInfo->sMemBlk.hOSMemHandle,
-                                               PVRSRV_HANDLE_TYPE_MEM_INFO_REF,
-                                               PVRSRV_HANDLE_ALLOC_FLAG_MULTI,
-                                               hParent);
-       }
-       else
-       {
-               psMapMemInfoMemOUT->sClientMemInfo.hMappingInfo = 0;
-       }
-#else
        psMapMemInfoMemOUT->sClientMemInfo.hMappingInfo = psKernelMemInfo->sMemBlk.hOSMemHandle;
-#endif
 
        PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
                                          &psMapMemInfoMemOUT->sClientMemInfo.hKernelMemInfo,
@@ -3859,24 +3370,8 @@ PVRSRVMapMemInfoMemBW(IMG_UINT32 ui32BridgeID,
                psMapMemInfoMemOUT->sClientSyncInfo.sReadOps2CompleteDevVAddr =
                        psKernelMemInfo->psKernelSyncInfo->sReadOps2CompleteDevVAddr;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle != IMG_NULL)
-       {
-               PVRSRVAllocSubHandleNR(psPerProc->psHandleBase,
-                                                               &psMapMemInfoMemOUT->sClientSyncInfo.hMappingInfo,
-                                                               psKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle,
-                                                               PVRSRV_HANDLE_TYPE_SYNC_INFO,
-                                                               PVRSRV_HANDLE_ALLOC_FLAG_MULTI,
-                                                               psMapMemInfoMemOUT->sClientMemInfo.hKernelMemInfo);
-       }
-       else
-       {
-               psMapMemInfoMemOUT->sClientSyncInfo.hMappingInfo = 0;
-       }
-#else
                psMapMemInfoMemOUT->sClientSyncInfo.hMappingInfo =
                        psKernelMemInfo->psKernelSyncInfo->psSyncDataMemInfoKM->sMemBlk.hOSMemHandle;
-#endif
 #endif
 
                psMapMemInfoMemOUT->sClientMemInfo.psClientSyncInfo = &psMapMemInfoMemOUT->sClientSyncInfo;
@@ -3940,7 +3435,7 @@ _SetDispatchTableEntry(IMG_UINT32 ui32Index,
                                           BridgeWrapperFunction pfFunction,
                                           const IMG_CHAR *pszFunctionName)
 {
-       static IMG_UINT32 ui32PrevIndex = ~0UL;         /* -1 */
+       static IMG_UINT uiPrevIndex = ~0U;              /* -1 */
 #if !defined(DEBUG)
        PVR_UNREFERENCED_PARAMETER(pszIOCName);
 #endif
@@ -3983,20 +3478,20 @@ _SetDispatchTableEntry(IMG_UINT32 ui32Index,
         * etc is likly to modify the available ioctls and thus be a point where
         * mistakes are exposed. This isn't run at at a performance critical time.
         */
-//     if((ui32PrevIndex != (IMG_UINT32)-1) &&
-       if((ui32PrevIndex != ~0UL) &&
-          ((ui32Index >= ui32PrevIndex + DISPATCH_TABLE_GAP_THRESHOLD) ||
-               (ui32Index <= ui32PrevIndex)))
+//     if((uiPrevIndex != (IMG_UINT)-1) &&
+       if((uiPrevIndex != ~0U) &&
+          ((ui32Index >= uiPrevIndex + DISPATCH_TABLE_GAP_THRESHOLD) ||
+               (ui32Index <= uiPrevIndex)))
        {
 #if defined(DEBUG_BRIDGE_KM)
                PVR_DPF((PVR_DBG_WARNING,
                                 "%s: There is a gap in the dispatch table between indices %u (%s) and %u (%s)",
-                                __FUNCTION__, ui32PrevIndex, g_BridgeDispatchTable[ui32PrevIndex].pszIOCName,
+                                __FUNCTION__, uiPrevIndex, g_BridgeDispatchTable[uiPrevIndex].pszIOCName,
                                 ui32Index, pszIOCName));
 #else
                PVR_DPF((PVR_DBG_WARNING,
                                 "%s: There is a gap in the dispatch table between indices %u and %u (%s)",
-                                __FUNCTION__, (IMG_UINT)ui32PrevIndex, (IMG_UINT)ui32Index, pszIOCName));
+                                __FUNCTION__, (IMG_UINT)uiPrevIndex, (IMG_UINT)ui32Index, pszIOCName));
 #endif
                PVR_DPF((PVR_DBG_ERROR, "NOTE: Enabling DEBUG_BRIDGE_KM_DISPATCH_TABLE may help debug this issue."));
        }
@@ -4009,7 +3504,7 @@ _SetDispatchTableEntry(IMG_UINT32 ui32Index,
        g_BridgeDispatchTable[ui32Index].ui32CopyFromUserTotalBytes = 0;
 #endif
 
-       ui32PrevIndex = ui32Index;
+       uiPrevIndex = ui32Index;
 }
 
 static IMG_INT
@@ -4106,10 +3601,6 @@ PVRSRVEventObjectOpenBW(IMG_UINT32 ui32BridgeID,
                                                  PVRSRV_BRIDGE_OUT_EVENT_OBJECT_OPEN *psEventObjectOpenOUT,
                                                  PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_EVENTOBJECT_KM sEventObject;
-       IMG_HANDLE hOSEvent;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_EVENT_OBJECT_OPEN);
 
@@ -4117,11 +3608,7 @@ PVRSRVEventObjectOpenBW(IMG_UINT32 ui32BridgeID,
 
        psEventObjectOpenOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &sEventObject.hOSEventKM,
-#else
                                                   &psEventObjectOpenIN->sEventObject.hOSEventKM,
-#endif
                                                   psEventObjectOpenIN->sEventObject.hOSEventKM,
                                                   PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT);
 
@@ -4130,38 +3617,18 @@ PVRSRVEventObjectOpenBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       OSMemCopy(&sEventObject.szName,
-                         &psEventObjectOpenIN->sEventObject.szName,
-                         EVENTOBJNAME_MAXLENGTH);
-
-       psEventObjectOpenOUT->eError = OSEventObjectOpenKM(&sEventObject, &hOSEvent);
-#else
        psEventObjectOpenOUT->eError = OSEventObjectOpenKM(&psEventObjectOpenIN->sEventObject, &psEventObjectOpenOUT->hOSEvent);
-#endif
 
        if(psEventObjectOpenOUT->eError != PVRSRV_OK)
        {
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-/* Windows7, WinXP and Vista already use an Index type handle which the client glue uses directly */
-/* Linux requires a SID handle */
-#if !defined (WINXP) && !defined(SUPPORT_VISTA)
-       PVRSRVAllocHandleNR(psPerProc->psHandleBase,
-                                               &psEventObjectOpenOUT->hOSEvent,
-                                               hOSEvent,
-                                               PVRSRV_HANDLE_TYPE_EVENT_OBJECT_CONNECT,
-                                               PVRSRV_HANDLE_ALLOC_FLAG_MULTI);
-#endif
-#else
        PVRSRVAllocHandleNR(psPerProc->psHandleBase,
                                          &psEventObjectOpenOUT->hOSEvent,
                                          psEventObjectOpenOUT->hOSEvent,
                                          PVRSRV_HANDLE_TYPE_EVENT_OBJECT_CONNECT,
                                          PVRSRV_HANDLE_ALLOC_FLAG_MULTI);
-#endif
 
        COMMIT_HANDLE_BATCH_OR_ERROR(psEventObjectOpenOUT->eError, psPerProc)
 
@@ -4176,19 +3643,12 @@ PVRSRVEventObjectCloseBW(IMG_UINT32 ui32BridgeID,
                                                  PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        IMG_HANDLE hOSEventKM;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_EVENTOBJECT_KM sEventObject;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_EVENT_OBJECT_CLOSE);
 
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &sEventObject.hOSEventKM,
-#else
                                                   &psEventObjectCloseIN->sEventObject.hOSEventKM,
-#endif
                                                   psEventObjectCloseIN->sEventObject.hOSEventKM,
                                                   PVRSRV_HANDLE_TYPE_SHARED_EVENT_OBJECT);
        if(psRetOUT->eError != PVRSRV_OK)
@@ -4206,20 +3666,7 @@ PVRSRVEventObjectCloseBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if(CopyFromUserWrapper(psPerProc, ui32BridgeID,
-                                                       &sEventObject.szName,
-                                                       &psEventObjectCloseIN->sEventObject.szName,
-                                                       EVENTOBJNAME_MAXLENGTH) != PVRSRV_OK)
-       {
-               /*not nulling pointer, out of scope*/
-               return -EFAULT;
-       }
-
-       psRetOUT->eError = OSEventObjectCloseKM(&sEventObject, hOSEventKM);
-#else
        psRetOUT->eError = OSEventObjectCloseKM(&psEventObjectCloseIN->sEventObject, hOSEventKM);
-#endif
 
        return 0;
 }
index b0145f7..abcbbac 100644 (file)
@@ -99,7 +99,7 @@ CopyToUserWrapper(PVRSRV_PER_PROCESS_DATA *pProcData,
 #define ASSIGN_AND_EXIT_ON_ERROR(error, src)           \
        ASSIGN_AND_RETURN_ON_ERROR(error, src, 0)
 
-#if defined (PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(NewHandleBatch)
 #endif
index 25baf29..2ccdc66 100644 (file)
@@ -52,11 +52,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * handle.
  */
 PVRSRV_ERROR
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRVLookupOSMemHandle(PVRSRV_HANDLE_BASE *psHandleBase, IMG_HANDLE *phOSMemHandle, IMG_SID hMHandle)
-#else
 PVRSRVLookupOSMemHandle(PVRSRV_HANDLE_BASE *psHandleBase, IMG_HANDLE *phOSMemHandle, IMG_HANDLE hMHandle)
-#endif
 {
        IMG_HANDLE hMHandleInt;
        PVRSRV_HANDLE_TYPE eHandleType;
@@ -76,7 +72,7 @@ PVRSRVLookupOSMemHandle(PVRSRV_HANDLE_BASE *psHandleBase, IMG_HANDLE *phOSMemHan
 
        switch(eHandleType)
        {
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                case PVRSRV_HANDLE_TYPE_MEM_INFO:
                case PVRSRV_HANDLE_TYPE_MEM_INFO_REF:
                case PVRSRV_HANDLE_TYPE_SHARED_SYS_MEM_INFO:
index 04d5168..e32fa88 100644 (file)
@@ -55,11 +55,7 @@ extern "C" {
  * Derive the internal OS specific memory handle from a secure
  * handle.
  */
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVLookupOSMemHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phOSMemHandle, IMG_SID hMHandle);
-#else
 PVRSRV_ERROR PVRSRVLookupOSMemHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phOSMemHandle, IMG_HANDLE hMHandle);
-#endif
 
 #if defined (__cplusplus)
 }
index bee5dc6..2b52844 100644 (file)
@@ -141,9 +141,6 @@ SGXGetInternalDevInfoBW(IMG_UINT32 ui32BridgeID,
                                                PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        IMG_HANDLE hDevCookieInt;
-#if defined (SUPPORT_SID_INTERFACE)
-       SGX_INTERNAL_DEVINFO_KM sSGXInternalDevInfo;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_GETINTERNALDEVINFO);
 
@@ -159,11 +156,7 @@ SGXGetInternalDevInfoBW(IMG_UINT32 ui32BridgeID,
 
        psSGXGetInternalDevInfoOUT->eError =
                SGXGetInternalDevInfoKM(hDevCookieInt,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                               &sSGXInternalDevInfo);
-#else
                                                                &psSGXGetInternalDevInfoOUT->sSGXInternalDevInfo);
-#endif
 
        /*
         * Handle is not allocated in batch mode, as there is no resource
@@ -172,11 +165,7 @@ SGXGetInternalDevInfoBW(IMG_UINT32 ui32BridgeID,
        psSGXGetInternalDevInfoOUT->eError =
                PVRSRVAllocHandle(psPerProc->psHandleBase,
                                                  &psSGXGetInternalDevInfoOUT->sSGXInternalDevInfo.hHostCtlKernelMemInfoHandle,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                 sSGXInternalDevInfo.hHostCtlKernelMemInfoHandle,
-#else
                                                  psSGXGetInternalDevInfoOUT->sSGXInternalDevInfo.hHostCtlKernelMemInfoHandle,
-#endif
                                                  PVRSRV_HANDLE_TYPE_MEM_INFO,
                                                  PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
 
@@ -194,12 +183,7 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
        IMG_UINT32 i;
        IMG_INT ret = 0;
        IMG_UINT32 ui32NumDstSyncs;
-#if defined (SUPPORT_SID_INTERFACE)
-       SGX_CCB_KICK_KM sCCBKickKM = {{0}};
-       IMG_HANDLE      ahSyncInfoHandles[16];
-#else
        IMG_HANDLE *phKernelSyncInfoHandles = IMG_NULL;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_DOKICK);
 
@@ -216,11 +200,7 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &sCCBKickKM.hCCBKernelMemInfo,
-#else
                                                   &psDoKickIN->sCCBKick.hCCBKernelMemInfo,
-#endif
                                                   psDoKickIN->sCCBKick.hCCBKernelMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
 
@@ -229,24 +209,11 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psDoKickIN->sCCBKick.ui32NumDstSyncObjects > 16)
-       {
-               return 0;
-       }
-                       
-       if(psDoKickIN->sCCBKick.hTA3DSyncInfo != 0)
-#else
        if(psDoKickIN->sCCBKick.hTA3DSyncInfo != IMG_NULL)
-#endif
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.hTA3DSyncInfo,
-#else
                                                           &psDoKickIN->sCCBKick.hTA3DSyncInfo,
-#endif
                                                           psDoKickIN->sCCBKick.hTA3DSyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -256,19 +223,11 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                }
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if(psDoKickIN->sCCBKick.hTASyncInfo != 0)
-#else
        if(psDoKickIN->sCCBKick.hTASyncInfo != IMG_NULL)
-#endif
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.hTASyncInfo,
-#else
                                                           &psDoKickIN->sCCBKick.hTASyncInfo,
-#endif
                                                           psDoKickIN->sCCBKick.hTASyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -292,19 +251,11 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
        }
 #endif
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if(psDoKickIN->sCCBKick.h3DSyncInfo != 0)
-#else
        if(psDoKickIN->sCCBKick.h3DSyncInfo != IMG_NULL)
-#endif
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.h3DSyncInfo,
-#else
                                                           &psDoKickIN->sCCBKick.h3DSyncInfo,
-#endif
                                                           psDoKickIN->sCCBKick.h3DSyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -323,18 +274,11 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       sCCBKickKM.ui32NumTASrcSyncs = psDoKickIN->sCCBKick.ui32NumTASrcSyncs;
-#endif
        for(i=0; i<psDoKickIN->sCCBKick.ui32NumTASrcSyncs; i++)
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.ahTASrcKernelSyncInfo[i],
-#else
                                                           &psDoKickIN->sCCBKick.ahTASrcKernelSyncInfo[i],
-#endif
                                                           psDoKickIN->sCCBKick.ahTASrcKernelSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -350,18 +294,11 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       sCCBKickKM.ui32NumTADstSyncs = psDoKickIN->sCCBKick.ui32NumTADstSyncs;
-#endif
        for(i=0; i<psDoKickIN->sCCBKick.ui32NumTADstSyncs; i++)
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.ahTADstKernelSyncInfo[i],
-#else
                                                           &psDoKickIN->sCCBKick.ahTADstKernelSyncInfo[i],
-#endif
                                                           psDoKickIN->sCCBKick.ahTADstKernelSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -377,18 +314,11 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       sCCBKickKM.ui32Num3DSrcSyncs = psDoKickIN->sCCBKick.ui32Num3DSrcSyncs;
-#endif
        for(i=0; i<psDoKickIN->sCCBKick.ui32Num3DSrcSyncs; i++)
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.ah3DSrcKernelSyncInfo[i],
-#else
                                                           &psDoKickIN->sCCBKick.ah3DSrcKernelSyncInfo[i],
-#endif
                                                           psDoKickIN->sCCBKick.ah3DSrcKernelSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -405,18 +335,12 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       sCCBKickKM.ui32NumSrcSyncs = psDoKickIN->sCCBKick.ui32NumSrcSyncs;
-#endif
+#if !defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
        for(i=0; i<psDoKickIN->sCCBKick.ui32NumSrcSyncs; i++)
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.ahSrcKernelSyncInfo[i],
-#else
                                                           &psDoKickIN->sCCBKick.ahSrcKernelSyncInfo[i],
-#endif
                                                           psDoKickIN->sCCBKick.ahSrcKernelSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -425,7 +349,8 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
        }
-#endif/* #if defined(SUPPORT_SGX_GENERALISED_SYNCOBJECTS) */
+#endif /* !defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+#endif /* defined(SUPPORT_SGX_GENERALISED_SYNCOBJECTS) */
 
        if (psDoKickIN->sCCBKick.ui32NumTAStatusVals > SGX_MAX_TA_STATUS_VALS)
        {
@@ -437,25 +362,14 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                psRetOUT->eError =
 #if defined(SUPPORT_SGX_NEW_STATUS_VALS)
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.asTAStatusUpdate[i].hKernelMemInfo,
-#else
                                                           &psDoKickIN->sCCBKick.asTAStatusUpdate[i].hKernelMemInfo,
-#endif
                                                           psDoKickIN->sCCBKick.asTAStatusUpdate[i].hKernelMemInfo,
                                                           PVRSRV_HANDLE_TYPE_MEM_INFO);
 
-#if defined (SUPPORT_SID_INTERFACE)
-               sCCBKickKM.asTAStatusUpdate[i].sCtlStatus = psDoKickIN->sCCBKick.asTAStatusUpdate[i].sCtlStatus;
-#endif
 
 #else
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.ahTAStatusSyncInfo[i],
-#else
                                                           &psDoKickIN->sCCBKick.ahTAStatusSyncInfo[i],
-#endif
                                                           psDoKickIN->sCCBKick.ahTAStatusSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 #endif
@@ -475,24 +389,13 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                psRetOUT->eError =
 #if defined(SUPPORT_SGX_NEW_STATUS_VALS)
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.as3DStatusUpdate[i].hKernelMemInfo,
-#else
                                                           &psDoKickIN->sCCBKick.as3DStatusUpdate[i].hKernelMemInfo,
-#endif
                                                           psDoKickIN->sCCBKick.as3DStatusUpdate[i].hKernelMemInfo,
                                                           PVRSRV_HANDLE_TYPE_MEM_INFO);
                                                           
-#if defined (SUPPORT_SID_INTERFACE)
-               sCCBKickKM.as3DStatusUpdate[i].sCtlStatus = psDoKickIN->sCCBKick.as3DStatusUpdate[i].sCtlStatus;
-#endif
 #else
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sCCBKickKM.ah3DStatusSyncInfo[i],
-#else
                                                           &psDoKickIN->sCCBKick.ah3DStatusSyncInfo[i],
-#endif
                                                           psDoKickIN->sCCBKick.ah3DStatusSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
 #endif
@@ -526,9 +429,6 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
 
-#if defined (SUPPORT_SID_INTERFACE)
-               sCCBKickKM.pahDstSyncHandles = phKernelSyncInfoHandles;
-#else
                if(CopyFromUserWrapper(psPerProc,
                                                        ui32BridgeID,
                                                        phKernelSyncInfoHandles,
@@ -541,17 +441,12 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
 
                /* Set sCCBKick.pahDstSyncHandles to point to the local memory */
                psDoKickIN->sCCBKick.pahDstSyncHandles = phKernelSyncInfoHandles;
-#endif
 
                for( i = 0; i < ui32NumDstSyncs; i++)
                {
                        psRetOUT->eError =
                                PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       &sCCBKickKM.pahDstSyncHandles[i],
-#else
                                                                        &psDoKickIN->sCCBKick.pahDstSyncHandles[i],
-#endif
                                                                        psDoKickIN->sCCBKick.pahDstSyncHandles[i],
                                                                        PVRSRV_HANDLE_TYPE_SYNC_INFO);
 
@@ -564,11 +459,7 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
 
                psRetOUT->eError =
                                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                          &sCCBKickKM.hKernelHWSyncListMemInfo,
-#else
                                                                           &psDoKickIN->sCCBKick.hKernelHWSyncListMemInfo,
-#endif
                                                                           psDoKickIN->sCCBKick.hKernelHWSyncListMemInfo,
                                                                           PVRSRV_HANDLE_TYPE_MEM_INFO);
 
@@ -578,34 +469,9 @@ SGXDoKickBW(IMG_UINT32 ui32BridgeID,
                }
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       OSMemCopy(&sCCBKickKM.sCommand, &psDoKickIN->sCCBKick.sCommand, sizeof(sCCBKickKM.sCommand));
-
-       sCCBKickKM.ui32NumDstSyncObjects = psDoKickIN->sCCBKick.ui32NumDstSyncObjects;
-       sCCBKickKM.ui32NumTAStatusVals   = psDoKickIN->sCCBKick.ui32NumTAStatusVals;
-       sCCBKickKM.ui32Num3DStatusVals   = psDoKickIN->sCCBKick.ui32Num3DStatusVals;
-       sCCBKickKM.bFirstKickOrResume    = psDoKickIN->sCCBKick.bFirstKickOrResume;
-       sCCBKickKM.ui32CCBOffset         = psDoKickIN->sCCBKick.ui32CCBOffset;
-       sCCBKickKM.bTADependency         = psDoKickIN->sCCBKick.bTADependency;
-
-#if defined(NO_HARDWARE) || defined(PDUMP)
-       sCCBKickKM.bTerminateOrAbort = psDoKickIN->sCCBKick.bTerminateOrAbort;
-#endif
-#if defined(PDUMP)
-       sCCBKickKM.ui32CCBDumpWOff = psDoKickIN->sCCBKick.ui32CCBDumpWOff;
-#endif
-
-#if defined(NO_HARDWARE)
-       sCCBKickKM.ui32WriteOpsPendingVal = psDoKickIN->sCCBKick.ui32WriteOpsPendingVal;
-#endif
-#endif /* #if defined (SUPPORT_SID_INTERFACE) */
        psRetOUT->eError =
                SGXDoKickKM(hDevCookieInt,
-#if defined (SUPPORT_SID_INTERFACE)
-                                       &sCCBKickKM);
-#else
                                        &psDoKickIN->sCCBKick);
-#endif
 
 PVRSRV_BRIDGE_SGX_DOKICK_RETURN_RESULT:
 
@@ -657,9 +523,6 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
 {
        IMG_HANDLE hDevCookieInt;
        PVRSRV_TRANSFER_SGX_KICK *psKick;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_TRANSFER_SGX_KICK_KM sKickKM = {0};
-#endif
        IMG_UINT32 i;
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_SUBMITTRANSFER);
@@ -693,11 +556,7 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &sKickKM.hCCBMemInfo,
-#else
                                                   &psKick->hCCBMemInfo,
-#endif
                                                   psKick->hCCBMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
@@ -709,11 +568,7 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.hTASyncInfo,
-#else
                                                           &psKick->hTASyncInfo,
-#endif
                                                           psKick->hTASyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -726,11 +581,7 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.h3DSyncInfo,
-#else
                                                           &psKick->h3DSyncInfo,
-#endif
                                                           psKick->h3DSyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -748,11 +599,7 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.ahSrcSyncInfo[i],
-#else
                                                           &psKick->ahSrcSyncInfo[i],
-#endif
                                                           psKick->ahSrcSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -770,11 +617,7 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.ahDstSyncInfo[i],
-#else
                                                           &psKick->ahDstSyncInfo[i],
-#endif
                                                           psKick->ahDstSyncInfo[i],
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -783,21 +626,7 @@ SGXSubmitTransferBW(IMG_UINT32 ui32BridgeID,
                }
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       sKickKM.sHWTransferContextDevVAddr = psKick->sHWTransferContextDevVAddr;
-       sKickKM.ui32SharedCmdCCBOffset = psKick->ui32SharedCmdCCBOffset;
-       sKickKM.ui32NumSrcSync         = psKick->ui32NumSrcSync;
-       sKickKM.ui32NumDstSync         = psKick->ui32NumDstSync;
-       sKickKM.ui32Flags              = psKick->ui32Flags;
-       sKickKM.ui32PDumpFlags         = psKick->ui32PDumpFlags;
-#if defined(PDUMP)
-       sKickKM.ui32CCBDumpWOff        = psKick->ui32CCBDumpWOff;
-#endif
-
-       psRetOUT->eError = SGXSubmitTransferKM(hDevCookieInt, &sKickKM);
-#else
        psRetOUT->eError = SGXSubmitTransferKM(hDevCookieInt, psKick);
-#endif
 
        return 0;
 }
@@ -896,9 +725,6 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
 {
        IMG_HANDLE hDevCookieInt;
        PVRSRV_2D_SGX_KICK   *psKick;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_2D_SGX_KICK_KM sKickKM;
-#endif
        IMG_UINT32 i;
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_SUBMIT2D);
@@ -935,11 +761,7 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
 
        psRetOUT->eError =
                PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &sKickKM.hCCBMemInfo,
-#else
                                                   &psKick->hCCBMemInfo,
-#endif
                                                   psKick->hCCBMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if(psRetOUT->eError != PVRSRV_OK)
@@ -947,19 +769,11 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if (psKick->hTASyncInfo != 0)
-#else
        if (psKick->hTASyncInfo != IMG_NULL)
-#endif
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.hTASyncInfo,
-#else
                                                           &psKick->hTASyncInfo,
-#endif
                                                           psKick->hTASyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -967,22 +781,12 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
        }
-#if defined (SUPPORT_SID_INTERFACE)
-       else
-       {
-               sKickKM.hTASyncInfo = IMG_NULL;
-       }
-#endif
 
        if (psKick->h3DSyncInfo != IMG_NULL)
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.h3DSyncInfo,
-#else
                                                           &psKick->h3DSyncInfo,
-#endif
                                                           psKick->h3DSyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -990,39 +794,12 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
        }
-#if defined (SUPPORT_SID_INTERFACE)
-       else
-       {
-               sKickKM.h3DSyncInfo = IMG_NULL;
-       }
-#endif
 
        if (psKick->ui32NumSrcSync > SGX_MAX_2D_SRC_SYNC_OPS)
        {
                psRetOUT->eError = PVRSRV_ERROR_INVALID_PARAMS;
                return 0;
        }
-#if defined (SUPPORT_SID_INTERFACE)
-       for (i = 0; i < SGX_MAX_2D_SRC_SYNC_OPS; i++)
-       {
-               if (i < psKick->ui32NumSrcSync)
-               {
-                       psRetOUT->eError =
-                               PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                                  &sKickKM.ahSrcSyncInfo[i],
-                                                                  psKick->ahSrcSyncInfo[i],
-                                                                  PVRSRV_HANDLE_TYPE_SYNC_INFO);
-                       if(psRetOUT->eError != PVRSRV_OK)
-                       {
-                               return 0;
-                       }
-               }
-               else
-               {
-                       sKickKM.ahSrcSyncInfo[i] = IMG_NULL;
-               }
-       }
-#else
        for (i = 0; i < psKick->ui32NumSrcSync; i++)
        {
                psRetOUT->eError =
@@ -1035,17 +812,12 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
        }
-#endif
 
        if (psKick->hDstSyncInfo != IMG_NULL)
        {
                psRetOUT->eError =
                        PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &sKickKM.hDstSyncInfo,
-#else
                                                           &psKick->hDstSyncInfo,
-#endif
                                                           psKick->hDstSyncInfo,
                                                           PVRSRV_HANDLE_TYPE_SYNC_INFO);
                if(psRetOUT->eError != PVRSRV_OK)
@@ -1053,28 +825,9 @@ SGXSubmit2DBW(IMG_UINT32 ui32BridgeID,
                        return 0;
                }
        }
-#if defined (SUPPORT_SID_INTERFACE)
-       else
-       {
-               sKickKM.hDstSyncInfo = IMG_NULL;
-       }
-
-       /* copy common members across */
-       sKickKM.ui32SharedCmdCCBOffset = psKick->ui32SharedCmdCCBOffset;
-       sKickKM.ui32NumSrcSync         = psKick->ui32NumSrcSync;
-       sKickKM.ui32PDumpFlags         = psKick->ui32PDumpFlags;
-       sKickKM.sHW2DContextDevVAddr   = psKick->sHW2DContextDevVAddr;
-#if defined(PDUMP)
-       sKickKM.ui32CCBDumpWOff        = psKick->ui32CCBDumpWOff;
-#endif
-#endif
 
        psRetOUT->eError =
-#if defined (SUPPORT_SID_INTERFACE)
-               SGXSubmit2DKM(hDevCookieInt, &sKickKM);
-#else
                SGXSubmit2DKM(hDevCookieInt, psKick);
-#endif
 
        return 0;
 }
@@ -1230,19 +983,13 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                                  PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        IMG_HANDLE hDevCookieInt;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_ERROR eError = PVRSRV_OK;
-#else
        PVRSRV_ERROR eError;
-#endif
        IMG_BOOL bDissociateFailed = IMG_FALSE;
        IMG_BOOL bLookupFailed = IMG_FALSE;
        IMG_BOOL bReleaseFailed = IMG_FALSE;
        IMG_HANDLE hDummy;
        IMG_UINT32 i;
-#if defined (SUPPORT_SID_INTERFACE)
-       SGX_BRIDGE_INIT_INFO_KM asInitInfoKM = {0};
-#endif
+       IMG_VOID *pCommands = IMG_NULL;
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_DEVINITPART2);
 
@@ -1265,6 +1012,40 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
+       /* Copy debug script commands from UM to KM */
+       for(i = 0; i < SGX_FEATURE_MP_CORE_COUNT_3D; i++)
+       {
+               /* Allocate memory in KM */
+               psSGXDevInitPart2OUT->eError = OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                                       SGX_MAX_PRINT_COMMANDS * sizeof(SGX_INIT_COMMAND),
+                                                       (IMG_VOID **) &pCommands,
+                                                       0,
+                                                       "debug script commands kernel copy");
+               
+               if(psSGXDevInitPart2OUT->eError != PVRSRV_OK)
+               {
+                       return 0;
+               }
+
+               /* Copy commands */
+               if(CopyFromUserWrapper(psPerProc,
+                                                       ui32BridgeID,
+                                                       pCommands,
+                                                       psSGXDevInitPart2IN->sInitInfo.sScripts.apsSGXREGDebugCommandsPart2[i],
+                                                       SGX_MAX_PRINT_COMMANDS * sizeof(SGX_INIT_COMMAND)) != PVRSRV_OK)
+               {
+                       OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                       SGX_MAX_PRINT_COMMANDS * sizeof(SGX_INIT_COMMAND),
+                                       pCommands,
+                                       0);
+                       return -EFAULT;
+
+               }
+               /* update pointer */
+               psSGXDevInitPart2IN->sInitInfo.sScripts.apsSGXREGDebugCommandsPart2[i] = pCommands;
+               
+       }
+       
        /* Check all the meminfo handles */
        eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                   &hDummy,
@@ -1372,28 +1153,6 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bLookupFailed = IMG_TRUE;
        }
 
-#if defined(FIX_HW_BRN_29702)
-       eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                  &hDummy,
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelCFIMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bLookupFailed = IMG_TRUE;
-       }
-#endif
-
-#if defined(FIX_HW_BRN_29823)
-       eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                  &hDummy,
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelDummyTermStreamMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bLookupFailed = IMG_TRUE;
-       }
-#endif
-
 
 #if defined(FIX_HW_BRN_31542) || defined(FIX_HW_BRN_36513)
        eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
@@ -1463,25 +1222,6 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        }
 #endif
 
-#if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && defined(FIX_HW_BRN_31559)
-       eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                  &hDummy,
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelVDMSnapShotBufferMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bLookupFailed = IMG_TRUE;
-       }
-
-       eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
-                                                  &hDummy,
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelVDMCtrlStreamBufferMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bLookupFailed = IMG_TRUE;
-       }
-#endif
 #if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && \
        defined(FIX_HW_BRN_33657) && defined(SUPPORT_SECURE_33657_FIX)
        eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
@@ -1507,17 +1247,9 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
        for (i = 0; i < SGX_MAX_INIT_MEM_HANDLES; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID hHandle = psSGXDevInitPart2IN->sInitInfo.asInitMemHandles[i];
-#else
                IMG_HANDLE hHandle = psSGXDevInitPart2IN->sInitInfo.asInitMemHandles[i];
-#endif
 
-#if defined (SUPPORT_SID_INTERFACE)
-               if (hHandle == 0)
-#else
                if (hHandle == IMG_NULL)
-#endif
                {
                        continue;
                }
@@ -1541,11 +1273,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
        /* Lookup and release the device memory handles */
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelCCBMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelCCBMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelCCBMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1554,11 +1282,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        }
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelCCBCtlMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelCCBCtlMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelCCBCtlMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1567,11 +1291,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        }
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelCCBEventKickerMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelCCBEventKickerMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelCCBEventKickerMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1581,11 +1301,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelSGXHostCtlMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelSGXHostCtlMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelSGXHostCtlMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1594,11 +1310,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        }
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelSGXTA3DCtlMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelSGXTA3DCtlMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelSGXTA3DCtlMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1608,11 +1320,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
 #if defined(FIX_HW_BRN_31272) || defined(FIX_HW_BRN_31780) || defined(FIX_HW_BRN_33920)
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelSGXPTLAWriteBackMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelSGXPTLAWriteBackMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelSGXPTLAWriteBackMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1622,11 +1330,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 #endif
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelSGXMiscMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelSGXMiscMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelSGXMiscMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1637,11 +1341,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
 #if defined(SGX_SUPPORT_HWPROFILING)
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelHWProfilingMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelHWProfilingMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelHWProfilingMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1652,11 +1352,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
 #if defined(SUPPORT_SGX_HWPERF)
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelHWPerfCBMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelHWPerfCBMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelHWPerfCBMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1666,11 +1362,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 #endif
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                 &asInitInfoKM.hKernelTASigBufferMemInfo,
-#else
                                                                                  &psSGXDevInitPart2IN->sInitInfo.hKernelTASigBufferMemInfo,
-#endif
                                                                                  psSGXDevInitPart2IN->sInitInfo.hKernelTASigBufferMemInfo,
                                                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1679,11 +1371,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        }
 
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                 &asInitInfoKM.hKernel3DSigBufferMemInfo,
-#else
                                                                                  &psSGXDevInitPart2IN->sInitInfo.hKernel3DSigBufferMemInfo,
-#endif
                                                                                  psSGXDevInitPart2IN->sInitInfo.hKernel3DSigBufferMemInfo,
                                                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1691,44 +1379,10 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
 
-#if defined(FIX_HW_BRN_29702)
-       eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelCFIMemInfo,
-#else
-                                                  &psSGXDevInitPart2IN->sInitInfo.hKernelCFIMemInfo,
-#endif
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelCFIMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bLookupFailed = IMG_TRUE;
-       }
-#endif
-
-#if defined(FIX_HW_BRN_29823)
-       eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelDummyTermStreamMemInfo,
-#else
-                                                  &psSGXDevInitPart2IN->sInitInfo.hKernelDummyTermStreamMemInfo,
-#endif
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelDummyTermStreamMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bReleaseFailed = IMG_TRUE;
-       }
-#endif
-
 
 #if defined(FIX_HW_BRN_31542) || defined(FIX_HW_BRN_36513)
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAVDMStreamMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAVDMStreamMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAVDMStreamMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1736,11 +1390,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAIndexStreamMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAIndexStreamMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAIndexStreamMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1748,11 +1398,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAPDSMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPDSMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPDSMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1760,11 +1406,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAUSEMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAUSEMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAUSEMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1772,11 +1414,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAParamMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAParamMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAParamMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1784,11 +1422,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAPMPTMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPMPTMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPMPTMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1796,11 +1430,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWATPCMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWATPCMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWATPCMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1808,11 +1438,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelClearClipWAPSGRgnHdrMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPSGRgnHdrMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPSGRgnHdrMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1820,25 +1446,6 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                bReleaseFailed = IMG_TRUE;
        }
 #endif
-#if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && defined(FIX_HW_BRN_31559)
-       eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-                                                  &psSGXDevInitPart2IN->sInitInfo.hKernelVDMSnapShotBufferMemInfo,
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelVDMSnapShotBufferMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bReleaseFailed = IMG_TRUE;
-       }
-
-       eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-                                                  &psSGXDevInitPart2IN->sInitInfo.hKernelVDMCtrlStreamBufferMemInfo,
-                                                  psSGXDevInitPart2IN->sInitInfo.hKernelVDMCtrlStreamBufferMemInfo,
-                                                  PVRSRV_HANDLE_TYPE_MEM_INFO);
-       if (eError != PVRSRV_OK)
-       {
-               bReleaseFailed = IMG_TRUE;
-       }
-#endif
 #if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && \
        defined(FIX_HW_BRN_33657) && defined(SUPPORT_SECURE_33657_FIX)
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
@@ -1853,11 +1460,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
 #if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
        eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                  &asInitInfoKM.hKernelEDMStatusBufferMemInfo,
-#else
                                                   &psSGXDevInitPart2IN->sInitInfo.hKernelEDMStatusBufferMemInfo,
-#endif
                                                   psSGXDevInitPart2IN->sInitInfo.hKernelEDMStatusBufferMemInfo,
                                                   PVRSRV_HANDLE_TYPE_MEM_INFO);
        if (eError != PVRSRV_OK)
@@ -1868,26 +1471,14 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
        for (i = 0; i < SGX_MAX_INIT_MEM_HANDLES; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID hHandle = psSGXDevInitPart2IN->sInitInfo.asInitMemHandles[i];
-               IMG_HANDLE *phHandleKM = &asInitInfoKM.asInitMemHandles[i];
-
-               if (hHandle == 0)
-#else
                IMG_HANDLE *phHandle = &psSGXDevInitPart2IN->sInitInfo.asInitMemHandles[i];
 
                if (*phHandle == IMG_NULL)
-#endif
                        continue;
 
                eError = PVRSRVLookupAndReleaseHandle(psPerProc->psHandleBase,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          phHandleKM,
-                                                          hHandle,
-#else
                                                           phHandle,
                                                           *phHandle,
-#endif
                                                           PVRSRV_HANDLE_TYPE_MEM_INFO);
                if (eError != PVRSRV_OK)
                {
@@ -1908,62 +1499,38 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        }
 
        /* Dissociate device memory from caller */
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelCCBMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelCCBMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelCCBCtlMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelCCBCtlMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelCCBEventKickerMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelCCBEventKickerMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXHostCtlMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXHostCtlMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXTA3DCtlMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXTA3DCtlMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
 #if defined(FIX_HW_BRN_31272) || defined(FIX_HW_BRN_31780) || defined(FIX_HW_BRN_33920)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXPTLAWriteBackMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXPTLAWriteBackMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
@@ -1971,11 +1538,7 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 #endif
 
        /* Dissociate SGX MiscInfo buffer from user space */
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXMiscMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXMiscMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
@@ -1983,166 +1546,49 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 
 
 #if defined(SGX_SUPPORT_HWPROFILING)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelHWProfilingMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelHWProfilingMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
 #endif
-#endif
 
 #if defined(SUPPORT_SGX_HWPERF)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelHWPerfCBMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelHWPerfCBMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 #endif
 
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelTASigBufferMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelTASigBufferMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernel3DSigBufferMemInfo);
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernel3DSigBufferMemInfo);
-#endif
        if (eError != PVRSRV_OK)
        {
                bDissociateFailed = IMG_TRUE;
        }
 
-#if defined(FIX_HW_BRN_29702)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelCFIMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelCFIMemInfo);
-       bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#endif
-
-#if defined(FIX_HW_BRN_29823)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelDummyTermStreamMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelDummyTermStreamMemInfo);
-       bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#endif
-
 #if defined(FIX_HW_BRN_31542) || defined(FIX_HW_BRN_36513)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAVDMStreamMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAVDMStreamMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAIndexStreamMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAIndexStreamMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAPDSMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPDSMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAUSEMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAUSEMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAParamMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAParamMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAPMPTMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPMPTMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWATPCMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWATPCMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelClearClipWAPSGRgnHdrMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelClearClipWAPSGRgnHdrMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
 #endif
-#endif
 
-#if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && defined(FIX_HW_BRN_31559)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelVDMSnapShotBufferMemInfo);
-       bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-       
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelVDMCtrlStreamBufferMemInfo);
-       bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
 #if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && \
        defined(FIX_HW_BRN_33657) && defined(SUPPORT_SECURE_33657_FIX)
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelVDMStateUpdateBufferMemInfo);
@@ -2150,25 +1596,13 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
 #endif
 
 #if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
-#if defined (SUPPORT_SID_INTERFACE)
-       eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelEDMStatusBufferMemInfo);
-       if (eError != PVRSRV_OK)
-       {
-               bDissociateFailed = IMG_TRUE;
-       }
-#else
        eError = PVRSRVDissociateDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelEDMStatusBufferMemInfo);
        bDissociateFailed |= (IMG_BOOL)(eError != PVRSRV_OK);
-#endif
 #endif
 
        for (i = 0; i < SGX_MAX_INIT_MEM_HANDLES; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_HANDLE hHandle = asInitInfoKM.asInitMemHandles[i];
-#else
                IMG_HANDLE hHandle = psSGXDevInitPart2IN->sInitInfo.asInitMemHandles[i];
-#endif
 
                if (hHandle == IMG_NULL)
                        continue;
@@ -2183,16 +1617,6 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
        /* If any dissociations failed, free all the device memory passed in */
        if(bDissociateFailed)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               PVRSRVFreeDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelCCBMemInfo);
-               PVRSRVFreeDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelCCBCtlMemInfo);
-               PVRSRVFreeDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXHostCtlMemInfo);
-               PVRSRVFreeDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXTA3DCtlMemInfo);
-#if defined(FIX_HW_BRN_31272) || defined(FIX_HW_BRN_31780) || defined(FIX_HW_BRN_33920)
-               PVRSRVFreeDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXPTLAWriteBackMemInfo);
-#endif
-               PVRSRVFreeDeviceMemKM(hDevCookieInt, asInitInfoKM.hKernelSGXMiscMemInfo);
-#else
                PVRSRVFreeDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelCCBMemInfo);
                PVRSRVFreeDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelCCBCtlMemInfo);
                PVRSRVFreeDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXHostCtlMemInfo);
@@ -2201,19 +1625,12 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                PVRSRVFreeDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXPTLAWriteBackMemInfo);
 #endif
                PVRSRVFreeDeviceMemKM(hDevCookieInt, psSGXDevInitPart2IN->sInitInfo.hKernelSGXMiscMemInfo);
-#endif
 
                for (i = 0; i < SGX_MAX_INIT_MEM_HANDLES; i++)
                {
-#if defined (SUPPORT_SID_INTERFACE)
-                       IMG_HANDLE hHandle = asInitInfoKM.asInitMemHandles[i];
-
-                       if (hHandle == 0)
-#else
                        IMG_HANDLE hHandle = psSGXDevInitPart2IN->sInitInfo.asInitMemHandles[i];
 
                        if (hHandle == IMG_NULL)
-#endif
                                continue;
 
                        PVRSRVFreeDeviceMemKM(hDevCookieInt, (PVRSRV_KERNEL_MEM_INFO *)hHandle);
@@ -2229,33 +1646,10 @@ SGXDevInitPart2BW(IMG_UINT32 ui32BridgeID,
                return 0;
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       asInitInfoKM.sScripts               = psSGXDevInitPart2IN->sInitInfo.sScripts;
-       asInitInfoKM.ui32ClientBuildOptions = psSGXDevInitPart2IN->sInitInfo.ui32ClientBuildOptions;
-       asInitInfoKM.sSGXStructSizes        = psSGXDevInitPart2IN->sInitInfo.sSGXStructSizes;
-       asInitInfoKM.ui32CacheControl       = psSGXDevInitPart2IN->sInitInfo.ui32CacheControl;
-       asInitInfoKM.ui32EDMTaskReg0        = psSGXDevInitPart2IN->sInitInfo.ui32EDMTaskReg0;
-       asInitInfoKM.ui32EDMTaskReg1        = psSGXDevInitPart2IN->sInitInfo.ui32EDMTaskReg1;
-       asInitInfoKM.ui32ClkGateStatusReg   = psSGXDevInitPart2IN->sInitInfo.ui32ClkGateStatusReg;
-       asInitInfoKM.ui32ClkGateStatusMask  = psSGXDevInitPart2IN->sInitInfo.ui32ClkGateStatusMask;
-
-       OSMemCopy(&asInitInfoKM.asInitDevData ,
-                         &psSGXDevInitPart2IN->sInitInfo.asInitDevData,
-                         sizeof(asInitInfoKM.asInitDevData));
-       OSMemCopy(&asInitInfoKM.aui32HostKickAddr,
-                         &psSGXDevInitPart2IN->sInitInfo.aui32HostKickAddr,
-                         sizeof(asInitInfoKM.aui32HostKickAddr));
-
-       psSGXDevInitPart2OUT->eError =
-               DevInitSGXPart2KM(psPerProc,
-                                                 hDevCookieInt,
-                                                 &asInitInfoKM);
-#else
        psSGXDevInitPart2OUT->eError =
                DevInitSGXPart2KM(psPerProc,
                                                  hDevCookieInt,
                                                  &psSGXDevInitPart2IN->sInitInfo);
-#endif
 
        return 0;
 }
@@ -2404,11 +1798,7 @@ SGXUnregisterHWTransferContextBW(IMG_UINT32 ui32BridgeID,
                                                           PVRSRV_BRIDGE_RETURN *psRetOUT,
                                                           PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_HANDLE hHWTransferContextInt = 0;
-#else
        IMG_HANDLE hHWTransferContextInt;
-#endif
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_UNREGISTER_HW_TRANSFER_CONTEXT);
 
@@ -2785,11 +2175,7 @@ SGXAddSharedPBDescBW(IMG_UINT32 ui32BridgeID,
        IMG_UINT32 ui32KernelMemInfoHandlesCount =
                psSGXAddSharedPBDescIN->ui32KernelMemInfoHandlesCount;
        IMG_INT ret = 0;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID *phKernelMemInfoHandles = 0;
-#else
        IMG_HANDLE *phKernelMemInfoHandles = IMG_NULL;
-#endif
        PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfos = IMG_NULL;
        IMG_UINT32 i;
        PVRSRV_ERROR eError;
@@ -2999,9 +2385,6 @@ SGXGetInfoForSrvinitBW(IMG_UINT32 ui32BridgeID,
 {
        IMG_HANDLE hDevCookieInt;
        IMG_UINT32 i;
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_HEAP_INFO_KM asHeapInfo[PVRSRV_MAX_CLIENT_HEAPS];
-#endif
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGXINFO_FOR_SRVINIT);
 
        NEW_HANDLE_BATCH_OR_ERROR(psSGXInfoForSrvinitOUT->eError, psPerProc, PVRSRV_MAX_CLIENT_HEAPS);
@@ -3024,12 +2407,7 @@ SGXGetInfoForSrvinitBW(IMG_UINT32 ui32BridgeID,
 
        psSGXInfoForSrvinitOUT->eError =
                SGXGetInfoForSrvinitKM(hDevCookieInt,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          &asHeapInfo[0],
-                                                          &psSGXInfoForSrvinitOUT->sInitInfo.sPDDevPAddr);
-#else
                                                           &psSGXInfoForSrvinitOUT->sInitInfo);
-#endif
 
        if(psSGXInfoForSrvinitOUT->eError != PVRSRV_OK)
        {
@@ -3042,28 +2420,6 @@ SGXGetInfoForSrvinitBW(IMG_UINT32 ui32BridgeID,
 
                psHeapInfo = &psSGXInfoForSrvinitOUT->sInitInfo.asHeapInfo[i];
 
-#if defined (SUPPORT_SID_INTERFACE)
-               if ((asHeapInfo[i].ui32HeapID != (IMG_UINT32)SGX_UNDEFINED_HEAP_ID) &&
-                       (asHeapInfo[i].hDevMemHeap != IMG_NULL))
-               {
-                       /* Allocate heap handle */
-                       PVRSRVAllocHandleNR(psPerProc->psHandleBase,
-                                                         &psHeapInfo->hDevMemHeap,
-                                                         asHeapInfo[i].hDevMemHeap,
-                                                         PVRSRV_HANDLE_TYPE_DEV_MEM_HEAP,
-                                                         PVRSRV_HANDLE_ALLOC_FLAG_SHARED);
-               }
-               else
-               {
-                       psHeapInfo->hDevMemHeap = 0;
-               }
-
-               psHeapInfo->ui32HeapID       = asHeapInfo[i].ui32HeapID;
-               psHeapInfo->sDevVAddrBase    = asHeapInfo[i].sDevVAddrBase;
-               psHeapInfo->ui32HeapByteSize = asHeapInfo[i].ui32HeapByteSize;
-               psHeapInfo->ui32Attribs      = asHeapInfo[i].ui32Attribs;
-               psHeapInfo->ui32XTileStride  = asHeapInfo[i].ui32XTileStride;
-#else
                if (psHeapInfo->ui32HeapID != (IMG_UINT32)SGX_UNDEFINED_HEAP_ID)
                {
                        IMG_HANDLE hDevMemHeapExt;
@@ -3079,7 +2435,6 @@ SGXGetInfoForSrvinitBW(IMG_UINT32 ui32BridgeID,
                                psHeapInfo->hDevMemHeap = hDevMemHeapExt;
                        }
                }
-#endif
        }
 
        COMMIT_HANDLE_BATCH_OR_ERROR(psSGXInfoForSrvinitOUT->eError, psPerProc);
@@ -3097,11 +2452,7 @@ SGXGetInfoForSrvinitBW(IMG_UINT32 ui32BridgeID,
 *****************************************************************************/
 static IMG_VOID
 DumpBufferArray(PVRSRV_PER_PROCESS_DATA   *psPerProc,
-#if defined (SUPPORT_SID_INTERFACE)
-                               PSGX_KICKTA_DUMP_BUFFER_KM psBufferArray,
-#else
                                PSGX_KICKTA_DUMP_BUFFER psBufferArray,
-#endif
                                IMG_UINT32                 ui32BufferArrayLength,
                                IMG_BOOL                   bDumpPolls)
 {
@@ -3109,11 +2460,7 @@ DumpBufferArray(PVRSRV_PER_PROCESS_DATA   *psPerProc,
 
        for (i=0; i<ui32BufferArrayLength; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               PSGX_KICKTA_DUMP_BUFFER_KM psBuffer;
-#else
                PSGX_KICKTA_DUMP_BUFFER psBuffer;
-#endif
                PVRSRV_KERNEL_MEM_INFO    *psCtrlMemInfoKM;
                IMG_CHAR * pszName;
                IMG_HANDLE hUniqueTag;
@@ -3225,17 +2572,12 @@ SGXPDumpBufferArrayBW(IMG_UINT32 ui32BridgeID,
                                   PVRSRV_PER_PROCESS_DATA *psPerProc)
 {
        IMG_UINT32 i;
-#if defined (SUPPORT_SID_INTERFACE)
-       SGX_KICKTA_DUMP_BUFFER *psUMPtr;
-       SGX_KICKTA_DUMP_BUFFER_KM *psKickTADumpBufferKM, *psKMPtr;
-#else
 #if defined(__QNXNTO__)
     const IMG_UINT32 NAME_BUFFER_SIZE = 30;
     IMG_PCHAR pszNameBuffer, pszName;
     IMG_UINT32 ui32NameBufferArraySize, ui32NameLength;
 #endif
        SGX_KICKTA_DUMP_BUFFER *psKickTADumpBuffer;
-#endif
        IMG_UINT32 ui32BufferArrayLength =
                psPDumpBufferArrayIN->ui32BufferArrayLength;
        IMG_UINT32 ui32BufferArraySize =
@@ -3246,22 +2588,14 @@ SGXPDumpBufferArrayBW(IMG_UINT32 ui32BridgeID,
 
        PVRSRV_BRIDGE_ASSERT_CMD(ui32BridgeID, PVRSRV_BRIDGE_SGX_PDUMP_BUFFER_ARRAY);
 
-#if defined (SUPPORT_SID_INTERFACE)
-       if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
-                                 ui32BufferArraySize,
-                                 (IMG_PVOID *)&psKickTADumpBufferKM, 0,
-                                 "Array of Kick Tile Accelerator Dump Buffer") != PVRSRV_OK)
-#else
        if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
                                  ui32BufferArraySize,
                                  (IMG_PVOID *)&psKickTADumpBuffer, 0,
                                  "Array of Kick Tile Accelerator Dump Buffer") != PVRSRV_OK)
-#endif                           
        {
                return -ENOMEM;
        }
 
-#if !defined (SUPPORT_SID_INTERFACE)
        if(CopyFromUserWrapper(psPerProc,
                                       ui32BridgeID,
                                                   psKickTADumpBuffer,
@@ -3310,26 +2644,15 @@ SGXPDumpBufferArrayBW(IMG_UINT32 ui32BridgeID,
             }
         }
     }
-#endif
 #endif
 
        for(i = 0; i < ui32BufferArrayLength; i++)
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_VOID *pvMemInfo = IMG_NULL;
-               psUMPtr = &psPDumpBufferArrayIN->psBufferArray[i];
-               psKMPtr = &psKickTADumpBufferKM[i];
-#else
                IMG_VOID *pvMemInfo;
-#endif
 
                eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                                        &pvMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       psUMPtr->hKernelMemInfo,
-#else
                                                                        psKickTADumpBuffer[i].hKernelMemInfo,
-#endif
                                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
 
                if(eError != PVRSRV_OK)
@@ -3338,20 +2661,12 @@ SGXPDumpBufferArrayBW(IMG_UINT32 ui32BridgeID,
                                         "PVRSRVLookupHandle failed (%d)", eError));
                        break;
                }
-#if defined (SUPPORT_SID_INTERFACE)
-               psKMPtr->hKernelMemInfo = pvMemInfo;
-#else
                psKickTADumpBuffer[i].hKernelMemInfo = pvMemInfo;
-#endif
 
 #if defined(SUPPORT_SGX_NEW_STATUS_VALS)
                eError = PVRSRVLookupHandle(psPerProc->psHandleBase,
                                                                        &pvMemInfo,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       psUMPtr->hCtrlKernelMemInfo,
-#else
                                                                        psKickTADumpBuffer[i].hCtrlKernelMemInfo,
-#endif
                                                                        PVRSRV_HANDLE_TYPE_MEM_INFO);
 
                if(eError != PVRSRV_OK)
@@ -3360,45 +2675,22 @@ SGXPDumpBufferArrayBW(IMG_UINT32 ui32BridgeID,
                                         "PVRSRVLookupHandle failed (%d)", eError));
                        break;
                }
-#if defined (SUPPORT_SID_INTERFACE)
-               psKMPtr->hCtrlKernelMemInfo = pvMemInfo;
-               psKMPtr->sCtrlDevVAddr = psUMPtr->sCtrlDevVAddr;
-#else
                psKickTADumpBuffer[i].hCtrlKernelMemInfo = pvMemInfo;
 #endif
-#endif
 
-#if defined (SUPPORT_SID_INTERFACE)
-               psKMPtr->ui32SpaceUsed     = psUMPtr->ui32SpaceUsed;
-               psKMPtr->ui32Start         = psUMPtr->ui32Start;
-               psKMPtr->ui32End           = psUMPtr->ui32End;
-               psKMPtr->ui32BufferSize    = psUMPtr->ui32BufferSize;
-               psKMPtr->ui32BackEndLength = psUMPtr->ui32BackEndLength;
-               psKMPtr->uiAllocIndex      = psUMPtr->uiAllocIndex;
-               psKMPtr->pvLinAddr         = psUMPtr->pvLinAddr;
-               psKMPtr->pszName           = psUMPtr->pszName;
-#endif
        }
 
        if(eError == PVRSRV_OK)
        {
                DumpBufferArray(psPerProc,
-#if defined (SUPPORT_SID_INTERFACE)
-                                               psKickTADumpBufferKM,
-#else
                                                psKickTADumpBuffer,
-#endif
                                                ui32BufferArrayLength,
                                                psPDumpBufferArrayIN->bDumpPolls);
        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-       OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, ui32BufferArraySize, psKickTADumpBufferKM, 0);
-#else
        OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, ui32BufferArraySize, psKickTADumpBuffer, 0);
 #if defined (__QNXNTO__)
        OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, ui32NameBufferArraySize, pszNameBuffer, 0);
-#endif
 #endif
        /*not nulling pointer, out of scope*/
 
@@ -3702,7 +2994,7 @@ SGXPDumpHWPerfCBBW(IMG_UINT32                                             ui32BridgeID,
                                   PVRSRV_PER_PROCESS_DATA                      *psPerProc)
 {
 #if defined(SUPPORT_SGX_HWPERF)
-#if defined(__linux__)
+#if defined(__linux__) || defined(__QNXNTO__)
        PVRSRV_SGXDEV_INFO      *psDevInfo;
        PVRSRV_DEVICE_NODE *psDeviceNode;
        IMG_HANDLE hDevMemContextInt = 0;
index 1f7c444..30e37ad 100644 (file)
@@ -50,20 +50,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "lists.h"
 
 static IMG_BOOL
-ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags);
+ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags);
 static IMG_VOID
 BM_FreeMemory (IMG_VOID *pH, IMG_UINTPTR_T base, BM_MAPPING *psMapping);
 static IMG_BOOL
 BM_ImportMemory(IMG_VOID *pH, IMG_SIZE_T uSize,
                                IMG_SIZE_T *pActualSize, BM_MAPPING **ppsMapping,
-                               IMG_UINT32 uFlags, IMG_PVOID pvPrivData,
+                               IMG_UINT32 ui32Flags, IMG_PVOID pvPrivData,
                                IMG_UINT32 ui32PrivDataLength, IMG_UINTPTR_T *pBase);
 
 static IMG_BOOL
 DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                BM_MAPPING *pMapping,
                                IMG_SIZE_T *pActualSize,
-                               IMG_UINT32 uFlags,
+                               IMG_UINT32 ui32Flags,
                                IMG_UINT32 dev_vaddr_alignment,
                                IMG_DEV_VIRTADDR *pDevVAddr);
 static IMG_VOID
@@ -90,7 +90,7 @@ DevMemoryFree (BM_MAPPING *pMapping);
        @Input      psBMHeap - BM heap
        @Input      psDevVAddr - device virtual address (optional)
        @Input      uSize - requested buffer size in bytes.
-       @Input      uFlags - property flags for the buffer.
+       @Input      ui32Flags - property flags for the buffer.
     @Input      uDevVAddrAlignment - required device virtual address
                                         alignment, or 0.
     @Input      pvPrivData - opaque private data passed through to allocator
@@ -107,7 +107,7 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
                         BM_HEAP                        *psBMHeap,
                         IMG_DEV_VIRTADDR       *psDevVAddr,
                         IMG_SIZE_T                     uSize,
-                        IMG_UINT32                     uFlags,
+                        IMG_UINT32                     ui32Flags,
                         IMG_UINT32                     uDevVAddrAlignment,
                         IMG_PVOID                      pvPrivData,
                         IMG_UINT32                     ui32PrivDataLength,
@@ -122,16 +122,16 @@ AllocMemory (BM_CONTEXT                   *pBMContext,
        RA_ARENA                        *pArena = IMG_NULL;
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "AllocMemory (uSize=0x%x, uFlags=0x%x, align=0x%x)",
-                         uSize, uFlags, uDevVAddrAlignment));
+                         "AllocMemory (uSize=0x%" SIZE_T_FMT_LEN "x, ui32Flags=0x%x, align=0x%x)",
+                         uSize, ui32Flags, uDevVAddrAlignment));
 
        /*
                what to do depends on combination of DevVaddr generation
                and backing RAM requirement
        */
-       if(uFlags & PVRSRV_MEM_RAM_BACKED_ALLOCATION)
+       if(ui32Flags & PVRSRV_MEM_RAM_BACKED_ALLOCATION)
        {
-               if(uFlags & PVRSRV_MEM_USER_SUPPLIED_DEVVADDR)
+               if(ui32Flags & PVRSRV_MEM_USER_SUPPLIED_DEVVADDR)
                {
                        /* user supplied DevVAddr, RAM backing */
                        PVR_DPF ((PVR_DBG_ERROR, "AllocMemory: combination of DevVAddr management and RAM backing mode unsupported"));
@@ -156,17 +156,17 @@ AllocMemory (BM_CONTEXT                   *pBMContext,
                }
 
                /* Now allocate from the arena we chose above. */
-               if (uFlags & PVRSRV_MEM_SPARSE)
+               if (ui32Flags & PVRSRV_MEM_SPARSE)
                {
                        IMG_BOOL bSuccess;
-                       IMG_SIZE_T puiActualSize;
+                       IMG_SIZE_T uActualSize;
 
                        /* Allocate physcial memory */
                        bSuccess = BM_ImportMemory(psBMHeap,
                                                                           ui32ChunkSize * ui32NumPhysChunks,
-                                                                          &puiActualSize,
+                                                                          &uActualSize,
                                                                           &pMapping,
-                                                                          uFlags,
+                                                                          ui32Flags,
                                                                           pvPrivData,
                                                                           ui32PrivDataLength,
                                                                           IMG_NULL);   /* We allocate VM space */
@@ -177,7 +177,7 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
                                return IMG_FALSE;
                        }
 
-                       if (puiActualSize != ui32ChunkSize * ui32NumPhysChunks)
+                       if (uActualSize != ui32ChunkSize * ui32NumPhysChunks)
                        {
                                /*
                                        Most likley the chunksize was not host page multiple so
@@ -199,8 +199,8 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
                        bSuccess = DevMemoryAlloc (pBMContext,
                                                                                pMapping,
                                                                                IMG_NULL,
-                                                                               uFlags,
-                                                                               (IMG_UINT32)uDevVAddrAlignment,
+                                                                               ui32Flags,
+                                                                               uDevVAddrAlignment,
                                                                                &pMapping->DevVAddr);
                        if (!bSuccess)
                        {
@@ -221,14 +221,14 @@ AllocMemory (BM_CONTEXT                   *pBMContext,
                                                  uSize,
                                                  IMG_NULL,
                                                  (IMG_VOID*) &pMapping,
-                                                 uFlags,
+                                                 ui32Flags,
                                                  uDevVAddrAlignment,
                                                  0,
                                                  pvPrivData,
                                                  ui32PrivDataLength,
                                                  (IMG_UINTPTR_T *)&(pBuf->DevVAddr.uiAddr)))
                        {
-                               PVR_DPF((PVR_DBG_ERROR, "AllocMemory: RA_Alloc(0x%x) FAILED", uSize));
+                               PVR_DPF((PVR_DBG_ERROR, "AllocMemory: RA_Alloc(0x%" SIZE_T_FMT_LEN "x) FAILED", uSize));
                                return IMG_FALSE;
                        }
                }
@@ -264,9 +264,9 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
                 * will have a physical address, else 0 */
                pBuf->CpuPAddr.uiAddr = pMapping->CpuPAddr.uiAddr + uOffset;
 
-               if(uFlags & PVRSRV_MEM_ZERO)
+               if(ui32Flags & PVRSRV_MEM_ZERO)
                {
-                       if(!ZeroBuf(pBuf, pMapping, uSize, psBMHeap->ui32Attribs | uFlags))
+                       if(!ZeroBuf(pBuf, pMapping, uSize, psBMHeap->ui32Attribs | ui32Flags))
                        {
                                return IMG_FALSE;
                        }
@@ -274,7 +274,7 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
        }
        else
        {
-               if(uFlags & PVRSRV_MEM_USER_SUPPLIED_DEVVADDR)
+               if(ui32Flags & PVRSRV_MEM_USER_SUPPLIED_DEVVADDR)
                {
                        /* user supplied DevVAddr, no RAM backing */
                        PVR_ASSERT(psDevVAddr != IMG_NULL);
@@ -322,7 +322,7 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
                                                        (IMG_PVOID *)&pMapping, IMG_NULL,
                                                        "Buffer Manager Mapping") != PVRSRV_OK)
                {
-                       PVR_DPF((PVR_DBG_ERROR, "AllocMemory: OSAllocMem(0x%x) FAILED", sizeof(*pMapping)));
+                       PVR_DPF((PVR_DBG_ERROR, "AllocMemory: OSAllocMem(0x%" SIZE_T_FMT_LEN "x) FAILED", sizeof(*pMapping)));
                        return IMG_FALSE;
                }
 
@@ -349,18 +349,18 @@ AllocMemory (BM_CONTEXT                   *pBMContext,
 
        /* output some stats */
        PVR_DPF ((PVR_DBG_MESSAGE,
-                               "AllocMemory: pMapping=%08x: DevV=%08X CpuV=%08x CpuP=%08X uSize=0x%x",
-                               (IMG_UINTPTR_T)pMapping,
+                               "AllocMemory: pMapping=%p: DevV=%08X CpuV=%p CpuP=" CPUPADDR_FMT " uSize=0x%" SIZE_T_FMT_LEN "x",
+                               pMapping,
                                pMapping->DevVAddr.uiAddr,
-                               (IMG_UINTPTR_T)pMapping->CpuVAddr,
+                               pMapping->CpuVAddr,
                                pMapping->CpuPAddr.uiAddr,
                                pMapping->uSize));
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                               "AllocMemory: pBuf=%08x: DevV=%08X CpuV=%08x CpuP=%08X uSize=0x%x",
-                               (IMG_UINTPTR_T)pBuf,
+                               "AllocMemory: pBuf=%p: DevV=%08X CpuV=%p CpuP=" CPUPADDR_FMT " uSize=0x%" SIZE_T_FMT_LEN "x",
+                               pBuf,
                                pBuf->DevVAddr.uiAddr,
-                               (IMG_UINTPTR_T)pBuf->CpuVAddr,
+                               pBuf->CpuVAddr,
                                pBuf->CpuPAddr.uiAddr,
                                uSize));
 
@@ -385,7 +385,7 @@ AllocMemory (BM_CONTEXT                     *pBMContext,
        @Input      bPhysContig - Is the wrap physically contiguous.
        @Input      psAddr - List of pages to wrap.
        @Input      pvCPUVAddr - Optional CPU Kernel virtual address (page aligned) of memory to wrap
-       @Input      uFlags - property flags for the buffer.
+       @Input      ui32Flags - property flags for the buffer.
        @Output     Buf - receives a pointer to a descriptor of the allocated
                                         buffer.
        @Return         IMG_TRUE - Success
@@ -395,27 +395,36 @@ AllocMemory (BM_CONTEXT                   *pBMContext,
 static IMG_BOOL
 WrapMemory (BM_HEAP *psBMHeap,
                        IMG_SIZE_T uSize,
-                       IMG_SIZE_T ui32BaseOffset,
+                       IMG_SIZE_T uiBaseOffset,
                        IMG_BOOL bPhysContig,
                        IMG_SYS_PHYADDR *psAddr,
                        IMG_VOID *pvCPUVAddr,
-                       IMG_UINT32 uFlags,
+                       IMG_UINT32 ui32Flags,
                        BM_BUF *pBuf)
 {
        IMG_DEV_VIRTADDR DevVAddr = {0};
        BM_MAPPING *pMapping;
        IMG_BOOL bResult;
-       IMG_SIZE_T const ui32PageSize = HOST_PAGESIZE();
+       IMG_SIZE_T const uPageSize = HOST_PAGESIZE();
+       /* We should not pass down R/W flags into the OS layers so create ui32Attribs */
+       IMG_UINT32 ui32Attribs = ui32Flags & ~(PVRSRV_MEM_READ | PVRSRV_MEM_WRITE);
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "WrapMemory(psBMHeap=%08X, size=0x%x, offset=0x%x, bPhysContig=0x%x, pvCPUVAddr = 0x%08x, flags=0x%x)",
-                         (IMG_UINTPTR_T)psBMHeap, uSize, ui32BaseOffset, bPhysContig, (IMG_UINTPTR_T)pvCPUVAddr, uFlags));
-
-       PVR_ASSERT((psAddr->uiAddr & (ui32PageSize - 1)) == 0);
+                         "WrapMemory(psBMHeap=%p, size=0x%" SIZE_T_FMT_LEN "x, offset=0x%" SIZE_T_FMT_LEN 
+                         "x, bPhysContig=0x%x, sysPAddr=0x" SYSPADDR_FMT ", pvCPUVAddr = 0x%p, flags=0x%x)",
+                         psBMHeap, 
+              uSize, 
+              uiBaseOffset, 
+              bPhysContig, 
+                         psAddr->uiAddr,
+              pvCPUVAddr, 
+              ui32Flags));
+
+       PVR_ASSERT((psAddr->uiAddr & (uPageSize - 1)) == 0);
        /* Only need lower 12 bits of the cpu addr - don't care what size a void* is */
-       PVR_ASSERT(((IMG_UINTPTR_T)pvCPUVAddr & (ui32PageSize - 1)) == 0);
+       PVR_ASSERT(((IMG_UINTPTR_T)pvCPUVAddr & (uPageSize - 1)) == 0);
 
-       uSize += ui32BaseOffset;
+       uSize += uiBaseOffset;
        uSize = HOST_PAGEALIGN (uSize);
 
        /* allocate a mocked-up mapping */
@@ -424,7 +433,7 @@ WrapMemory (BM_HEAP *psBMHeap,
                                                (IMG_PVOID *)&pMapping, IMG_NULL,
                                                "Mocked-up mapping") != PVRSRV_OK)
        {
-               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSAllocMem(0x%x) FAILED",sizeof(*pMapping)));
+               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSAllocMem(0x%" SIZE_T_FMT_LEN "x) FAILED", sizeof(*pMapping)));
                return IMG_FALSE;
        }
 
@@ -446,10 +455,10 @@ WrapMemory (BM_HEAP *psBMHeap,
                        if(OSRegisterMem(pMapping->CpuPAddr,
                                                        pMapping->CpuVAddr,
                                                        pMapping->uSize,
-                                                       uFlags,
+                                                       ui32Attribs,
                                                        &pMapping->hOSMemHandle) != PVRSRV_OK)
                        {
-                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSRegisterMem Phys=0x%08X, Size=%d) failed",
+                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSRegisterMem Phys=0x" CPUPADDR_FMT ", Size=%" SIZE_T_FMT_LEN "u) failed",
                                        pMapping->CpuPAddr.uiAddr, pMapping->uSize));
                                goto fail_cleanup;
                        }
@@ -462,10 +471,10 @@ WrapMemory (BM_HEAP *psBMHeap,
                        if(OSRegisterDiscontigMem(pMapping->psSysAddr,
                                                        pMapping->CpuVAddr,
                                                        pMapping->uSize,
-                                                       uFlags,
+                                                       ui32Attribs,
                                                        &pMapping->hOSMemHandle) != PVRSRV_OK)
                        {
-                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSRegisterDiscontigMem Size=%d) failed",
+                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSRegisterDiscontigMem Size=0x%" SIZE_T_FMT_LEN "u) failed",
                                        pMapping->uSize));
                                goto fail_cleanup;
                        }
@@ -480,12 +489,12 @@ WrapMemory (BM_HEAP *psBMHeap,
 
                        if(OSReservePhys(pMapping->CpuPAddr,
                                                         pMapping->uSize,
-                                                        uFlags,
+                                                        ui32Attribs,
                                                         IMG_NULL,
                                                         &pMapping->CpuVAddr,
                                                         &pMapping->hOSMemHandle) != PVRSRV_OK)
                        {
-                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSReservePhys Phys=0x%08X, Size=%d) failed",
+                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSReservePhys Phys=0x" CPUPADDR_FMT ", Size=%" SIZE_T_FMT_LEN "u) failed",
                                        pMapping->CpuPAddr.uiAddr, pMapping->uSize));
                                goto fail_cleanup;
                        }
@@ -497,11 +506,11 @@ WrapMemory (BM_HEAP *psBMHeap,
 
                        if(OSReserveDiscontigPhys(pMapping->psSysAddr,
                                                         pMapping->uSize,
-                                                        uFlags,
+                                                        ui32Attribs,
                                                         &pMapping->CpuVAddr,
                                                         &pMapping->hOSMemHandle) != PVRSRV_OK)
                        {
-                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSReserveDiscontigPhys Size=%d) failed",
+                               PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSReserveDiscontigPhys Size=%" SIZE_T_FMT_LEN "u) failed",
                                        pMapping->uSize));
                                goto fail_cleanup;
                        }
@@ -509,18 +518,18 @@ WrapMemory (BM_HEAP *psBMHeap,
        }
 
        /*
-        * Allocate device memory for this buffer. Map wrapped pages as read/write
+        * Allocate device memory for this buffer.
         */
        bResult = DevMemoryAlloc(psBMHeap->pBMContext,
                                                         pMapping,
                                                         IMG_NULL,
-                                                        uFlags | PVRSRV_MEM_READ | PVRSRV_MEM_WRITE,
-                                                        IMG_CAST_TO_DEVVADDR_UINT(ui32PageSize),
+                                                        ui32Flags,
+                                                        IMG_CAST_TO_DEVVADDR_UINT(uPageSize),
                                                         &DevVAddr);
        if (!bResult)
        {
                PVR_DPF((PVR_DBG_ERROR,
-                               "WrapMemory: DevMemoryAlloc(0x%x) failed",
+                               "WrapMemory: DevMemoryAlloc(0x%" SIZE_T_FMT_LEN "x) failed",
                                pMapping->uSize));
                goto fail_cleanup;
        }
@@ -531,17 +540,17 @@ WrapMemory (BM_HEAP *psBMHeap,
         * addresses associated with this allocation are placed at the same
         * offset within the underlying chunk.
         */
-       pBuf->CpuPAddr.uiAddr = pMapping->CpuPAddr.uiAddr + ui32BaseOffset;
-       if(!ui32BaseOffset)
+       pBuf->CpuPAddr.uiAddr = pMapping->CpuPAddr.uiAddr + uiBaseOffset;
+       if(!uiBaseOffset)
        {
                pBuf->hOSMemHandle = pMapping->hOSMemHandle;
        }
        else
        {
                if(OSGetSubMemHandle(pMapping->hOSMemHandle,
-                                                        ui32BaseOffset,
-                                                        (pMapping->uSize-ui32BaseOffset),
-                                                        uFlags,
+                                                        uiBaseOffset,
+                                                        (pMapping->uSize - uiBaseOffset),
+                                                        ui32Attribs,
                                                         &pBuf->hOSMemHandle)!=PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR, "WrapMemory: OSGetSubMemHandle failed"));
@@ -550,13 +559,13 @@ WrapMemory (BM_HEAP *psBMHeap,
        }
        if(pMapping->CpuVAddr)
        {
-               pBuf->CpuVAddr = (IMG_VOID*) ((IMG_UINTPTR_T)pMapping->CpuVAddr + ui32BaseOffset);
+               pBuf->CpuVAddr = (IMG_VOID*) ((IMG_UINTPTR_T)pMapping->CpuVAddr + uiBaseOffset);
        }
-       pBuf->DevVAddr.uiAddr = pMapping->DevVAddr.uiAddr + IMG_CAST_TO_DEVVADDR_UINT(ui32BaseOffset);
+       pBuf->DevVAddr.uiAddr = pMapping->DevVAddr.uiAddr + IMG_CAST_TO_DEVVADDR_UINT(uiBaseOffset);
 
-       if(uFlags & PVRSRV_MEM_ZERO)
+       if(ui32Flags & PVRSRV_MEM_ZERO)
        {
-               if(!ZeroBuf(pBuf, pMapping, uSize, uFlags))
+               if(!ZeroBuf(pBuf, pMapping, uSize, ui32Flags))
                {
                        return IMG_FALSE;
                }
@@ -564,19 +573,19 @@ WrapMemory (BM_HEAP *psBMHeap,
 
        PVR_DPF ((PVR_DBG_MESSAGE, "DevVaddr.uiAddr=%08X", DevVAddr.uiAddr));
        PVR_DPF ((PVR_DBG_MESSAGE,
-                               "WrapMemory: DevV=%08X CpuP=%08X uSize=0x%x",
+                               "WrapMemory: DevV=%08X CpuP=" CPUPADDR_FMT " uSize=0x%" SIZE_T_FMT_LEN "x",
                                pMapping->DevVAddr.uiAddr, pMapping->CpuPAddr.uiAddr, pMapping->uSize));
        PVR_DPF ((PVR_DBG_MESSAGE,
-                               "WrapMemory: DevV=%08X CpuP=%08X uSize=0x%x",
+                               "WrapMemory: DevV=%08X CpuP=" CPUPADDR_FMT " uSize=0x%" SIZE_T_FMT_LEN "x",
                                pBuf->DevVAddr.uiAddr, pBuf->CpuPAddr.uiAddr, uSize));
 
        pBuf->pMapping = pMapping;
        return IMG_TRUE;
 
 fail_cleanup:
-       if(ui32BaseOffset && pBuf->hOSMemHandle)
+       if(uiBaseOffset && pBuf->hOSMemHandle)
        {
-               OSReleaseSubMemHandle(pBuf->hOSMemHandle, uFlags);
+               OSReleaseSubMemHandle(pBuf->hOSMemHandle, ui32Attribs);
        }
 
        if(pMapping && (pMapping->CpuVAddr || pMapping->hOSMemHandle))
@@ -584,16 +593,16 @@ fail_cleanup:
                switch(pMapping->eCpuMemoryOrigin)
                {
                        case hm_wrapped:
-                               OSUnReservePhys(pMapping->CpuVAddr, pMapping->uSize, uFlags, pMapping->hOSMemHandle);
+                               OSUnReservePhys(pMapping->CpuVAddr, pMapping->uSize, ui32Attribs, pMapping->hOSMemHandle);
                                break;
                        case hm_wrapped_virtaddr:
-                               OSUnRegisterMem(pMapping->CpuVAddr, pMapping->uSize, uFlags, pMapping->hOSMemHandle);
+                               OSUnRegisterMem(pMapping->CpuVAddr, pMapping->uSize, ui32Attribs, pMapping->hOSMemHandle);
                                break;
                        case hm_wrapped_scatter:
-                               OSUnReserveDiscontigPhys(pMapping->CpuVAddr, pMapping->uSize, uFlags, pMapping->hOSMemHandle);
+                               OSUnReserveDiscontigPhys(pMapping->CpuVAddr, pMapping->uSize, ui32Attribs, pMapping->hOSMemHandle);
                                break;
                        case hm_wrapped_scatter_virtaddr:
-                               OSUnRegisterDiscontigMem(pMapping->CpuVAddr, pMapping->uSize, uFlags, pMapping->hOSMemHandle);
+                               OSUnRegisterDiscontigMem(pMapping->CpuVAddr, pMapping->uSize, ui32Attribs, pMapping->hOSMemHandle);
                                break;
                        default:
                                break;
@@ -609,19 +618,19 @@ fail_cleanup:
 
 
 static IMG_BOOL
-ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags)
+ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags)
 {
        IMG_VOID *pvCpuVAddr;
 
        if(pBuf->CpuVAddr)
        {
-               OSMemSet(pBuf->CpuVAddr, 0, ui32Bytes);
+               OSMemSet(pBuf->CpuVAddr, 0, uBytes);
        }
        else if(pMapping->eCpuMemoryOrigin == hm_contiguous
                        || pMapping->eCpuMemoryOrigin == hm_wrapped)
        {
                pvCpuVAddr = OSMapPhysToLin(pBuf->CpuPAddr,
-                                                                       ui32Bytes,
+                                                                       uBytes,
                                                                        PVRSRV_HAP_KERNEL_ONLY
                                                                        | (ui32Flags & PVRSRV_HAP_CACHETYPE_MASK),
                                                                        IMG_NULL);
@@ -630,17 +639,17 @@ ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui3
                        PVR_DPF((PVR_DBG_ERROR, "ZeroBuf: OSMapPhysToLin for contiguous buffer failed"));
                        return IMG_FALSE;
                }
-               OSMemSet(pvCpuVAddr, 0, ui32Bytes);
+               OSMemSet(pvCpuVAddr, 0, uBytes);
                OSUnMapPhysToLin(pvCpuVAddr,
-                                                ui32Bytes,
+                                                uBytes,
                                                 PVRSRV_HAP_KERNEL_ONLY
                                                 | (ui32Flags & PVRSRV_HAP_CACHETYPE_MASK),
                                                 IMG_NULL);
        }
        else
        {
-               IMG_SIZE_T ui32BytesRemaining = ui32Bytes;
-               IMG_SIZE_T ui32CurrentOffset = 0;
+               IMG_SIZE_T uBytesRemaining = uBytes;
+               IMG_SIZE_T uCurrentOffset = 0;
                IMG_CPU_PHYADDR CpuPAddr;
 
                /* Walk through the pBuf one page at a time and use
@@ -648,21 +657,21 @@ ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui3
 
                PVR_ASSERT(pBuf->hOSMemHandle);
 
-               while(ui32BytesRemaining > 0)
+               while(uBytesRemaining > 0)
                {
-                       IMG_SIZE_T ui32BlockBytes = MIN(ui32BytesRemaining, HOST_PAGESIZE());
-                       CpuPAddr = OSMemHandleToCpuPAddr(pBuf->hOSMemHandle, ui32CurrentOffset);
+                       IMG_SIZE_T uBlockBytes = MIN(uBytesRemaining, HOST_PAGESIZE());
+                       CpuPAddr = OSMemHandleToCpuPAddr(pBuf->hOSMemHandle, uCurrentOffset);
                        /* If the CpuPAddr isn't page aligned then start by writing up to the next page
-                        * boundary (or ui32BytesRemaining if less), so that subsequent iterations can
+                        * boundary (or uBytesRemaining if less), so that subsequent iterations can
                         * copy full physical pages. */
                        if(CpuPAddr.uiAddr & (HOST_PAGESIZE() -1))
                        {
-                               ui32BlockBytes =
-                                       MIN(ui32BytesRemaining, (IMG_UINT32)(HOST_PAGEALIGN(CpuPAddr.uiAddr) - CpuPAddr.uiAddr));
+                               uBlockBytes =
+                                       MIN(uBytesRemaining, (IMG_UINT32)(HOST_PAGEALIGN(CpuPAddr.uiAddr) - CpuPAddr.uiAddr));
                        }
 
                        pvCpuVAddr = OSMapPhysToLin(CpuPAddr,
-                                                                               ui32BlockBytes,
+                                                                               uBlockBytes,
                                                                                PVRSRV_HAP_KERNEL_ONLY
                                                                                | (ui32Flags & PVRSRV_HAP_CACHETYPE_MASK),
                                                                                IMG_NULL);
@@ -671,15 +680,15 @@ ZeroBuf(BM_BUF *pBuf, BM_MAPPING *pMapping, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui3
                                PVR_DPF((PVR_DBG_ERROR, "ZeroBuf: OSMapPhysToLin while zeroing non-contiguous memory FAILED"));
                                return IMG_FALSE;
                        }
-                       OSMemSet(pvCpuVAddr, 0, ui32BlockBytes);
+                       OSMemSet(pvCpuVAddr, 0, uBlockBytes);
                        OSUnMapPhysToLin(pvCpuVAddr,
-                                                        ui32BlockBytes,
+                                                        uBlockBytes,
                                                         PVRSRV_HAP_KERNEL_ONLY
                                                         | (ui32Flags & PVRSRV_HAP_CACHETYPE_MASK),
                                                         IMG_NULL);
 
-                       ui32BytesRemaining -= ui32BlockBytes;
-                       ui32CurrentOffset += ui32BlockBytes;
+                       uBytesRemaining -= uBlockBytes;
+                       uCurrentOffset += uBlockBytes;
                }
        }
 
@@ -713,9 +722,9 @@ FreeBuf (BM_BUF *pBuf, IMG_UINT32 ui32Flags, IMG_BOOL bFromAllocator)
        PVRSRV_DEVICE_NODE *psDeviceNode;
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                       "FreeBuf: pBuf=0x%x: DevVAddr=%08X CpuVAddr=0x%x CpuPAddr=%08X",
-                       (IMG_UINTPTR_T)pBuf, pBuf->DevVAddr.uiAddr,
-                       (IMG_UINTPTR_T)pBuf->CpuVAddr, pBuf->CpuPAddr.uiAddr));
+                       "FreeBuf: pBuf=0x%p: DevVAddr=%08X CpuVAddr=0x%p CpuPAddr=" CPUPADDR_FMT,
+                       pBuf, pBuf->DevVAddr.uiAddr,
+                       pBuf->CpuVAddr, pBuf->CpuPAddr.uiAddr));
 
        /* record mapping */
        pMapping = pBuf->pMapping;
@@ -1526,7 +1535,7 @@ BM_Alloc (  IMG_HANDLE                    hDevMemHeap,
        BM_CONTEXT *pBMContext;
        BM_HEAP *psBMHeap;
        SYS_DATA *psSysData;
-       IMG_UINT32 uFlags;
+       IMG_UINT32 ui32Flags;
 
        if (pui32Flags == IMG_NULL)
        {
@@ -1535,11 +1544,11 @@ BM_Alloc (  IMG_HANDLE                  hDevMemHeap,
                return IMG_FALSE;
        }
 
-       uFlags = *pui32Flags;
+       ui32Flags = *pui32Flags;
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                 "BM_Alloc (uSize=0x%x, uFlags=0x%x, uDevVAddrAlignment=0x%x)",
-                       uSize, uFlags, uDevVAddrAlignment));
+                 "BM_Alloc (uSize=0x%" SIZE_T_FMT_LEN "x, ui32Flags=0x%x, uDevVAddrAlignment=0x%x)",
+                       uSize, ui32Flags, uDevVAddrAlignment));
 
        SysAcquireData(&psSysData);
 
@@ -1571,7 +1580,7 @@ BM_Alloc (  IMG_HANDLE                    hDevMemHeap,
                                        psBMHeap,
                                        psDevVAddr,
                                        uSize,
-                                       uFlags,
+                                       ui32Flags,
                                        uDevVAddrAlignment,
                                        pvPrivData,
                                        ui32PrivDataLength,
@@ -1588,24 +1597,24 @@ BM_Alloc (  IMG_HANDLE                  hDevMemHeap,
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                 "BM_Alloc (uSize=0x%x, uFlags=0x%x)",
-                 uSize, uFlags));
+                 "BM_Alloc (uSize=0x%" SIZE_T_FMT_LEN "x, ui32Flags=0x%x)",
+                 uSize, ui32Flags));
 
        /*
         * Assign the handle and return.
         */
        pBuf->ui32RefCount = 1;
        *phBuf = (BM_HANDLE)pBuf;
-       *pui32Flags = uFlags | psBMHeap->ui32Attribs;
+       *pui32Flags = ui32Flags | psBMHeap->ui32Attribs;
 
        /*
         * If the user has specified heap CACHETYPE flags themselves,
         * override any CACHETYPE flags inherited from the heap.
         */
-       if(uFlags & PVRSRV_HAP_CACHETYPE_MASK)
+       if(ui32Flags & PVRSRV_HAP_CACHETYPE_MASK)
        {
                *pui32Flags &= ~PVRSRV_HAP_CACHETYPE_MASK;
-               *pui32Flags |= (uFlags & PVRSRV_HAP_CACHETYPE_MASK);
+               *pui32Flags |= (ui32Flags & PVRSRV_HAP_CACHETYPE_MASK);
        }
 
        return IMG_TRUE;
@@ -1624,13 +1633,13 @@ BM_Alloc (  IMG_HANDLE                  hDevMemHeap,
 
        @Input      psDeviceNode
     @Input      psSysPAddr - system address array
-    @Input      ui32PageSize - size of address array
+    @Input      uPageSize - size of address array
     
        @Return     IMG_BOOL
 
  *****************************************************************************/
 static IMG_BOOL
-ValidSysPAddrArrayForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR *psSysPAddr, IMG_UINT32 ui32PageCount, IMG_SIZE_T ui32PageSize)
+ValidSysPAddrArrayForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR *psSysPAddr, IMG_UINT32 ui32PageCount, IMG_SIZE_T uPageSize)
 {
        IMG_UINT32 i;
 
@@ -1644,7 +1653,7 @@ ValidSysPAddrArrayForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR *psSy
                        return IMG_FALSE;
                }
 
-               sEndSysPAddr.uiAddr = sStartSysPAddr.uiAddr + ui32PageSize;
+               sEndSysPAddr.uiAddr = sStartSysPAddr.uiAddr + uPageSize;
 
                if (!SysVerifySysPAddrToDevPAddr(psDeviceNode->sDevId.eDeviceType, sEndSysPAddr))
                {
@@ -1671,7 +1680,7 @@ ValidSysPAddrArrayForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR *psSy
 
  *****************************************************************************/
 static IMG_BOOL
-ValidSysPAddrRangeForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR sStartSysPAddr, IMG_SIZE_T ui32Range)
+ValidSysPAddrRangeForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR sStartSysPAddr, IMG_SIZE_T uRange)
 {
        IMG_SYS_PHYADDR sEndSysPAddr;
 
@@ -1680,7 +1689,7 @@ ValidSysPAddrRangeForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR sStar
                return IMG_FALSE;
        }
 
-       sEndSysPAddr.uiAddr = sStartSysPAddr.uiAddr + ui32Range;
+       sEndSysPAddr.uiAddr = sStartSysPAddr.uiAddr + uRange;
 
        if (!SysVerifySysPAddrToDevPAddr(psDeviceNode->sDevId.eDeviceType, sEndSysPAddr))
        {
@@ -1690,9 +1699,9 @@ ValidSysPAddrRangeForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR sStar
        return IMG_TRUE;
 }
 
-#define        WRAP_MAPPING_SIZE(ui32ByteSize, ui32PageOffset) HOST_PAGEALIGN((ui32ByteSize) + (ui32PageOffset))
+#define        WRAP_MAPPING_SIZE(uByteSize, uPageOffset) HOST_PAGEALIGN((uByteSize) + (uPageOffset))
 
-#define        WRAP_PAGE_COUNT(ui32ByteSize, ui32PageOffset, ui32HostPageSize) (WRAP_MAPPING_SIZE(ui32ByteSize, ui32PageOffset) / (ui32HostPageSize))
+#define        WRAP_PAGE_COUNT(uByteSize, uPageOffset, uHostPageSize)  (WRAP_MAPPING_SIZE(uByteSize, uPageOffset) / (uHostPageSize))
 
 #endif
 
@@ -1707,12 +1716,12 @@ ValidSysPAddrRangeForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR sStar
                                The wrapped memory must be page aligned. BM_Wrap will
                                roundup the size to a multiple of cpu pages.
 
-       @Input      ui32Size - size of memory to wrap.
+       @Input      uSize - size of memory to wrap.
        @Input      ui32Offset - Offset into page of memory to wrap.
        @Input      bPhysContig - Is the wrap physically contiguous.
        @Input      psSysAddr - list of system physical page addresses of memory to wrap.
        @Input      pvCPUVAddr - optional CPU kernel virtual address (Page aligned) of memory to wrap.
-    @Input      uFlags - bit mask of buffer property flags.
+    @Input      ui32Flags - bit mask of buffer property flags.
     @output     phBuf - receives the buffer handle.
 
        @Return         IMG_TRUE - Success.
@@ -1721,8 +1730,8 @@ ValidSysPAddrRangeForDev(PVRSRV_DEVICE_NODE *psDeviceNode, IMG_SYS_PHYADDR sStar
  *****************************************************************************/
 IMG_BOOL
 BM_Wrap (      IMG_HANDLE hDevMemHeap,
-                       IMG_SIZE_T ui32Size,
-                       IMG_SIZE_T ui32Offset,
+                       IMG_SIZE_T uSize,
+                       IMG_SIZE_T uOffset,
                        IMG_BOOL bPhysContig,
                        IMG_SYS_PHYADDR *psSysAddr,
                        IMG_VOID *pvCPUVAddr,
@@ -1734,29 +1743,41 @@ BM_Wrap (       IMG_HANDLE hDevMemHeap,
        BM_HEAP *psBMHeap;
        SYS_DATA *psSysData;
        IMG_SYS_PHYADDR sHashAddress;
-       IMG_UINT32 uFlags;
+       IMG_UINT32 ui32Flags;
 
        psBMHeap = (BM_HEAP*)hDevMemHeap;
        psBMContext = psBMHeap->pBMContext;
 
-       uFlags = psBMHeap->ui32Attribs & (PVRSRV_HAP_CACHETYPE_MASK | PVRSRV_HAP_MAPTYPE_MASK);
+       ui32Flags = psBMHeap->ui32Attribs & (PVRSRV_HAP_CACHETYPE_MASK | PVRSRV_HAP_MAPTYPE_MASK);
 
        if ((pui32Flags != IMG_NULL) && ((*pui32Flags & PVRSRV_HAP_CACHETYPE_MASK) != 0))
        {
-               uFlags &= ~PVRSRV_HAP_CACHETYPE_MASK;
-               uFlags |= *pui32Flags & PVRSRV_HAP_CACHETYPE_MASK;
+               ui32Flags &= ~PVRSRV_HAP_CACHETYPE_MASK;
+               ui32Flags |= *pui32Flags & PVRSRV_HAP_CACHETYPE_MASK;
+       }
+
+       if ((pui32Flags != IMG_NULL) && ((*pui32Flags & (PVRSRV_MEM_READ | PVRSRV_MEM_WRITE)) != 0))
+       {
+               ui32Flags &= ~(PVRSRV_MEM_READ | PVRSRV_MEM_WRITE);
+               ui32Flags |= *pui32Flags & (PVRSRV_MEM_READ | PVRSRV_MEM_WRITE);
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                 "BM_Wrap (uSize=0x%x, uOffset=0x%x, bPhysContig=0x%x, pvCPUVAddr=0x%x, uFlags=0x%x)",
-                       ui32Size, ui32Offset, bPhysContig, (IMG_UINTPTR_T)pvCPUVAddr, uFlags));
+                 "BM_Wrap (uSize=0x%" SIZE_T_FMT_LEN "x, uOffset=0x%" SIZE_T_FMT_LEN 
+                 "x, bPhysContig=0x%x, syspAddr=0x" SYSPADDR_FMT ", pvCPUVAddr=0x%p, ui32Flags=0x%x)",
+                       uSize, 
+            uOffset, 
+            bPhysContig, 
+                       psSysAddr->uiAddr,
+            pvCPUVAddr, 
+            ui32Flags));
 
        SysAcquireData(&psSysData);
 
 #if defined(PVR_LMA)
        if (bPhysContig)
        {
-               if (!ValidSysPAddrRangeForDev(psBMContext->psDeviceNode, *psSysAddr, WRAP_MAPPING_SIZE(ui32Size, ui32Offset)))
+               if (!ValidSysPAddrRangeForDev(psBMContext->psDeviceNode, *psSysAddr, WRAP_MAPPING_SIZE(uSize, uOffset)))
                {
                        PVR_DPF((PVR_DBG_ERROR, "BM_Wrap: System address range invalid for device"));
                        return IMG_FALSE;
@@ -1764,9 +1785,9 @@ BM_Wrap ( IMG_HANDLE hDevMemHeap,
        }
        else
        {
-               IMG_SIZE_T ui32HostPageSize = HOST_PAGESIZE();
+               IMG_SIZE_T uHostPageSize = HOST_PAGESIZE();
 
-               if (!ValidSysPAddrArrayForDev(psBMContext->psDeviceNode, psSysAddr, WRAP_PAGE_COUNT(ui32Size, ui32Offset, ui32HostPageSize), ui32HostPageSize))
+               if (!ValidSysPAddrArrayForDev(psBMContext->psDeviceNode, psSysAddr, WRAP_PAGE_COUNT(uSize, uOffset, uHostPageSize), uHostPageSize))
                {
                        PVR_DPF((PVR_DBG_ERROR, "BM_Wrap: Array of system addresses invalid for device"));
                        return IMG_FALSE;
@@ -1780,27 +1801,29 @@ BM_Wrap (       IMG_HANDLE hDevMemHeap,
        sHashAddress = psSysAddr[0];
 
        /* Add the in-page offset to ensure a unique hash */
-       sHashAddress.uiAddr += ui32Offset;
+       sHashAddress.uiAddr += uOffset;
 
-       /* See if this address has already been wrapped */
-       pBuf = (BM_BUF *)HASH_Retrieve(psBMContext->pBufferHash, sHashAddress.uiAddr);
+       /* See if this address has already been wrapped, note that the cast is ok as this is only local mem */
+       pBuf = (BM_BUF *)HASH_Retrieve(psBMContext->pBufferHash, (IMG_UINTPTR_T)sHashAddress.uiAddr);
 
        if(pBuf)
        {
-               IMG_SIZE_T ui32MappingSize = HOST_PAGEALIGN (ui32Size + ui32Offset);
+               IMG_SIZE_T uMappingSize = HOST_PAGEALIGN (uSize + uOffset);
 
                /* Check base address, size and contiguity type match */
-               if(pBuf->pMapping->uSize == ui32MappingSize && (pBuf->pMapping->eCpuMemoryOrigin == hm_wrapped ||
+               if(pBuf->pMapping->uSize == uMappingSize && (pBuf->pMapping->eCpuMemoryOrigin == hm_wrapped ||
                                                                                                                pBuf->pMapping->eCpuMemoryOrigin == hm_wrapped_virtaddr))
                {
                        PVR_DPF((PVR_DBG_MESSAGE,
-                                       "BM_Wrap (Matched previous Wrap! uSize=0x%x, uOffset=0x%x, SysAddr=%08X)",
-                                       ui32Size, ui32Offset, sHashAddress.uiAddr));
+                                       "BM_Wrap (Matched previous Wrap! uSize=0x%" SIZE_T_FMT_LEN "x, uOffset=0x%" SIZE_T_FMT_LEN "x, SysAddr=" SYSPADDR_FMT ")",
+                                       uSize, 
+                    uOffset, 
+                    sHashAddress.uiAddr));
 
                        PVRSRVBMBufIncRef(pBuf);
                        *phBuf = (BM_HANDLE)pBuf;
                        if(pui32Flags)
-                               *pui32Flags = uFlags;
+                               *pui32Flags = ui32Flags;
 
                        return IMG_TRUE;
                }
@@ -1828,7 +1851,7 @@ BM_Wrap ( IMG_HANDLE hDevMemHeap,
        /*
         * Actually perform the memory wrap.
         */
-       if (WrapMemory (psBMHeap, ui32Size, ui32Offset, bPhysContig, psSysAddr, pvCPUVAddr, uFlags, pBuf) != IMG_TRUE)
+       if (WrapMemory (psBMHeap, uSize, uOffset, bPhysContig, psSysAddr, pvCPUVAddr, ui32Flags, pBuf) != IMG_TRUE)
        {
                PVR_DPF((PVR_DBG_ERROR, "BM_Wrap: WrapMemory FAILED"));
                OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof (BM_BUF), pBuf, IMG_NULL);
@@ -1844,17 +1867,17 @@ BM_Wrap (       IMG_HANDLE hDevMemHeap,
                /* Have we calculated the right Hash key ? */
                PVR_ASSERT(SysSysPAddrToCpuPAddr(sHashAddress).uiAddr == pBuf->CpuPAddr.uiAddr);
 
-               if (!HASH_Insert (psBMContext->pBufferHash, sHashAddress.uiAddr, (IMG_UINTPTR_T)pBuf))
+               if (!HASH_Insert (psBMContext->pBufferHash, (IMG_UINTPTR_T)sHashAddress.uiAddr, (IMG_UINTPTR_T)pBuf))
                {
-                       FreeBuf (pBuf, uFlags, IMG_TRUE);
+                       FreeBuf (pBuf, ui32Flags, IMG_TRUE);
                        PVR_DPF((PVR_DBG_ERROR, "BM_Wrap: HASH_Insert FAILED"));
                        return IMG_FALSE;
                }
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                       "BM_Wrap (uSize=0x%x, uFlags=0x%x, devVAddr=%08X)",
-                       ui32Size, uFlags, pBuf->DevVAddr.uiAddr));
+                       "BM_Wrap (uSize=0x%" SIZE_T_FMT_LEN "x, ui32Flags=0x%x, devVAddr=%08X)",
+                       uSize, ui32Flags, pBuf->DevVAddr.uiAddr));
 
        /*
         * Assign the handle and return.
@@ -1864,7 +1887,7 @@ BM_Wrap ( IMG_HANDLE hDevMemHeap,
        if(pui32Flags)
        {
                /* need to override the heap attributes SINGLE PROC to MULT_PROC. */
-               *pui32Flags = (uFlags & ~PVRSRV_HAP_MAPTYPE_MASK) | PVRSRV_HAP_MULTI_PROCESS;
+               *pui32Flags = (ui32Flags & ~PVRSRV_HAP_MAPTYPE_MASK) | PVRSRV_HAP_MULTI_PROCESS;
        }
 
        return IMG_TRUE;
@@ -1931,7 +1954,7 @@ BM_Free (BM_HANDLE hBuf,
        SYS_DATA *psSysData;
        IMG_SYS_PHYADDR sHashAddr;
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "BM_Free (h=0x%x)", (IMG_UINTPTR_T)hBuf));
+       PVR_DPF ((PVR_DBG_MESSAGE, "BM_Free (h=0x%p)", hBuf));
        PVR_ASSERT (pBuf!=IMG_NULL);
 
        if (pBuf == IMG_NULL)
@@ -1981,8 +2004,8 @@ BM_HandleToCpuVaddr (BM_HANDLE hBuf)
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                               "BM_HandleToCpuVaddr(h=0x%x)=0x%x",
-                               (IMG_UINTPTR_T)hBuf, (IMG_UINTPTR_T)pBuf->CpuVAddr));
+                               "BM_HandleToCpuVaddr(h=0x%p)=0x%p",
+                               hBuf, pBuf->CpuVAddr));
        return pBuf->CpuVAddr;
 }
 
@@ -2012,7 +2035,7 @@ BM_HandleToDevVaddr (BM_HANDLE hBuf)
                return DevVAddr;
        }
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "BM_HandleToDevVaddr(h=0x%x)=%08X", (IMG_UINTPTR_T)hBuf, pBuf->DevVAddr.uiAddr));
+       PVR_DPF ((PVR_DBG_MESSAGE, "BM_HandleToDevVaddr(h=0x%p)=%08X", hBuf, pBuf->DevVAddr.uiAddr));
        return pBuf->DevVAddr;
 }
 
@@ -2043,7 +2066,7 @@ BM_HandleToSysPaddr (BM_HANDLE hBuf)
                return PhysAddr;
        }
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "BM_HandleToSysPaddr(h=0x%x)=%08X", (IMG_UINTPTR_T)hBuf, pBuf->CpuPAddr.uiAddr));
+       PVR_DPF ((PVR_DBG_MESSAGE, "BM_HandleToSysPaddr(h=0lx%p)=" CPUPADDR_FMT, hBuf, pBuf->CpuPAddr.uiAddr));
        return SysCpuPAddrToSysPAddr (pBuf->CpuPAddr);
 }
 
@@ -2073,8 +2096,8 @@ BM_HandleToOSMemHandle(BM_HANDLE hBuf)
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                               "BM_HandleToOSMemHandle(h=0x%x)=0x%x",
-                               (IMG_UINTPTR_T)hBuf, (IMG_UINTPTR_T)pBuf->hOSMemHandle));
+                               "BM_HandleToOSMemHandle(h=0x%p)=0x%p",
+                               hBuf, pBuf->hOSMemHandle));
        return pBuf->hOSMemHandle;
 }
 
@@ -2096,7 +2119,7 @@ BM_HandleToOSMemHandle(BM_HANDLE hBuf)
                                         allocation.
        @Output     pActualSize - the actual size of the block allocated in
                                         bytes.
-       @Input      uFlags -  allocation flags
+       @Input      ui32Flags -  allocation flags
        @Input      dev_vaddr_alignment - required device virtual address
                                         alignment, or 0.
        @Output     pDevVAddr - receives the device virtual base address of the
@@ -2109,25 +2132,35 @@ static IMG_BOOL
 DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                BM_MAPPING *pMapping,
                                IMG_SIZE_T *pActualSize,
-                               IMG_UINT32 uFlags,
+                               IMG_UINT32 ui32Flags,
                                IMG_UINT32 dev_vaddr_alignment,
                                IMG_DEV_VIRTADDR *pDevVAddr)
 {
        PVRSRV_DEVICE_NODE *psDeviceNode;
 #ifdef PDUMP
        IMG_UINT32 ui32PDumpSize = (IMG_UINT32)pMapping->uSize;
+       IMG_UINT32 ui32PDumpFlags;
 #endif
 
        psDeviceNode = pBMContext->psDeviceNode;
 
-       if(uFlags & PVRSRV_MEM_INTERLEAVED)
+#ifdef PDUMP
+#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
+       ui32PDumpFlags = psDeviceNode->pfnMMUIsHeapShared(pMapping->pBMHeap->pMMUHeap)
+                                               ? PDUMP_FLAGS_PERSISTENT : PDUMP_FLAGS_CONTINUOUS;
+#else
+       ui32PDumpFlags = PDUMP_FLAGS_CONTINUOUS;
+#endif
+#endif
+
+       if(ui32Flags & PVRSRV_MEM_INTERLEAVED)
        {
                /* double the size */
                pMapping->uSize *= 2;
        }
 
 #ifdef PDUMP
-       if(uFlags & PVRSRV_MEM_DUMMY)
+       if(ui32Flags & PVRSRV_MEM_DUMMY)
        {
                /* only one page behind a dummy allocation */
                ui32PDumpSize = pMapping->pBMHeap->sDevArena.ui32DataPageSize;
@@ -2160,12 +2193,8 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                         pMapping->hOSMemHandle,
                                         ui32PDumpSize,
                                         pMapping->pBMHeap->sDevArena.ui32DataPageSize,
-#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
-                                        psDeviceNode->pfnMMUIsHeapShared(pMapping->pBMHeap->pMMUHeap),
-#else
-                                        IMG_FALSE, // unused
-#endif /* SUPPORT_PDUMP_MULTI_PROCESS */
-                                        (IMG_HANDLE)pMapping);
+                                        (IMG_HANDLE)pMapping,
+                                        ui32PDumpFlags);
 #endif
 
        switch (pMapping->eCpuMemoryOrigin)
@@ -2174,7 +2203,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                case hm_wrapped_virtaddr:
                case hm_contiguous:
                {
-                       if (uFlags & PVRSRV_MEM_SPARSE)
+                       if (ui32Flags & PVRSRV_MEM_SPARSE)
                        {
                                /* Check if this device supports sparse mappings */
                                PVR_ASSERT(psDeviceNode->pfnMMUMapPagesSparse != IMG_NULL);
@@ -2185,7 +2214,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                                                pMapping->ui32NumVirtChunks,
                                                                pMapping->ui32NumPhysChunks,
                                                                pMapping->pabMapChunk,
-                                                               uFlags,
+                                                               ui32Flags,
                                                                (IMG_HANDLE)pMapping);
                        }
                        else
@@ -2194,7 +2223,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                                                pMapping->DevVAddr,
                                                                SysCpuPAddrToSysPAddr (pMapping->CpuPAddr),
                                                                pMapping->uSize,
-                                                               uFlags,
+                                                               ui32Flags,
                                                                (IMG_HANDLE)pMapping);
                        }
                        *pDevVAddr = pMapping->DevVAddr;
@@ -2202,7 +2231,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                }
                case hm_env:
                {
-                       if (uFlags & PVRSRV_MEM_SPARSE)
+                       if (ui32Flags & PVRSRV_MEM_SPARSE)
                        {
                                /* Check if this device supports sparse mappings */
                                PVR_ASSERT(psDeviceNode->pfnMMUMapShadowSparse != IMG_NULL);
@@ -2215,7 +2244,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                                                pMapping->CpuVAddr,
                                                                pMapping->hOSMemHandle,
                                                                pDevVAddr,
-                                                               uFlags,
+                                                               ui32Flags,
                                                                (IMG_HANDLE)pMapping);
                        }
                        else
@@ -2226,7 +2255,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                                                pMapping->CpuVAddr,
                                                                pMapping->hOSMemHandle,
                                                                pDevVAddr,
-                                                               uFlags,
+                                                               ui32Flags,
                                                                (IMG_HANDLE)pMapping);
                        }
                        break;
@@ -2238,7 +2267,7 @@ DevMemoryAlloc (BM_CONTEXT *pBMContext,
                                                        pMapping->DevVAddr,
                                                        pMapping->psSysAddr,
                                                        pMapping->uSize,
-                                                       uFlags,
+                                                       ui32Flags,
                                                        (IMG_HANDLE)pMapping);
 
                        *pDevVAddr = pMapping->DevVAddr;
@@ -2265,11 +2294,21 @@ DevMemoryFree (BM_MAPPING *pMapping)
        IMG_DEV_PHYADDR     sDevPAddr;
 #ifdef PDUMP
        IMG_UINT32 ui32PSize;
+       IMG_UINT32 ui32PDumpFlags;
 #endif
 
        psDeviceNode = pMapping->pBMHeap->pBMContext->psDeviceNode;
        sDevPAddr = psDeviceNode->pfnMMUGetPhysPageAddr(pMapping->pBMHeap->pMMUHeap, pMapping->DevVAddr);
 
+#ifdef PDUMP
+#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
+       ui32PDumpFlags = psDeviceNode->pfnMMUIsHeapShared(pMapping->pBMHeap->pMMUHeap)
+                                               ? PDUMP_FLAGS_PERSISTENT : PDUMP_FLAGS_CONTINUOUS;
+#else
+       ui32PDumpFlags = PDUMP_FLAGS_CONTINUOUS;
+#endif
+#endif
+
        if (sDevPAddr.uiAddr != 0)
        {
 #ifdef PDUMP
@@ -2290,7 +2329,8 @@ DevMemoryFree (BM_MAPPING *pMapping)
                            pMapping->pBMHeap->sDevArena.ui32DataPageSize,
                            (IMG_HANDLE)pMapping,
                            (pMapping->ui32Flags & PVRSRV_MEM_INTERLEAVED) ? IMG_TRUE : IMG_FALSE,
-                           (pMapping->ui32Flags & PVRSRV_MEM_SPARSE) ? IMG_TRUE : IMG_FALSE);
+                           (pMapping->ui32Flags & PVRSRV_MEM_SPARSE) ? IMG_TRUE : IMG_FALSE,
+                                               ui32PDumpFlags);
 #endif
        }
        PVR_ASSERT(pMapping->uSizeVM != 0);
@@ -2595,7 +2635,7 @@ IMG_VOID _BM_XProcIndexRelease(IMG_UINT32 ui32Index)
                        }
                        sSysPAddr = gXProcWorkaroundShareData[ui32Index].sSysPAddr;
                        RA_Free (gXProcWorkaroundShareData[ui32Index].psArena,
-                                        sSysPAddr.uiAddr,
+                                        (IMG_UINTPTR_T)sSysPAddr.uiAddr,
                                         IMG_FALSE);
                }
                else
@@ -2642,7 +2682,7 @@ static IMG_VOID XProcWorkaroundFreeShareable(IMG_HANDLE hOSMemHandle)
                                         which may be >= requested size
        @Output     ppsMapping - receives the arbitrary user reference
                                         associated with the underlying storage.
-       @Input      uFlags - bit mask of allocation flags
+       @Input      ui32Flags - bit mask of allocation flags
     @Input      pvPrivData - opaque private data passed through to allocator
     @Input      ui32PrivDataLength - length of opaque private data
        @Output     pBase - receives a pointer to the allocated storage.
@@ -2656,7 +2696,7 @@ BM_ImportMemory (IMG_VOID *pH,
                          IMG_SIZE_T uRequestSize,
                          IMG_SIZE_T *pActualSize,
                          BM_MAPPING **ppsMapping,
-                         IMG_UINT32 uFlags,
+                         IMG_UINT32 ui32Flags,
                          IMG_PVOID pvPrivData,
                          IMG_UINT32 ui32PrivDataLength,
                          IMG_UINTPTR_T *pBase)
@@ -2670,8 +2710,9 @@ BM_ImportMemory (IMG_VOID *pH,
        IMG_SIZE_T uDevVAddrAlignment = 0; /* ? */
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "BM_ImportMemory (pBMContext=0x%x, uRequestSize=0x%x, uFlags=0x%x, uAlign=0x%x)",
-                         (IMG_UINTPTR_T)pBMContext, uRequestSize, uFlags, uDevVAddrAlignment));
+                         "BM_ImportMemory (pBMContext=0x%p, uRequestSize=0x%" SIZE_T_FMT_LEN 
+                         "x, ui32Flags=0x%x, uAlign=0x%" SIZE_T_FMT_LEN "x)",
+                         pBMContext, uRequestSize, ui32Flags, uDevVAddrAlignment));
 
        PVR_ASSERT (ppsMapping != IMG_NULL);
        PVR_ASSERT (pBMContext != IMG_NULL);
@@ -2699,12 +2740,12 @@ BM_ImportMemory (IMG_VOID *pH,
        pMapping->DevVAddr.uiAddr = 0;
        pMapping->CpuPAddr.uiAddr = 0;
        pMapping->uSize = uSize;
-       if ((uFlags & PVRSRV_MEM_SPARSE) == 0)
+       if ((ui32Flags & PVRSRV_MEM_SPARSE) == 0)
        {
                pMapping->uSizeVM = uSize;
        }
        pMapping->pBMHeap = pBMHeap;
-       pMapping->ui32Flags = uFlags;
+       pMapping->ui32Flags = ui32Flags;
 
        /*
         * If anyone want's to know, pass back the actual size of our allocation.
@@ -2726,12 +2767,12 @@ BM_ImportMemory (IMG_VOID *pH,
                uPSize = pMapping->uSize;
        }
 
-       if (uFlags & PVRSRV_MEM_XPROC)
+       if (ui32Flags & PVRSRV_MEM_XPROC)
        {
                IMG_UINT32 ui32Attribs = pBMHeap->ui32Attribs | PVRSRV_MEM_XPROC;
         IMG_BOOL bBadBackingStoreType;
 
-        if(uFlags & PVRSRV_MEM_ION)
+        if(ui32Flags & PVRSRV_MEM_ION)
         {
             ui32Attribs |= PVRSRV_MEM_ION;
         }
@@ -2770,7 +2811,7 @@ BM_ImportMemory (IMG_VOID *pH,
                                           &pMapping->hOSMemHandle) != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,
-                                       "BM_ImportMemory: XProcWorkaroundAllocShareable(0x%x) failed",
+                                       "BM_ImportMemory: XProcWorkaroundAllocShareable(0x%" SIZE_T_FMT_LEN "x) failed",
                                        uPSize));
                        goto fail_mapping_alloc;
                }
@@ -2814,7 +2855,7 @@ BM_ImportMemory (IMG_VOID *pH,
                                               &pMapping->hOSMemHandle) != PVRSRV_OK)
             {
                 PVR_DPF((PVR_DBG_ERROR,
-                         "BM_ImportMemory: XProcWorkaroundAllocShareable(0x%x) failed",
+                         "BM_ImportMemory: XProcWorkaroundAllocShareable(0x%" SIZE_T_FMT_LEN "x) failed",
                          uPSize));
                 goto fail_mapping_alloc;
             }
@@ -2874,7 +2915,7 @@ BM_ImportMemory (IMG_VOID *pH,
                                                 &pMapping->hOSMemHandle) != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,
-                                       "BM_ImportMemory: OSAllocPages(0x%x) failed",
+                                       "BM_ImportMemory: OSAllocPages(0x%" SIZE_T_FMT_LEN "x) failed",
                                        uPSize));
                        goto fail_mapping_alloc;
                }
@@ -2916,7 +2957,7 @@ BM_ImportMemory (IMG_VOID *pH,
                                           ui32PrivDataLength,
                                           (IMG_UINTPTR_T *)&sSysPAddr.uiAddr))
                {
-                       PVR_DPF((PVR_DBG_ERROR, "BM_ImportMemory: RA_Alloc(0x%x) FAILED", uPSize));
+                       PVR_DPF((PVR_DBG_ERROR, "BM_ImportMemory: RA_Alloc(0x%" SIZE_T_FMT_LEN "x) FAILED", uPSize));
                        goto fail_mapping_alloc;
                }
 
@@ -2945,18 +2986,18 @@ BM_ImportMemory (IMG_VOID *pH,
        /*
         * Allocate some device memory for what we just allocated.
         */
-       if ((uFlags & PVRSRV_MEM_SPARSE) == 0)
+       if ((ui32Flags & PVRSRV_MEM_SPARSE) == 0)
        {
                bResult = DevMemoryAlloc (pBMContext,
                                                                        pMapping,
                                                                        IMG_NULL,
-                                                                       uFlags,
+                                                                       ui32Flags,
                                                                        (IMG_UINT32)uDevVAddrAlignment,
                                                                        &pMapping->DevVAddr);
                if (!bResult)
                {
                        PVR_DPF((PVR_DBG_ERROR,
-                                       "BM_ImportMemory: DevMemoryAlloc(0x%x) failed",
+                                       "BM_ImportMemory: DevMemoryAlloc(0x%" SIZE_T_FMT_LEN "x) failed",
                                        pMapping->uSize));
                        goto fail_dev_mem_alloc;
                }
@@ -2991,7 +3032,7 @@ fail_dev_mem_alloc:
                        uPSize = pMapping->uSize;
                }
 
-               if (uFlags & PVRSRV_MEM_XPROC)
+               if (ui32Flags & PVRSRV_MEM_XPROC)
                {
                        XProcWorkaroundFreeShareable(pMapping->hOSMemHandle);
                }
@@ -3015,7 +3056,7 @@ fail_dev_mem_alloc:
                                                                pMapping->hOSMemHandle);
                        }
                        sSysPAddr = SysCpuPAddrToSysPAddr(pMapping->CpuPAddr);
-                       RA_Free (pBMHeap->pLocalDevMemArena, sSysPAddr.uiAddr, IMG_FALSE);
+                       RA_Free (pBMHeap->pLocalDevMemArena, (IMG_UINTPTR_T)sSysPAddr.uiAddr, IMG_FALSE);
                }
        }
 fail_mapping_alloc:
@@ -3051,8 +3092,8 @@ BM_FreeMemory (IMG_VOID *h, IMG_UINTPTR_T _base, BM_MAPPING *psMapping)
        PVR_UNREFERENCED_PARAMETER (_base);
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "BM_FreeMemory (h=0x%x, base=0x%x, psMapping=0x%x)",
-                         (IMG_UINTPTR_T)h, _base, (IMG_UINTPTR_T)psMapping));
+                         "BM_FreeMemory (h=0x%p, base=0x" UINTPTR_FMT ", psMapping=0x%p)",
+                         h, _base, psMapping));
 
        PVR_ASSERT (psMapping != IMG_NULL);
 
@@ -3107,7 +3148,7 @@ BM_FreeMemory (IMG_VOID *h, IMG_UINTPTR_T _base, BM_MAPPING *psMapping)
 
                sSysPAddr = SysCpuPAddrToSysPAddr(psMapping->CpuPAddr);
 
-               RA_Free (pBMHeap->pLocalDevMemArena, sSysPAddr.uiAddr, IMG_FALSE);
+               RA_Free (pBMHeap->pLocalDevMemArena, (IMG_UINTPTR_T)sSysPAddr.uiAddr, IMG_FALSE);
        }
        else
        {
@@ -3118,8 +3159,8 @@ BM_FreeMemory (IMG_VOID *h, IMG_UINTPTR_T _base, BM_MAPPING *psMapping)
        /*not nulling pointer, copy on stack*/
 
        PVR_DPF((PVR_DBG_MESSAGE,
-                       "..BM_FreeMemory (h=0x%x, base=0x%x)",
-                       (IMG_UINTPTR_T)h, _base));
+                       "..BM_FreeMemory (h=0x%p, base=0x" UINTPTR_FMT ")",
+                       h, _base));
 }
 
 /*!
index 7d4db5b..c71e00a 100644 (file)
@@ -1,4 +1,5 @@
 /*************************************************************************/ /*!
+@File
 @Title          Device class services functions
 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
 @Description    Kernel services functions for device class devices
@@ -50,13 +51,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "lists.h"
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include "pvr_sync.h"
+#endif
+
 PVRSRV_ERROR AllocateDeviceID(SYS_DATA *psSysData, IMG_UINT32 *pui32DevID);
 PVRSRV_ERROR FreeDeviceID(SYS_DATA *psSysData, IMG_UINT32 ui32DevID);
 
-#if defined(SUPPORT_MISR_IN_THREAD)
-void OSVSyncMISR(IMG_HANDLE, IMG_BOOL);
-#endif
-
 #if defined(SUPPORT_CUSTOM_SWAP_OPERATIONS)
 IMG_VOID PVRSRVFreeCommandCompletePacketKM(IMG_HANDLE  hCmdCookie,
                                                                                   IMG_BOOL             bScheduleMISR);
@@ -1163,6 +1164,14 @@ static PVRSRV_ERROR DestroyDCSwapChain(PVRSRV_DC_SWAPCHAIN *psSwapChain)
 #if !defined(SUPPORT_DC_CMDCOMPLETE_WHEN_NO_LONGER_DISPLAYED)
        if (psSwapChain->ppsLastSyncInfos)
        {
+               for (i = 0; i < psSwapChain->ui32LastNumSyncInfos; i++)
+               {
+                       if (psSwapChain->ppsLastSyncInfos[i])
+                       {
+                               PVRSRVKernelSyncInfoDecRef(psSwapChain->ppsLastSyncInfos[i], IMG_NULL);
+                               psSwapChain->ppsLastSyncInfos[i] = IMG_NULL;
+                       }
+               }
                OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_KERNEL_SYNC_INFO *) * psSwapChain->ui32LastNumSyncInfos,
                                        psSwapChain->ppsLastSyncInfos, IMG_NULL);
        }
@@ -1273,7 +1282,6 @@ PVRSRV_ERROR PVRSRVCreateDCSwapChainKM (PVRSRV_PER_PROCESS_DATA   *psPerProc,
        IMG_UINT32 i;
        DISPLAY_INFO sDisplayInfo;
 
-
        if(!hDeviceKM
        || !psDstSurfAttrib
        || !psSrcSurfAttrib
@@ -1284,18 +1292,14 @@ PVRSRV_ERROR PVRSRVCreateDCSwapChainKM (PVRSRV_PER_PROCESS_DATA *psPerProc,
                return PVRSRV_ERROR_INVALID_PARAMS;
        }
 
+       OSMemSet (apsSyncData, 0, sizeof(PVRSRV_SYNC_DATA *) * PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS);
+
        if (ui32BufferCount > PVRSRV_MAX_DC_SWAPCHAIN_BUFFERS)
        {
                PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateDCSwapChainKM: Too many buffers"));
                return PVRSRV_ERROR_TOOMANYBUFFERS;
        }
 
-       if (ui32BufferCount < 2)
-       {
-               PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateDCSwapChainKM: Too few buffers"));
-               return PVRSRV_ERROR_TOO_FEW_BUFFERS;
-       }
-
        psDCInfo = DCDeviceHandleToDCInfo(hDeviceKM);
 
        if( ui32Flags & PVRSRV_CREATE_SWAPCHAIN_QUERY )
@@ -1425,7 +1429,7 @@ PVRSRV_ERROR PVRSRVCreateDCSwapChainKM (PVRSRV_PER_PROCESS_DATA   *psPerProc,
        psSwapChain->ui32RefCount = 1;
        psSwapChain->ui32Flags = ui32Flags;
 
-       /* Save pointer in DC structure if ti's shared struct */
+       /* Save pointer in DC structure if it's shared struct */
        if( ui32Flags & PVRSRV_CREATE_SWAPCHAIN_SHARED )
        {
                if(! psDCInfo->psDCSwapChainShared ) 
@@ -1607,32 +1611,6 @@ PVRSRV_ERROR PVRSRVGetDCBuffersKM(IMG_HANDLE     hDeviceKM,
                phBuffer[i] = (IMG_HANDLE)&psSwapChain->asBuffer[i];
        }
 
-#if defined(SUPPORT_GET_DC_BUFFERS_SYS_PHYADDRS)
-       for(i = 0; i < *pui32BufferCount; i++)
-       {
-               IMG_UINT32 ui32ByteSize, ui32TilingStride;
-               IMG_SYS_PHYADDR *pPhyAddr;
-               IMG_BOOL bIsContiguous;
-               IMG_HANDLE hOSMapInfo;
-               IMG_VOID *pvVAddr;
-
-               eError = psDCInfo->psFuncTable->pfnGetBufferAddr(psDCInfo->hExtDevice,
-                                                                                                                ahExtBuffer[i],
-                                                                                                                &pPhyAddr,
-                                                                                                                &ui32ByteSize,
-                                                                                                                &pvVAddr,
-                                                                                                                &hOSMapInfo,
-                                                                                                                &bIsContiguous,
-                                                                                                                &ui32TilingStride);
-               if(eError != PVRSRV_OK)
-               {
-                       break;
-               }
-
-               psPhyAddr[i] = *pPhyAddr;
-       }
-#endif /* defined(SUPPORT_GET_DC_BUFFERS_SYS_PHYADDRS) */
-
        return eError;
 }
 
@@ -1714,6 +1692,7 @@ PVRSRV_ERROR PVRSRVSwapToDCBufferKM(IMG_HANDLE    hDeviceKM,
                                                                        apsSrcSync,
                                                                        sizeof(DISPLAYCLASS_FLIP_COMMAND) + (sizeof(IMG_RECT) * ui32ClipRectCount),
                                                                        IMG_NULL,
+                                                                       IMG_NULL,
                                                                        IMG_NULL);
        if(eError != PVRSRV_OK)
        {
@@ -1833,20 +1812,26 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE hDeviceKM,
                                                                         PVRSRV_KERNEL_SYNC_INFO **ppsSyncInfos,
                                                                         IMG_UINT32     ui32NumMemSyncInfos,
                                                                         IMG_PVOID      pvPrivData,
-                                                                        IMG_UINT32     ui32PrivDataLength)
+                                                                        IMG_UINT32     ui32PrivDataLength,
+                                                                        IMG_HANDLE     *phFence)
 {
+       IMG_UINT32 ui32NumSyncInfos = ui32NumMemSyncInfos;
        PVRSRV_KERNEL_SYNC_INFO **ppsCompiledSyncInfos;
        IMG_UINT32 i, ui32NumCompiledSyncInfos;
        DISPLAYCLASS_FLIP_COMMAND2 *psFlipCmd;
        PVRSRV_DISPLAYCLASS_INFO *psDCInfo;
        PVRSRV_DC_SWAPCHAIN *psSwapChain;
-       PVRSRV_ERROR eError = PVRSRV_OK;
        CALLBACK_DATA *psCallbackData;
        PVRSRV_QUEUE_INFO *psQueue;
        PVRSRV_COMMAND *psCommand;
        IMG_PVOID *ppvMemInfos;
+       PVRSRV_ERROR eError;
        SYS_DATA *psSysData;
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       struct sync_fence *apsFence[SGX_MAX_SRC_SYNCS_TA];
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+
        if(!hDeviceKM || !hSwapChain || !ppsMemInfos || !ppsSyncInfos || ui32NumMemSyncInfos < 1)
        {
                PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Invalid parameters"));
@@ -1895,6 +1880,15 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE  hDeviceKM,
        psCallbackData->ppvMemInfos = ppvMemInfos;
        psCallbackData->ui32NumMemInfos = ui32NumMemSyncInfos;
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       eError = PVRSyncFencesToSyncInfos(ppsSyncInfos, &ui32NumSyncInfos, apsFence);
+       if(eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: PVRSyncFencesToSyncInfos failed"));
+               goto Exit;
+       }
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+
        /* get the queue from the buffer structure */
        psQueue = psSwapChain->psQueue;
 
@@ -1902,21 +1896,35 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE hDeviceKM,
        if(psSwapChain->ppsLastSyncInfos)
        {
                IMG_UINT32 ui32NumUniqueSyncInfos = psSwapChain->ui32LastNumSyncInfos;
+               IMG_BOOL *abUnique;
                IMG_UINT32 j;
 
+               if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                         sizeof(IMG_BOOL) * psSwapChain->ui32LastNumSyncInfos,
+                                         (IMG_VOID **)&abUnique, IMG_NULL,
+                                         "Unique booleans") != PVRSRV_OK)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Failed to allocate space for unique booleans"));
+                       goto Exit;
+               }
+
                for(j = 0; j < psSwapChain->ui32LastNumSyncInfos; j++)
                {
-                       for(i = 0; i < ui32NumMemSyncInfos; i++)
+                       abUnique[j] = IMG_TRUE;
+                       for(i = 0; i < ui32NumSyncInfos; i++)
                        {
+                               PVR_ASSERT(psSwapChain->ppsLastSyncInfos[j]);
+                               PVR_ASSERT(ppsSyncInfos[i]);
                                if(psSwapChain->ppsLastSyncInfos[j] == ppsSyncInfos[i])
                                {
-                                       psSwapChain->ppsLastSyncInfos[j] = IMG_NULL;
+                                       abUnique[j] = IMG_FALSE;
                                        ui32NumUniqueSyncInfos--;
+                                       break;
                                }
                        }
                }
 
-               ui32NumCompiledSyncInfos = ui32NumMemSyncInfos + ui32NumUniqueSyncInfos;
+               ui32NumCompiledSyncInfos = ui32NumSyncInfos + ui32NumUniqueSyncInfos;
 
                if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
                                          sizeof(PVRSRV_KERNEL_SYNC_INFO *) * ui32NumCompiledSyncInfos,
@@ -1924,24 +1932,108 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE        hDeviceKM,
                                          "Compiled syncinfos") != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Failed to allocate space for meminfo list"));
+                       OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                         sizeof(IMG_BOOL) * psSwapChain->ui32LastNumSyncInfos,
+                                         (IMG_VOID *)abUnique, IMG_NULL);
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+                       for(i = 0; apsFence[i]; i++)
+                               if(apsFence[i])
+                                       sync_fence_put(apsFence[i]);
+#endif
                        goto Exit;
                }
                                
-               OSMemCopy(ppsCompiledSyncInfos, ppsSyncInfos, sizeof(PVRSRV_KERNEL_SYNC_INFO *) * ui32NumMemSyncInfos);
-               for(j = 0, i = ui32NumMemSyncInfos; j < psSwapChain->ui32LastNumSyncInfos; j++)
+               OSMemCopy(ppsCompiledSyncInfos, ppsSyncInfos, sizeof(PVRSRV_KERNEL_SYNC_INFO *) * ui32NumSyncInfos);
+               for(j = 0, i = ui32NumSyncInfos; j < psSwapChain->ui32LastNumSyncInfos; j++)
                {
-                       if(psSwapChain->ppsLastSyncInfos[j])
+                       if(abUnique[j])
                        {
                                ppsCompiledSyncInfos[i] = psSwapChain->ppsLastSyncInfos[j];
                                i++;
                        }
                }
+
+               OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                 sizeof(IMG_BOOL) * psSwapChain->ui32LastNumSyncInfos,
+                                 (IMG_VOID *)abUnique, IMG_NULL);
        }
        else
 #endif /* !defined(SUPPORT_DC_CMDCOMPLETE_WHEN_NO_LONGER_DISPLAYED) */
        {
-               ppsCompiledSyncInfos = ppsSyncInfos;
-               ui32NumCompiledSyncInfos = ui32NumMemSyncInfos;
+               IMG_UINT32 j, ui32Missing = 0;
+
+               /* Older synchronization schemes would just pass down the syncinfos
+                * hanging off of the meminfos. So we would expect identical lists.
+                * However, newer drivers may send down additional synchronization
+                * i.e. for TQ fence operations. In such a case we need to allocate
+                * more space for the compiled syncinfos to ensure everything is
+                * ROP2 synchronized.
+                */
+               for(j = 0; j < ui32NumSyncInfos; j++)
+               {
+                       IMG_BOOL bFound = IMG_FALSE;
+
+                       for(i = 0; i < ui32NumSyncInfos; i++)
+                       {
+                               if(ppsSyncInfos[j] == ppsMemInfos[i]->psKernelSyncInfo)
+                               {
+                                       bFound = IMG_TRUE;
+                                       break;
+                               }
+                       }
+
+                       if(!bFound)
+                               ui32Missing++;
+               }
+
+               if(ui32Missing)
+               {
+                       IMG_UINT32 k;
+
+                       ui32NumCompiledSyncInfos = ui32NumSyncInfos + ui32Missing;
+
+                       if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                                 sizeof(PVRSRV_KERNEL_SYNC_INFO *) * ui32NumCompiledSyncInfos,
+                                                 (IMG_VOID **)&ppsCompiledSyncInfos, IMG_NULL,
+                                                 "Compiled syncinfos") != PVRSRV_OK)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Failed to allocate space for meminfo list"));
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+                               for(i = 0; apsFence[i]; i++)
+                                       if(apsFence[i])
+                                               sync_fence_put(apsFence[i]);
+#endif
+                               goto Exit;
+                       }
+
+                       for(i = 0; i < ui32NumSyncInfos; i++)
+                       {
+                               ppsCompiledSyncInfos[i] = ppsSyncInfos[i];
+                       }
+
+                       k = i;
+                       for(i = 0; i < ui32NumSyncInfos; i++)
+                       {
+                               for(j = 0; j < ui32NumSyncInfos; j++)
+                               {
+                                       if(ppsSyncInfos[j] == ppsMemInfos[i]->psKernelSyncInfo)
+                                               break;
+                               }
+
+                               if(j == ui32NumSyncInfos)
+                               {
+                                       /* Insert the unique one */
+                                       PVR_ASSERT(k < ui32NumCompiledSyncInfos);
+                                       ppsCompiledSyncInfos[k] = ppsMemInfos[i]->psKernelSyncInfo;
+                                       k++;
+                               }
+                       }
+               }
+               else
+               {
+                       ppsCompiledSyncInfos = ppsSyncInfos;
+                       ui32NumCompiledSyncInfos = ui32NumSyncInfos;
+               }
        }
 
        /* insert the command (header) */
@@ -1955,7 +2047,18 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE  hDeviceKM,
                                                                        ppsCompiledSyncInfos,
                                                                        sizeof(DISPLAYCLASS_FLIP_COMMAND2),
                                                                        FreePrivateData,
-                                                                       psCallbackData);
+                                                                       psCallbackData,
+                                                                       phFence);
+
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       /* InsertCommand bumped the refcount on the raw sync objects, so we
+        * can put the fences now. Even if the fences are deleted, the syncs
+        * will persist.
+        */
+       for(i = 0; apsFence[i]; i++)
+               if(apsFence[i])
+                       sync_fence_put(apsFence[i]);
+#endif
 
        if (ppsCompiledSyncInfos != ppsSyncInfos)
        {
@@ -2023,6 +2126,11 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE  hDeviceKM,
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Failed to submit command"));
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+               sync_fence_put(psCommand->pvCleanupFence);
+               sync_fence_put(*phFence);
+               *phFence = IMG_NULL;
+#endif
                goto Exit;
        }
 
@@ -2037,34 +2145,60 @@ PVRSRV_ERROR PVRSRVSwapToDCBuffer2KM(IMG_HANDLE hDeviceKM,
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Failed to schedule MISR"));
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+               sync_fence_put(*phFence);
+               *phFence = IMG_NULL;
+#endif
                goto Exit;
        }
 
 #if !defined(SUPPORT_DC_CMDCOMPLETE_WHEN_NO_LONGER_DISPLAYED)
        /* Reallocate the syncinfo list if it was too small */
-       if (psSwapChain->ui32LastNumSyncInfos < ui32NumMemSyncInfos)
+       if (psSwapChain->ui32LastNumSyncInfos < ui32NumSyncInfos)
        {
                if (psSwapChain->ppsLastSyncInfos)
                {
+                       for (i = 0; i < psSwapChain->ui32LastNumSyncInfos; i++)
+                       {
+                               if (psSwapChain->ppsLastSyncInfos[i])
+                               {
+                                       PVRSRVKernelSyncInfoDecRef(psSwapChain->ppsLastSyncInfos[i], IMG_NULL);
+                                       psSwapChain->ppsLastSyncInfos[i] = IMG_NULL;
+                               }
+                       }
                        OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_KERNEL_SYNC_INFO *) * psSwapChain->ui32LastNumSyncInfos,
                                                psSwapChain->ppsLastSyncInfos, IMG_NULL);
                }
 
                if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
-                                         sizeof(PVRSRV_KERNEL_SYNC_INFO *) * ui32NumMemSyncInfos,
+                                         sizeof(PVRSRV_KERNEL_SYNC_INFO *) * ui32NumSyncInfos,
                                          (IMG_VOID **)&psSwapChain->ppsLastSyncInfos, IMG_NULL,
                                          "Last syncinfos") != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"PVRSRVSwapToDCBuffer2KM: Failed to allocate space for meminfo list"));
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+                       sync_fence_put(*phFence);
+                       *phFence = IMG_NULL;
+#endif
                        goto Exit;
                }
        }
 
-       psSwapChain->ui32LastNumSyncInfos = ui32NumMemSyncInfos;
+       for (i = 0; i < psSwapChain->ui32LastNumSyncInfos; i++)
+       {
+               if (psSwapChain->ppsLastSyncInfos[i])
+               {
+                       PVRSRVKernelSyncInfoDecRef(psSwapChain->ppsLastSyncInfos[i], IMG_NULL);
+                       psSwapChain->ppsLastSyncInfos[i] = IMG_NULL;
+               }
+       }
+
+       psSwapChain->ui32LastNumSyncInfos = ui32NumSyncInfos;
 
-       for(i = 0; i < ui32NumMemSyncInfos; i++)
+       for(i = 0; i < ui32NumSyncInfos; i++)
        {
                psSwapChain->ppsLastSyncInfos[i] = ppsSyncInfos[i];
+               PVRSRVKernelSyncInfoIncRef(psSwapChain->ppsLastSyncInfos[i], IMG_NULL);
        }
 #endif /* !defined(SUPPORT_DC_CMDCOMPLETE_WHEN_NO_LONGER_DISPLAYED) */
 
@@ -2116,7 +2250,7 @@ PVRSRV_ERROR PVRSRVSwapToDCSystemKM(IMG_HANDLE    hDeviceKM,
        psSwapChain = psSwapChainRef->psSwapChain;
 
        /*
-               If more then 1 reference to the swapchain exist then
+               If more than 1 reference to the swapchain exists then
                ignore any request to swap to the system buffer
        */
        if (psSwapChain->ui32RefCount > 1)
@@ -2165,6 +2299,7 @@ PVRSRV_ERROR PVRSRVSwapToDCSystemKM(IMG_HANDLE    hDeviceKM,
                                                                        apsSrcSync,
                                                                        sizeof(DISPLAYCLASS_FLIP_COMMAND),
                                                                        IMG_NULL,
+                                                                       IMG_NULL,
                                                                        IMG_NULL);
        if(eError != PVRSRV_OK)
        {
@@ -2392,11 +2527,7 @@ IMG_BOOL PVRGetDisplayClassJTable(PVRSRV_DC_DISP2SRV_KMJTABLE *psJTable)
        psJTable->pfnPVRSRVOEMFunction = &SysOEMFunction;
        psJTable->pfnPVRSRVRegisterCmdProcList = &PVRSRVRegisterCmdProcListKM;
        psJTable->pfnPVRSRVRemoveCmdProcList = &PVRSRVRemoveCmdProcListKM;
-#if defined(SUPPORT_MISR_IN_THREAD)
-        psJTable->pfnPVRSRVCmdComplete = &OSVSyncMISR;
-#else
-        psJTable->pfnPVRSRVCmdComplete = &PVRSRVCommandCompleteKM;
-#endif
+       psJTable->pfnPVRSRVCmdComplete = &PVRSRVCommandCompleteKM;
        psJTable->pfnPVRSRVRegisterSystemISRHandler = &PVRSRVRegisterSystemISRHandler;
        psJTable->pfnPVRSRVRegisterPowerDevice = &PVRSRVRegisterPowerDevice;
 #if defined(SUPPORT_CUSTOM_SWAP_OPERATIONS)
index 519eea2..a6c0b92 100644 (file)
@@ -47,10 +47,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "pdump_km.h"
 #include "pvr_bridge_km.h"
 #include "osfunc.h"
+#include "devicemem.h"
 
 #if defined(SUPPORT_ION)
 #include "ion.h"
 #include "env_perproc.h"
+#include "ion_sync.h"
+
+/* Start size of the g_IonSyncHash hash table */
+#define ION_SYNC_HASH_SIZE 20
+HASH_TABLE *g_psIonSyncHash = IMG_NULL;
 #endif
 
 /* local function prototypes */
@@ -113,11 +119,7 @@ static IMG_UINT32 g_ui32SyncUID = 0;
 ******************************************************************************/
 IMG_EXPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapsKM(IMG_HANDLE hDevCookie,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                       PVRSRV_HEAP_INFO_KM *psHeapInfo)
-#else
                                                                                                        PVRSRV_HEAP_INFO *psHeapInfo)
-#endif
 {
        PVRSRV_DEVICE_NODE *psDeviceNode;
        IMG_UINT32 ui32HeapCount;
@@ -185,11 +187,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDeviceMemContextKM(IMG_HANDLE                                        hDevCook
                                                                                                                 PVRSRV_PER_PROCESS_DATA        *psPerProc,
                                                                                                                 IMG_HANDLE                             *phDevMemContext,
                                                                                                                 IMG_UINT32                             *pui32ClientHeapCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                                PVRSRV_HEAP_INFO_KM            *psHeapInfo,
-#else
                                                                                                                 PVRSRV_HEAP_INFO                       *psHeapInfo,
-#endif
                                                                                                                 IMG_BOOL                                       *pbCreated,
                                                                                                                 IMG_BOOL                                       *pbShared)
 {
@@ -201,7 +199,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDeviceMemContextKM(IMG_HANDLE                                 hDevCook
        IMG_DEV_PHYADDR sPDDevPAddr;
        IMG_UINT32 i;
 
-#if !defined(PVR_SECURE_HANDLES) && !defined (SUPPORT_SID_INTERFACE)
+#if !defined(PVR_SECURE_HANDLES)
        PVR_UNREFERENCED_PARAMETER(pbShared);
 #endif
 
@@ -257,7 +255,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDeviceMemContextKM(IMG_HANDLE                                 hDevCook
                                psHeapInfo[ui32ClientHeapCount].ui32XTileStride = 0;
                                #endif
 
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                                pbShared[ui32ClientHeapCount] = IMG_TRUE;
 #endif
                                ui32ClientHeapCount++;
@@ -291,7 +289,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateDeviceMemContextKM(IMG_HANDLE                                 hDevCook
                                #else
                                psHeapInfo[ui32ClientHeapCount].ui32XTileStride = 0;
                                #endif
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                                pbShared[ui32ClientHeapCount] = IMG_FALSE;
 #endif
 
@@ -342,11 +340,7 @@ IMG_EXPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfoKM(IMG_HANDLE                                      hDevCookie,
                                                                                                                 IMG_HANDLE                             hDevMemContext,
                                                                                                                 IMG_UINT32                             *pui32ClientHeapCount,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                                                                PVRSRV_HEAP_INFO_KM            *psHeapInfo,
-#else
                                                                                                                 PVRSRV_HEAP_INFO                       *psHeapInfo,
-#endif
                                                                                                                 IMG_BOOL                                       *pbShared)
 {
        PVRSRV_DEVICE_NODE *psDeviceNode;
@@ -355,7 +349,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfoKM(IMG_HANDLE                                   hDevCookie
        IMG_HANDLE hDevMemHeap;
        IMG_UINT32 i;
 
-#if !defined(PVR_SECURE_HANDLES) && !defined (SUPPORT_SID_INTERFACE)
+#if !defined(PVR_SECURE_HANDLES)
        PVR_UNREFERENCED_PARAMETER(pbShared);
 #endif
 
@@ -393,7 +387,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfoKM(IMG_HANDLE                                   hDevCookie
                                psHeapInfo[ui32ClientHeapCount].ui32HeapByteSize = psDeviceMemoryHeap[i].ui32HeapSize;
                                psHeapInfo[ui32ClientHeapCount].ui32Attribs = psDeviceMemoryHeap[i].ui32Attribs;
                                psHeapInfo[ui32ClientHeapCount].ui32XTileStride = psDeviceMemoryHeap[i].ui32XTileStride;
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                                pbShared[ui32ClientHeapCount] = IMG_TRUE;
 #endif
                                ui32ClientHeapCount++;
@@ -423,7 +417,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetDeviceMemHeapInfoKM(IMG_HANDLE                                   hDevCookie
                                psHeapInfo[ui32ClientHeapCount].ui32HeapByteSize = psDeviceMemoryHeap[i].ui32HeapSize;
                                psHeapInfo[ui32ClientHeapCount].ui32Attribs = psDeviceMemoryHeap[i].ui32Attribs;
                                psHeapInfo[ui32ClientHeapCount].ui32XTileStride = psDeviceMemoryHeap[i].ui32XTileStride;
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
                                pbShared[ui32ClientHeapCount] = IMG_FALSE;
 #endif
 
@@ -713,13 +707,26 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVAllocSyncInfoKM(IMG_HANDLE                                        hDevCookie,
        psSyncData->ui32LastReadOpDumpVal = 0;
        psSyncData->ui64LastWrite = 0;
 
+       /*
+               Note:
+               PDumping here means that we PDump syncs that we might not
+               need to know about for the multi-process but this
+               unavoidable as there is no point where we can PDump
+               that guarantees it will be initialised before we us it
+               (e.g. kick time is too late as the client might have
+               issued a POL on it before that point)
+       */
 #if defined(PDUMP)
        PDUMPCOMMENT("Allocating kernel sync object");
        PDUMPMEM(psKernelSyncInfo->psSyncDataMemInfoKM->pvLinAddrKM,
                        psKernelSyncInfo->psSyncDataMemInfoKM,
                        0,
                        (IMG_UINT32)psKernelSyncInfo->psSyncDataMemInfoKM->uAllocSize,
+#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
+                       PDUMP_FLAGS_PERSISTENT,
+#else
                        PDUMP_FLAGS_CONTINUOUS,
+#endif
                        MAKEUNIQUETAG(psKernelSyncInfo->psSyncDataMemInfoKM));
 #endif
 
@@ -851,11 +858,7 @@ PVRSRV_ERROR FreeMemCallBackCommon(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
        {
                if((psMemInfo->ui32Flags & PVRSRV_MEM_EXPORTED) != 0)
                {
-#if defined (SUPPORT_SID_INTERFACE)
-                       IMG_SID hMemInfo = 0;
-#else
                        IMG_HANDLE hMemInfo = IMG_NULL;
-#endif
 
                        /* find the handle */
                        eError = PVRSRVFindHandle(KERNEL_HANDLE_BASE,
@@ -887,9 +890,22 @@ PVRSRV_ERROR FreeMemCallBackCommon(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
                                freeExternal(psMemInfo);
                        case PVRSRV_MEMTYPE_DEVICE:
                        case PVRSRV_MEMTYPE_DEVICECLASS:
-                               if (psMemInfo->psKernelSyncInfo)
+#if defined(SUPPORT_ION)
+                               if (psMemInfo->hIonSyncInfo)
                                {
-                                       PVRSRVKernelSyncInfoDecRef(psMemInfo->psKernelSyncInfo, psMemInfo);
+                                       /*
+                                               For syncs attached to Ion imported buffers we handle
+                                               things a little differently
+                                       */
+                                       PVRSRVIonBufferSyncInfoDecRef(psMemInfo->hIonSyncInfo, psMemInfo);
+                               }
+                               else
+#endif
+                               {
+                                       if (psMemInfo->psKernelSyncInfo)
+                                       {
+                                               PVRSRVKernelSyncInfoDecRef(psMemInfo->psKernelSyncInfo, psMemInfo);
+                                       }
                                }
                                break;
                        default:
@@ -1165,6 +1181,90 @@ static PVRSRV_ERROR IonUnmapCallback(IMG_PVOID  pvParam,
        return FreeMemCallBackCommon(psMemInfo, ui32Param, PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR);
 }
 
+PVRSRV_ERROR PVRSRVIonBufferSyncAcquire(IMG_HANDLE hUnique,
+                                                                               IMG_HANDLE hDevCookie,
+                                                                               IMG_HANDLE hDevMemContext,
+                                                                               PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo)
+{
+       PVRSRV_ION_SYNC_INFO *psIonSyncInfo;
+       PVRSRV_ERROR eError;
+       IMG_BOOL bRet;
+
+       /* Check the hash to see if we already have a sync for this buffer */
+       psIonSyncInfo = (PVRSRV_ION_SYNC_INFO *) HASH_Retrieve(g_psIonSyncHash, (IMG_UINTPTR_T) hUnique);
+       if (psIonSyncInfo == 0)
+       {
+               /* This buffer is new to us, create the syncinfo for it */
+               eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT,
+                                                       sizeof(PVRSRV_ION_SYNC_INFO),
+                                                       (IMG_VOID **)&psIonSyncInfo, IMG_NULL,
+                                                       "Ion Synchronization Info");
+               if (eError != PVRSRV_OK)
+               {
+                       return eError;
+               }
+
+               eError = PVRSRVAllocSyncInfoKM(hDevCookie,
+                                                                          hDevMemContext,
+                                                                          &psIonSyncInfo->psSyncInfo);
+               if (eError != PVRSRV_OK)
+               {
+                       OSFreeMem(PVRSRV_PAGEABLE_SELECT,
+                                         sizeof(PVRSRV_ION_SYNC_INFO),
+                                         psIonSyncInfo,
+                                         IMG_NULL);
+
+                       return eError;
+               }
+#if defined(SUPPORT_MEMINFO_IDS)
+               psIonSyncInfo->ui64Stamp = ++g_ui64MemInfoID;
+#else
+               psIonSyncInfo->ui64Stamp = 0;
+#endif
+               bRet = HASH_Insert(g_psIonSyncHash, (IMG_UINTPTR_T) hUnique, (IMG_UINTPTR_T) psIonSyncInfo);
+               if (!bRet)
+               {
+                       eError = PVRSRV_ERROR_OUT_OF_MEMORY;
+
+                       PVRSRVKernelSyncInfoDecRef(psIonSyncInfo->psSyncInfo, IMG_NULL);
+                       OSFreeMem(PVRSRV_PAGEABLE_SELECT,
+                                         sizeof(PVRSRV_ION_SYNC_INFO),
+                                         psIonSyncInfo,
+                                         IMG_NULL);
+
+                       return eError;
+               }
+
+               psIonSyncInfo->ui32RefCount = 0;
+               psIonSyncInfo->hUnique = hUnique;
+       }
+
+       psIonSyncInfo->ui32RefCount++;
+       *ppsIonSyncInfo = psIonSyncInfo;
+       return PVRSRV_OK;
+}
+
+IMG_VOID PVRSRVIonBufferSyncRelease(PVRSRV_ION_SYNC_INFO *psIonSyncInfo)
+{
+       psIonSyncInfo->ui32RefCount--;
+
+       if (psIonSyncInfo->ui32RefCount == 0)
+       {
+               PVRSRV_ION_SYNC_INFO *psLookup;
+               /*
+                       If we're holding the last reference to the syncinfo
+                       then free it
+               */
+               psLookup = (PVRSRV_ION_SYNC_INFO *) HASH_Remove(g_psIonSyncHash, (IMG_UINTPTR_T) psIonSyncInfo->hUnique);
+               PVR_ASSERT(psLookup == psIonSyncInfo);
+               PVRSRVKernelSyncInfoDecRef(psIonSyncInfo->psSyncInfo, IMG_NULL);
+               OSFreeMem(PVRSRV_PAGEABLE_SELECT,
+                                 sizeof(PVRSRV_ION_SYNC_INFO),
+                                 psIonSyncInfo,
+                                 IMG_NULL);
+       }
+}
+
 /*!
 ******************************************************************************
 
@@ -1176,10 +1276,19 @@ static PVRSRV_ERROR IonUnmapCallback(IMG_PVOID  pvParam,
 
  @Input           psPerProc : PerProcess data
  @Input    hDevCookie : Device node cookie
- @Input    hDevMemContext : Device memory context cookie
- @Input    hIon : Handle to ION buffer
+ @Input    hDevMemHeap : Heap ion handles are mapped into
+ @Input    ui32NumBuffers : Number of ion handles to map. (If one handle is being
+                            mapped, this should be 1, not 0.)
+ @Input    phIon : Array of ui32NumBuffers ion handles (fds)
  @Input    ui32Flags : Mapping flags
- @Input    ui32Size : Mapping size
+ @Input    ui32ChunkCount : If ui32NumBuffers is 1, this is the number of
+                            "chunks" specified to be mapped into device-virtual
+                            address space. If ui32NumBuffers > 1, it is ignored.
+ @Input    pauiOffset : Array of offsets in device-virtual address space to map
+                        "chunks" of physical from the ion allocation.
+ @Input    pauiSize : Array of sizes in bytes of device-virtual address space to
+                      map "chunks" of physical from the ion allocation.
+ @Input    puiIonBufferSize : Size in bytes of resulting device-virtual mapping.
  @Output   ppsKernelMemInfo: Output kernel meminfo if successful
 
  @Return   PVRSRV_ERROR  :
@@ -1188,35 +1297,56 @@ static PVRSRV_ERROR IonUnmapCallback(IMG_PVOID  pvParam,
 IMG_EXPORT
 PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
                                                                  IMG_HANDLE hDevCookie,
-                                                                 IMG_HANDLE hDevMemContext,
-                                                                 IMG_HANDLE hIon,
+                                                                 IMG_HANDLE hDevMemHeap,
+                                                                 IMG_UINT32 ui32NumFDs,
+                                                                 IMG_INT32  *pi32BufferFDs,
                                                                  IMG_UINT32 ui32Flags,
-                                                                 IMG_UINT32 ui32Size,
-                                                                 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo)
+                                                                 IMG_UINT32 ui32ChunkCount,
+                                                                 IMG_SIZE_T *pauiOffset,
+                                                                 IMG_SIZE_T *pauiSize,
+                                                                 IMG_SIZE_T *puiIonBufferSize,
+                                                                 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo,
+                                                                 IMG_UINT64 *pui64Stamp)
 {
        PVRSRV_ENV_PER_PROCESS_DATA *psPerProcEnv = PVRSRVProcessPrivateData(psPerProc);
        PVRSRV_DEVICE_NODE *psDeviceNode; 
        PVRSRV_KERNEL_MEM_INFO *psNewKernelMemInfo;
-       DEVICE_MEMORY_INFO *psDevMemoryInfo;
-       DEVICE_MEMORY_HEAP_INFO *psDeviceMemoryHeap;
        IMG_SYS_PHYADDR *pasSysPhysAddr;
+       IMG_SYS_PHYADDR *pasAdjustedSysPhysAddr;
        PVRSRV_MEMBLK *psMemBlock;
        PVRSRV_ERROR eError;
-       IMG_HANDLE hDevMemHeap = IMG_NULL;
        IMG_HANDLE hPriv;
+       IMG_HANDLE hUnique;
        BM_HANDLE hBuffer;
-       IMG_UINT32 ui32HeapCount;
+       IMG_SIZE_T uiMapSize = 0;
+       IMG_SIZE_T uiAdjustOffset = 0;
        IMG_UINT32 ui32PageCount;
        IMG_UINT32 i;
        IMG_BOOL bAllocSync = (ui32Flags & PVRSRV_MEM_NO_SYNCOBJ)?IMG_FALSE:IMG_TRUE;
 
-       if ((hDevCookie == IMG_NULL) || (ui32Size == 0)
-                || (hDevMemContext == IMG_NULL) || (ppsKernelMemInfo == IMG_NULL))
+       if ((hDevCookie == IMG_NULL) || (ui32ChunkCount == 0)
+                || (hDevMemHeap == IMG_NULL) || (ppsKernelMemInfo == IMG_NULL))
        {
                PVR_DPF((PVR_DBG_ERROR, "%s: Invalid params", __FUNCTION__));
                return PVRSRV_ERROR_INVALID_PARAMS;
        }
 
+       for (i=0;i<ui32ChunkCount;i++)
+       {
+               if ((pauiOffset[i] & HOST_PAGEMASK) != 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"%s: Chunk offset is not page aligned", __FUNCTION__));
+                       return PVRSRV_ERROR_INVALID_PARAMS;
+               }
+
+               if ((pauiSize[i] & HOST_PAGEMASK) != 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"%s: Chunk size is not page aligned", __FUNCTION__));
+                       return PVRSRV_ERROR_INVALID_PARAMS;
+               }
+               uiMapSize += pauiSize[i];
+       }
+
        psDeviceNode = (PVRSRV_DEVICE_NODE *)hDevCookie;
 
        if(OSAllocMem(PVRSRV_PAGEABLE_SELECT,
@@ -1229,59 +1359,63 @@ PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
        }
        OSMemSet(psNewKernelMemInfo, 0, sizeof(PVRSRV_KERNEL_MEM_INFO));
 
-       /* Choose the heap to map to */
-       ui32HeapCount = psDeviceNode->sDevMemoryInfo.ui32HeapCount;
-       psDevMemoryInfo = &psDeviceNode->sDevMemoryInfo;
-       psDeviceMemoryHeap = psDeviceNode->sDevMemoryInfo.psDeviceMemoryHeap;   
-       for(i=0; i<PVRSRV_MAX_CLIENT_HEAPS; i++)
+       /* Import the ION buffer into our ion_client and DMA map it */
+       eError = IonImportBufferAndAcquirePhysAddr(psPerProcEnv->psIONClient,
+                                                                                          ui32NumFDs,
+                                                                                          pi32BufferFDs,
+                                                                                          &ui32PageCount,
+                                                                                          &pasSysPhysAddr,
+                                                                                          &psNewKernelMemInfo->pvLinAddrKM,
+                                                                                          &hPriv,
+                                                                                          &hUnique);
+       if (eError != PVRSRV_OK)
        {
-               if(HEAP_IDX(psDeviceMemoryHeap[i].ui32HeapID) == psDevMemoryInfo->ui32IonHeapID)
-               {
-                       if(psDeviceMemoryHeap[i].DevMemHeapType == DEVICE_MEMORY_HEAP_PERCONTEXT)
-                       {
-                               if (psDeviceMemoryHeap[i].ui32HeapSize > 0)
-                               {
-                                       hDevMemHeap = BM_CreateHeap(hDevMemContext, &psDeviceMemoryHeap[i]);
-                               }
-                               else
-                               {
-                                       hDevMemHeap = IMG_NULL;
-                               }
-                       }
-                       else
-                       {
-                               hDevMemHeap = psDevMemoryInfo->psDeviceMemoryHeap[i].hDevMemHeap;
-                       }
-                       break;
-               }
+               PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get ion buffer/buffer phys addr", __FUNCTION__));
+               goto exitFailedImport;
        }
-       
-       if (hDevMemHeap == IMG_NULL)
+
+       /*
+               Make sure the number of pages detected by the ion import are at least
+               the size of the total chunked region
+       */
+       if(ui32PageCount * PAGE_SIZE < uiMapSize)
        {
-               PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get ION heap", __FUNCTION__));
-               eError = PVRSRV_ERROR_FAILED_TO_RETRIEVE_HEAPINFO;
-               goto exitFailedHeap;
+               PVR_DPF((PVR_DBG_ERROR, "%s: ion allocator returned fewer page addresses "
+                                                               "than specified chunk size(s)", __FUNCTION__));
+               eError = PVRSRV_ERROR_INVALID_PARAMS;
+               goto exitFailedAdjustedAlloc; 
        }
 
-       /* Import the ION buffer into our ion_client and DMA map it */
-       eError = IonImportBufferAndAquirePhysAddr(psPerProcEnv->psIONClient,
-                                                                                         hIon,
-                                                                                         &ui32PageCount,
-                                                                                         &pasSysPhysAddr,
-                                                                                         &psNewKernelMemInfo->pvLinAddrKM,
-                                                                                         &hPriv);
-       if (eError != PVRSRV_OK)
+       /*
+               An Ion buffer might have a number of "chunks" in it which need to be
+               mapped virtually continuous so we need to create a new array of
+               addresses based on this chunk data for the actual wrap
+       */
+       if(OSAllocMem(PVRSRV_PAGEABLE_SELECT,
+                                       sizeof(IMG_SYS_PHYADDR) * (uiMapSize/HOST_PAGESIZE()),
+                                       (IMG_VOID **)&pasAdjustedSysPhysAddr, IMG_NULL,
+                                       "Ion adjusted system address array") != PVRSRV_OK)
        {
-               PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get ion buffer/buffer phys addr", __FUNCTION__));
-               goto exitFailedHeap;
+               PVR_DPF((PVR_DBG_ERROR,"%s: Failed to alloc memory for adjusted array", __FUNCTION__));
+               goto exitFailedAdjustedAlloc;
+       }
+       OSMemSet(pasAdjustedSysPhysAddr, 0, sizeof(IMG_SYS_PHYADDR) * (uiMapSize/HOST_PAGESIZE()));
+
+       for (i=0;i<ui32ChunkCount;i++)
+       {
+               OSMemCopy(&pasAdjustedSysPhysAddr[uiAdjustOffset],
+                                 &pasSysPhysAddr[pauiOffset[i]/HOST_PAGESIZE()],
+                                 (pauiSize[i]/HOST_PAGESIZE()) * sizeof(IMG_SYS_PHYADDR));
+
+               uiAdjustOffset += pauiSize[i]/HOST_PAGESIZE();
        }
 
        /* Wrap the returned addresses into our memory context */
        if (!BM_Wrap(hDevMemHeap,
-                                ui32Size,
+                                uiMapSize,
                                 0,
                                 IMG_FALSE,
-                                pasSysPhysAddr,
+                                pasAdjustedSysPhysAddr,
                                 IMG_NULL,
                                 &ui32Flags,    /* This function clobbers our bits in ui32Flags */
                                 &hBuffer))
@@ -1297,11 +1431,11 @@ PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
        psMemBlock->hOSMemHandle = BM_HandleToOSMemHandle(hBuffer);
        psMemBlock->hBuffer = (IMG_HANDLE) hBuffer;
        psMemBlock->hOSWrapMem = hPriv;                 /* Saves creating a new element as we know hOSWrapMem will not be used */
-       psMemBlock->psIntSysPAddr = pasSysPhysAddr;
+       psMemBlock->psIntSysPAddr = pasAdjustedSysPhysAddr;
 
        psNewKernelMemInfo->ui32Flags = ui32Flags;
        psNewKernelMemInfo->sDevVAddr = psMemBlock->sDevVirtAddr;
-       psNewKernelMemInfo->uAllocSize = ui32Size;
+       psNewKernelMemInfo->uAllocSize = uiMapSize;
        psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_ION;
        PVRSRVKernelMemInfoIncRef(psNewKernelMemInfo);
 
@@ -1314,13 +1448,25 @@ PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
        }
        else
        {
-               eError = PVRSRVAllocSyncInfoKM(hDevCookie,
-                                                                          hDevMemContext,
-                                                                          &psNewKernelMemInfo->psKernelSyncInfo);
+               PVRSRV_ION_SYNC_INFO *psIonSyncInfo;
+               BM_HEAP *psBMHeap;
+               IMG_HANDLE hDevMemContext;
+
+               psBMHeap = (BM_HEAP*)hDevMemHeap;
+               hDevMemContext = (IMG_HANDLE)psBMHeap->pBMContext;
+
+               eError = PVRSRVIonBufferSyncInfoIncRef(hUnique,
+                                                                                          hDevCookie,
+                                                                                          hDevMemContext,
+                                                                                          &psIonSyncInfo,
+                                                                                          psNewKernelMemInfo);
                if(eError != PVRSRV_OK)
                {
                        goto exitFailedSync;
                }
+               psNewKernelMemInfo->hIonSyncInfo = psIonSyncInfo;
+               psNewKernelMemInfo->psKernelSyncInfo = IonBufferSyncGetKernelSyncInfo(psIonSyncInfo);
+               *pui64Stamp = IonBufferSyncGetStamp(psIonSyncInfo);
        }
 
        /* register with the resman */
@@ -1337,23 +1483,29 @@ PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
 
        psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_ION;
 
+       /*
+               As the user doesn't tell us the size, just the "chunk" information
+               return actual size of the Ion buffer so we can mmap it.
+       */
+       *puiIonBufferSize = ui32PageCount * HOST_PAGESIZE();
        *ppsKernelMemInfo = psNewKernelMemInfo;
        return PVRSRV_OK;
 
 exitFailedResman:
        if (psNewKernelMemInfo->psKernelSyncInfo)
        {
-               PVRSRVKernelSyncInfoDecRef(psNewKernelMemInfo->psKernelSyncInfo, psNewKernelMemInfo);
+               PVRSRVIonBufferSyncInfoDecRef(psNewKernelMemInfo->hIonSyncInfo, psNewKernelMemInfo);
        }
 exitFailedSync:
        BM_Free(hBuffer, ui32Flags);
 exitFailedWrap:
-       IonUnimportBufferAndReleasePhysAddr(hPriv);
        OSFreeMem(PVRSRV_PAGEABLE_SELECT,
-                         sizeof(IMG_SYS_PHYADDR) * ui32PageCount,
-                         pasSysPhysAddr,
+                         sizeof(IMG_SYS_PHYADDR) * uiAdjustOffset,
+                         pasAdjustedSysPhysAddr,
                          IMG_NULL);
-exitFailedHeap:
+exitFailedAdjustedAlloc:
+       IonUnimportBufferAndReleasePhysAddr(hPriv);
+exitFailedImport:
        OSFreeMem(PVRSRV_PAGEABLE_SELECT,
                          sizeof(PVRSRV_KERNEL_MEM_INFO),
                          psNewKernelMemInfo,
@@ -1561,6 +1713,16 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemoryKM(IMG_HANDLE                               hDevCookie,
        IMG_UINT32              i;
        IMG_SIZE_T          uPageCount = 0;
 
+       PVR_DPF ((PVR_DBG_MESSAGE,
+                       "PVRSRVWrapExtMemoryKM (uSize=0x%" SIZE_T_FMT_LEN "x, uPageOffset=0x%"
+                       SIZE_T_FMT_LEN "x, bPhysContig=%d, extSysPAddr=" SYSPADDR_FMT
+                       ", pvLinAddr=%p, ui32Flags=%u)",
+                       uByteSize,
+                       uPageOffset,
+                       bPhysContig,
+                       psExtSysPAddr?psExtSysPAddr->uiAddr:0x0,
+                       pvLinAddr,
+                       ui32Flags));
 
        psDeviceNode = (PVRSRV_DEVICE_NODE*)hDevCookie;
        PVR_ASSERT(psDeviceNode != IMG_NULL);
@@ -1609,6 +1771,18 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemoryKM(IMG_HANDLE                               hDevCookie,
                */
                bPhysContig = IMG_FALSE;
        }
+       else
+       {
+               if (psExtSysPAddr)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVWrapExtMemoryKM: invalid parameter, physical address passing is not supported"));
+               }
+               else
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVWrapExtMemoryKM: invalid parameter, no address specificed"));
+               }
+               return PVRSRV_ERROR_INVALID_PARAMS;
+       }
 
        /* Choose the heap to map to */
        psDevMemoryInfo = &((BM_CONTEXT*)hDevMemContext)->psDeviceNode->sDevMemoryInfo;
@@ -1654,7 +1828,11 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemoryKM(IMG_HANDLE                               hDevCookie,
        }
 
        OSMemSet(psMemInfo, 0, sizeof(*psMemInfo));
-       psMemInfo->ui32Flags = ui32Flags;
+       /*
+               Force the memory to be read/write. This used to be done in the BM, but
+               ion imports don't want this behaviour
+       */
+       psMemInfo->ui32Flags = ui32Flags | PVRSRV_MEM_READ | PVRSRV_MEM_WRITE;
 
        psMemBlock = &(psMemInfo->sMemBlk);
 
@@ -1940,7 +2118,12 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceMemoryKM(PVRSRV_PER_PROCESS_DATA        *psPer
        }
 
        OSMemSet(psMemInfo, 0, sizeof(*psMemInfo));
-       psMemInfo->ui32Flags = psSrcMemInfo->ui32Flags;
+
+       /*
+               Force the memory to be read/write. This used to be done in the BM, but
+               ion imports don't want this behaviour
+       */
+       psMemInfo->ui32Flags = psSrcMemInfo->ui32Flags | PVRSRV_MEM_READ | PVRSRV_MEM_WRITE;
 
        psMemBlock = &(psMemInfo->sMemBlk);
 
@@ -2148,9 +2331,9 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA    *
        DEVICE_MEMORY_INFO *psDevMemoryInfo;
        DEVICE_MEMORY_HEAP_INFO *psDeviceMemoryHeap;
        IMG_HANDLE hDevMemHeap = IMG_NULL;
-       IMG_SIZE_T uByteSize;
-       IMG_SIZE_T ui32Offset;
-       IMG_SIZE_T ui32PageSize = HOST_PAGESIZE();
+       IMG_UINT32 ui32ByteSize;
+       IMG_SIZE_T uOffset;
+       IMG_SIZE_T uPageSize = HOST_PAGESIZE();
        BM_HANDLE               hBuffer;
        PVRSRV_MEMBLK   *psMemBlock;
        IMG_BOOL                bBMError;
@@ -2199,7 +2382,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA    *
        eError = psDeviceClassBuffer->pfnGetBufferAddr(psDeviceClassBuffer->hExtDevice,
                                                                                                   psDeviceClassBuffer->hExtBuffer,
                                                                                                   &psSysPAddr,
-                                                                                                  &uByteSize,
+                                                                                                  &ui32ByteSize,
                                                                                                   &pvCPUVAddr,
                                                                                                   phOSMapInfo,
                                                                                                   &bPhysContig,
@@ -2246,8 +2429,8 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA    *
        }
 
        /* Only need lower 12 bits of the cpu addr - don't care what size a void* is */
-       ui32Offset = ((IMG_UINTPTR_T)pvCPUVAddr) & (ui32PageSize - 1);
-       pvPageAlignedCPUVAddr = (IMG_VOID *)((IMG_UINTPTR_T)pvCPUVAddr - ui32Offset);
+       uOffset = ((IMG_UINTPTR_T)pvCPUVAddr) & (uPageSize - 1);
+       pvPageAlignedCPUVAddr = (IMG_VOID *)((IMG_UINTPTR_T)pvCPUVAddr - uOffset);
 
        eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT,
                                        sizeof(PVRSRV_KERNEL_MEM_INFO),
@@ -2261,11 +2444,17 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA  *
 
        OSMemSet(psMemInfo, 0, sizeof(*psMemInfo));
 
+       /*
+               Force the memory to be read/write. This used to be done in the BM, but
+               ion imports don't want this behaviour
+       */
+       psMemInfo->ui32Flags |= PVRSRV_MEM_READ | PVRSRV_MEM_WRITE;
+
        psMemBlock = &(psMemInfo->sMemBlk);
 
        bBMError = BM_Wrap(hDevMemHeap,
-                                          uByteSize,
-                                          ui32Offset,
+                                          ui32ByteSize,
+                                          uOffset,
                                           bPhysContig,
                                           psSysPAddr,
                                           pvPageAlignedCPUVAddr,
@@ -2294,7 +2483,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA    *
 
        /* Fill in the public fields of the MEM_INFO structure */
        psMemInfo->sDevVAddr = psMemBlock->sDevVirtAddr;
-       psMemInfo->uAllocSize = uByteSize;
+       psMemInfo->uAllocSize = ui32ByteSize;
        psMemInfo->psKernelSyncInfo = psDeviceClassBuffer->psKernelSyncInfo;
 
        PVR_ASSERT(psMemInfo->psKernelSyncInfo != IMG_NULL);
@@ -2360,7 +2549,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA    *
                 *      behaviour.      
                 */
                PDUMPCOMMENT("Dump display surface");
-               PDUMPMEM(IMG_NULL, psMemInfo, ui32Offset, psMemInfo->uAllocSize, PDUMP_FLAGS_CONTINUOUS, ((BM_BUF*)psMemInfo->sMemBlk.hBuffer)->pMapping);
+               PDUMPMEM(IMG_NULL, psMemInfo, uOffset, psMemInfo->uAllocSize, PDUMP_FLAGS_CONTINUOUS, ((BM_BUF*)psMemInfo->sMemBlk.hBuffer)->pMapping);
        }
 #endif
        return PVRSRV_OK;
@@ -2423,6 +2612,33 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVChangeDeviceMemoryAttributesKM(IMG_HANDLE hKerne
        return PVRSRV_OK;
 }
 
+PVRSRV_ERROR IMG_CALLCONV PVRSRVInitDeviceMem(IMG_VOID)
+{
+       PVRSRV_ERROR eError = PVRSRV_OK;
+
+#if defined(SUPPORT_ION)
+       /*
+               For Ion buffers we need to store which ones we know about so
+               we don't give the same buffer a different sync
+       */
+       g_psIonSyncHash = HASH_Create(ION_SYNC_HASH_SIZE);
+       if (g_psIonSyncHash == IMG_NULL)
+       {
+               eError = PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+#endif
+
+       return eError;
+}
+
+IMG_VOID IMG_CALLCONV PVRSRVDeInitDeviceMem(IMG_VOID)
+{
+#if defined(SUPPORT_ION)
+       HASH_Delete(g_psIonSyncHash);
+#endif
+}
+
+
 
 /******************************************************************************
  End of file (devicemem.c)
index 1e26047..b9facfd 100644 (file)
@@ -40,7 +40,7 @@ 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.
 */ /**************************************************************************/
 
-#if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
 /* See handle.h for a description of the handle API. */
 
 /*
@@ -78,14 +78,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define        INDEX_IS_VALID(psBase, i) ((i) < (psBase)->ui32TotalHandCount)
 
 /* Valid handles are never NULL, but handle array indices are based from 0 */
-#if defined (SUPPORT_SID_INTERFACE)
-#define        INDEX_TO_HANDLE(i) ((IMG_SID)((i) + 1))
-#define        HANDLE_TO_INDEX(h) ((IMG_UINT32)(h) - 1)
-#else
 #define        INDEX_TO_HANDLE(i) ((IMG_HANDLE)((IMG_UINTPTR_T)(i) + 1))
 #define        HANDLE_TO_INDEX(h) ((IMG_UINT32)(IMG_UINTPTR_T)(h) - 1)
 
-#endif
 
 #define        INDEX_TO_BLOCK_INDEX(i)         DIVIDE_BY_BLOCK_SIZE(i)
 #define BLOCK_INDEX_TO_INDEX(i)                MULTIPLY_BY_BLOCK_SIZE(i)
@@ -150,11 +145,7 @@ struct sHandleList
 {
        IMG_UINT32 ui32Prev;
        IMG_UINT32 ui32Next;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hParent;
-#else
        IMG_HANDLE hParent;
-#endif
 };
 
 enum ePVRSRVInternalHandleFlag
@@ -324,11 +315,7 @@ typedef IMG_UINTPTR_T HAND_KEY[HAND_KEY_LEN];
 #pragma inline(HandleListInit)
 #endif
 static INLINE
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_VOID HandleListInit(IMG_UINT32 ui32Index, struct sHandleList *psList, IMG_SID hParent)
-#else
 IMG_VOID HandleListInit(IMG_UINT32 ui32Index, struct sHandleList *psList, IMG_HANDLE hParent)
-#endif
 {
        psList->ui32Next = ui32Index;
        psList->ui32Prev = ui32Index;
@@ -484,11 +471,7 @@ IMG_BOOL NoParent(struct sHandle *psHandle)
 #pragma inline(ParentHandle)
 #endif
 static INLINE
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_SID ParentHandle(struct sHandle *psHandle)
-#else
 IMG_HANDLE ParentHandle(struct sHandle *psHandle)
-#endif
 {
        return psHandle->sSiblings.hParent;
 }
@@ -721,11 +704,7 @@ PVRSRV_ERROR IterateOverChildren(PVRSRV_HANDLE_BASE *psBase, struct sHandle *psP
 #pragma inline(GetHandleStructure)
 #endif
 static INLINE
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR GetHandleStructure(PVRSRV_HANDLE_BASE *psBase, struct sHandle **ppsHandle, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType)
-#else
 PVRSRV_ERROR GetHandleStructure(PVRSRV_HANDLE_BASE *psBase, struct sHandle **ppsHandle, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType)
-#endif
 {
        IMG_UINT32 ui32Index = HANDLE_TO_INDEX(hHandle);
        struct sHandle *psHandle;
@@ -734,9 +713,6 @@ PVRSRV_ERROR GetHandleStructure(PVRSRV_HANDLE_BASE *psBase, struct sHandle **pps
        if (!INDEX_IS_VALID(psBase, ui32Index))
        {
                PVR_DPF((PVR_DBG_ERROR, "GetHandleStructure: Handle index out of range (%u >= %u)", ui32Index, psBase->ui32TotalHandCount));
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#endif
                return PVRSRV_ERROR_HANDLE_INDEX_OUT_OF_RANGE;
        }
 
@@ -744,9 +720,6 @@ PVRSRV_ERROR GetHandleStructure(PVRSRV_HANDLE_BASE *psBase, struct sHandle **pps
        if (psHandle->eType == PVRSRV_HANDLE_TYPE_NONE)
        {
                PVR_DPF((PVR_DBG_ERROR, "GetHandleStructure: Handle not allocated (index: %u)", ui32Index));
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#endif
                return PVRSRV_ERROR_HANDLE_NOT_ALLOCATED;
        }
 
@@ -757,9 +730,6 @@ PVRSRV_ERROR GetHandleStructure(PVRSRV_HANDLE_BASE *psBase, struct sHandle **pps
        if (eType != PVRSRV_HANDLE_TYPE_NONE && eType != psHandle->eType)
        {
                PVR_DPF((PVR_DBG_ERROR, "GetHandleStructure: Handle type mismatch (%d != %d)", eType, psHandle->eType));
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#endif
                return PVRSRV_ERROR_HANDLE_TYPE_MISMATCH;
        }
 
@@ -787,11 +757,7 @@ PVRSRV_ERROR GetHandleStructure(PVRSRV_HANDLE_BASE *psBase, struct sHandle **pps
 #pragma inline(ParentIfPrivate)
 #endif
 static INLINE
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_SID ParentIfPrivate(struct sHandle *psHandle)
-#else
 IMG_HANDLE ParentIfPrivate(struct sHandle *psHandle)
-#endif
 {
        return TEST_ALLOC_FLAG(psHandle, PVRSRV_HANDLE_ALLOC_FLAG_PRIVATE) ?
                        ParentHandle(psHandle) : IMG_NULL;
@@ -814,11 +780,7 @@ IMG_HANDLE ParentIfPrivate(struct sHandle *psHandle)
 #pragma inline(InitKey)
 #endif
 static INLINE
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_VOID InitKey(HAND_KEY aKey, PVRSRV_HANDLE_BASE *psBase, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, IMG_SID hParent)
-#else
 IMG_VOID InitKey(HAND_KEY aKey, PVRSRV_HANDLE_BASE *psBase, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, IMG_HANDLE hParent)
-#endif
 {
        PVR_UNREFERENCED_PARAMETER(psBase);
 
@@ -1125,14 +1087,9 @@ static PVRSRV_ERROR FreeHandle(PVRSRV_HANDLE_BASE *psBase, struct sHandle *psHan
 
        if (!TEST_ALLOC_FLAG(psHandle, PVRSRV_HANDLE_ALLOC_FLAG_MULTI) && !BATCHED_HANDLE_PARTIALLY_FREE(psHandle))
        {
-#if defined (SUPPORT_SID_INTERFACE)
-               IMG_SID hHandle;
-               hHandle = (IMG_SID) HASH_Remove_Extended(psBase->psHashTab, aKey);
-#else
                IMG_HANDLE hHandle;
                hHandle = (IMG_HANDLE) HASH_Remove_Extended(psBase->psHashTab, aKey);
 
-#endif
 
                PVR_ASSERT(hHandle != IMG_NULL);
                PVR_ASSERT(hHandle == INDEX_TO_HANDLE(ui32Index));
@@ -1339,11 +1296,7 @@ static PVRSRV_ERROR FreeHandleBase(PVRSRV_HANDLE_BASE *psBase)
 #pragma inline(FindHandle)
 #endif
 static INLINE
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_SID FindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, IMG_SID hParent)
-#else
 IMG_HANDLE FindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, IMG_HANDLE hParent)
-#endif
 {
        HAND_KEY aKey;
 
@@ -1351,11 +1304,7 @@ IMG_HANDLE FindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_VOID *pvData, PVRSRV_HANDL
 
        InitKey(aKey, psBase, pvData, eType, hParent);
 
-#if defined (SUPPORT_SID_INTERFACE)
-       return (IMG_SID) HASH_Retrieve_Extended(psBase->psHashTab, aKey);
-#else
        return (IMG_HANDLE) HASH_Retrieve_Extended(psBase->psHashTab, aKey);
-#endif
 }
 
 /*!
@@ -1457,19 +1406,11 @@ static PVRSRV_ERROR EnsureFreeHandles(PVRSRV_HANDLE_BASE *psBase, IMG_UINT32 ui3
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-static PVRSRV_ERROR AllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_SID hParent)
-#else
 static PVRSRV_ERROR AllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_HANDLE hParent)
-#endif
 {
        IMG_UINT32 ui32NewIndex = DEFAULT_MAX_INDEX_PLUS_ONE;
        struct sHandle *psNewHandle = IMG_NULL;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hHandle;
-#else
        IMG_HANDLE hHandle;
-#endif
        HAND_KEY aKey;
        PVRSRV_ERROR eError;
 
@@ -1662,24 +1603,12 @@ static PVRSRV_ERROR AllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVAllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag)
-#else
 PVRSRV_ERROR PVRSRVAllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag)
-#endif
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hHandle;
-#else
        IMG_HANDLE hHandle;
-#endif
        PVRSRV_ERROR eError;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       *phHandle = 0;
-#else
        *phHandle = IMG_NULL;
-#endif
 
        if (HANDLES_BATCHED(psBase))
        {
@@ -1697,11 +1626,7 @@ PVRSRV_ERROR PVRSRVAllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle,
        {
                /* See if there is already a handle for this data pointer */
                hHandle = FindHandle(psBase, pvData, eType, IMG_NULL);
-#if defined (SUPPORT_SID_INTERFACE)
-               if (hHandle != 0)
-#else
                if (hHandle != IMG_NULL)
-#endif
                {
                        struct sHandle *psHandle;
 
@@ -1724,9 +1649,6 @@ PVRSRV_ERROR PVRSRVAllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle,
                                goto exit_ok;
                        }
                        
-#if defined (SUPPORT_SID_INTERFACE)
-                       PVR_DBG_BREAK
-#endif
                        return PVRSRV_ERROR_HANDLE_NOT_SHAREABLE;
                }
        }
@@ -1759,26 +1681,15 @@ exit_ok:
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_SID hParent)
-#else
 PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_HANDLE hParent)
-#endif
 {
        struct sHandle *psPHand;
        struct sHandle *psCHand;
        PVRSRV_ERROR eError;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hParentKey;
-       IMG_SID hHandle;
-
-       *phHandle = 0;
-#else
        IMG_HANDLE hParentKey;
        IMG_HANDLE hHandle;
 
        *phHandle = IMG_NULL;
-#endif
 
        if (HANDLES_BATCHED(psBase))
        {
@@ -1806,11 +1717,7 @@ PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHand
        {
                /* See if there is already a handle for this data pointer */
                hHandle = FindHandle(psBase, pvData, eType, hParentKey);
-#if defined (SUPPORT_SID_INTERFACE)
-               if (hHandle != 0)
-#else
                if (hHandle != IMG_NULL)
-#endif
                {
                        struct sHandle *psCHandle;
                        PVRSRV_ERROR eErr;
@@ -1835,9 +1742,6 @@ PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHand
                                *phHandle = hHandle;
                                goto exit_ok;
                        }
-#if defined (SUPPORT_SID_INTERFACE)
-                       PVR_DBG_BREAK
-#endif
                        return PVRSRV_ERROR_HANDLE_NOT_SHAREABLE;
                }
        }
@@ -1886,26 +1790,14 @@ exit_ok:
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVFindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType)
-#else
 PVRSRV_ERROR PVRSRVFindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType)
-#endif
 {
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hHandle;
-#else
        IMG_HANDLE hHandle;
-#endif
 
        PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);
 
        /* See if there is a handle for this data pointer */
-#if defined (SUPPORT_SID_INTERFACE)
-       hHandle = (IMG_SID) FindHandle(psBase, pvData, eType, IMG_NULL);
-#else
        hHandle = (IMG_HANDLE) FindHandle(psBase, pvData, eType, IMG_NULL);
-#endif
        if (hHandle == IMG_NULL)
        {
                return PVRSRV_ERROR_HANDLE_NOT_FOUND;
@@ -1933,11 +1825,7 @@ PVRSRV_ERROR PVRSRVFindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle,
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVLookupHandleAnyType(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, PVRSRV_HANDLE_TYPE *peType, IMG_SID hHandle)
-#else
 PVRSRV_ERROR PVRSRVLookupHandleAnyType(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, PVRSRV_HANDLE_TYPE *peType, IMG_HANDLE hHandle)
-#endif
 {
        struct sHandle *psHandle;
        PVRSRV_ERROR eError;
@@ -1946,9 +1834,7 @@ PVRSRV_ERROR PVRSRVLookupHandleAnyType(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *pp
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVLookupHandleAnyType: Error looking up handle (%d)", eError));
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#endif
+               OSDumpStack();
                return eError;
        }
 
@@ -1974,27 +1860,18 @@ PVRSRV_ERROR PVRSRVLookupHandleAnyType(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *pp
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVLookupHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType)
-#else
 PVRSRV_ERROR PVRSRVLookupHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType)
-#endif
 {
        struct sHandle *psHandle;
        PVRSRV_ERROR eError;
 
        PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);
-#if defined (SUPPORT_SID_INTERFACE)
-       PVR_ASSERT(hHandle != 0);
-#endif
 
        eError = GetHandleStructure(psBase, &psHandle, hHandle, eType);
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVLookupHandle: Error looking up handle (%d)", eError));
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#endif
+               OSDumpStack();
                return eError;
        }
 
@@ -2020,25 +1897,19 @@ PVRSRV_ERROR PVRSRVLookupHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData,
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVLookupSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType, IMG_SID hAncestor)
-#else
 PVRSRV_ERROR PVRSRVLookupSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType, IMG_HANDLE hAncestor)
-#endif
 {
        struct sHandle *psPHand;
        struct sHandle *psCHand;
        PVRSRV_ERROR eError;
 
        PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);
-#if defined (SUPPORT_SID_INTERFACE)
-       PVR_ASSERT(hHandle != 0);
-#endif
 
        eError = GetHandleStructure(psBase, &psCHand, hHandle, eType);
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVLookupSubHandle: Error looking up subhandle (%d)", eError));
+               OSDumpStack();
                return eError;
        }
 
@@ -2076,11 +1947,7 @@ PVRSRV_ERROR PVRSRVLookupSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvDat
                not regarded as an error.
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVGetParentHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phParent, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType)
-#else
 PVRSRV_ERROR PVRSRVGetParentHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *phParent, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType)
-#endif
 {
        struct sHandle *psHandle;
        PVRSRV_ERROR eError;
@@ -2091,6 +1958,7 @@ PVRSRV_ERROR PVRSRVGetParentHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *phPare
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVGetParentHandle: Error looking up subhandle (%d)", eError));
+               OSDumpStack();
                return eError;
        }
 
@@ -2116,11 +1984,7 @@ PVRSRV_ERROR PVRSRVGetParentHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *phPare
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVLookupAndReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType)
-#else
 PVRSRV_ERROR PVRSRVLookupAndReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType)
-#endif
 {
        struct sHandle *psHandle;
        PVRSRV_ERROR eError;
@@ -2131,9 +1995,7 @@ PVRSRV_ERROR PVRSRVLookupAndReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVLookupAndReleaseHandle: Error looking up handle (%d)", eError));
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#endif
+               OSDumpStack();
                return eError;
        }
 
@@ -2157,11 +2019,7 @@ PVRSRV_ERROR PVRSRVLookupAndReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID
  @Return       Error code or PVRSRV_OK
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType)
-#else
 PVRSRV_ERROR PVRSRVReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType)
-#endif
 {
        struct sHandle *psHandle;
        PVRSRV_ERROR eError;
@@ -2172,6 +2030,7 @@ PVRSRV_ERROR PVRSRVReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE hHandle,
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PVRSRVReleaseHandle: Error looking up handle (%d)", eError));
+               OSDumpStack();
                return eError;
        }
 
@@ -2683,7 +2542,7 @@ PVRSRV_ERROR PVRSRVHandleDeInit(IMG_VOID)
 }
 #else
 /* disable warning about empty module */
-#endif /* #if defined(PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE) */
+#endif /* #if defined(PVR_SECURE_HANDLES) */
 /******************************************************************************
  End of file (handle.c)
 ******************************************************************************/
index 1569425..72432fd 100644 (file)
@@ -425,8 +425,8 @@ HASH_Insert_Extended (HASH_TABLE *pHash, IMG_VOID *pKey, IMG_UINTPTR_T v)
        BUCKET *pBucket;
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-              "HASH_Insert_Extended: Hash=0x%08x, pKey=0x%08x, v=0x%x",
-              (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey, v));
+              "HASH_Insert_Extended: Hash=0x%p, pKey=0x%p, v=0x" UINTPTR_FMT,
+              pHash, pKey, v));
 
        PVR_ASSERT (pHash != IMG_NULL);
 
@@ -488,8 +488,8 @@ IMG_BOOL
 HASH_Insert (HASH_TABLE *pHash, IMG_UINTPTR_T k, IMG_UINTPTR_T v)
 {
        PVR_DPF ((PVR_DBG_MESSAGE,
-              "HASH_Insert: Hash=0x%x, k=0x%x, v=0x%x",
-              (IMG_UINTPTR_T)pHash, k, v));
+              "HASH_Insert: Hash=0x%p, k=0x" UINTPTR_FMT ", v=0x" UINTPTR_FMT,
+              pHash, k, v));
 
        return HASH_Insert_Extended(pHash, &k, v);
 }
@@ -513,8 +513,8 @@ HASH_Remove_Extended(HASH_TABLE *pHash, IMG_VOID *pKey)
        BUCKET **ppBucket;
        IMG_UINT32 uIndex;
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Remove_Extended: Hash=0x%x, pKey=0x%x",
-                       (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey));
+       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Remove_Extended: Hash=0x%p, pKey=0x%p",
+                       pHash, pKey));
 
        PVR_ASSERT (pHash != IMG_NULL);
 
@@ -553,14 +553,14 @@ HASH_Remove_Extended(HASH_TABLE *pHash, IMG_VOID *pKey)
             }
 
                        PVR_DPF ((PVR_DBG_MESSAGE,
-                      "HASH_Remove_Extended: Hash=0x%x, pKey=0x%x = 0x%x",
-                      (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey, v));
+                      "HASH_Remove_Extended: Hash=0x%p, pKey=0x%p = 0x" UINTPTR_FMT,
+                      pHash, pKey, v));
                        return v;
                }
        }
        PVR_DPF ((PVR_DBG_MESSAGE,
-              "HASH_Remove_Extended: Hash=0x%x, pKey=0x%x = 0x0 !!!!",
-              (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey));
+              "HASH_Remove_Extended: Hash=0x%p, pKey=0x%p = 0x0 !!!!",
+              pHash, pKey));
        return 0;
 }
 
@@ -580,8 +580,8 @@ HASH_Remove_Extended(HASH_TABLE *pHash, IMG_VOID *pKey)
 IMG_UINTPTR_T
 HASH_Remove (HASH_TABLE *pHash, IMG_UINTPTR_T k)
 {
-       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Remove: Hash=0x%x, k=0x%x",
-                       (IMG_UINTPTR_T)pHash, k));
+       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Remove: Hash=0x%p, k=0x" UINTPTR_FMT,
+                       pHash, k));
 
        return HASH_Remove_Extended(pHash, &k);
 }
@@ -605,8 +605,8 @@ HASH_Retrieve_Extended (HASH_TABLE *pHash, IMG_VOID *pKey)
        BUCKET **ppBucket;
        IMG_UINT32 uIndex;
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Retrieve_Extended: Hash=0x%x, pKey=0x%x",
-                       (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey));
+       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Retrieve_Extended: Hash=0x%p, pKey=0x%p",
+                       pHash, pKey));
 
        PVR_ASSERT (pHash != IMG_NULL);
 
@@ -627,14 +627,14 @@ HASH_Retrieve_Extended (HASH_TABLE *pHash, IMG_VOID *pKey)
                        IMG_UINTPTR_T v = pBucket->v;
 
                        PVR_DPF ((PVR_DBG_MESSAGE,
-                      "HASH_Retrieve: Hash=0x%x, pKey=0x%x = 0x%x",
-                      (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey, v));
+                      "HASH_Retrieve: Hash=0x%p, pKey=0x%p = 0x" UINTPTR_FMT,
+                      pHash, pKey, v));
                        return v;
                }
        }
        PVR_DPF ((PVR_DBG_MESSAGE,
-              "HASH_Retrieve: Hash=0x%x, pKey=0x%x = 0x0 !!!!",
-              (IMG_UINTPTR_T)pHash, (IMG_UINTPTR_T)pKey));
+              "HASH_Retrieve: Hash=0x%p, pKey=0x%p = 0x0 !!!!",
+              pHash, pKey));
        return 0;
 }
 
@@ -653,8 +653,8 @@ HASH_Retrieve_Extended (HASH_TABLE *pHash, IMG_VOID *pKey)
 IMG_UINTPTR_T
 HASH_Retrieve (HASH_TABLE *pHash, IMG_UINTPTR_T k)
 {
-       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Retrieve: Hash=0x%x, k=0x%x",
-                       (IMG_UINTPTR_T)pHash, k));
+       PVR_DPF ((PVR_DBG_MESSAGE, "HASH_Retrieve: Hash=0x%p, k=0x" UINTPTR_FMT,
+                       pHash, k));
        return HASH_Retrieve_Extended(pHash, &k);
 }
 
index 04432b1..f79e7cb 100644 (file)
@@ -86,12 +86,12 @@ extern "C"
        */
        IMG_VOID OSCheckMemDebug(IMG_PVOID pvCpuVAddr, IMG_SIZE_T uSize, const IMG_CHAR *pszFileName, const IMG_UINT32 uLine)
        {
-               OSMEM_DEBUG_INFO const *psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINT32)pvCpuVAddr - TEST_BUFFER_PADDING_STATUS);
+               OSMEM_DEBUG_INFO const *psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINTPTR_T)pvCpuVAddr - TEST_BUFFER_PADDING_STATUS);
 
                /* invalid pointer */
                if (pvCpuVAddr == IMG_NULL)
                {
-                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : null pointer"
+                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : null pointer"
                                         " - referenced %s:%d - allocated %s:%d",
                                         pvCpuVAddr,
                                         pszFileName, uLine,
@@ -102,7 +102,7 @@ extern "C"
                /* align */
                if (((IMG_UINT32)pvCpuVAddr&3) != 0)
                {
-                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : invalid alignment"
+                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : invalid alignment"
                                         " - referenced %s:%d - allocated %s:%d",
                                         pvCpuVAddr,
                                         pszFileName, uLine,
@@ -113,7 +113,7 @@ extern "C"
                /*check guard region before*/
                if (!MemCheck((IMG_PVOID)psInfo->sGuardRegionBefore, 0xB1, sizeof(psInfo->sGuardRegionBefore)))
                {
-                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : guard region before overwritten"
+                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : guard region before overwritten"
                                         " - referenced %s:%d - allocated %s:%d",
                                         pvCpuVAddr,
                                         pszFileName, uLine,
@@ -124,7 +124,9 @@ extern "C"
                /*check size*/
                if (uSize != psInfo->uSize)
                {
-                       PVR_DPF((PVR_DBG_WARNING, "Pointer 0x%X : supplied size was different to stored size (0x%X != 0x%X)"
+                       PVR_DPF((PVR_DBG_WARNING, 
+                                       "Pointer 0x%p : supplied size was different to stored size (0x%" 
+                                       SIZE_T_FMT_LEN "X != 0x%" SIZE_T_FMT_LEN "X)"
                                         " - referenced %s:%d - allocated %s:%d",
                                         pvCpuVAddr, uSize, psInfo->uSize,
                                         pszFileName, uLine,
@@ -135,7 +137,9 @@ extern "C"
                /*check size parity*/
                if ((0x01234567 ^ psInfo->uSizeParityCheck) != psInfo->uSize)
                {
-                       PVR_DPF((PVR_DBG_WARNING, "Pointer 0x%X : stored size parity error (0x%X != 0x%X)"
+                       PVR_DPF((PVR_DBG_WARNING, 
+                                       "Pointer 0x%p : stored size parity error (0x%"
+                                       SIZE_T_FMT_LEN "X != 0x%" SIZE_T_FMT_LEN "X)"
                                         " - referenced %s:%d - allocated %s:%d",
                                         pvCpuVAddr, psInfo->uSize, 0x01234567 ^ psInfo->uSizeParityCheck,
                                         pszFileName, uLine,
@@ -151,9 +155,9 @@ extern "C"
                /*check padding after*/
                if (uSize)
                {
-                       if (!MemCheck((IMG_VOID*)((IMG_UINT32)pvCpuVAddr + uSize), 0xB2, TEST_BUFFER_PADDING_AFTER))
+                       if (!MemCheck((IMG_VOID*)((IMG_UINTPTR_T)pvCpuVAddr + uSize), 0xB2, TEST_BUFFER_PADDING_AFTER))
                        {
-                               PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : guard region after overwritten"
+                               PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : guard region after overwritten"
                                                 " - referenced from %s:%d - allocated from %s:%d",
                                                 pvCpuVAddr,
                                                 pszFileName, uLine,
@@ -164,7 +168,7 @@ extern "C"
                /* allocated... */
                if (psInfo->eValid != isAllocated)
                {
-                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%X : not allocated (freed? %d)"
+                       PVR_DPF((PVR_DBG_ERROR, "Pointer 0x%p : not allocated (freed? %d)"
                                         " - referenced %s:%d - freed %s:%d",
                                         pvCpuVAddr, psInfo->eValid == isFree,
                                         pszFileName, uLine,
@@ -223,12 +227,12 @@ extern "C"
                psInfo->uSizeParityCheck = 0x01234567 ^ ui32Size;
 
                /*point to the user data section*/
-               *ppvCpuVAddr = (IMG_PVOID) ((IMG_UINT32)*ppvCpuVAddr)+TEST_BUFFER_PADDING_STATUS;
+               *ppvCpuVAddr = (IMG_PVOID) ((IMG_UINTPTR_T)*ppvCpuVAddr)+TEST_BUFFER_PADDING_STATUS;
 
 #ifdef PVRSRV_LOG_MEMORY_ALLOCS
                /*this is here to simplify the surounding logging macro, that is a expression
                maybe the macro should be an expression */
-               PVR_TRACE(("Allocated pointer (after debug info): 0x%X from %s:%d", *ppvCpuVAddr, pszFilename, ui32Line));
+               PVR_TRACE(("Allocated pointer (after debug info): 0x%p from %s:%d", *ppvCpuVAddr, pszFilename, ui32Line));
 #endif
 
                return PVRSRV_OK;
@@ -250,7 +254,7 @@ extern "C"
                OSMemSet(pvCpuVAddr, 0xBF, ui32Size + TEST_BUFFER_PADDING_AFTER);
 
                /*point to the starting address of the total allocated memory*/
-               psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINT32) pvCpuVAddr - TEST_BUFFER_PADDING_STATUS);
+               psInfo = (OSMEM_DEBUG_INFO *)((IMG_UINTPTR_T) pvCpuVAddr - TEST_BUFFER_PADDING_STATUS);
 
                /*update dbg info struct*/
                psInfo->uSize = 0;
index 2d96dc3..4d172b3 100644 (file)
@@ -75,26 +75,9 @@ static IMG_UINT16 gui16MMUContextUsage = 0;
 IMG_UINT32 g_ui32EveryLineCounter = 1U;
 #endif
 
-#ifdef INLINE_IS_PRAGMA
-#pragma inline(_PDumpIsPersistent)
-#endif
-static INLINE
-IMG_BOOL _PDumpIsPersistent(IMG_VOID)
-{
-       PVRSRV_PER_PROCESS_DATA* psPerProc = PVRSRVFindPerProcessData();
-
-       if(psPerProc == IMG_NULL)
-       {
-               /* only occurs early in driver init, and init phase is already persistent */
-               return IMG_FALSE;
-       }
-       return psPerProc->bPDumpPersistent;
-}
-
 #if defined(SUPPORT_PDUMP_MULTI_PROCESS)
 
 
-static INLINE
 IMG_BOOL _PDumpIsProcessActive(IMG_VOID)
 {
        PVRSRV_PER_PROCESS_DATA* psPerProc = PVRSRVFindPerProcessData();
@@ -240,16 +223,20 @@ PVRSRV_ERROR PDumpRegWithFlagsKM(IMG_CHAR *pszPDumpRegName,
 {
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING()
+
+       PDUMP_LOCK();
        PDUMP_DBG(("PDumpRegWithFlagsKM"));
 
        eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "WRW :%s:0x%08X 0x%08X\r\n",
                                                                pszPDumpRegName, ui32Reg, ui32Data);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -293,14 +280,10 @@ PVRSRV_ERROR PDumpRegPolWithFlagsKM(IMG_CHAR *pszPDumpRegName,
 
        PVRSRV_ERROR eErr;
        IMG_UINT32      ui32PollCount;
-
        PDUMP_GET_SCRIPT_STRING();
+
+       PDUMP_LOCK();
        PDUMP_DBG(("PDumpRegPolWithFlagsKM"));
-       if ( _PDumpIsPersistent() )
-       {
-               /* Don't pdump-poll if the process is persistent */
-               return PVRSRV_OK;
-       }
 
        ui32PollCount = POLL_COUNT_LONG;
 
@@ -309,10 +292,12 @@ PVRSRV_ERROR PDumpRegPolWithFlagsKM(IMG_CHAR *pszPDumpRegName,
                                                        ui32Mask, eOperator, ui32PollCount, POLL_DELAY);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -355,8 +340,8 @@ PVRSRV_ERROR PDumpMallocPages (PVRSRV_DEVICE_IDENTIFIER     *psDevID,
                            IMG_HANDLE         hOSMemHandle,
                            IMG_UINT32         ui32NumBytes,
                            IMG_UINT32         ui32PageSize,
-                           IMG_BOOL                      bShared,
-                           IMG_HANDLE         hUniqueTag)
+                           IMG_HANDLE         hUniqueTag,
+                           IMG_UINT32            ui32Flags)
 {
        PVRSRV_ERROR eErr;
        IMG_PUINT8              pui8LinAddr;
@@ -364,16 +349,11 @@ PVRSRV_ERROR PDumpMallocPages (PVRSRV_DEVICE_IDENTIFIER   *psDevID,
        IMG_UINT32              ui32NumPages;
        IMG_DEV_PHYADDR sDevPAddr;
        IMG_UINT32              ui32Page;
-       IMG_UINT32              ui32Flags = PDUMP_FLAGS_CONTINUOUS;
-
+       IMG_UINT32              ui32PageSizeShift = 0;
+       IMG_UINT32              ui32PageSizeTmp;
        PDUMP_GET_SCRIPT_STRING();
-#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
-       /* Always dump physical pages backing a shared allocation */
-       ui32Flags |= ( _PDumpIsPersistent() || bShared ) ? PDUMP_FLAGS_PERSISTENT : 0;
-#else
-       PVR_UNREFERENCED_PARAMETER(bShared);
-       ui32Flags |= ( _PDumpIsPersistent() ) ? PDUMP_FLAGS_PERSISTENT : 0;
-#endif
+
+       PDUMP_LOCK();
 
        /* However, lin addr is only required in non-linux OSes */
 #if !defined(LINUX)
@@ -383,13 +363,23 @@ PVRSRV_ERROR PDumpMallocPages (PVRSRV_DEVICE_IDENTIFIER   *psDevID,
        PVR_ASSERT(((IMG_UINT32) ui32DevVAddr & HOST_PAGEMASK) == 0);
        PVR_ASSERT(((IMG_UINT32) ui32NumBytes & HOST_PAGEMASK) == 0);
 
+       /*
+          Compute the amount to right-shift in order to divide by the page-size.
+          Required for 32-bit PAE kernels (thus phys addresses are 64-bits) where
+          64-bit division is unsupported.
+        */
+       ui32PageSizeTmp = ui32PageSize;
+       while (ui32PageSizeTmp >>= 1)
+               ui32PageSizeShift++;
+
        /*
                Write a comment to the PDump2 script streams indicating the memory allocation
        */
-       eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "-- MALLOC :%s:VA_%08X 0x%08X %u\r\n",
-                       psDevID->pszPDumpDevName, ui32DevVAddr, ui32NumBytes, ui32PageSize);
+       eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "-- MALLOC :%s:VA_%08X 0x%08X %u (%d pages)\r\n",
+                       psDevID->pszPDumpDevName, ui32DevVAddr, ui32NumBytes, ui32PageSize, ui32NumBytes / ui32PageSize);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -399,7 +389,7 @@ PVRSRV_ERROR PDumpMallocPages (PVRSRV_DEVICE_IDENTIFIER     *psDevID,
        */
        pui8LinAddr = (IMG_PUINT8) pvLinAddr;
        ui32Offset = 0;
-       ui32NumPages = ui32NumBytes / ui32PageSize;
+       ui32NumPages = ui32NumBytes >> ui32PageSizeShift;
        while (ui32NumPages)
        { 
                ui32NumPages--;
@@ -415,24 +405,29 @@ PVRSRV_ERROR PDumpMallocPages (PVRSRV_DEVICE_IDENTIFIER   *psDevID,
                                pui8LinAddr,
                                ui32PageSize,
                                &sDevPAddr);
-               ui32Page = (IMG_UINT32)(sDevPAddr.uiAddr / ui32PageSize);
+               ui32Page = (IMG_UINT32)(sDevPAddr.uiAddr >> ui32PageSizeShift);
                /* increment kernel virtual address */
                pui8LinAddr     += ui32PageSize;
                ui32Offset += ui32PageSize;
 
-               eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "MALLOC :%s:PA_%08X%08X %u %u 0x%08X\r\n",
+               sDevPAddr.uiAddr = ui32Page * ui32PageSize;
+
+               eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "MALLOC :%s:PA_" UINTPTR_FMT DEVPADDR_FMT " %u %u 0x" DEVPADDR_FMT "\r\n",
                                                                                                psDevID->pszPDumpDevName,
-                                                                                               (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
-                                                                                               ui32Page * ui32PageSize,
+                                                                                               (IMG_UINTPTR_T)hUniqueTag,
+                                                                                               sDevPAddr.uiAddr,
                                                                                                ui32PageSize,
                                                                                                ui32PageSize,
-                                                                                               ui32Page * ui32PageSize);
+                                                                                               sDevPAddr.uiAddr);
                if(eErr != PVRSRV_OK)
                {
+                       PDUMP_UNLOCK();
                        return eErr;
                }
                PDumpOSWriteString2(hScript, ui32Flags);
        }
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -454,13 +449,13 @@ PVRSRV_ERROR PDumpMallocPageTable (PVRSRV_DEVICE_IDENTIFIER       *psDevId,
 {
        PVRSRV_ERROR eErr;
        IMG_DEV_PHYADDR sDevPAddr;
-
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        PVR_ASSERT(((IMG_UINTPTR_T)pvLinAddr & (ui32PTSize - 1)) == 0);
+
        ui32Flags |= PDUMP_FLAGS_CONTINUOUS;
-       ui32Flags |= ( _PDumpIsPersistent() ) ? PDUMP_FLAGS_PERSISTENT : 0;
-       
+
        /*
                Write a comment to the PDump2 script streams indicating the memory allocation
        */
@@ -472,6 +467,7 @@ PVRSRV_ERROR PDumpMallocPageTable (PVRSRV_DEVICE_IDENTIFIER *psDevId,
                                                        ui32PTSize);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -491,19 +487,22 @@ PVRSRV_ERROR PDumpMallocPageTable (PVRSRV_DEVICE_IDENTIFIER       *psDevId,
                        ui32PTSize,
                        &sDevPAddr);
 
-       eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "MALLOC :%s:PA_%08X%08X 0x%X %u 0x%08X\r\n",
+       eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "MALLOC :%s:PA_" UINTPTR_FMT DEVPADDR_FMT 
+                                                                                                " 0x%X %u 0x" DEVPADDR_FMT "\r\n",
                                                                                        psDevId->pszPDumpDevName,
-                                                                                       (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
+                                                                                       (IMG_UINTPTR_T)hUniqueTag,
                                                                                        sDevPAddr.uiAddr,
                                                                                        ui32PTSize,//size
                                                                                        ui32PTSize,//alignment
                                                                                        sDevPAddr.uiAddr);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -521,21 +520,20 @@ PVRSRV_ERROR PDumpFreePages       (BM_HEAP                        *psBMHeap,
                          IMG_UINT32        ui32PageSize,
                          IMG_HANDLE        hUniqueTag,
                                                 IMG_BOOL                  bInterleaved,
-                                                IMG_BOOL                  bSparse)
+                                                IMG_BOOL                  bSparse,
+                                                IMG_UINT32                ui32Flags)
 {
        PVRSRV_ERROR eErr;
        IMG_UINT32 ui32NumPages, ui32PageCounter;
        IMG_DEV_PHYADDR sDevPAddr;
-       IMG_UINT32 ui32Flags = PDUMP_FLAGS_CONTINUOUS;
        PVRSRV_DEVICE_NODE *psDeviceNode;
-
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        PVR_ASSERT(((IMG_UINT32) sDevVAddr.uiAddr & (ui32PageSize - 1)) == 0);
        PVR_ASSERT(((IMG_UINT32) ui32NumBytes & (ui32PageSize - 1)) == 0);
 
        psDeviceNode = psBMHeap->pBMContext->psDeviceNode;
-       ui32Flags |= ( _PDumpIsPersistent() ) ? PDUMP_FLAGS_PERSISTENT : 0;
 
        /*
                Write a comment to the PDUMP2 script streams indicating the memory free
@@ -544,22 +542,10 @@ PVRSRV_ERROR PDumpFreePages       (BM_HEAP                        *psBMHeap,
                                                        psDeviceNode->sDevId.pszPDumpDevName, sDevVAddr.uiAddr);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
 
-#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
-       /* if we're dumping a shared heap, need to ensure phys allocation
-        * is freed even if this app isn't the one marked for pdumping
-        */
-       {
-               PVRSRV_DEVICE_NODE *psDeviceNode = psBMHeap->pBMContext->psDeviceNode;
-               
-               if( psDeviceNode->pfnMMUIsHeapShared(psBMHeap->pMMUHeap) )
-               {
-                       ui32Flags |= PDUMP_FLAGS_PERSISTENT;
-               }
-       }
-#endif
        PDumpOSWriteString2(hScript, ui32Flags);
 
        /*
@@ -580,10 +566,13 @@ PVRSRV_ERROR PDumpFreePages       (BM_HEAP                        *psBMHeap,
 
                        PVR_ASSERT(sDevPAddr.uiAddr != 0);
 
-                       eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "FREE :%s:PA_%08X%08X\r\n",
-                                                                       psDeviceNode->sDevId.pszPDumpDevName, (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag, sDevPAddr.uiAddr);
+                       eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "FREE :%s:PA_" UINTPTR_FMT DEVPADDR_FMT "\r\n",
+                                                                       psDeviceNode->sDevId.pszPDumpDevName, 
+                                    (IMG_UINTPTR_T)hUniqueTag, 
+                                    sDevPAddr.uiAddr);
                        if(eErr != PVRSRV_OK)
                        {
+                               PDUMP_UNLOCK();
                                return eErr;
                        }
                        PDumpOSWriteString2(hScript, ui32Flags);
@@ -595,6 +584,8 @@ PVRSRV_ERROR PDumpFreePages (BM_HEAP                        *psBMHeap,
 
                sDevVAddr.uiAddr += ui32PageSize;
        }
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -614,12 +605,10 @@ PVRSRV_ERROR PDumpFreePageTable   (PVRSRV_DEVICE_IDENTIFIER *psDevID,
 {
        PVRSRV_ERROR eErr;
        IMG_DEV_PHYADDR sDevPAddr;
-
        PDUMP_GET_SCRIPT_STRING();
-
        PVR_UNREFERENCED_PARAMETER(ui32PTSize);
-       ui32Flags |= PDUMP_FLAGS_CONTINUOUS;
-       ui32Flags |= ( _PDumpIsPersistent() ) ? PDUMP_FLAGS_PERSISTENT : 0;
+
+       PDUMP_LOCK();
 
        /* override QAC warning about wrap around */
        PVR_ASSERT(((IMG_UINTPTR_T)pvLinAddr & (ui32PTSize-1UL)) == 0); /* PRQA S 3382 */
@@ -630,6 +619,7 @@ PVRSRV_ERROR PDumpFreePageTable     (PVRSRV_DEVICE_IDENTIFIER *psDevID,
        eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "-- FREE :%s:PAGE_TABLE\r\n", psDevID->pszPDumpDevName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -650,17 +640,19 @@ PVRSRV_ERROR PDumpFreePageTable   (PVRSRV_DEVICE_IDENTIFIER *psDevID,
                        &sDevPAddr);
 
        {
-               eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "FREE :%s:PA_%08X%08X\r\n",
+               eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "FREE :%s:PA_" UINTPTR_FMT DEVPADDR_FMT "\r\n",
                                                                psDevID->pszPDumpDevName,
-                                                               (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
+                                                               (IMG_UINTPTR_T)hUniqueTag,
                                                                sDevPAddr.uiAddr);
                if(eErr != PVRSRV_OK)
                {
+                       PDUMP_UNLOCK();
                        return eErr;
                }
                PDumpOSWriteString2(hScript, ui32Flags);
        }
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -684,8 +676,11 @@ PVRSRV_ERROR PDumpPDRegWithFlags(PDUMP_MMU_ATTRIB *psMMUAttrib,
 {
        PVRSRV_ERROR eErr;
        IMG_CHAR *pszRegString;
+       IMG_DEV_PHYADDR sDevPAddr;
+
        PDUMP_GET_SCRIPT_STRING()
-       
+
+       PDUMP_LOCK();
        if(psMMUAttrib->pszPDRegRegion != IMG_NULL)
        {       
                pszRegString = psMMUAttrib->pszPDRegRegion;
@@ -699,14 +694,18 @@ PVRSRV_ERROR PDumpPDRegWithFlags(PDUMP_MMU_ATTRIB *psMMUAttrib,
                Write to the MMU script stream indicating the physical page directory
        */
 #if defined(SGX_FEATURE_36BIT_MMU)
+       sDevPAddr.uiAddr = ((ui32Data & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PDEAlignShift);
+
        eErr = PDumpOSBufprintf(hScript, ui32MaxLen,
-                        "WRW :%s:$1 :%s:PA_%08X%08X:0x0\r\n",
+                        "WRW :%s:$1 :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X\r\n",
                         psMMUAttrib->sDevId.pszPDumpDevName,
                         psMMUAttrib->sDevId.pszPDumpDevName,
-                        (IMG_UINT32)hUniqueTag,
-                        (ui32Data & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PDEAlignShift);
+                        (IMG_UINTPTR_T)hUniqueTag,
+                        sDevPAddr.uiAddr,
+                        ui32Data & ~psMMUAttrib->ui32PDEMask);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -715,6 +714,7 @@ PVRSRV_ERROR PDumpPDRegWithFlags(PDUMP_MMU_ATTRIB *psMMUAttrib,
                        psMMUAttrib->sDevId.pszPDumpDevName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -725,25 +725,31 @@ PVRSRV_ERROR PDumpPDRegWithFlags(PDUMP_MMU_ATTRIB *psMMUAttrib,
                         psMMUAttrib->sDevId.pszPDumpDevName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
 #else
+       sDevPAddr.uiAddr = ((ui32Data & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PDEAlignShift);
+
        eErr = PDumpOSBufprintf(hScript,
                                ui32MaxLen,
-                               "WRW :%s:0x%08X :%s:PA_%08X%08X:0x%08X\r\n",
+                               "WRW :%s:0x%08X :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X\r\n",
                                pszRegString,
                                ui32Reg,
                                psMMUAttrib->sDevId.pszPDumpDevName,
-                               (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
-                               (ui32Data & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PDEAlignShift,
+                               (IMG_UINTPTR_T)hUniqueTag,
+                               sDevPAddr.uiAddr,
                                ui32Data & ~psMMUAttrib->ui32PDEMask);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
 #endif
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -800,14 +806,10 @@ PVRSRV_ERROR PDumpMemPolKM(PVRSRV_KERNEL_MEM_INFO         *psMemInfo,
 
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        if (PDumpOSIsSuspended())
        {
-               return PVRSRV_OK;
-       }
-
-       if ( _PDumpIsPersistent() )
-       {
-               /* Don't pdump-poll if the process is persistent */
+               PDUMP_UNLOCK();
                return PVRSRV_OK;
        }
 
@@ -831,6 +833,7 @@ PVRSRV_ERROR PDumpMemPolKM(PVRSRV_KERNEL_MEM_INFO           *psMemInfo,
                         MEMPOLL_DELAY);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -864,11 +867,11 @@ PVRSRV_ERROR PDumpMemPolKM(PVRSRV_KERNEL_MEM_INFO         *psMemInfo,
 
        eErr = PDumpOSBufprintf(hScript,
                         ui32MaxLen,
-                        "POL :%s:PA_%08X%08X:0x%08X 0x%08X 0x%08X %d %d %d\r\n",
+                        "POL :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08X 0x%08X %d %d %d\r\n",
                         psMMUAttrib->sDevId.pszPDumpDevName,
-                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
+                        (IMG_UINTPTR_T)hUniqueTag,
                         sDevPAddr.uiAddr & ~(psMMUAttrib->ui32DataPageMask),
-                        sDevPAddr.uiAddr & (psMMUAttrib->ui32DataPageMask),
+                        (unsigned int)(sDevPAddr.uiAddr & (psMMUAttrib->ui32DataPageMask)),
                         ui32Value,
                         ui32Mask,
                         eOperator,
@@ -876,10 +879,12 @@ PVRSRV_ERROR PDumpMemPolKM(PVRSRV_KERNEL_MEM_INFO         *psMemInfo,
                         MEMPOLL_DELAY);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -913,12 +918,13 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
        IMG_UINT32 ui32ParamOutPos;
        PDUMP_MMU_ATTRIB *psMMUAttrib;
        IMG_UINT32 ui32DataPageSize;
-
        PDUMP_GET_SCRIPT_AND_FILE_STRING();
-       
+
+       PDUMP_LOCK();
        /* PRQA S 3415 1 */ /* side effects desired */
        if (ui32Bytes == 0 || PDumpOSIsSuspended())
        {
+               PDUMP_UNLOCK();
                return PVRSRV_OK;
        }
 
@@ -931,24 +937,10 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
 
        if (!PDumpOSJTInitialised())
        {
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_PDUMP_NOT_AVAILABLE;
        }
 
-#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
-       /* if we're dumping a shared heap, need to ensure phys allocation
-        * is initialised even if this app isn't the one marked for pdumping
-        */
-       {
-               BM_HEAP *pHeap = ((BM_BUF*)psMemInfo->sMemBlk.hBuffer)->pMapping->pBMHeap;
-               PVRSRV_DEVICE_NODE *psDeviceNode = pHeap->pBMContext->psDeviceNode;
-               
-               if( psDeviceNode->pfnMMUIsHeapShared(pHeap->pMMUHeap) )
-               {
-                       ui32Flags |= PDUMP_FLAGS_PERSISTENT;
-               }
-       }
-#endif
-
        /* setup memory addresses */
        if(pvAltLinAddr)
        {
@@ -979,6 +971,7 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
                                                ui32Bytes,
                                                ui32Flags))
        {
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_PDUMP_BUFFER_FULL;
        }
 
@@ -992,6 +985,7 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
        }
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
 
@@ -1000,9 +994,9 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
        */
        eErr = PDumpOSBufprintf(hScript,
                         ui32MaxLenScript,
-                        "-- LDB :%s:VA_%08X%08X:0x%08X 0x%08X 0x%08X %s\r\n",
+                        "-- LDB :%s:VA_" UINTPTR_FMT "%08X:0x%08X 0x%08X 0x%08X %s\r\n",
                         psMMUAttrib->sDevId.pszPDumpDevName,
-                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
+                        (IMG_UINTPTR_T)hUniqueTag,
                         psMemInfo->sDevVAddr.uiAddr,
                         ui32Offset,
                         ui32Bytes,
@@ -1010,6 +1004,7 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
                         pszFileName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -1059,16 +1054,17 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
 
                eErr = PDumpOSBufprintf(hScript,
                                         ui32MaxLenScript,
-                                        "LDB :%s:PA_%08X%08X:0x%08X 0x%08X 0x%08X %s\r\n",
+                                        "LDB :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08X 0x%08X %s\r\n",
                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
+                                        (IMG_UINTPTR_T)hUniqueTag,
                                         sDevPAddr.uiAddr & ~(psMMUAttrib->ui32DataPageMask),
-                                        sDevPAddr.uiAddr & (psMMUAttrib->ui32DataPageMask),
+                                        (unsigned int)(sDevPAddr.uiAddr & (psMMUAttrib->ui32DataPageMask)),
                                         ui32BlockBytes,
                                         ui32ParamOutPos,
                                         pszFileName);
                if(eErr != PVRSRV_OK)
                {
+                       PDUMP_UNLOCK();
                        return eErr;
                }
                PDumpOSWriteString2(hScript, ui32Flags);
@@ -1092,6 +1088,7 @@ static PVRSRV_ERROR _PDumpMemIntKM(IMG_PVOID pvAltLinAddr,
                ui32ParamOutPos += ui32BlockBytes;
        }
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -1191,26 +1188,35 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
        IMG_UINT32 ui32BlockBytes;
        IMG_UINT8* pui8LinAddr;
        IMG_DEV_PHYADDR sDevPAddr;
+       IMG_DEV_PHYADDR sDevPAddrTmp;
        IMG_CPU_PHYADDR sCpuPAddr;
        IMG_UINT32 ui32Offset;
        IMG_UINT32 ui32ParamOutPos;
        IMG_UINT32 ui32PageMask; /* mask for the physical page backing the PT */
 
+#if !defined(SGX_FEATURE_36BIT_MMU)
+       IMG_DEV_PHYADDR sDevPAddrTmp2;
+#endif
        PDUMP_GET_SCRIPT_AND_FILE_STRING();
-       ui32Flags |= ( _PDumpIsPersistent() ) ? PDUMP_FLAGS_PERSISTENT : 0;
+
+       PDUMP_LOCK();
+
 
        if (PDumpOSIsSuspended())
        {
+               PDUMP_UNLOCK();
                return PVRSRV_OK;
        }
 
        if (!PDumpOSJTInitialised())
        {
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_PDUMP_NOT_AVAILABLE;
        }
 
        if (!pvLinAddr)
        {
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_INVALID_PARAMS;
        }
 
@@ -1229,6 +1235,7 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                                                        ui32Bytes,
                                                        ui32Flags | PDUMP_FLAGS_CONTINUOUS))
                {
+                       PDUMP_UNLOCK();
                        return PVRSRV_ERROR_PDUMP_BUFFER_FULL;
                }
 
@@ -1242,6 +1249,7 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                }
                if(eErr != PVRSRV_OK)
                {
+                       PDUMP_UNLOCK();
                        return eErr;
                }
        }
@@ -1295,16 +1303,17 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                {
                        eErr = PDumpOSBufprintf(hScript,
                                         ui32MaxLenScript,
-                                        "LDB :%s:PA_%08X%08X:0x%08X 0x%08X 0x%08X %s\r\n",
+                                        "LDB :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08X 0x%08X %s\r\n",
                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
+                                        (IMG_UINTPTR_T)hUniqueTag1,
                                         sDevPAddr.uiAddr & ~ui32PageMask,
-                                        sDevPAddr.uiAddr & ui32PageMask,
+                                        (unsigned int)(sDevPAddr.uiAddr & ui32PageMask),
                                         ui32BlockBytes,
                                         ui32ParamOutPos,
                                         pszFileName);
                        if(eErr != PVRSRV_OK)
                        {
+                               PDUMP_UNLOCK();
                                return eErr;
                        }
                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
@@ -1319,15 +1328,18 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                                {
                                        /* PT entry points to non-null page */
 #if defined(SGX_FEATURE_36BIT_MMU)
+                                       sDevPAddrTmp.uiAddr = ((ui32PTE & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PTEAlignShift);
+
                                        eErr = PDumpOSBufprintf(hScript,
                                                        ui32MaxLenScript,
-                                                        "WRW :%s:$1 :%s:PA_%08X%08X:0x0\r\n",
+                                                        "WRW :%s:$1 :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x0\r\n",
                                                         psMMUAttrib->sDevId.pszPDumpDevName,
                                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                                        (IMG_UINT32)hUniqueTag2,
-                                                        (ui32PTE & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PTEAlignShift);
+                                                        (IMG_UINTPTR_T)hUniqueTag2,
+                                                        sDevPAddrTmp.uiAddr);
                                        if(eErr != PVRSRV_OK)
                                        {
+                                               PDUMP_UNLOCK();
                                                return eErr;
                                        }
                                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
@@ -1336,6 +1348,7 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                                                                psMMUAttrib->sDevId.pszPDumpDevName);
                                        if(eErr != PVRSRV_OK)
                                        {
+                                               PDUMP_UNLOCK();
                                                return eErr;
                                        }
                                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
@@ -1345,36 +1358,44 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                                                                ui32PTE & ~psMMUAttrib->ui32PDEMask);
                                        if(eErr != PVRSRV_OK)
                                        {
+                                               PDUMP_UNLOCK();
                                                return eErr;
                                        }
                                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
+                                       sDevPAddrTmp.uiAddr = (sDevPAddr.uiAddr + ui32Offset) & ~ui32PageMask;
+
                                        eErr = PDumpOSBufprintf(hScript,
                                                        ui32MaxLenScript,
-                                                        "WRW :%s:PA_%08X%08X:0x%08X :%s:$1\r\n",
+                                                        "WRW :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X :%s:$1\r\n",
                                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                                        (IMG_UINT32)hUniqueTag1,
-                                                        (sDevPAddr.uiAddr + ui32Offset) & ~ui32PageMask,
-                                                        (sDevPAddr.uiAddr + ui32Offset) & ui32PageMask,
+                                                        (IMG_UINTPTR_T)hUniqueTag1,
+                                                        sDevPAddrTmp.uiAddr,
+                                                        (unsigned int)((sDevPAddr.uiAddr + ui32Offset) & ui32PageMask),
                                                         psMMUAttrib->sDevId.pszPDumpDevName);
                                        if(eErr != PVRSRV_OK)
                                        {
+                                               PDUMP_UNLOCK();
                                                return eErr;
                                        }
                                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
 #else
+                                       sDevPAddrTmp.uiAddr  = (sDevPAddr.uiAddr + ui32Offset) & ~ui32PageMask;
+                                       sDevPAddrTmp2.uiAddr = (ui32PTE & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PTEAlignShift;
+
                                        eErr = PDumpOSBufprintf(hScript,
                                                        ui32MaxLenScript,
-                                                        "WRW :%s:PA_%08X%08X:0x%08X :%s:PA_%08X%08X:0x%08X\r\n",
+                                                        "WRW :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X\r\n",
                                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
-                                                        (sDevPAddr.uiAddr + ui32Offset) & ~ui32PageMask,
-                                                        (sDevPAddr.uiAddr + ui32Offset) & ui32PageMask,
+                                                        (IMG_UINTPTR_T)hUniqueTag1,
+                                                        sDevPAddrTmp.uiAddr,
+                                                        (unsigned int)((sDevPAddr.uiAddr + ui32Offset) & ui32PageMask),
                                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag2,
-                                                        (ui32PTE & psMMUAttrib->ui32PDEMask) << psMMUAttrib->ui32PTEAlignShift,
-                                                        ui32PTE & ~psMMUAttrib->ui32PDEMask);
+                                                        (IMG_UINTPTR_T)hUniqueTag2,
+                                                        sDevPAddrTmp2.uiAddr,
+                                                        (unsigned int)(ui32PTE & ~psMMUAttrib->ui32PDEMask));
                                        if(eErr != PVRSRV_OK)
                                        {
+                                               PDUMP_UNLOCK();
                                                return eErr;
                                        }
                                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
@@ -1385,17 +1406,20 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
 #if !defined(FIX_HW_BRN_31620)
                                        PVR_ASSERT((ui32PTE & psMMUAttrib->ui32PTEValid) == 0UL);
 #endif
+                                       sDevPAddrTmp.uiAddr = (sDevPAddr.uiAddr + ui32Offset) & ~ui32PageMask;
+
                                        eErr = PDumpOSBufprintf(hScript,
                                                        ui32MaxLenScript,
-                                                        "WRW :%s:PA_%08X%08X:0x%08X 0x%08X%08X\r\n",
+                                                        "WRW :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08X" UINTPTR_FMT "\r\n",
                                                         psMMUAttrib->sDevId.pszPDumpDevName,
-                                                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
-                                                        (sDevPAddr.uiAddr + ui32Offset) & ~ui32PageMask,
-                                                        (sDevPAddr.uiAddr + ui32Offset) & ui32PageMask,
-                                                        (ui32PTE << psMMUAttrib->ui32PTEAlignShift),
-                                                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag2);
+                                                        (IMG_UINTPTR_T)hUniqueTag1,
+                                                        sDevPAddrTmp.uiAddr,
+                                                        (unsigned int)((sDevPAddr.uiAddr + ui32Offset) & ui32PageMask),
+                                                        ui32PTE << psMMUAttrib->ui32PTEAlignShift,
+                                                        (IMG_UINTPTR_T)hUniqueTag2);
                                        if(eErr != PVRSRV_OK)
                                        {
+                                               PDUMP_UNLOCK();
                                                return eErr;
                                        }
                                        PDumpOSWriteString2(hScript, ui32Flags | PDUMP_FLAGS_CONTINUOUS);
@@ -1415,6 +1439,7 @@ PVRSRV_ERROR PDumpMemPTEntriesKM(PDUMP_MMU_ATTRIB *psMMUAttrib,
                ui32ParamOutPos += ui32BlockBytes;
        }
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -1433,11 +1458,14 @@ PVRSRV_ERROR PDumpPDDevPAddrKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
        IMG_UINT32 ui32ParamOutPos;
        PDUMP_MMU_ATTRIB *psMMUAttrib;
        IMG_UINT32 ui32PageMask; /* mask for the physical page backing the PT */
+       IMG_DEV_PHYADDR sDevPAddrTmp;
 
        PDUMP_GET_SCRIPT_AND_FILE_STRING();
 
+       PDUMP_LOCK();
        if (!PDumpOSJTInitialised())
        {
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_PDUMP_NOT_AVAILABLE;
        }
 
@@ -1452,6 +1480,7 @@ PVRSRV_ERROR PDumpPDDevPAddrKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
                                                sizeof(IMG_DEV_PHYADDR),
                                                ui32Flags))
        {
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_PDUMP_BUFFER_FULL;
        }
 
@@ -1465,24 +1494,28 @@ PVRSRV_ERROR PDumpPDDevPAddrKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
        }
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
 
        /* Write a comment indicating the PD phys addr write, so that the offsets
         * into the param stream increase in correspondence with the number of bytes
         * written. */
+       sDevPAddrTmp.uiAddr = sPDDevPAddr.uiAddr & ~ui32PageMask;
+
        eErr = PDumpOSBufprintf(hScript,
                        ui32MaxLenScript,
-                       "-- LDB :%s:PA_0x%08X%08X:0x%08X 0x%08X 0x%08X %s\r\n",
+                       "-- LDB :%s:PA_0x" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08" SIZE_T_FMT_LEN "X 0x%08X %s\r\n",
                        psMMUAttrib->sDevId.pszPDumpDevName,
-                       (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
-                       sPDDevPAddr.uiAddr & ~ui32PageMask,
-                       sPDDevPAddr.uiAddr & ui32PageMask,
+                       (IMG_UINTPTR_T)hUniqueTag1,
+                       sDevPAddrTmp.uiAddr,
+                       (unsigned int)(sPDDevPAddr.uiAddr & ui32PageMask),
                        sizeof(IMG_DEV_PHYADDR),
                        ui32ParamOutPos,
                        pszFileName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
@@ -1496,103 +1529,70 @@ PVRSRV_ERROR PDumpPDDevPAddrKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
        BM_GetPhysPageAddr(psMemInfo, sDevVPageAddr, &sDevPAddr);
        sDevPAddr.uiAddr += ui32PageByteOffset + ui32Offset;
 
-       if ((sPDDevPAddr.uiAddr & psMMUAttrib->ui32PDEMask) != 0UL)
-       {
 #if defined(SGX_FEATURE_36BIT_MMU)
-               eErr = PDumpOSBufprintf(hScript,
-                               ui32MaxLenScript,
-                                "WRW :%s:$1 :%s:PA_%08X%08X:0x0\r\n",
-                                psMMUAttrib->sDevId.pszPDumpDevName,
-                                psMMUAttrib->sDevId.pszPDumpDevName,
-                                (IMG_UINT32)hUniqueTag2,
-                                sPDDevPAddr.uiAddr);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
-               PDumpOSWriteString2(hScript, ui32Flags);
+       sDevPAddrTmp.uiAddr = sPDDevPAddr.uiAddr & ~ui32PageMask;
 
-               eErr = PDumpOSBufprintf(hScript, ui32MaxLenScript, "AND  :%s:$2 :%s:$1 0xFFFFFFFF\r\n",
-                                       psMMUAttrib->sDevId.pszPDumpDevName,
-                                       psMMUAttrib->sDevId.pszPDumpDevName);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
-               PDumpOSWriteString2(hScript, ui32Flags);
-
-               eErr = PDumpOSBufprintf(hScript,
+       eErr = PDumpOSBufprintf(hScript,
                                ui32MaxLenScript,
-                                "WRW :%s:PA_%08X%08X:0x%08X :%s:$2\r\n",
+                                "WRW :%s:$1 :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X\r\n",
                                 psMMUAttrib->sDevId.pszPDumpDevName,
-                                (IMG_UINT32)hUniqueTag1,
-                                (sDevPAddr.uiAddr) & ~(psMMUAttrib->ui32DataPageMask),
-                                (sDevPAddr.uiAddr) & (psMMUAttrib->ui32DataPageMask),
-                                psMMUAttrib->sDevId.pszPDumpDevName);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
-               PDumpOSWriteString2(hScript, ui32Flags);
+                                psMMUAttrib->sDevId.pszPDumpDevName,
+                                (IMG_UINTPTR_T)hUniqueTag2,
+                                sDevPAddrTmp.uiAddr,
+                                (unsigned int)(sPDDevPAddr.uiAddr & ui32PageMask));
+       if(eErr != PVRSRV_OK)
+       {
+               PDUMP_UNLOCK();
+               return eErr;
+       }
+       PDumpOSWriteString2(hScript, ui32Flags);
 
-               eErr = PDumpOSBufprintf(hScript, ui32MaxLenScript, "SHR :%s:$2 :%s:$1 0x20\r\n",
+       eErr = PDumpOSBufprintf(hScript, ui32MaxLenScript, "SHR :%s:$1 :%s:$1 0x4\r\n",
                                psMMUAttrib->sDevId.pszPDumpDevName,
                                psMMUAttrib->sDevId.pszPDumpDevName);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
-               PDumpOSWriteString2(hScript, ui32Flags);
+       if(eErr != PVRSRV_OK)
+       {
+               PDUMP_UNLOCK();
+               return eErr;
+       }
 
-               eErr = PDumpOSBufprintf(hScript,
+       PDumpOSWriteString2(hScript, ui32Flags);
+       sDevPAddrTmp.uiAddr = sDevPAddr.uiAddr & ~(psMMUAttrib->ui32DataPageMask);
+
+       eErr = PDumpOSBufprintf(hScript,
                                ui32MaxLenScript,
-                                "WRW :%s:PA_%08X%08X:0x%08X :%s:$2\r\n",
+                                "WRW :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X :%s:$1\r\n",
                                 psMMUAttrib->sDevId.pszPDumpDevName,
-                                (IMG_UINT32)hUniqueTag1,
-                                (sDevPAddr.uiAddr + 4) & ~(psMMUAttrib->ui32DataPageMask),
-                                (sDevPAddr.uiAddr + 4) & (psMMUAttrib->ui32DataPageMask),
+                                (IMG_UINTPTR_T)hUniqueTag1,
+                                sDevPAddrTmp.uiAddr,
+                                (unsigned int)((sDevPAddr.uiAddr) & (psMMUAttrib->ui32DataPageMask)),
                                 psMMUAttrib->sDevId.pszPDumpDevName);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
-               PDumpOSWriteString2(hScript, ui32Flags);
-#else
-               eErr = PDumpOSBufprintf(hScript,
-                                ui32MaxLenScript,
-                                "WRW :%s:PA_%08X%08X:0x%08X :%s:PA_%08X%08X:0x%08X\r\n",
-                                psMMUAttrib->sDevId.pszPDumpDevName,
-                                (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
-                                sDevPAddr.uiAddr & ~ui32PageMask,
-                                sDevPAddr.uiAddr & ui32PageMask,
-                                psMMUAttrib->sDevId.pszPDumpDevName,
-                                (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag2,
-                                sPDDevPAddr.uiAddr & psMMUAttrib->ui32PDEMask,
-                                sPDDevPAddr.uiAddr & ~psMMUAttrib->ui32PDEMask);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
-#endif
+       if(eErr != PVRSRV_OK)
+       {
+               PDUMP_UNLOCK();
+               return eErr;
        }
-       else
+#else
+       eErr = PDumpOSBufprintf(hScript,
+                               ui32MaxLenScript,
+                               "WRW :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X \r\n",
+                               psMMUAttrib->sDevId.pszPDumpDevName,
+                               (IMG_UINTPTR_T)hUniqueTag1,
+                               sDevPAddr.uiAddr & ~ui32PageMask,
+                               (unsigned int)(sDevPAddr.uiAddr & ui32PageMask),
+                               psMMUAttrib->sDevId.pszPDumpDevName,
+                               (IMG_UINTPTR_T)hUniqueTag2,
+                               sPDDevPAddr.uiAddr & psMMUAttrib->ui32PDEMask,
+                               (unsigned int)(sPDDevPAddr.uiAddr & ~psMMUAttrib->ui32PDEMask));
+       if(eErr != PVRSRV_OK)
        {
-               PVR_ASSERT(!(sDevPAddr.uiAddr & psMMUAttrib->ui32PTEValid));
-               eErr = PDumpOSBufprintf(hScript,
-                                ui32MaxLenScript,
-                                "WRW :%s:PA_%08X%08X:0x%08X 0x%08X\r\n",
-                                psMMUAttrib->sDevId.pszPDumpDevName,
-                                (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
-                                sDevPAddr.uiAddr & ~ui32PageMask,
-                                sDevPAddr.uiAddr & ui32PageMask,
-                                sPDDevPAddr.uiAddr);
-               if(eErr != PVRSRV_OK)
-               {
-                       return eErr;
-               }
+               PDUMP_UNLOCK();
+               return eErr;
        }
+#endif
        PDumpOSWriteString2(hScript, ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -1612,13 +1612,10 @@ PVRSRV_ERROR PDumpCommentKM(IMG_CHAR *pszComment, IMG_UINT32 ui32Flags)
 #endif
        IMG_UINT32 ui32LenCommentPrefix;
        PDUMP_GET_SCRIPT_STRING();
+
+       PDUMP_LOCK();
        PDUMP_DBG(("PDumpCommentKM"));
-#if defined(PDUMP_DEBUG_OUTFILES)
-       /* include comments in the "extended" init phase.
-        * default is to ignore them.
-        */
-       ui32Flags |= ( _PDumpIsPersistent() ) ? PDUMP_FLAGS_PERSISTENT : 0;
-#endif
+
        /* Put \r \n sequence at the end if it isn't already there */
        PDumpOSVerifyLineEnding(pszComment, ui32MaxLen);
 
@@ -1637,23 +1634,27 @@ PVRSRV_ERROR PDumpCommentKM(IMG_CHAR *pszComment, IMG_UINT32 ui32Flags)
                {
                        PVR_DPF((PVR_DBG_WARNING, "Incomplete comment, %d: %s (continuous set)",
                                         g_ui32EveryLineCounter, pszComment));
+                       PDUMP_UNLOCK();
                        return PVRSRV_ERROR_PDUMP_BUFFER_FULL;
                }
                else if(ui32Flags & PDUMP_FLAGS_PERSISTENT)
                {
                        PVR_DPF((PVR_DBG_WARNING, "Incomplete comment, %d: %s (persistent set)",
                                         g_ui32EveryLineCounter, pszComment));
+                       PDUMP_UNLOCK();
                        return PVRSRV_ERROR_CMD_NOT_PROCESSED;
                }
                else
                {
                        PVR_DPF((PVR_DBG_WARNING, "Incomplete comment, %d: %s",
                                         g_ui32EveryLineCounter, pszComment));
+                       PDUMP_UNLOCK();
                        return PVRSRV_ERROR_CMD_NOT_PROCESSED;
                }
 #else
                PVR_DPF((PVR_DBG_WARNING, "Incomplete comment, %s",
                                         pszComment));
+               PDUMP_UNLOCK();
                return PVRSRV_ERROR_CMD_NOT_PROCESSED;
 #endif
        }
@@ -1675,9 +1676,12 @@ PVRSRV_ERROR PDumpCommentKM(IMG_CHAR *pszComment, IMG_UINT32 ui32Flags)
        if( (eErr != PVRSRV_OK) &&
                (eErr != PVRSRV_ERROR_PDUMP_BUF_OVERFLOW))
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -1696,6 +1700,7 @@ PVRSRV_ERROR PDumpCommentWithFlags(IMG_UINT32 ui32Flags, IMG_CHAR * pszFormat, .
        PDUMP_va_list ap;
        PDUMP_GET_MSG_STRING();
 
+       PDUMP_LOCK_MSG();
        /* Construct the string */
        PDUMP_va_start(ap, pszFormat);
        eErr = PDumpOSVSprintf(pszMsg, ui32MaxLen, pszFormat, ap);
@@ -1703,9 +1708,12 @@ PVRSRV_ERROR PDumpCommentWithFlags(IMG_UINT32 ui32Flags, IMG_CHAR * pszFormat, .
 
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK_MSG();
                return eErr;
        }
-       return PDumpCommentKM(pszMsg, ui32Flags);
+       eErr = PDumpCommentKM(pszMsg, ui32Flags);
+       PDUMP_UNLOCK_MSG();
+       return eErr;
 }
 
 /**************************************************************************
@@ -1723,6 +1731,7 @@ PVRSRV_ERROR PDumpComment(IMG_CHAR *pszFormat, ...)
        PDUMP_va_list ap;
        PDUMP_GET_MSG_STRING();
 
+       PDUMP_LOCK_MSG();
        /* Construct the string */
        PDUMP_va_start(ap, pszFormat);
        eErr = PDumpOSVSprintf(pszMsg, ui32MaxLen, pszFormat, ap);
@@ -1730,9 +1739,12 @@ PVRSRV_ERROR PDumpComment(IMG_CHAR *pszFormat, ...)
 
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK_MSG();
                return eErr;
        }
-       return PDumpCommentKM(pszMsg, PDUMP_FLAGS_CONTINUOUS);
+       eErr = PDumpCommentKM(pszMsg, PDUMP_FLAGS_CONTINUOUS);
+       PDUMP_UNLOCK_MSG();
+       return eErr;
 }
 
 /**************************************************************************
@@ -1748,10 +1760,12 @@ PVRSRV_ERROR PDumpDriverInfoKM(IMG_CHAR *pszString, IMG_UINT32 ui32Flags)
        IMG_UINT32      ui32MsgLen;
        PDUMP_GET_MSG_STRING();
 
+       PDUMP_LOCK_MSG();
        /* Construct the string */
        eErr = PDumpOSSprintf(pszMsg, ui32MaxLen, "%s", pszString);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK_MSG();
                return eErr;
        }
 
@@ -1766,13 +1780,17 @@ PVRSRV_ERROR PDumpDriverInfoKM(IMG_CHAR *pszString, IMG_UINT32 ui32Flags)
        {
                if      (ui32Flags & PDUMP_FLAGS_CONTINUOUS)
                {
+                       PDUMP_UNLOCK_MSG();
                        return PVRSRV_ERROR_PDUMP_BUFFER_FULL;
                }
                else
                {
+                       PDUMP_UNLOCK_MSG();
                        return PVRSRV_ERROR_CMD_NOT_PROCESSED;
                }
        }
+
+       PDUMP_UNLOCK_MSG();
        return PVRSRV_OK;
 }
 
@@ -1818,13 +1836,9 @@ PVRSRV_ERROR PDumpBitmapKM(      PVRSRV_DEVICE_NODE *psDeviceNode,
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
 
-       if ( _PDumpIsPersistent() )
-       {
-               return PVRSRV_OK;
-       }
-
        PDumpCommentWithFlags(ui32PDumpFlags, "\r\n-- Dump bitmap of render\r\n");
 
+       PDUMP_LOCK();
        /* find MMU context ID */
        ui32MMUContextID = psDeviceNode->pfnMMUGetContextID( hDevMemContext );
 
@@ -1845,10 +1859,13 @@ PVRSRV_ERROR PDumpBitmapKM(     PVRSRV_DEVICE_NODE *psDeviceNode,
                                eMemFormat);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
 
        PDumpOSWriteString2( hScript, ui32PDumpFlags);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -1880,9 +1897,9 @@ PVRSRV_ERROR PDumpReadRegKM               (       IMG_CHAR *pszPDumpRegName,
 {
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
-
        PVR_UNREFERENCED_PARAMETER(ui32Size);
 
+       PDUMP_LOCK();
        eErr = PDumpOSBufprintf(hScript,
                        ui32MaxLen,
                        "SAB :%s:0x%08X 0x%08X %s\r\n",
@@ -1892,11 +1909,13 @@ PVRSRV_ERROR PDumpReadRegKM             (       IMG_CHAR *pszPDumpRegName,
                        pszFileName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
 
        PDumpOSWriteString2( hScript, ui32PDumpFlags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -1954,6 +1973,7 @@ static PVRSRV_ERROR PDumpSignatureRegister        (PVRSRV_DEVICE_IDENTIFIER *psDevId,
 
        PDumpOSWriteString2(hScript, ui32Flags);
        *pui32FileOffset += ui32Size;
+
        return PVRSRV_OK;
 }
 
@@ -2000,7 +2020,6 @@ PVRSRV_ERROR PDump3DSignatureRegisters(PVRSRV_DEVICE_IDENTIFIER *psDevId,
 {
        PVRSRV_ERROR eErr;
        IMG_UINT32      ui32FileOffset, ui32Flags;
-
        PDUMP_GET_FILE_STRING();
 
        ui32Flags = bLastFrame ? PDUMP_FLAGS_LASTFRAME : 0;
@@ -2013,6 +2032,12 @@ PVRSRV_ERROR PDump3DSignatureRegisters(PVRSRV_DEVICE_IDENTIFIER *psDevId,
                return eErr;
        }
 
+       /*
+               Note:
+               PDumpCommentWithFlags will take the lock so we defer the lock
+               taking until here
+       */
+       PDUMP_LOCK();
        PDumpRegisterRange(psDevId,
                                                pszFileName,
                                                pui32Registers,
@@ -2021,6 +2046,7 @@ PVRSRV_ERROR PDump3DSignatureRegisters(PVRSRV_DEVICE_IDENTIFIER *psDevId,
                                                sizeof(IMG_UINT32),
                                                ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2044,7 +2070,6 @@ PVRSRV_ERROR PDumpTASignatureRegisters    (PVRSRV_DEVICE_IDENTIFIER *psDevId,
 {
        PVRSRV_ERROR eErr;
        IMG_UINT32      ui32FileOffset, ui32Flags;
-
        PDUMP_GET_FILE_STRING();
 
        ui32Flags = bLastFrame ? PDUMP_FLAGS_LASTFRAME : 0;
@@ -2057,6 +2082,12 @@ PVRSRV_ERROR PDumpTASignatureRegisters   (PVRSRV_DEVICE_IDENTIFIER *psDevId,
                return eErr;
        }
 
+       /*
+               Note:
+               PDumpCommentWithFlags will take the lock so we defer the lock
+               taking until here
+       */
+       PDUMP_LOCK();
        PDumpRegisterRange(psDevId,
                                                pszFileName, 
                                                pui32Registers, 
@@ -2064,6 +2095,7 @@ PVRSRV_ERROR PDumpTASignatureRegisters    (PVRSRV_DEVICE_IDENTIFIER *psDevId,
                                                &ui32FileOffset, 
                                                sizeof(IMG_UINT32), 
                                                ui32Flags);
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2085,7 +2117,6 @@ PVRSRV_ERROR PDumpCounterRegisters (PVRSRV_DEVICE_IDENTIFIER *psDevId,
 {
        PVRSRV_ERROR eErr;
        IMG_UINT32      ui32FileOffset, ui32Flags;
-
        PDUMP_GET_FILE_STRING();
 
        ui32Flags = bLastFrame ? PDUMP_FLAGS_LASTFRAME : 0UL;
@@ -2097,7 +2128,12 @@ PVRSRV_ERROR PDumpCounterRegisters (PVRSRV_DEVICE_IDENTIFIER *psDevId,
        {
                return eErr;
        }
-
+       /*
+               Note:
+               PDumpCommentWithFlags will take the lock so we defer the lock
+               taking until here
+       */
+       PDUMP_LOCK();
        PDumpRegisterRange(psDevId,
                                                pszFileName,
                                                pui32Registers,
@@ -2106,6 +2142,7 @@ PVRSRV_ERROR PDumpCounterRegisters (PVRSRV_DEVICE_IDENTIFIER *psDevId,
                                                sizeof(IMG_UINT32),
                                                ui32Flags);
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2124,14 +2161,18 @@ PVRSRV_ERROR PDumpRegRead(IMG_CHAR *pszPDumpRegName,
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "RDW :%s:0x%X\r\n",
                                                        pszPDumpRegName, 
                                                        ui32RegOffset);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2156,7 +2197,8 @@ PVRSRV_ERROR PDumpSaveMemKM (PVRSRV_DEVICE_IDENTIFIER *psDevId,
 {
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
-       
+
+       PDUMP_LOCK();
        eErr = PDumpOSBufprintf(hScript,
                                                        ui32MaxLen,
                                                        "SAB :%s:v%x:0x%08X 0x%08X 0x%08X %s.bin\r\n",
@@ -2168,10 +2210,13 @@ PVRSRV_ERROR PDumpSaveMemKM (PVRSRV_DEVICE_IDENTIFIER *psDevId,
                                                        pszFileName);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
 
        PDumpOSWriteString2(hScript, ui32PDumpFlags);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2189,14 +2234,18 @@ PVRSRV_ERROR PDumpCycleCountRegRead(PVRSRV_DEVICE_IDENTIFIER *psDevId,
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "RDW :%s:0x%X\r\n", 
                                                        psDevId->pszPDumpRegName,
                                                        ui32RegOffset);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, bLastFrame ? PDUMP_FLAGS_LASTFRAME : 0);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2286,9 +2335,9 @@ PVRSRV_ERROR PDumpCBP(PPVRSRV_KERNEL_MEM_INFO             psROffMemInfo,
        IMG_DEV_VIRTADDR        sDevVPageAddr;
     //IMG_CPU_PHYADDR     CpuPAddr;
        PDUMP_MMU_ATTRIB *psMMUAttrib;
-
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        psMMUAttrib = ((BM_BUF*)psROffMemInfo->sMemBlk.hBuffer)->pMapping->pBMHeap->psMMUAttrib;
 
        /* Check the offset and size don't exceed the bounds of the allocation */
@@ -2324,19 +2373,22 @@ PVRSRV_ERROR PDumpCBP(PPVRSRV_KERNEL_MEM_INFO           psROffMemInfo,
 
        eErr = PDumpOSBufprintf(hScript,
                         ui32MaxLen,
-                        "CBP :%s:PA_%08X%08X:0x%08X 0x%08X 0x%08X 0x%08X\r\n",
+                        "CBP :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08X 0x%08X 0x%08X\r\n",
                         psMMUAttrib->sDevId.pszPDumpDevName,
-                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
+                        (IMG_UINTPTR_T)hUniqueTag,
                         sDevPAddr.uiAddr & ~(psMMUAttrib->ui32DataPageMask),
-                        sDevPAddr.uiAddr & (psMMUAttrib->ui32DataPageMask),
+                        (unsigned int)(sDevPAddr.uiAddr & (psMMUAttrib->ui32DataPageMask)),
                         ui32WPosVal,
                         ui32PacketSize,
                         ui32BufferSize);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2352,14 +2404,19 @@ PVRSRV_ERROR PDumpIDLWithFlags(IMG_UINT32 ui32Clocks, IMG_UINT32 ui32Flags)
 {
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
+
+       PDUMP_LOCK();
        PDUMP_DBG(("PDumpIDLWithFlags"));
 
        eErr = PDumpOSBufprintf(hScript, ui32MaxLen, "IDL %u\r\n", ui32Clocks);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, ui32Flags);
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2617,10 +2674,13 @@ PVRSRV_ERROR PDumpSetMMUContext(PVRSRV_DEVICE_TYPE eDeviceType,
        PVRSRV_ERROR eErr;
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
+
        eErr = _PdumpAllocMMUContext(&ui32MMUContextID);
        if(eErr != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PDumpSetMMUContext: _PdumpAllocMMUContext failed: %d", eErr));
+               PDUMP_UNLOCK();
                return eErr;
        }
 
@@ -2633,15 +2693,16 @@ PVRSRV_ERROR PDumpSetMMUContext(PVRSRV_DEVICE_TYPE eDeviceType,
 
        eErr = PDumpOSBufprintf(hScript,
                                                ui32MaxLen, 
-                                               "MMU :%s:v%d %d :%s:PA_%08X%08X\r\n",
+                                               "MMU :%s:v%d %d :%s:PA_" UINTPTR_FMT DEVPADDR_FMT "\r\n",
                                                pszMemSpace,
                                                ui32MMUContextID,
                                                ui32MMUType,
                                                pszMemSpace,
-                                               (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag1,
+                                               (IMG_UINTPTR_T)hUniqueTag1,
                                                sDevPAddr.uiAddr);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
        PDumpOSWriteString2(hScript, PDUMP_FLAGS_CONTINUOUS);
@@ -2649,6 +2710,7 @@ PVRSRV_ERROR PDumpSetMMUContext(PVRSRV_DEVICE_TYPE eDeviceType,
        /* return the MMU Context ID */
        *pui32MMUContextID = ui32MMUContextID;
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2674,6 +2736,12 @@ PVRSRV_ERROR PDumpClearMMUContext(PVRSRV_DEVICE_TYPE eDeviceType,
         * all OSes and platforms
         */
        PDumpComment("Clear MMU Context for memory space %s\r\n", pszMemSpace);
+
+       /*
+               Note:
+               PDumpComment takes the lock so we can't take it until here
+       */
+       PDUMP_LOCK();
        eErr = PDumpOSBufprintf(hScript,
                                                ui32MaxLen, 
                                                "MMU :%s:v%d\r\n",
@@ -2681,17 +2749,21 @@ PVRSRV_ERROR PDumpClearMMUContext(PVRSRV_DEVICE_TYPE eDeviceType,
                                                ui32MMUContextID);
        if(eErr != PVRSRV_OK)
        {
+               PDUMP_UNLOCK();
                return eErr;
        }
+
        PDumpOSWriteString2(hScript, PDUMP_FLAGS_CONTINUOUS);
 
        eErr = _PdumpFreeMMUContext(ui32MMUContextID);
        if(eErr != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR, "PDumpClearMMUContext: _PdumpFreeMMUContext failed: %d", eErr));
+               PDUMP_UNLOCK();
                return eErr;
        }
 
+       PDUMP_UNLOCK();
        return PVRSRV_OK;
 }
 
@@ -2719,6 +2791,7 @@ PVRSRV_ERROR PDumpStoreMemToFile(PDUMP_MMU_ATTRIB *psMMUAttrib,
 
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
        /*
                query the buffer manager for the physical pages that back the
                virtual address
@@ -2736,17 +2809,18 @@ PVRSRV_ERROR PDumpStoreMemToFile(PDUMP_MMU_ATTRIB *psMMUAttrib,
 
        PDumpOSBufprintf(hScript,
                         ui32MaxLen,
-                        "SAB :%s:PA_%08X%08X:0x%08X 0x%08X 0x%08X %s\r\n",
+                        "SAB :%s:PA_" UINTPTR_FMT DEVPADDR_FMT ":0x%08X 0x%08X 0x%08X %s\r\n",
                         psMMUAttrib->sDevId.pszPDumpDevName,
-                        (IMG_UINT32)(IMG_UINTPTR_T)hUniqueTag,
-                        sDevPAddr.uiAddr & ~psMMUAttrib->ui32DataPageMask,
-                        sDevPAddr.uiAddr & psMMUAttrib->ui32DataPageMask,
+                        (IMG_UINTPTR_T)hUniqueTag,
+                        (sDevPAddr.uiAddr & ~psMMUAttrib->ui32DataPageMask),
+                        (unsigned int)(sDevPAddr.uiAddr & psMMUAttrib->ui32DataPageMask),
                         ui32Size,
                         ui32FileOffset,
                         pszFileName);
 
        PDumpOSWriteString2(hScript, ui32PDumpFlags);
        
+       PDUMP_UNLOCK();
        return PVRSRV_OK;       
 }
 
@@ -2768,6 +2842,8 @@ PVRSRV_ERROR PDumpRegBasedCBP(IMG_CHAR            *pszPDumpRegName,
 {
        PDUMP_GET_SCRIPT_STRING();
 
+       PDUMP_LOCK();
+
        PDumpOSBufprintf(hScript,
                         ui32MaxLen,
                         "CBP :%s:0x%08X 0x%08X 0x%08X 0x%08X\r\n",
@@ -2777,7 +2853,8 @@ PVRSRV_ERROR PDumpRegBasedCBP(IMG_CHAR            *pszPDumpRegName,
                         ui32PacketSize,
                         ui32BufferSize);
        PDumpOSWriteString2(hScript, ui32Flags);
-       
+
+       PDUMP_UNLOCK();
        return PVRSRV_OK;               
 }
 
@@ -2843,7 +2920,7 @@ IMG_UINT32 DbgWrite(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BC
        /* Return if process is not marked for pdumping, unless it's persistent.
         */
        if ( (_PDumpIsProcessActive() == IMG_FALSE ) &&
-                ((ui32Flags & PDUMP_FLAGS_PERSISTENT) == 0) )
+                ((ui32Flags & PDUMP_FLAGS_PERSISTENT) == 0) && psCtrl->bInitPhaseComplete)
        {
                return ui32BCount;
        }
@@ -2867,6 +2944,7 @@ IMG_UINT32 DbgWrite(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BC
 
                        if (ui32BytesWritten == 0)
                        {
+                               PVR_DPF((PVR_DBG_ERROR, "DbgWrite: Failed to send persistent data"));
                                PDumpOSReleaseExecution();
                        }
 
@@ -2893,7 +2971,8 @@ IMG_UINT32 DbgWrite(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BC
 
        while (((IMG_UINT32) ui32BCount > 0) && (ui32BytesWritten != 0xFFFFFFFFU))
        {
-               if ((ui32Flags & PDUMP_FLAGS_CONTINUOUS) != 0)
+               /* If we're in the init phase we treat persisent as meaning continuous */
+               if (((ui32Flags & PDUMP_FLAGS_CONTINUOUS) != 0) || ((ui32Flags & PDUMP_FLAGS_PERSISTENT) != 0))
                {
                        /*
                                If pdump client (or its equivalent) isn't running then throw continuous data away.
@@ -2942,6 +3021,10 @@ IMG_UINT32 DbgWrite(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BC
                */
                if (ui32BytesWritten == 0)
                {
+                       if (ui32Flags & PDUMP_FLAGS_CONTINUOUS)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "Buffer is full during writing of %s", &pui8Data[ui32Off]));
+                       }
                        PDumpOSReleaseExecution();
                }
 
@@ -2950,7 +3033,13 @@ IMG_UINT32 DbgWrite(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BC
                        ui32Off += ui32BytesWritten;
                        ui32BCount -= ui32BytesWritten;
                }
-
+               else
+               {
+                       if (ui32Flags & PDUMP_FLAGS_CONTINUOUS)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "Error during writing of %s", &pui8Data[ui32Off]));
+                       }
+               }
                /* loop exits when i) all data is written, or ii) an unrecoverable error occurs */
        }
 
index d0f7f6b..7860891 100644 (file)
@@ -52,6 +52,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "ttrace.h"
 #endif
 #include "perfkm.h"
+#include "devicemem.h"
 
 #include "pvrversion.h"
 
@@ -62,6 +63,7 @@ IMG_UINT32    g_ui32InitFlags;
 /* mark which parts of Services were initialised */
 #define                INIT_DATA_ENABLE_PDUMPINIT      0x1U
 #define                INIT_DATA_ENABLE_TTARCE         0x2U
+#define                INIT_DATA_ENABLE_DEVMEM         0x4U
 
 /*!
 ******************************************************************************
@@ -203,8 +205,8 @@ IMG_UINT32 ReadHWReg(IMG_PVOID pvLinRegBaseAddr, IMG_UINT32 ui32Offset)
 IMG_EXPORT
 IMG_VOID WriteHWReg(IMG_PVOID pvLinRegBaseAddr, IMG_UINT32 ui32Offset, IMG_UINT32 ui32Value)
 {
-       PVR_DPF((PVR_DBG_MESSAGE,"WriteHWReg Base:%x, Offset: %x, Value %x",
-                       (IMG_UINTPTR_T)pvLinRegBaseAddr,ui32Offset,ui32Value));
+       PVR_DPF((PVR_DBG_MESSAGE,"WriteHWReg Base:%p, Offset: %x, Value %x",
+                       pvLinRegBaseAddr,ui32Offset,ui32Value));
 
        *(IMG_UINT32*)((IMG_UINTPTR_T)pvLinRegBaseAddr+ui32Offset) = ui32Value;
 }
@@ -424,6 +426,13 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVInit(PSYS_DATA psSysData)
        PDUMPINIT();
        g_ui32InitFlags |= INIT_DATA_ENABLE_PDUMPINIT;
 
+#if defined(SUPPORT_ION)
+       eError = PVRSRVInitDeviceMem();
+       if (eError != PVRSRV_OK)
+               goto Error;
+       g_ui32InitFlags |= INIT_DATA_ENABLE_DEVMEM;
+#endif
+
        PERFINIT();
        return eError;
 
@@ -460,6 +469,13 @@ IMG_VOID IMG_CALLCONV PVRSRVDeInit(PSYS_DATA psSysData)
 
        PERFDEINIT();
 
+#if defined(SUPPORT_ION)
+       if ((g_ui32InitFlags & INIT_DATA_ENABLE_DEVMEM) > 0)
+       {
+               PVRSRVDeInitDeviceMem();
+       }
+#endif
+
 #if defined(TTRACE)
        /* deinitialise ttrace */
        if ((g_ui32InitFlags & INIT_DATA_ENABLE_TTARCE) > 0)
@@ -1136,11 +1152,7 @@ static PVRSRV_ERROR PVRSRVGetMiscInfoKM_Device_AnyVaCb(PVRSRV_DEVICE_NODE *psDev
 
 ******************************************************************************/
 IMG_EXPORT
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO_KM *psMiscInfo)
-#else
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
-#endif
 {
        SYS_DATA *psSysData;
 
@@ -1326,16 +1338,10 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
                }
                else
                {
-#if defined (SUPPORT_SID_INTERFACE)
-                       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo = psMiscInfo->sCacheOpCtl.psKernelMemInfo;
-
-                       if(!psMiscInfo->sCacheOpCtl.psKernelMemInfo)
-#else
                        PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
                        PVRSRV_PER_PROCESS_DATA *psPerProc;
 
                        if(!psMiscInfo->sCacheOpCtl.u.psKernelMemInfo)
-#endif
                        {
                                PVR_DPF((PVR_DBG_WARNING, "PVRSRVGetMiscInfoKM: "
                                                 "Ignoring non-deferred cache op with no meminfo"));
@@ -1349,9 +1355,6 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
                                                 "to combine deferred cache ops with immediate ones"));
                        }
 
-#if defined (SUPPORT_SID_INTERFACE)
-                       PVR_DBG_BREAK
-#else
                        psPerProc = PVRSRVFindPerProcessData();
 
                        if(PVRSRVLookupHandle(psPerProc->psHandleBase,
@@ -1363,7 +1366,6 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
                                                 "Can't find kernel meminfo"));
                                return PVRSRV_ERROR_INVALID_PARAMS;
                        }
-#endif
 
                        if(psMiscInfo->sCacheOpCtl.eCacheOpType == PVRSRV_MISC_INFO_CPUCACHEOP_FLUSH)
                        {
@@ -1377,12 +1379,15 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
                        }
                        else if(psMiscInfo->sCacheOpCtl.eCacheOpType == PVRSRV_MISC_INFO_CPUCACHEOP_CLEAN)
                        {
-                               if(!OSCleanCPUCacheRangeKM(psKernelMemInfo->sMemBlk.hOSMemHandle,
-                                                                                  0,
-                                                                                  psMiscInfo->sCacheOpCtl.pvBaseVAddr,
-                                                                                  psMiscInfo->sCacheOpCtl.ui32Length))
+                               if(psMiscInfo->sCacheOpCtl.ui32Length!=0)
                                {
-                                       return PVRSRV_ERROR_CACHEOP_FAILED;
+                                       if(!OSCleanCPUCacheRangeKM(psKernelMemInfo->sMemBlk.hOSMemHandle,
+                                                                                          0,
+                                                                                          psMiscInfo->sCacheOpCtl.pvBaseVAddr,
+                                                                                          psMiscInfo->sCacheOpCtl.ui32Length))
+                                       {
+                                               return PVRSRV_ERROR_CACHEOP_FAILED;
+                                       }
                                }
                        }
                }
@@ -1390,16 +1395,11 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
 
        if((psMiscInfo->ui32StateRequest & PVRSRV_MISC_INFO_GET_REF_COUNT_PRESENT) != 0UL)
        {
-#if !defined (SUPPORT_SID_INTERFACE)
                PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
                PVRSRV_PER_PROCESS_DATA *psPerProc;
-#endif
 
                psMiscInfo->ui32StatePresent |= PVRSRV_MISC_INFO_GET_REF_COUNT_PRESENT;
 
-#if defined (SUPPORT_SID_INTERFACE)
-               PVR_DBG_BREAK
-#else
                psPerProc = PVRSRVFindPerProcessData();
 
                if(PVRSRVLookupHandle(psPerProc->psHandleBase,
@@ -1413,7 +1413,6 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetMiscInfoKM(PVRSRV_MISC_INFO *psMiscInfo)
                }
 
                psMiscInfo->sGetRefCountCtl.ui32RefCount = psKernelMemInfo->ui32RefCount;
-#endif
        }
 
        if ((psMiscInfo->ui32StateRequest & PVRSRV_MISC_INFO_GET_PAGE_SIZE_PRESENT) != 0UL)
@@ -1693,7 +1692,11 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVSaveRestoreLiveSegments(IMG_HANDLE hArena, IMG_P
                                return (PVRSRV_ERROR_OUT_OF_MEMORY);
                        }
 
-                       PVR_DPF((PVR_DBG_MESSAGE, "PVRSRVSaveRestoreLiveSegments: Base %08x size %08x", sSegDetails.sCpuPhyAddr.uiAddr, sSegDetails.uiSize));
+                       PVR_DPF((
+                PVR_DBG_MESSAGE, 
+                "PVRSRVSaveRestoreLiveSegments: Base " CPUPADDR_FMT " size %" SIZE_T_FMT_LEN "x", 
+                sSegDetails.sCpuPhyAddr.uiAddr, 
+                sSegDetails.uiSize));
 
                        /* Map the device's local memory area onto the host. */
                        pvLocalMemCPUVAddr = OSMapPhysToLin(sSegDetails.sCpuPhyAddr,
index 0cfcbff..92fa34b 100644 (file)
@@ -45,6 +45,27 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "lists.h"
 #include "ttrace.h"
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include <linux/sw_sync.h>
+static struct sync_fence *AllocQueueFence(struct sw_sync_timeline *psTimeline, IMG_UINT32 ui32FenceValue, const char *szName)
+{
+       struct sync_fence *psFence = IMG_NULL;
+       struct sync_pt *psPt;
+
+       psPt = sw_sync_pt_create(psTimeline, ui32FenceValue);
+       if(psPt)
+       {
+               psFence = sync_fence_create(szName, psPt);
+               if(!psFence)
+               {
+                       sync_pt_free(psPt);
+               }
+       }
+
+       return psFence;
+}
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+
 /*
  * The number of commands of each type which can be in flight at once.
  */
@@ -87,8 +108,8 @@ void ProcSeqShowQueue(struct seq_file *sfile,void* el)
 {
        PVRSRV_QUEUE_INFO *psQueue = (PVRSRV_QUEUE_INFO*)el;
        IMG_INT cmds = 0;
-       IMG_SIZE_T ui32ReadOffset;
-       IMG_SIZE_T ui32WriteOffset;
+       IMG_SIZE_T uReadOffset;
+       IMG_SIZE_T uWriteOffset;
        PVRSRV_COMMAND *psCmd;
 
        if(el == PVR_PROC_SEQ_START_TOKEN)
@@ -99,16 +120,16 @@ void ProcSeqShowQueue(struct seq_file *sfile,void* el)
                return;
        }
 
-       ui32ReadOffset = psQueue->ui32ReadOffset;
-       ui32WriteOffset = psQueue->ui32WriteOffset;
+       uReadOffset = psQueue->uReadOffset;
+       uWriteOffset = psQueue->uWriteOffset;
 
-       while (ui32ReadOffset != ui32WriteOffset)
+       while (uReadOffset != uWriteOffset)
        {
-               psCmd= (PVRSRV_COMMAND *)((IMG_UINTPTR_T)psQueue->pvLinQueueKM + ui32ReadOffset);
+               psCmd= (PVRSRV_COMMAND *)((IMG_UINTPTR_T)psQueue->pvLinQueueKM + uReadOffset);
 
-               seq_printf(sfile, "%x %x  %5u  %6u  %3u  %5u   %2u   %2u    %3u  \n",
-                                                       (IMG_UINTPTR_T)psQueue,
-                                                       (IMG_UINTPTR_T)psCmd,
+               seq_printf(sfile, "%p %p  %5u  %6u  %3" SIZE_T_FMT_LEN "u  %5u   %2u   %2u    %3" SIZE_T_FMT_LEN "u  \n",
+                                                       psQueue,
+                                                       psCmd,
                                                        psCmd->ui32ProcessID,
                                                        psCmd->CommandType,
                                                        psCmd->uCmdSize,
@@ -133,14 +154,14 @@ void ProcSeqShowQueue(struct seq_file *sfile,void* el)
                }
 
                /* taken from UPDATE_QUEUE_ROFF in queue.h */
-               ui32ReadOffset += psCmd->uCmdSize;
-               ui32ReadOffset &= psQueue->ui32QueueSize - 1;
+               uReadOffset += psCmd->uCmdSize;
+               uReadOffset &= psQueue->uQueueSize - 1;
                cmds++;
        }
 
        if (cmds == 0)
        {
-               seq_printf(sfile, "%x <empty>\n", (IMG_UINTPTR_T)psQueue);
+               seq_printf(sfile, "%p <empty>\n", psQueue);
        }
 }
 
@@ -181,15 +202,15 @@ void* ProcSeqOff2ElementQueue(struct seq_file * sfile, loff_t off)
  * Macro to return space in given command queue
  */
 #define GET_SPACE_IN_CMDQ(psQueue)                                                                             \
-       ((((psQueue)->ui32ReadOffset - (psQueue)->ui32WriteOffset)                              \
-       + ((psQueue)->ui32QueueSize - 1)) & ((psQueue)->ui32QueueSize - 1))
+       ((((psQueue)->uReadOffset - (psQueue)->uWriteOffset)                            \
+       + ((psQueue)->uQueueSize - 1)) & ((psQueue)->uQueueSize - 1))
 
 /*!
  * Macro to Write Offset in given command queue
  */
-#define UPDATE_QUEUE_WOFF(psQueue, ui32Size)                                                   \
-       (psQueue)->ui32WriteOffset = ((psQueue)->ui32WriteOffset + (ui32Size))  \
-       & ((psQueue)->ui32QueueSize - 1);
+#define UPDATE_QUEUE_WOFF(psQueue, uSize)                                                      \
+       (psQueue)->uWriteOffset = ((psQueue)->uWriteOffset + (uSize))   \
+       & ((psQueue)->uQueueSize - 1);
 
 /*!
  * Check if an ops complete value has gone past the pending value.
@@ -347,21 +368,21 @@ IMG_VOID QueueDumpDebugInfo(IMG_VOID)
        Kernel-side functions of User->Kernel transitions
 ******************************************************************************/
 
-static IMG_SIZE_T NearestPower2(IMG_SIZE_T ui32Value)
+static IMG_SIZE_T NearestPower2(IMG_SIZE_T uValue)
 {
-       IMG_SIZE_T ui32Temp, ui32Result = 1;
+       IMG_SIZE_T uTemp, uResult = 1;
 
-       if(!ui32Value)
+       if(!uValue)
                return 0;
 
-       ui32Temp = ui32Value - 1;
-       while(ui32Temp)
+       uTemp = uValue - 1;
+       while(uTemp)
        {
-               ui32Result <<= 1;
-               ui32Temp >>= 1;
+               uResult <<= 1;
+               uTemp >>= 1;
        }
 
-       return ui32Result;
+       return uResult;
 }
 
 
@@ -374,7 +395,7 @@ static IMG_SIZE_T NearestPower2(IMG_SIZE_T ui32Value)
  Creates a new command queue into which render/blt commands etc can be
  inserted.
 
- @Input    ui32QueueSize :
+ @Input    uQueueSize :
 
  @Output   ppsQueueInfo :
 
@@ -382,11 +403,11 @@ static IMG_SIZE_T NearestPower2(IMG_SIZE_T ui32Value)
 
 ******************************************************************************/
 IMG_EXPORT
-PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T ui32QueueSize,
+PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T uQueueSize,
                                                                                                         PVRSRV_QUEUE_INFO **ppsQueueInfo)
 {
        PVRSRV_QUEUE_INFO       *psQueueInfo;
-       IMG_SIZE_T                      ui32Power2QueueSize = NearestPower2(ui32QueueSize);
+       IMG_SIZE_T                      uPower2QueueSize = NearestPower2(uQueueSize);
        SYS_DATA                        *psSysData;
        PVRSRV_ERROR            eError;
        IMG_HANDLE                      hMemBlock;
@@ -410,7 +431,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T ui32QueueSize,
 
        /* allocate the command queue buffer - allow for overrun */
        eError = OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
-                                        ui32Power2QueueSize + PVRSRV_MAX_CMD_SIZE,
+                                        uPower2QueueSize + PVRSRV_MAX_CMD_SIZE,
                                         &psQueueInfo->pvLinQueueKM, &hMemBlock,
                                         "Command Queue");
        if (eError != PVRSRV_OK)
@@ -423,10 +444,19 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T ui32QueueSize,
        psQueueInfo->pvLinQueueUM = psQueueInfo->pvLinQueueKM;
 
        /* Sanity check: Should be zeroed by OSMemSet */
-       PVR_ASSERT(psQueueInfo->ui32ReadOffset == 0);
-       PVR_ASSERT(psQueueInfo->ui32WriteOffset == 0);
+       PVR_ASSERT(psQueueInfo->uReadOffset == 0);
+       PVR_ASSERT(psQueueInfo->uWriteOffset == 0);
 
-       psQueueInfo->ui32QueueSize = ui32Power2QueueSize;
+       psQueueInfo->uQueueSize = uPower2QueueSize;
+
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       psQueueInfo->pvTimeline = sw_sync_timeline_create("pvr_queue_proc");
+       if(psQueueInfo->pvTimeline == IMG_NULL)
+       {
+               PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateCommandQueueKM: sw_sync_timeline_create() failed"));
+               goto ErrorExit;
+       }
+#endif
 
        /* if this is the first q, create a lock resource for the q list */
        if (psSysData->psQueueList == IMG_NULL)
@@ -466,7 +496,7 @@ ErrorExit:
                if(psQueueInfo->pvLinQueueKM)
                {
                        OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
-                                               psQueueInfo->ui32QueueSize,
+                                               psQueueInfo->uQueueSize,
                                                psQueueInfo->pvLinQueueKM,
                                                psQueueInfo->hMemBlock[1]);
                        psQueueInfo->pvLinQueueKM = IMG_NULL;
@@ -510,7 +540,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyCommandQueueKM(PVRSRV_QUEUE_INFO *psQueue
        /* PRQA S 3415,4109 1 */ /* macro format critical - leave alone */
        LOOP_UNTIL_TIMEOUT(MAX_HW_TIME_US)
        {
-               if(psQueueInfo->ui32ReadOffset == psQueueInfo->ui32WriteOffset)
+               if(psQueueInfo->uReadOffset == psQueueInfo->uWriteOffset)
                {
                        bTimeout = IMG_FALSE;
                        break;
@@ -535,12 +565,16 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyCommandQueueKM(PVRSRV_QUEUE_INFO *psQueue
                goto ErrorExit;
        }
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       sync_timeline_destroy(psQueueInfo->pvTimeline);
+#endif
+
        if(psQueue == psQueueInfo)
        {
                psSysData->psQueueList = psQueueInfo->psNextKM;
 
                OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
-                                       NearestPower2(psQueueInfo->ui32QueueSize) + PVRSRV_MAX_CMD_SIZE,
+                                       NearestPower2(psQueueInfo->uQueueSize) + PVRSRV_MAX_CMD_SIZE,
                                        psQueueInfo->pvLinQueueKM,
                                        psQueueInfo->hMemBlock[1]);
                psQueueInfo->pvLinQueueKM = IMG_NULL;
@@ -560,7 +594,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyCommandQueueKM(PVRSRV_QUEUE_INFO *psQueue
                                psQueue->psNextKM = psQueueInfo->psNextKM;
 
                                OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
-                                                       psQueueInfo->ui32QueueSize,
+                                                       psQueueInfo->uQueueSize,
                                                        psQueueInfo->pvLinQueueKM,
                                                        psQueueInfo->hMemBlock[1]);
                                psQueueInfo->pvLinQueueKM = IMG_NULL;
@@ -626,15 +660,15 @@ ErrorExit:
 *****************************************************************************/
 IMG_EXPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetQueueSpaceKM(PVRSRV_QUEUE_INFO *psQueue,
-                                                                                               IMG_SIZE_T ui32ParamSize,
+                                                                                               IMG_SIZE_T uParamSize,
                                                                                                IMG_VOID **ppvSpace)
 {
        IMG_BOOL bTimeout = IMG_TRUE;
 
        /*      round to 4byte units */
-       ui32ParamSize =  (ui32ParamSize+3) & 0xFFFFFFFC;
+       uParamSize =  (uParamSize + 3) & 0xFFFFFFFC;
 
-       if (ui32ParamSize > PVRSRV_MAX_CMD_SIZE)
+       if (uParamSize > PVRSRV_MAX_CMD_SIZE)
        {
                PVR_DPF((PVR_DBG_WARNING,"PVRSRVGetQueueSpace: max command size is %d bytes", PVRSRV_MAX_CMD_SIZE));
                return PVRSRV_ERROR_CMD_TOO_BIG;
@@ -643,7 +677,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetQueueSpaceKM(PVRSRV_QUEUE_INFO *psQueue,
        /* PRQA S 3415,4109 1 */ /* macro format critical - leave alone */
        LOOP_UNTIL_TIMEOUT(MAX_HW_TIME_US)
        {
-               if (GET_SPACE_IN_CMDQ(psQueue) > ui32ParamSize)
+               if (GET_SPACE_IN_CMDQ(psQueue) > uParamSize)
                {
                        bTimeout = IMG_FALSE;
                        break;
@@ -659,7 +693,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVGetQueueSpaceKM(PVRSRV_QUEUE_INFO *psQueue,
        }
        else
        {
-               *ppvSpace = (IMG_VOID *)((IMG_UINTPTR_T)psQueue->pvLinQueueUM + psQueue->ui32WriteOffset);
+               *ppvSpace = (IMG_VOID *)((IMG_UINTPTR_T)psQueue->pvLinQueueUM + psQueue->uWriteOffset);
        }
 
        return PVRSRV_OK;
@@ -695,17 +729,22 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVInsertCommandKM(PVRSRV_QUEUE_INFO *psQueue,
                                                                                                PVRSRV_KERNEL_SYNC_INFO *apsDstSync[],
                                                                                                IMG_UINT32                      ui32SrcSyncCount,
                                                                                                PVRSRV_KERNEL_SYNC_INFO *apsSrcSync[],
-                                                                                               IMG_SIZE_T                      ui32DataByteSize,
+                                                                                               IMG_SIZE_T                      uDataByteSize,
                                                                                                PFN_QUEUE_COMMAND_COMPLETE pfnCommandComplete,
-                                                                                               IMG_HANDLE                      hCallbackData)
+                                                                                               IMG_HANDLE                      hCallbackData,
+                                                                                               IMG_HANDLE                      *phFence)
 {
        PVRSRV_ERROR    eError;
        PVRSRV_COMMAND  *psCommand;
-       IMG_SIZE_T              ui32CommandSize;
+       IMG_SIZE_T              uCommandSize;
        IMG_UINT32              i;
        SYS_DATA *psSysData;
        DEVICE_COMMAND_DATA *psDeviceCommandData;
 
+#if !defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       PVR_UNREFERENCED_PARAMETER(phFence);
+#endif
+
        /* Check that we've got enough space in our command complete data for this command */
        SysAcquireData(&psSysData);
        psDeviceCommandData = psSysData->apsDeviceCommandData[ui32DevIndex];
@@ -718,24 +757,63 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVInsertCommandKM(PVRSRV_QUEUE_INFO *psQueue,
        }
 
        /* Round up to nearest 32 bit size so pointer arithmetic works */
-       ui32DataByteSize = (ui32DataByteSize + 3UL) & ~3UL;
+       uDataByteSize = (uDataByteSize + 3UL) & ~3UL;
 
        /*  calc. command size */
-       ui32CommandSize = sizeof(PVRSRV_COMMAND)
+       uCommandSize = sizeof(PVRSRV_COMMAND)
                                        + ((ui32DstSyncCount + ui32SrcSyncCount) * sizeof(PVRSRV_SYNC_OBJECT))
-                                       + ui32DataByteSize;
+                                       + uDataByteSize;
 
        /* wait for space in queue */
-       eError = PVRSRVGetQueueSpaceKM (psQueue, ui32CommandSize, (IMG_VOID**)&psCommand);
+       eError = PVRSRVGetQueueSpaceKM (psQueue, uCommandSize, (IMG_VOID**)&psCommand);
        if(eError != PVRSRV_OK)
        {
                return eError;
        }
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       if(phFence != IMG_NULL)
+       {
+               struct sync_fence *psRetireFence, *psCleanupFence;
+
+               /* New command? New timeline target */
+               psQueue->ui32FenceValue++;
+
+               psRetireFence = AllocQueueFence(psQueue->pvTimeline, psQueue->ui32FenceValue, "pvr_queue_retire");
+               if(!psRetireFence)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVInsertCommandKM: sync_fence_create() failed"));
+                       psQueue->ui32FenceValue--;
+                       return PVRSRV_ERROR_INVALID_PARAMS;
+               }
+
+               /* This similar to the retire fence, except that it is destroyed
+                * when a display command completes, rather than at the whim of
+                * userspace. It is used to keep the timeline alive.
+                */
+               psCleanupFence = AllocQueueFence(psQueue->pvTimeline, psQueue->ui32FenceValue, "pvr_queue_cleanup");
+               if(!psCleanupFence)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVInsertCommandKM: sync_fence_create() #2 failed"));
+                       sync_fence_put(psRetireFence);
+                       psQueue->ui32FenceValue--;
+                       return PVRSRV_ERROR_INVALID_PARAMS;
+               }
+
+               psCommand->pvCleanupFence = psCleanupFence;
+               psCommand->pvTimeline = psQueue->pvTimeline;
+               *phFence = psRetireFence;
+       }
+       else
+       {
+               psCommand->pvTimeline = IMG_NULL;
+       }
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+
        psCommand->ui32ProcessID        = OSGetCurrentProcessIDKM();
 
        /* setup the command */
-       psCommand->uCmdSize             = ui32CommandSize; /* this may change if cmd shrinks */
+       psCommand->uCmdSize                     = uCommandSize; /* this may change if cmd shrinks */
        psCommand->ui32DevIndex         = ui32DevIndex;
        psCommand->CommandType          = CommandType;
        psCommand->ui32DstSyncCount     = ui32DstSyncCount;
@@ -752,7 +830,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVInsertCommandKM(PVRSRV_QUEUE_INFO   *psQueue,
                                                                + (ui32SrcSyncCount * sizeof(PVRSRV_SYNC_OBJECT)));
 /* PRQA L:END_PTR_ASSIGNMENTS */
 
-       psCommand->uDataSize            = ui32DataByteSize;/* this may change if cmd shrinks */
+       psCommand->uDataSize            = uDataByteSize;/* this may change if cmd shrinks */
 
        psCommand->pfnCommandComplete = pfnCommandComplete;
        psCommand->hCallbackData = hCallbackData;
@@ -829,18 +907,18 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVSubmitCommandKM(PVRSRV_QUEUE_INFO *psQueue,
        if (psCommand->ui32DstSyncCount > 0)
        {
                psCommand->psDstSync = (PVRSRV_SYNC_OBJECT*)(((IMG_UINTPTR_T)psQueue->pvLinQueueKM)
-                                                                       + psQueue->ui32WriteOffset + sizeof(PVRSRV_COMMAND));
+                                                                       + psQueue->uWriteOffset + sizeof(PVRSRV_COMMAND));
        }
 
        if (psCommand->ui32SrcSyncCount > 0)
        {
                psCommand->psSrcSync = (PVRSRV_SYNC_OBJECT*)(((IMG_UINTPTR_T)psQueue->pvLinQueueKM)
-                                                                       + psQueue->ui32WriteOffset + sizeof(PVRSRV_COMMAND)
+                                                                       + psQueue->uWriteOffset + sizeof(PVRSRV_COMMAND)
                                                                        + (psCommand->ui32DstSyncCount * sizeof(PVRSRV_SYNC_OBJECT)));
        }
 
        psCommand->pvData = (PVRSRV_SYNC_OBJECT*)(((IMG_UINTPTR_T)psQueue->pvLinQueueKM)
-                                                                       + psQueue->ui32WriteOffset + sizeof(PVRSRV_COMMAND)
+                                                                       + psQueue->uWriteOffset + sizeof(PVRSRV_COMMAND)
                                                                        + (psCommand->ui32DstSyncCount * sizeof(PVRSRV_SYNC_OBJECT))
                                                                        + (psCommand->ui32SrcSyncCount * sizeof(PVRSRV_SYNC_OBJECT)));
 
@@ -897,8 +975,8 @@ PVRSRV_ERROR CheckIfSyncIsQueued(PVRSRV_SYNC_OBJECT *psSync, COMMAND_COMPLETE_DA
                                        if (SYNCOPS_STALE(ui32WriteOpsComplete, psSync->ui32WriteOpsPending))
                                        {
                                                PVR_DPF((PVR_DBG_WARNING,
-                                                               "CheckIfSyncIsQueued: Stale syncops psSyncData:0x%x ui32WriteOpsComplete:0x%x ui32WriteOpsPending:0x%x",
-                                                               (IMG_UINTPTR_T)psSyncData, ui32WriteOpsComplete, psSync->ui32WriteOpsPending));
+                                                               "CheckIfSyncIsQueued: Stale syncops psSyncData:0x%p ui32WriteOpsComplete:0x%x ui32WriteOpsPending:0x%x",
+                                                               psSyncData, ui32WriteOpsComplete, psSync->ui32WriteOpsPending));
                                                return PVRSRV_OK;
                                        }
                                }
@@ -979,8 +1057,8 @@ PVRSRV_ERROR PVRSRVProcessCommand(SYS_DATA                 *psSysData,
                                SYNCOPS_STALE(ui32ReadOpsComplete, psWalkerObj->ui32ReadOps2Pending))
                        {
                                PVR_DPF((PVR_DBG_WARNING,
-                                               "PVRSRVProcessCommand: Stale syncops psSyncData:0x%x ui32WriteOpsComplete:0x%x ui32WriteOpsPending:0x%x",
-                                               (IMG_UINTPTR_T)psSyncData, ui32WriteOpsComplete, psWalkerObj->ui32WriteOpsPending));
+                                               "PVRSRVProcessCommand: Stale syncops psSyncData:0x%p ui32WriteOpsComplete:0x%x ui32WriteOpsPending:0x%x",
+                                               psSyncData, ui32WriteOpsComplete, psWalkerObj->ui32WriteOpsPending));
                        }
 
                        if (!bFlush ||
@@ -1047,6 +1125,11 @@ PVRSRV_ERROR PVRSRVProcessCommand(SYS_DATA                       *psSysData,
        psCmdCompleteData->pfnCommandComplete = psCommand->pfnCommandComplete;
        psCmdCompleteData->hCallbackData = psCommand->hCallbackData;
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       psCmdCompleteData->pvCleanupFence = psCommand->pvCleanupFence;
+       psCmdCompleteData->pvTimeline = psCommand->pvTimeline;
+#endif
+
        /* copy dst updates over */
        psCmdCompleteData->ui32SrcSyncCount = psCommand->ui32SrcSyncCount;
        for (i=0; i<psCommand->ui32SrcSyncCount; i++)
@@ -1082,10 +1165,13 @@ PVRSRV_ERROR PVRSRVProcessCommand(SYS_DATA                      *psSysData,
                */
                psCmdCompleteData->bInUse = IMG_FALSE;
                eError = PVRSRV_ERROR_CMD_NOT_PROCESSED;
+               PVR_LOG(("Failed to submit command from queue processor, this could cause sync wedge!"));
+       }
+       else
+       {
+               /* Increment the CCB offset */
+               psDeviceCommandData[psCommand->CommandType].ui32CCBOffset = (ui32CCBOffset + 1) % DC_NUM_COMMANDS_PER_TYPE;
        }
-       
-       /* Increment the CCB offset */
-       psDeviceCommandData[psCommand->CommandType].ui32CCBOffset = (ui32CCBOffset + 1) % DC_NUM_COMMANDS_PER_TYPE;
 
        return eError;
 }
@@ -1147,9 +1233,9 @@ PVRSRV_ERROR PVRSRVProcessQueues(IMG_BOOL bFlush)
 
        while (psQueue)
        {
-               while (psQueue->ui32ReadOffset != psQueue->ui32WriteOffset)
+               while (psQueue->uReadOffset != psQueue->uWriteOffset)
                {
-                       psCommand = (PVRSRV_COMMAND*)((IMG_UINTPTR_T)psQueue->pvLinQueueKM + psQueue->ui32ReadOffset);
+                       psCommand = (PVRSRV_COMMAND*)((IMG_UINTPTR_T)psQueue->pvLinQueueKM + psQueue->uReadOffset);
 
                        if (PVRSRVProcessCommand(psSysData, psCommand, bFlush) == PVRSRV_OK)
                        {
@@ -1181,7 +1267,7 @@ PVRSRV_ERROR PVRSRVProcessQueues(IMG_BOOL bFlush)
 /*!
 ******************************************************************************
 
- @Function     PVRSRVCommandCompleteKM
+ @Function     PVRSRVFreeCommandCompletePacketKM
 
  @Description  Updates non-private command complete sync objects
 
@@ -1285,6 +1371,14 @@ IMG_VOID PVRSRVCommandCompleteKM(IMG_HANDLE      hCmdCookie,
                psCmdCompleteData->pfnCommandComplete(psCmdCompleteData->hCallbackData);
        }
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       if(psCmdCompleteData->pvTimeline)
+       {
+               sw_sync_timeline_inc(psCmdCompleteData->pvTimeline, 1);
+               sync_fence_put(psCmdCompleteData->pvCleanupFence);
+       }
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+
        /* free command complete storage */
        psCmdCompleteData->bInUse = IMG_FALSE;
 
@@ -1298,8 +1392,6 @@ IMG_VOID PVRSRVCommandCompleteKM(IMG_HANDLE       hCmdCookie,
 }
 
 
-
-
 /*!
 ******************************************************************************
 
index a2a13ab..0370c4f 100644 (file)
@@ -734,7 +734,7 @@ _InsertResourceSpan (RA_ARENA *pArena, IMG_UINTPTR_T base, IMG_SIZE_T uSize)
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "RA_InsertResourceSpan: arena='%s', base=0x%x, size=0x%x",
+                         "RA_InsertResourceSpan: arena='%s', base=0x" UINTPTR_FMT ", size=0x%" SIZE_T_FMT_LEN "x",
                          pArena->name, base, uSize));
 
        pSpanStart = _BuildSpanMarker (base, uSize);
@@ -1002,9 +1002,13 @@ _AttemptAllocAligned (RA_ARENA *pArena,
                                else
                                        aligned_base = pBT->base;
                                PVR_DPF ((PVR_DBG_MESSAGE,
-                                                 "RA_AttemptAllocAligned: pBT-base=0x%x "
-                                                 "pBT-size=0x%x alignedbase=0x%x size=0x%x",
-                                               pBT->base, pBT->uSize, aligned_base, uSize));
+                                                 "RA_AttemptAllocAligned: pBT-base=0x" UINTPTR_FMT " "
+                                                 "pBT-size=0x%" SIZE_T_FMT_LEN "x alignedbase=0x" 
+                                                 UINTPTR_FMT " size=0x%" SIZE_T_FMT_LEN "x",
+                                               pBT->base, 
+                        pBT->uSize, 
+                        aligned_base, 
+                        uSize));
 
                                if (pBT->base + pBT->uSize >= aligned_base + uSize)
                                {
@@ -1148,8 +1152,8 @@ RA_Create (IMG_CHAR *name,
        IMG_INT i;
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "RA_Create: name='%s', base=0x%x, uSize=0x%x, alloc=0x%x, free=0x%x",
-                         name, base, uSize, (IMG_UINTPTR_T)imp_alloc, (IMG_UINTPTR_T)imp_free));
+                         "RA_Create: name='%s', base=0x" UINTPTR_FMT ", uSize=0x%" SIZE_T_FMT_LEN "x, alloc=0x%p, free=0x%p",
+                         name, base, uSize, imp_alloc, imp_free));
 
 
        if (OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
@@ -1293,7 +1297,7 @@ RA_Delete (RA_ARENA *pArena)
                {
                        PVR_DPF ((PVR_DBG_ERROR,"RA_Delete: allocations still exist in the arena that is being destroyed"));
                        PVR_DPF ((PVR_DBG_ERROR,"Likely Cause: client drivers not freeing alocations before destroying devmemcontext"));
-                       PVR_DPF ((PVR_DBG_ERROR,"RA_Delete: base = 0x%x size=0x%x", pBT->base, pBT->uSize));
+                       PVR_DPF ((PVR_DBG_ERROR,"RA_Delete: base = 0x" UINTPTR_FMT " size=0x%" SIZE_T_FMT_LEN "x", pBT->base, pBT->uSize));
                }
 
                _SegmentListRemove (pArena, pBT);
@@ -1349,7 +1353,7 @@ RA_TestDelete (RA_ARENA *pArena)
                        if (pBT->type != btt_free)
                        {
                                PVR_DPF ((PVR_DBG_ERROR,"RA_TestDelete: detected resource leak!"));
-                               PVR_DPF ((PVR_DBG_ERROR,"RA_TestDelete: base = 0x%x size=0x%x", pBT->base, pBT->uSize));
+                               PVR_DPF ((PVR_DBG_ERROR,"RA_TestDelete: base = 0x" UINTPTR_FMT " size=0x%" SIZE_T_FMT_LEN "x", pBT->base, pBT->uSize));
                                return IMG_FALSE;
                        }
                }
@@ -1384,7 +1388,7 @@ RA_Add (RA_ARENA *pArena, IMG_UINTPTR_T base, IMG_SIZE_T uSize)
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "RA_Add: name='%s', base=0x%x, size=0x%x", pArena->name, base, uSize));
+                         "RA_Add: name='%s', base=0x" UINTPTR_FMT ", size=0x%" SIZE_T_FMT_LEN "x", pArena->name, base, uSize));
 
        uSize = (uSize + pArena->uQuantum - 1) / pArena->uQuantum * pArena->uQuantum;
        return ((IMG_BOOL)(_InsertResource (pArena, base, uSize) != IMG_NULL));
@@ -1450,7 +1454,7 @@ RA_Alloc (RA_ARENA *pArena,
        }
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "RA_Alloc: arena='%s', size=0x%x(0x%x), alignment=0x%x, offset=0x%x",
+                         "RA_Alloc: arena='%s', size=0x%" SIZE_T_FMT_LEN "x(0x%" SIZE_T_FMT_LEN "x), alignment=0x%x, offset=0x%x",
                   pArena->name, uSize, uRequestSize, uAlignment, uAlignmentOffset));
 
        /* if allocation failed then we might have an import source which
@@ -1493,7 +1497,7 @@ RA_Alloc (RA_ARENA *pArena,
                                pArena->pImportFree(pArena->pImportHandle, import_base,
                                                                        psImportMapping);
                                PVR_DPF ((PVR_DBG_MESSAGE,
-                                                 "RA_Alloc: name='%s', size=0x%x failed!",
+                                                 "RA_Alloc: name='%s', size=0x%" SIZE_T_FMT_LEN "x failed!",
                                                  pArena->name, uSize));
                                /* RA_Dump (arena); */
                                return IMG_FALSE;
@@ -1522,7 +1526,7 @@ RA_Alloc (RA_ARENA *pArena,
 #endif
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "RA_Alloc: name='%s', size=0x%x, *base=0x%x = %d",
+                         "RA_Alloc: name='%s', size=0x%" SIZE_T_FMT_LEN "x, *base=0x" UINTPTR_FMT " = %d",
                          pArena->name, uSize, *base, bResult));
 
        /*  RA_Dump (pArena);
@@ -1582,8 +1586,14 @@ IMG_UINT32 ValidateArena(RA_ARENA *pArena)
                                                  (eNextSpan == IMPORTED_RESOURCE_SPAN_END)))
                                        {
                                                /* error - next span must be live, free or end */
-                                               PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                               PVR_DPF((PVR_DBG_ERROR, 
+                                                               "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT 
+                                                               ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                                PVR_DBG_BREAK;
                                        }
@@ -1595,8 +1605,14 @@ IMG_UINT32 ValidateArena(RA_ARENA *pArena)
                                                  (eNextSpan == IMPORTED_RESOURCE_SPAN_END)))
                                        {
                                                /* error - next span must be live or end */
-                                               PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                               PVR_DPF((PVR_DBG_ERROR, 
+                                                               "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT
+                                                               ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                                PVR_DBG_BREAK;
                                        }
@@ -1609,8 +1625,14 @@ IMG_UINT32 ValidateArena(RA_ARENA *pArena)
                                                (eNextSpan == IMPORTED_RESOURCE_SPAN_END))
                                        {
                                                /* error - next span cannot be live, free or end */
-                                               PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                               PVR_DPF((PVR_DBG_ERROR, 
+                                                               "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT
+                                                               ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                                PVR_DBG_BREAK;
                                        }
@@ -1623,16 +1645,28 @@ IMG_UINT32 ValidateArena(RA_ARENA *pArena)
                                                  (eNextSpan == IMPORTED_RESOURCE_SPAN_FREE)))
                                        {
                                                /* error - next span must be live or free */
-                                               PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                               PVR_DPF((PVR_DBG_ERROR, 
+                                                               "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT 
+                                                               ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                                PVR_DBG_BREAK;
                                        }
                                break;
 
                                default:
-                                       PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                       PVR_DPF((PVR_DBG_ERROR, 
+                                                       "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT 
+                                                       ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                       pSegment->ui32BoundaryTagID, 
+                                                       pSegment->base, 
+                                                       pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                       pSegment->pNextSegment->base, 
+                                                       pArena->name));
 
                                        PVR_DBG_BREAK;
                                break;
@@ -1656,8 +1690,14 @@ IMG_UINT32 ValidateArena(RA_ARENA *pArena)
                                                  (eNextSpan == RESOURCE_SPAN_LIVE)))
                                        {
                                                /* error - next span must be free or live */
-                                               PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                               PVR_DPF((PVR_DBG_ERROR, 
+                                                               "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT 
+                                                               ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                                PVR_DBG_BREAK;
                                        }
@@ -1669,16 +1709,28 @@ IMG_UINT32 ValidateArena(RA_ARENA *pArena)
                                                  (eNextSpan == RESOURCE_SPAN_LIVE)))
                                        {
                                                /* error - next span must be free or live */
-                                               PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                               PVR_DPF((PVR_DBG_ERROR, 
+                                                               "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT 
+                                                               ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                                PVR_DBG_BREAK;
                                        }
                                break;
 
                                default:
-                                       PVR_DPF((PVR_DBG_ERROR, "ValidateArena ERROR: adjacent boundary tags %d (base=0x%x) and %d (base=0x%x) are incompatible (arena: %s)",
-                                                               pSegment->ui32BoundaryTagID, pSegment->base, pSegment->pNextSegment->ui32BoundaryTagID, pSegment->pNextSegment->base, pArena->name));
+                                       PVR_DPF((PVR_DBG_ERROR, 
+                                                       "ValidateArena ERROR: adjacent boundary tags %d (base=0x" UINTPTR_FMT 
+                                                       ") and %d (base=0x" UINTPTR_FMT ") are incompatible (arena: %s)",
+                                                               pSegment->ui32BoundaryTagID, 
+                                                               pSegment->base, 
+                                                               pSegment->pNextSegment->ui32BoundaryTagID, 
+                                                               pSegment->pNextSegment->base, 
+                                                               pArena->name));
 
                                        PVR_DBG_BREAK;
                                break;
@@ -1730,7 +1782,7 @@ RA_Free (RA_ARENA *pArena, IMG_UINTPTR_T base, IMG_BOOL bFreeBackingStore)
 #endif
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                         "RA_Free: name='%s', base=0x%x", pArena->name, base));
+                         "RA_Free: name='%s', base=0x" UINTPTR_FMT, pArena->name, base));
 
        pBT = (BT *) HASH_Remove (pArena->pSegmentHash, base);
        PVR_ASSERT (pBT != IMG_NULL);
@@ -1763,7 +1815,11 @@ RA_Free (RA_ARENA *pArena, IMG_UINTPTR_T base, IMG_BOOL bFreeBackingStore)
        {
                *p++ = 0xAA;
        }
-       PVR_DPF((PVR_DBG_MESSAGE,"BM_FREESPACE_CHECK: RA_Free Cleared %08X to %08X (size=0x%x)",(IMG_BYTE*)pBT->base + SysGetDevicePhysOffset(),endp-1,pBT->uSize));
+       PVR_DPF((PVR_DBG_MESSAGE,
+                       "BM_FREESPACE_CHECK: RA_Free Cleared %p to %p (size=0x%" SIZE_T_FMT_LEN "x)",
+                       (IMG_BYTE*)pBT->base + SysGetDevicePhysOffset(),
+                       endp - 1,
+                       pBT->uSize));
 }
 #endif
                _FreeBT (pArena, pBT, bFreeBackingStore);
@@ -1894,7 +1950,7 @@ RA_Dump (RA_ARENA *pArena)
        BT *pBT;
        PVR_ASSERT (pArena != IMG_NULL);
        PVR_DPF ((PVR_DBG_MESSAGE,"Arena '%s':", pArena->name));
-       PVR_DPF ((PVR_DBG_MESSAGE,"  alloc=%08X free=%08X handle=%08X quantum=%d",
+       PVR_DPF ((PVR_DBG_MESSAGE,"  alloc=%p free=%p handle=%p quantum=%d",
                         pArena->pImportAlloc, pArena->pImportFree, pArena->pImportHandle,
                         pArena->uQuantum));
        PVR_DPF ((PVR_DBG_MESSAGE,"  segment Chain:"));
@@ -1907,8 +1963,8 @@ RA_Dump (RA_ARENA *pArena)
 
        for (pBT=pArena->pHeadSegment; pBT!=IMG_NULL; pBT=pBT->pNextSegment)
        {
-               PVR_DPF ((PVR_DBG_MESSAGE,"\tbase=0x%x size=0x%x type=%s",
-                                (IMG_UINT32) pBT->base, pBT->uSize, _BTType (pBT->type)));
+               PVR_DPF ((PVR_DBG_MESSAGE,"\tbase=0x" UINTPTR_FMT " size=0x%" SIZE_T_FMT_LEN "x type=%s",
+                                pBT->base, pBT->uSize, _BTType (pBT->type)));
        }
 
 #ifdef HASH_TRACE
@@ -1925,42 +1981,42 @@ static void RA_ProcSeqShowInfo(struct seq_file *sfile, void* el)
 {
        PVR_PROC_SEQ_HANDLERS *handlers = (PVR_PROC_SEQ_HANDLERS*)sfile->private;
        RA_ARENA *pArena = (RA_ARENA *)handlers->data;
-       IMG_INT off = (IMG_INT)el;
+       IMG_UINTPTR_T off = (IMG_UINTPTR_T)el;
 
        switch (off)
        {
        case 1:
-               seq_printf(sfile, "quantum\t\t\t%u\n", pArena->uQuantum);
+               seq_printf(sfile, "quantum\t\t\t%" SIZE_T_FMT_LEN "u\n", pArena->uQuantum);
                break;
        case 2:
-               seq_printf(sfile, "import_handle\t\t%08X\n", (IMG_UINT)pArena->pImportHandle);
+               seq_printf(sfile, "import_handle\t\t%p\n", pArena->pImportHandle);
                break;
 #ifdef RA_STATS
        case 3:
-               seq_printf(sfile,"span count\t\t%u\n", pArena->sStatistics.uSpanCount);
+               seq_printf(sfile,"span count\t\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uSpanCount);
                break;
        case 4:
-               seq_printf(sfile, "live segment count\t%u\n", pArena->sStatistics.uLiveSegmentCount);
+               seq_printf(sfile, "live segment count\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uLiveSegmentCount);
                break;
        case 5:
-               seq_printf(sfile, "free segment count\t%u\n", pArena->sStatistics.uFreeSegmentCount);
+               seq_printf(sfile, "free segment count\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uFreeSegmentCount);
                break;
        case 6:
-               seq_printf(sfile, "free resource count\t%u (0x%x)\n",
+               seq_printf(sfile, "free resource count\t%" SIZE_T_FMT_LEN "u (0x%" SIZE_T_FMT_LEN "x)\n",
                                                        pArena->sStatistics.uFreeResourceCount,
-                                                       (IMG_UINT)pArena->sStatistics.uFreeResourceCount);
+                                                       pArena->sStatistics.uFreeResourceCount);
                break;
        case 7:
-               seq_printf(sfile, "total allocs\t\t%u\n", pArena->sStatistics.uCumulativeAllocs);
+               seq_printf(sfile, "total allocs\t\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uCumulativeAllocs);
                break;
        case 8:
-               seq_printf(sfile, "total frees\t\t%u\n", pArena->sStatistics.uCumulativeFrees);
+               seq_printf(sfile, "total frees\t\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uCumulativeFrees);
                break;
        case 9:
-               seq_printf(sfile, "import count\t\t%u\n", pArena->sStatistics.uImportCount);
+               seq_printf(sfile, "import count\t\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uImportCount);
                break;
        case 10:
-               seq_printf(sfile, "export count\t\t%u\n", pArena->sStatistics.uExportCount);
+               seq_printf(sfile, "export count\t\t%" SIZE_T_FMT_LEN "u\n", pArena->sStatistics.uExportCount);
                break;
 #endif
        }
@@ -1974,7 +2030,7 @@ static void* RA_ProcSeqOff2ElementInfo(struct seq_file * sfile, loff_t off)
 #else
        if(off <= 1)
 #endif
-               return (void*)(IMG_INT)(off+1);
+               return (void*)(IMG_UINTPTR_T)(off+1);
        return 0;
 }
 
@@ -1992,9 +2048,9 @@ static void RA_ProcSeqShowRegs(struct seq_file *sfile, void* el)
 
        if (pBT)
        {
-               seq_printf(sfile, "%08x %8x %4s %08x\n",
-                                  (IMG_UINT)pBT->base, (IMG_UINT)pBT->uSize, _BTType (pBT->type),
-                              (IMG_UINT)pBT->psMapping);
+               seq_printf(sfile, "%p %" SIZE_T_FMT_LEN "x %4s %p\n",
+                                  (IMG_PVOID)pBT->base, pBT->uSize, _BTType (pBT->type),
+                              pBT->psMapping);
        }
 }
 
@@ -2043,7 +2099,7 @@ PVRSRV_ERROR RA_GetStats(RA_ARENA *pArena,
 
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "  allocCB=%p freeCB=%p handle=%p quantum=%d\n",
+       i32Count = OSSNPrintf(pszStr, 100, "  allocCB=%p freeCB=%p handle=%p quantum=%" SIZE_T_FMT_LEN "u\n",
                                                         pArena->pImportAlloc,
                                                         pArena->pImportFree,
                                                         pArena->pImportHandle,
@@ -2051,37 +2107,44 @@ PVRSRV_ERROR RA_GetStats(RA_ARENA *pArena,
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "span count\t\t%u\n", pArena->sStatistics.uSpanCount);
+       i32Count = OSSNPrintf(pszStr, 100, "span count\t\t%" SIZE_T_FMT_LEN "u\n", 
+                             pArena->sStatistics.uSpanCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "live segment count\t%u\n", pArena->sStatistics.uLiveSegmentCount);
+       i32Count = OSSNPrintf(pszStr, 100, "live segment count\t%" SIZE_T_FMT_LEN "u\n", 
+                             pArena->sStatistics.uLiveSegmentCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "free segment count\t%u\n", pArena->sStatistics.uFreeSegmentCount);
+       i32Count = OSSNPrintf(pszStr, 100, "free segment count\t%" SIZE_T_FMT_LEN "u\n", 
+                             pArena->sStatistics.uFreeSegmentCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "free resource count\t%u (0x%x)\n",
+       i32Count = OSSNPrintf(pszStr, 100, "free resource count\t%" SIZE_T_FMT_LEN "u (0x%" SIZE_T_FMT_LEN "x)\n",
                                                        pArena->sStatistics.uFreeResourceCount,
-                                                       (IMG_UINT)pArena->sStatistics.uFreeResourceCount);
+                                                       pArena->sStatistics.uFreeResourceCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "total allocs\t\t%u\n", pArena->sStatistics.uCumulativeAllocs);
+       i32Count = OSSNPrintf(pszStr, 100, "total allocs\t\t%" SIZE_T_FMT_LEN "u\n", 
+                            pArena->sStatistics.uCumulativeAllocs);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "total frees\t\t%u\n", pArena->sStatistics.uCumulativeFrees);
+       i32Count = OSSNPrintf(pszStr, 100, "total frees\t\t%" SIZE_T_FMT_LEN "u\n", 
+                            pArena->sStatistics.uCumulativeFrees);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "import count\t\t%u\n", pArena->sStatistics.uImportCount);
+       i32Count = OSSNPrintf(pszStr, 100, "import count\t\t%" SIZE_T_FMT_LEN "u\n", 
+                            pArena->sStatistics.uImportCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "export count\t\t%u\n", pArena->sStatistics.uExportCount);
+       i32Count = OSSNPrintf(pszStr, 100, "export count\t\t%" SIZE_T_FMT_LEN "u\n", 
+                            pArena->sStatistics.uExportCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
 
        CHECK_SPACE(ui32StrLen);
@@ -2107,8 +2170,8 @@ PVRSRV_ERROR RA_GetStats(RA_ARENA *pArena,
        for (pBT=pArena->pHeadSegment; pBT!=IMG_NULL; pBT=pBT->pNextSegment)
        {
                CHECK_SPACE(ui32StrLen);
-               i32Count = OSSNPrintf(pszStr, 100, "\tbase=0x%x size=0x%x type=%s ref=%p\n",
-                                                                                        (IMG_UINT32) pBT->base,
+               i32Count = OSSNPrintf(pszStr, 100, "\tbase=0x%p size=0x%" SIZE_T_FMT_LEN "x type=%s ref=%p\n",
+                                                                                        (void *)pBT->base,
                                                                                         pBT->uSize,
                                                                                         _BTType(pBT->type),
                                                                                         pBT->psMapping);
@@ -2129,7 +2192,7 @@ PVRSRV_ERROR RA_GetStatsFreeMem(RA_ARENA *pArena,
        IMG_UINT32      ui32StrLen = *pui32StrLen;
        IMG_INT32       i32Count;
        CHECK_SPACE(ui32StrLen);
-       i32Count = OSSNPrintf(pszStr, 100, "Bytes free: Arena %-30s: %u (0x%x)\n", pArena->name,
+       i32Count = OSSNPrintf(pszStr, 100, "Bytes free: Arena %-30s: %" SIZE_T_FMT_LEN "u (0x%" SIZE_T_FMT_LEN "x)\n", pArena->name,
                pArena->sStatistics.uFreeResourceCount,
                pArena->sStatistics.uFreeResourceCount);
        UPDATE_SPACE(pszStr, i32Count, ui32StrLen);
index fa64b23..a6dcb19 100644 (file)
@@ -71,9 +71,11 @@ static DEFINE_SPINLOCK(gsCCBLock);
 #if defined(__linux__)
 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP         (1U << 16)
 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2                (1U << 17)
+#define PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC     (1U << 18)
 #else
 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP         0
 #define PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2                0
+#define PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC     0
 #endif
 
 #define PVRSRV_REFCOUNT_CCB_DEBUG_ALL          ~0U
@@ -81,6 +83,9 @@ static DEFINE_SPINLOCK(gsCCBLock);
 /*static const IMG_UINT guiDebugMask = PVRSRV_REFCOUNT_CCB_DEBUG_ALL;*/
 static const IMG_UINT guiDebugMask =
        PVRSRV_REFCOUNT_CCB_DEBUG_SYNCINFO |
+#if defined(SUPPORT_ION)
+       PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC |
+#endif
        PVRSRV_REFCOUNT_CCB_DEBUG_MMAP2;
 
 typedef struct
@@ -120,7 +125,7 @@ void PVRSRVDumpRefCountCCB(void)
 
                /* Early on, we won't have MAX_REFCOUNT_CCB_SIZE messages */
                if(!psRefCountCCBEntry->pszFile)
-                       break;
+                       continue;
 
                PVR_LOG(("%s %d %s:%d", psRefCountCCBEntry->pcMesg,
                                                                psRefCountCCBEntry->ui32PID,
@@ -477,7 +482,7 @@ void PVRSRVOffsetStructIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
                         psOffsetStruct,
                         psOffsetStruct->ui32RefCount,
                         psOffsetStruct->ui32RefCount + 1,
-                        psOffsetStruct->ui32RealByteSize);
+                        psOffsetStruct->uiRealByteSize);
        gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
        giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
 
@@ -509,7 +514,7 @@ void PVRSRVOffsetStructDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
                         psOffsetStruct,
                         psOffsetStruct->ui32RefCount,
                         psOffsetStruct->ui32RefCount - 1,
-                        psOffsetStruct->ui32RealByteSize);
+                        psOffsetStruct->uiRealByteSize);
        gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
        giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
 
@@ -541,7 +546,7 @@ void PVRSRVOffsetStructIncMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
                         psOffsetStruct,
                         psOffsetStruct->ui32Mapped,
                         psOffsetStruct->ui32Mapped + 1,
-                        psOffsetStruct->ui32RealByteSize);
+                        psOffsetStruct->uiRealByteSize);
        gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
        giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
 
@@ -573,7 +578,7 @@ void PVRSRVOffsetStructDecMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
                         psOffsetStruct,
                         psOffsetStruct->ui32Mapped,
                         psOffsetStruct->ui32Mapped - 1,
-                        psOffsetStruct->ui32RealByteSize);
+                        psOffsetStruct->uiRealByteSize);
        gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
        giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
 
@@ -583,6 +588,88 @@ skip:
        psOffsetStruct->ui32Mapped--;
 }
 
+#if defined(SUPPORT_ION)
+PVRSRV_ERROR PVRSRVIonBufferSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
+                                                                                       IMG_HANDLE hUnique,
+                                                                                       IMG_HANDLE hDevCookie,
+                                                                                       IMG_HANDLE hDevMemContext,
+                                                                                       PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo,
+                                                                                       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
+{
+       PVRSRV_ERROR eError;
+
+       /*
+               We have to do the call 1st as we need to Ion syninfo which it returns
+       */
+       eError = PVRSRVIonBufferSyncAcquire(hUnique,
+                                                                               hDevCookie,
+                                                                               hDevMemContext,
+                                                                               ppsIonSyncInfo);
+
+       if (eError == PVRSRV_OK)
+       {
+               if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC))
+                       goto skip;
+
+               PVRSRV_LOCK_CCB();
+
+               gsRefCountCCB[giOffset].pszFile = pszFile;
+               gsRefCountCCB[giOffset].iLine = iLine;
+               gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
+               snprintf(gsRefCountCCB[giOffset].pcMesg,
+                                PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
+                                PVRSRV_REFCOUNT_CCB_FMT_STRING,
+                                "ION_SYNC",
+                                (*ppsIonSyncInfo)->psSyncInfo,
+                                psKernelMemInfo,
+                                NULL,
+                                *ppsIonSyncInfo,
+                                (*ppsIonSyncInfo)->ui32RefCount - 1,
+                                (*ppsIonSyncInfo)->ui32RefCount,
+                                0);
+               gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
+               giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
+
+               PVRSRV_UNLOCK_CCB();
+       }
+
+skip:
+       return eError;
+}
+
+void PVRSRVIonBufferSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
+                                                                       PVRSRV_ION_SYNC_INFO *psIonSyncInfo,
+                                                                       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
+{
+       if(!(guiDebugMask & PVRSRV_REFCOUNT_CCB_DEBUG_ION_SYNC))
+               goto skip;
+
+       PVRSRV_LOCK_CCB();
+
+       gsRefCountCCB[giOffset].pszFile = pszFile;
+       gsRefCountCCB[giOffset].iLine = iLine;
+       gsRefCountCCB[giOffset].ui32PID = OSGetCurrentProcessIDKM();
+       snprintf(gsRefCountCCB[giOffset].pcMesg,
+                        PVRSRV_REFCOUNT_CCB_MESG_MAX - 1,
+                        PVRSRV_REFCOUNT_CCB_FMT_STRING,
+                        "ION_SYNC",
+                        psIonSyncInfo->psSyncInfo,
+                        psKernelMemInfo,
+                        NULL,
+                        psIonSyncInfo,
+                        psIonSyncInfo->ui32RefCount,
+                        psIonSyncInfo->ui32RefCount - 1,
+                        0);
+       gsRefCountCCB[giOffset].pcMesg[PVRSRV_REFCOUNT_CCB_MESG_MAX - 1] = 0;
+       giOffset = (giOffset + 1) % PVRSRV_REFCOUNT_CCB_MAX;
+
+       PVRSRV_UNLOCK_CCB();
+skip:
+       PVRSRVIonBufferSyncRelease(psIonSyncInfo);
+}
+
+#endif /* defined (SUPPORT_ION) */
+
 #endif /* defined(__linux__) */
 
 #endif /* defined(PVRSRV_REFCOUNT_DEBUG) */
index aef102f..1bb3ebf 100644 (file)
@@ -359,11 +359,12 @@ IMG_VOID PVRSRVResManDisconnect(PRESMAN_CONTEXT psResManContext,
                FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DEVICEMEM_MAPPING, 0, 0, IMG_TRUE);
                FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_KERNEL_DEVICEMEM_ALLOCATION, 0, 0, IMG_TRUE);
                FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DEVICEMEM_ALLOCATION, 0, 0, IMG_TRUE);
-               FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DEVICEMEM_CONTEXT, 0, 0, IMG_TRUE);
-               FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_SHARED_MEM_INFO, 0, 0, IMG_TRUE);
 #if defined(SUPPORT_ION)
                FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DEVICEMEM_ION, 0, 0, IMG_TRUE);
 #endif
+               FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DEVICEMEM_CONTEXT, 0, 0, IMG_TRUE);
+               FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_SHARED_MEM_INFO, 0, 0, IMG_TRUE);
+
                /* DISPLAY CLASS types: */
                FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DISPLAYCLASS_SWAPCHAIN_REF, 0, 0, IMG_TRUE);
                FreeResourceByCriteria(psResManContext, RESMAN_CRITERIA_RESTYPE, RESMAN_TYPE_DISPLAYCLASS_DEVICE, 0, 0, IMG_TRUE);
@@ -436,13 +437,13 @@ PRESMAN_ITEM ResManRegisterRes(PRESMAN_CONTEXT    psResManContext,
        VALIDATERESLIST();
 
        PVR_DPF((PVR_DBG_MESSAGE, "ResManRegisterRes: register resource "
-                       "Context 0x%x, ResType 0x%x, pvParam 0x%x, ui32Param 0x%x, "
-                       "FreeFunc %08X",
-                       (IMG_UINTPTR_T)psResManContext,
+                       "Context 0x%p, ResType 0x%x, pvParam 0x%p, ui32Param 0x%x, "
+                       "FreeFunc %p",
+                       psResManContext,
                        ui32ResType,
-                       (IMG_UINTPTR_T)pvParam,
+                       pvParam,
                        ui32Param,
-                       (IMG_UINTPTR_T)pfnFreeResource));
+                       pfnFreeResource));
 
        /* Allocate memory for the new resource structure */
        if (OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
@@ -504,8 +505,8 @@ PVRSRV_ERROR ResManFreeResByPtr(RESMAN_ITEM *psResItem, IMG_BOOL bForceCleanup)
                return PVRSRV_OK;
        }
 
-       PVR_DPF((PVR_DBG_MESSAGE, "ResManFreeResByPtr: freeing resource at %08X",
-                       (IMG_UINTPTR_T)psResItem));
+       PVR_DPF((PVR_DBG_MESSAGE, "ResManFreeResByPtr: freeing resource at %p",
+                       psResItem));
 
        /*Acquire resource list sync object*/
        ACQUIRE_SYNC_OBJ;
@@ -558,9 +559,9 @@ PVRSRV_ERROR ResManFreeResByCriteria(PRESMAN_CONTEXT        psResManContext,
        VALIDATERESLIST();
 
        PVR_DPF((PVR_DBG_MESSAGE, "ResManFreeResByCriteria: "
-                       "Context 0x%x, Criteria 0x%x, Type 0x%x, Addr 0x%x, Param 0x%x",
-                       (IMG_UINTPTR_T)psResManContext, ui32SearchCriteria, ui32ResType,
-                       (IMG_UINTPTR_T)pvParam, ui32Param));
+                       "Context 0x%p, Criteria 0x%x, Type 0x%x, Addr 0x%p, Param 0x%x",
+                       psResManContext, ui32SearchCriteria, ui32ResType,
+                       pvParam, ui32Param));
 
        /* Free resources by criteria for this context */
        eError = FreeResourceByCriteria(psResManContext, ui32SearchCriteria,
@@ -688,17 +689,17 @@ IMG_INTERNAL PVRSRV_ERROR ResManFindResourceByPtr(PRESMAN_CONTEXT psResManContex
        ACQUIRE_SYNC_OBJ;
 
        PVR_DPF((PVR_DBG_MESSAGE,
-                       "FindResourceByPtr: psItem=%08X, psItem->psNext=%08X",
-                       (IMG_UINTPTR_T)psItem, (IMG_UINTPTR_T)psItem->psNext));
+                       "FindResourceByPtr: psItem=%p, psItem->psNext=%p",
+                       psItem, psItem->psNext));
 
        PVR_DPF((PVR_DBG_MESSAGE,
-                       "FindResourceByPtr: Resource Ctx 0x%x, Type 0x%x, Addr 0x%x, "
-                       "Param 0x%x, FnCall %08X, Flags 0x%x",
-                       (IMG_UINTPTR_T)psResManContext,
+                       "FindResourceByPtr: Resource Ctx 0x%p, Type 0x%x, Addr 0x%p, "
+                       "Param 0x%x, FnCall %p, Flags 0x%x",
+                       psResManContext,
                        psItem->ui32ResType,
-                       (IMG_UINTPTR_T)psItem->pvParam,
+                       psItem->pvParam,
                        psItem->ui32Param,
-                       (IMG_UINTPTR_T)psItem->pfnFreeResource,
+                       psItem->pfnFreeResource,
                        psItem->ui32Flags));
 
        /* Search resource items starting at after the first dummy item */
@@ -754,15 +755,16 @@ static PVRSRV_ERROR FreeResourceByPtr(RESMAN_ITEM *psItem,
 #endif
 
        PVR_DPF((PVR_DBG_MESSAGE,
-                       "FreeResourceByPtr: psItem=%08X, psItem->psNext=%08X",
-                       (IMG_UINTPTR_T)psItem, (IMG_UINTPTR_T)psItem->psNext));
+                       "FreeResourceByPtr: psItem=%p, psItem->psNext=%p",
+                       psItem, psItem->psNext));
 
        PVR_DPF((PVR_DBG_MESSAGE,
-                       "FreeResourceByPtr: Type 0x%x, Addr 0x%x, "
-                       "Param 0x%x, FnCall %08X, Flags 0x%x",
+                       "FreeResourceByPtr: Type 0x%x, Addr 0x%p, "
+                       "Param 0x%x, FnCall %p, Flags 0x%x",
                        psItem->ui32ResType,
-                       (IMG_UINTPTR_T)psItem->pvParam, psItem->ui32Param,
-                       (IMG_UINTPTR_T)psItem->pfnFreeResource, psItem->ui32Flags));
+                       psItem->pvParam, 
+            psItem->ui32Param,
+                       psItem->pfnFreeResource, psItem->ui32Flags));
 
        /* Release resource list sync object just in case the free routine calls the resource manager */
        RELEASE_SYNC_OBJ;
@@ -941,11 +943,11 @@ static IMG_VOID ValidateResList(PRESMAN_LIST psResList)
                if (psCurContext->ppsThis != ppsThisContext)
                {
                        PVR_DPF((PVR_DBG_WARNING,
-                                       "psCC=%08X psCC->ppsThis=%08X psCC->psNext=%08X ppsTC=%08X",
-                                       (IMG_UINTPTR_T)psCurContext,
-                                       (IMG_UINTPTR_T)psCurContext->ppsThis,
-                                       (IMG_UINTPTR_T)psCurContext->psNext,
-                                       (IMG_UINTPTR_T)ppsThisContext));
+                                       "psCC=%p psCC->ppsThis=%p psCC->psNext=%p ppsTC=%p",
+                                       psCurContext,
+                                       psCurContext->ppsThis,
+                                       psCurContext->psNext,
+                                       ppsThisContext));
                        PVR_ASSERT(psCurContext->ppsThis == ppsThisContext);
                }
 
@@ -959,11 +961,11 @@ static IMG_VOID ValidateResList(PRESMAN_LIST psResList)
                        if (psCurItem->ppsThis != ppsThisItem)
                        {
                                PVR_DPF((PVR_DBG_WARNING,
-                                               "psCurItem=%08X psCurItem->ppsThis=%08X psCurItem->psNext=%08X ppsThisItem=%08X",
-                                               (IMG_UINTPTR_T)psCurItem,
-                                               (IMG_UINTPTR_T)psCurItem->ppsThis,
-                                               (IMG_UINTPTR_T)psCurItem->psNext,
-                                               (IMG_UINTPTR_T)ppsThisItem));
+                                               "psCurItem=%p psCurItem->ppsThis=%p psCurItem->psNext=%p ppsThisItem=%p",
+                                               psCurItem,
+                                               psCurItem->ppsThis,
+                                               psCurItem->psNext,
+                                               ppsThisItem));
                                PVR_ASSERT(psCurItem->ppsThis == ppsThisItem);
                        }
 
diff --git a/services4/srvkm/common/ttrace.c b/services4/srvkm/common/ttrace.c
new file mode 100644 (file)
index 0000000..2fb6364
--- /dev/null
@@ -0,0 +1,597 @@
+/*************************************************************************/ /*!
+@Title          Timed Trace functions
+@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.
+*/ /**************************************************************************/
+#if defined (TTRACE)
+
+#include "services_headers.h"
+#include "ttrace.h"
+
+#if defined(PVRSRV_NEED_PVR_DPF)
+#define CHECKSIZE(n,m) \
+       if ((n & m) != n) \
+               PVR_DPF((PVR_DBG_ERROR,"Size check failed for " #m))
+#else
+#define CHECKSIZE(n,m)
+#endif
+
+#define TIME_TRACE_HASH_TABLE_SIZE     32
+
+HASH_TABLE *g_psBufferTable;
+IMG_UINT32 g_ui32HostUID;
+IMG_HANDLE g_psTimer;
+
+/* Trace buffer struct */
+typedef struct
+{
+       IMG_UINT32      ui32Woff;       /* Offset to where next item will be written */
+       IMG_UINT32      ui32Roff;       /* Offset to where to start reading from */
+       IMG_UINT32      ui32ByteCount;  /* Number of bytes in buffer */
+       IMG_UINT8       ui8Data[0];
+} sTimeTraceBuffer;
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceItemSize
+
+ @Description
+
+ Calculate the size of a trace item
+
+ @Input psTraceItem :  Trace item
+
+ @Return size of trace item
+
+******************************************************************************/
+static IMG_UINT32
+PVRSRVTimeTraceItemSize(IMG_UINT32 *psTraceItem)
+{
+       IMG_UINT32 ui32Size = PVRSRV_TRACE_ITEM_SIZE;
+
+       ui32Size += READ_HEADER(SIZE, psTraceItem[PVRSRV_TRACE_DATA_HEADER]);
+
+       return ui32Size;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceAllocItem
+
+ @Description
+
+ Allocate a trace item from the buffer of the current process
+
+ @Output ppsTraceItem :        Pointer to allocated trace item
+
+ @Input ui32Size : Size of data packet to be allocated
+
+ @Return none
+
+******************************************************************************/
+static IMG_VOID
+PVRSRVTimeTraceAllocItem(IMG_UINT32 **pui32Item, IMG_UINT32 ui32Size)
+{
+       IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
+       IMG_UINT32 ui32AllocOffset;
+       sTimeTraceBuffer *psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
+
+       /* The caller only asks for extra data space */
+       ui32Size += PVRSRV_TRACE_ITEM_SIZE;
+
+       /* Always round to 32-bit */
+       ui32Size = ((ui32Size - 1) & (~0x3)) + 0x04;
+
+       if (!psBuffer)
+       {
+               PVRSRV_ERROR eError;
+
+               PVR_DPF((PVR_DBG_MESSAGE, "PVRSRVTimeTraceAllocItem: Creating buffer for PID %u", ui32PID));
+               eError = PVRSRVTimeTraceBufferCreate(ui32PID);
+               if (eError != PVRSRV_OK)
+               {
+                       *pui32Item = IMG_NULL;
+                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Failed to create buffer"));
+                       return;
+               }
+               
+               psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
+               if (psBuffer == IMG_NULL)
+               {
+                       *pui32Item = NULL;
+                       PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Failed to retrieve buffer"));
+                       return;
+               }
+       }
+
+       /* Can't allocate more then buffer size */
+       if (ui32Size >= TIME_TRACE_BUFFER_SIZE)
+       {
+               *pui32Item = NULL;
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Error trace item too large (%d)", ui32Size));
+               return;
+       }
+
+       /* FIXME: Enter critical section? */
+
+       /* Always ensure we have enough space to write a padding message */
+       if ((psBuffer->ui32Woff + ui32Size + PVRSRV_TRACE_ITEM_SIZE) > TIME_TRACE_BUFFER_SIZE)
+       {
+               IMG_UINT32 *ui32WriteEOB = (IMG_UINT32 *) &psBuffer->ui8Data[psBuffer->ui32Woff];
+               IMG_UINT32 ui32Remain = TIME_TRACE_BUFFER_SIZE - psBuffer->ui32Woff;
+
+               /* Not enough space at the end of the buffer, back to the start */
+               *ui32WriteEOB++ = WRITE_HEADER(GROUP, PVRSRV_TRACE_GROUP_PADDING);
+               *ui32WriteEOB++ = 0;            /* Don't need timestamp */
+               *ui32WriteEOB++ = 0;            /* Don't need UID */
+               *ui32WriteEOB = WRITE_HEADER(SIZE, (ui32Remain - PVRSRV_TRACE_ITEM_SIZE));
+               psBuffer->ui32ByteCount += ui32Remain;
+               psBuffer->ui32Woff = ui32AllocOffset = 0;
+       }
+       else
+               ui32AllocOffset = psBuffer->ui32Woff;
+
+       psBuffer->ui32Woff = psBuffer->ui32Woff + ui32Size;
+       psBuffer->ui32ByteCount += ui32Size;
+
+       /* This allocation will start overwriting past our read pointer, move the read pointer along */
+       while (psBuffer->ui32ByteCount > TIME_TRACE_BUFFER_SIZE)
+       {
+               IMG_UINT32 *psReadItem = (IMG_UINT32 *) &psBuffer->ui8Data[psBuffer->ui32Roff];
+               IMG_UINT32 ui32ReadSize;
+
+               ui32ReadSize = PVRSRVTimeTraceItemSize(psReadItem);
+               psBuffer->ui32Roff = (psBuffer->ui32Roff + ui32ReadSize) & (TIME_TRACE_BUFFER_SIZE - 1);
+               psBuffer->ui32ByteCount -= ui32ReadSize;
+       }
+
+       *pui32Item = (IMG_UINT32 *) &psBuffer->ui8Data[ui32AllocOffset];
+       /* FIXME: Exit critical section? */
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceBufferCreate
+
+ @Description
+
+ Create a trace buffer.
+
+ Note: We assume that this will only be called once per process.
+
+ @Input ui32PID : PID of the process that is creating the buffer
+
+ @Return none
+
+******************************************************************************/
+PVRSRV_ERROR PVRSRVTimeTraceBufferCreate(IMG_UINT32 ui32PID)
+{
+       sTimeTraceBuffer *psBuffer;
+       PVRSRV_ERROR eError = PVRSRV_OK;
+
+       eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT,
+                                       sizeof(sTimeTraceBuffer) + TIME_TRACE_BUFFER_SIZE,
+                                       (IMG_VOID **)&psBuffer, IMG_NULL,
+                                       "Time Trace Buffer");
+       if (eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceBufferCreate: Error allocating trace buffer"));
+               return eError;
+       }
+
+       OSMemSet(psBuffer, 0, TIME_TRACE_BUFFER_SIZE);
+
+       if (!HASH_Insert(g_psBufferTable, (IMG_UINTPTR_T) ui32PID, (IMG_UINTPTR_T) psBuffer))
+       {
+               OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(sTimeTraceBuffer) + TIME_TRACE_BUFFER_SIZE,
+                               psBuffer, NULL);
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceBufferCreate: Error adding trace buffer to hash table"));
+               return PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+
+       return eError;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceBufferDestroy
+
+ @Description
+
+ Destroy a trace buffer.
+
+ Note: We assume that this will only be called once per process.
+
+ @Input ui32PID : PID of the process that is creating the buffer
+
+ @Return none
+
+******************************************************************************/
+PVRSRV_ERROR PVRSRVTimeTraceBufferDestroy(IMG_UINT32 ui32PID)
+{
+       sTimeTraceBuffer *psBuffer;
+
+#if defined(DUMP_TTRACE_BUFFERS_ON_EXIT)
+       PVRSRVDumpTimeTraceBuffers();
+#endif
+       psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
+       if (psBuffer)
+       {
+               OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(sTimeTraceBuffer) + TIME_TRACE_BUFFER_SIZE,
+                               psBuffer, NULL);
+               HASH_Remove(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
+               return PVRSRV_OK;
+       }
+
+       PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceBufferDestroy: Can't find trace buffer in hash table"));
+       return PVRSRV_ERROR_INVALID_PARAMS;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceInit
+
+ @Description
+
+ Initialise the timed trace subsystem.
+
+ @Return Error
+
+******************************************************************************/
+PVRSRV_ERROR PVRSRVTimeTraceInit(IMG_VOID)
+{
+       g_psBufferTable = HASH_Create(TIME_TRACE_HASH_TABLE_SIZE);
+
+       /* Create hash table to store the per process buffers in */
+       if (!g_psBufferTable)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceInit: Error creating hash table"));
+               return PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+
+       /* Create the kernel buffer */
+       PVRSRVTimeTraceBufferCreate(KERNEL_ID);
+
+       g_psTimer = OSFuncHighResTimerCreate();
+
+       if (!g_psTimer)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceInit: Error creating timer"));
+               return PVRSRV_ERROR_INIT_FAILURE;
+       }
+       return PVRSRV_OK;
+}
+
+static PVRSRV_ERROR _PVRSRVTimeTraceBufferDestroy(IMG_UINTPTR_T hKey, IMG_UINTPTR_T hData)
+{
+       PVR_UNREFERENCED_PARAMETER(hData);
+       PVR_DPF((PVR_DBG_MESSAGE, "_PVRSRVTimeTraceBufferDestroy: Destroying buffer for PID %u", (IMG_UINT32) hKey));
+
+       PVRSRVTimeTraceBufferDestroy(hKey);
+       return PVRSRV_OK;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceDeinit
+
+ @Description
+
+  De-initialise the timed trace subsystem.
+
+ @Return Error
+
+******************************************************************************/
+IMG_VOID PVRSRVTimeTraceDeinit(IMG_VOID)
+{
+       PVRSRVTimeTraceBufferDestroy(KERNEL_ID);
+       /* Free any buffers the where created at alloc item time */
+       HASH_Iterate(g_psBufferTable, _PVRSRVTimeTraceBufferDestroy);
+       HASH_Delete(g_psBufferTable);
+       OSFuncHighResTimerDestroy(g_psTimer);
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceWriteHeader
+
+ @Description
+
+ Write the header for a trace item.
+
+ @Input pui32TraceItem : Pointer to trace item
+
+ @Input ui32Group : Trace item's group ID
+
+ @Input ui32Class : Trace item's class ID
+
+ @Input ui32Token : Trace item's ui32Token ID
+
+ @Input ui32Size : Trace item's data payload size
+
+ @Input ui32Type : Trace item's data type
+
+ @Input ui32Count : Trace item's data count
+
+ @Return Pointer to data payload space, or NULL if no data payload
+
+******************************************************************************/
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(PVRSRVTimeTraceWriteHeader)
+#endif
+static INLINE IMG_VOID *PVRSRVTimeTraceWriteHeader(IMG_UINT32 *pui32TraceItem, IMG_UINT32 ui32Group,
+                                                       IMG_UINT32 ui32Class, IMG_UINT32 ui32Token,
+                                                       IMG_UINT32 ui32Size, IMG_UINT32 ui32Type,
+                                                       IMG_UINT32 ui32Count)
+{
+       /* Sanity check arg's */
+       CHECKSIZE(ui32Group, PVRSRV_TRACE_GROUP_MASK);
+       CHECKSIZE(ui32Class, PVRSRV_TRACE_CLASS_MASK);
+       CHECKSIZE(ui32Token, PVRSRV_TRACE_TOKEN_MASK);
+
+       CHECKSIZE(ui32Size, PVRSRV_TRACE_SIZE_MASK);
+       CHECKSIZE(ui32Type, PVRSRV_TRACE_TYPE_MASK);
+       CHECKSIZE(ui32Count, PVRSRV_TRACE_COUNT_MASK);
+
+       /* Trace header */
+       pui32TraceItem[PVRSRV_TRACE_HEADER] = WRITE_HEADER(GROUP, ui32Group);
+       pui32TraceItem[PVRSRV_TRACE_HEADER] |= WRITE_HEADER(CLASS, ui32Class);
+       pui32TraceItem[PVRSRV_TRACE_HEADER] |= WRITE_HEADER(TOKEN, ui32Token);
+
+       /* Data header */
+       pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] = WRITE_HEADER(SIZE, ui32Size);
+       pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] |= WRITE_HEADER(TYPE, ui32Type);
+       pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] |= WRITE_HEADER(COUNT, ui32Count);
+
+       pui32TraceItem[PVRSRV_TRACE_TIMESTAMP] = OSFuncHighResTimerGetus(g_psTimer);
+       pui32TraceItem[PVRSRV_TRACE_HOSTUID] = g_ui32HostUID++;
+
+       return ui32Size?((IMG_VOID *) &pui32TraceItem[PVRSRV_TRACE_DATA_PAYLOAD]):NULL;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceArray
+
+ @Description
+
+ Write trace item with an array of data
+
+ @Input ui32Group : Trace item's group ID
+
+ @Input ui32Class : Trace item's class ID
+
+ @Input ui32Token : Trace item's ui32Token ID
+
+ @Input ui32Size : Trace item's data payload size
+
+ @Input ui32Type : Trace item's data type
+
+ @Input ui32Count : Trace item's data count
+
+ @Input pui8Data : Pointer to data array
+
+ @Return Pointer to data payload space, or NULL if no data payload
+
+******************************************************************************/
+IMG_VOID PVRSRVTimeTraceArray(IMG_UINT32 ui32Group, IMG_UINT32 ui32Class, IMG_UINT32 ui32Token,
+                               IMG_UINT32 ui32Type, IMG_UINT32 ui32Count, IMG_UINT8 *pui8Data)
+{
+       IMG_UINT32 *pui32TraceItem;
+       IMG_UINT32 ui32Size, ui32TypeSize;
+       IMG_UINT8 *ui8Ptr;
+
+       /* Only the 1st 4 sizes are for ui types, others are "special" */
+       switch (ui32Type)
+       {
+               case PVRSRV_TRACE_TYPE_UI8:     ui32TypeSize = 1;
+                                               break;
+               case PVRSRV_TRACE_TYPE_UI16:    ui32TypeSize = 2;
+                                               break;
+               case PVRSRV_TRACE_TYPE_UI32:    ui32TypeSize = 4;
+                                               break;
+               case PVRSRV_TRACE_TYPE_UI64:    ui32TypeSize = 8;
+                                               break;
+               default:
+                       PVR_DPF((PVR_DBG_ERROR, "Unsupported size\n"));
+                       return;
+       }
+
+       ui32Size = ui32TypeSize * ui32Count;
+
+       /* Allocate space from the buffer */
+       PVRSRVTimeTraceAllocItem(&pui32TraceItem, ui32Size);
+
+       if (!pui32TraceItem)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "Can't find buffer\n"));
+               return;
+       }
+
+       ui8Ptr = PVRSRVTimeTraceWriteHeader(pui32TraceItem, ui32Group, ui32Class, ui32Token,
+                                               ui32Size, ui32Type, ui32Count);
+
+       if (ui8Ptr)
+       {
+               OSMemCopy(ui8Ptr, pui8Data, ui32Size);
+       }
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVTimeTraceSyncObject
+
+ @Description
+
+ Write trace item with a sync object
+
+ @Input ui32Group : Trace item's group ID
+
+ @Input ui32Token : Trace item's ui32Token ID
+
+ @Input psSync : Sync object
+
+ @Input ui8SyncOpp : Sync object operation
+
+ @Return None
+
+******************************************************************************/
+IMG_VOID PVRSRVTimeTraceSyncObject(IMG_UINT32 ui32Group, IMG_UINT32 ui32Token,
+                                  PVRSRV_KERNEL_SYNC_INFO *psSync, IMG_UINT8 ui8SyncOp)
+{
+       IMG_UINT32 *pui32TraceItem;
+       IMG_UINT32 *ui32Ptr;
+       IMG_UINT32 ui32Size = PVRSRV_TRACE_TYPE_SYNC_SIZE;
+
+
+       PVRSRVTimeTraceAllocItem(&pui32TraceItem, ui32Size);
+
+       if (!pui32TraceItem)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "Can't find buffer\n"));
+               return;
+       }
+
+       ui32Ptr = PVRSRVTimeTraceWriteHeader(pui32TraceItem, ui32Group, PVRSRV_TRACE_CLASS_SYNC,
+                                               ui32Token, ui32Size, PVRSRV_TRACE_TYPE_SYNC, 1);
+
+       ui32Ptr[PVRSRV_TRACE_SYNC_UID] = psSync->ui32UID;
+       ui32Ptr[PVRSRV_TRACE_SYNC_WOP] = psSync->psSyncData->ui32WriteOpsPending;
+       ui32Ptr[PVRSRV_TRACE_SYNC_WOC] = psSync->psSyncData->ui32WriteOpsComplete;
+       ui32Ptr[PVRSRV_TRACE_SYNC_ROP] = psSync->psSyncData->ui32ReadOpsPending;
+       ui32Ptr[PVRSRV_TRACE_SYNC_ROC] = psSync->psSyncData->ui32ReadOpsComplete;
+       ui32Ptr[PVRSRV_TRACE_SYNC_RO2P] = psSync->psSyncData->ui32ReadOps2Pending;
+       ui32Ptr[PVRSRV_TRACE_SYNC_RO2C] = psSync->psSyncData->ui32ReadOps2Complete;
+       ui32Ptr[PVRSRV_TRACE_SYNC_WO_DEV_VADDR] = psSync->sWriteOpsCompleteDevVAddr.uiAddr;
+       ui32Ptr[PVRSRV_TRACE_SYNC_RO_DEV_VADDR] = psSync->sReadOpsCompleteDevVAddr.uiAddr;
+       ui32Ptr[PVRSRV_TRACE_SYNC_RO2_DEV_VADDR] = psSync->sReadOps2CompleteDevVAddr.uiAddr;
+       ui32Ptr[PVRSRV_TRACE_SYNC_OP] = ui8SyncOp;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVDumpTimeTraceBuffer
+
+ @Description
+
+ Dump the contents of the trace buffer.
+
+ @Input hKey : Trace item's group ID
+
+ @Input hData : Trace item's ui32Token ID
+
+ @Return Error
+
+******************************************************************************/
+static PVRSRV_ERROR PVRSRVDumpTimeTraceBuffer(IMG_UINTPTR_T hKey, IMG_UINTPTR_T hData)
+{
+       sTimeTraceBuffer *psBuffer = (sTimeTraceBuffer *) hData;
+       IMG_UINT32 ui32ByteCount = psBuffer->ui32ByteCount;
+       IMG_UINT32 ui32Walker = psBuffer->ui32Roff;
+       IMG_UINT32 ui32Read, ui32LineLen, ui32EOL, ui32MinLine;
+
+       PVR_DPF((PVR_DBG_ERROR, "TTB for PID %u:\n", (IMG_UINT32) hKey));
+
+       while (ui32ByteCount)
+       {
+               IMG_UINT32 *pui32Buffer = (IMG_UINT32 *) &psBuffer->ui8Data[ui32Walker];
+
+               ui32LineLen = (ui32ByteCount/sizeof(IMG_UINT32));
+               ui32EOL = (TIME_TRACE_BUFFER_SIZE - ui32Walker)/sizeof(IMG_UINT32);
+               ui32MinLine = (ui32LineLen < ui32EOL)?ui32LineLen:ui32EOL;
+
+               if (ui32MinLine >= 4)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X %08X %08X %08X", ui32ByteCount,
+                                       pui32Buffer[0], pui32Buffer[1], pui32Buffer[2], pui32Buffer[3]));
+                       ui32Read = 4 * sizeof(IMG_UINT32);
+               }
+               else if (ui32MinLine >= 3)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X %08X %08X", ui32ByteCount,
+                                       pui32Buffer[0], pui32Buffer[1], pui32Buffer[2]));
+                       ui32Read = 3 * sizeof(IMG_UINT32);
+               }
+               else if (ui32MinLine >= 2)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X %08X", ui32ByteCount,
+                                       pui32Buffer[0], pui32Buffer[1]));
+                       ui32Read = 2 * sizeof(IMG_UINT32);
+               }
+               else
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "\t(TTB-%X) %08X", ui32ByteCount,
+                                       pui32Buffer[0]));
+                       ui32Read = sizeof(IMG_UINT32);
+               }
+
+               ui32Walker = (ui32Walker + ui32Read) & (TIME_TRACE_BUFFER_SIZE - 1);
+               ui32ByteCount -= ui32Read;
+       }
+
+       return PVRSRV_OK;
+}
+
+/*!
+******************************************************************************
+
+ @Function     PVRSRVDumpTimeTraceBuffers
+
+ @Description
+
+ Dump the contents of all the trace buffers.
+
+ @Return None
+
+******************************************************************************/
+IMG_VOID PVRSRVDumpTimeTraceBuffers(IMG_VOID)
+{
+       HASH_Iterate(g_psBufferTable, PVRSRVDumpTimeTraceBuffer);
+}
+
+#endif /* TTRACE */
index 44dc824..e6944bf 100644 (file)
@@ -848,6 +848,15 @@ _AllocPageTableMemory (MMU_HEAP *pMMUHeap,
        }
        else
        {
+               /* 
+                  We cannot use IMG_SYS_PHYADDR here, as that is 64-bit for 32-bit PAE builds.
+                  The physical address in this call to RA_Alloc is specifically the SysPAddr 
+                  of local (card) space, and it is highly unlikely we would ever need to 
+                  support > 4GB of local (card) memory (this does assume that such local
+                  memory will be mapped into System physical memory space at a low address so
+                  that any and all local memory exists within the 4GB SYSPAddr range).
+                */
+               IMG_UINTPTR_T uiLocalPAddr;
                IMG_SYS_PHYADDR sSysPAddr;
 
                /*
@@ -864,12 +873,15 @@ _AllocPageTableMemory (MMU_HEAP *pMMUHeap,
                                        0,
                                        IMG_NULL,
                                        0,
-                                       &(sSysPAddr.uiAddr))!= IMG_TRUE)
+                                       &uiLocalPAddr)!= IMG_TRUE)
                {
                        PVR_DPF((PVR_DBG_ERROR, "_AllocPageTableMemory: ERROR call to RA_Alloc failed"));
                        return IMG_FALSE;
                }
 
+               /* Munge the local PAddr back into the SysPAddr */
+               sSysPAddr.uiAddr = uiLocalPAddr;
+
                /* derive the CPU virtual address */
                sCpuPAddr = SysSysPAddrToCpuPAddr(sSysPAddr);
                /* note: actual ammount is pMMUHeap->ui32PTSize but must be a multiple of 4k pages */
@@ -986,8 +998,9 @@ _FreePageTableMemory (MMU_HEAP *pMMUHeap, MMU_PT_INFO *psPTInfoList)
                /*
                        just free from the first local memory arena
                        (unlikely to be more than one local mem area(?))
+                       Note that the cast to IMG_UINTPTR_T is ok as we're local mem.
                */
-               RA_Free (pMMUHeap->psDevArena->psDeviceMemoryHeapInfo->psLocalDevMemArena, sSysPAddr.uiAddr, IMG_FALSE);
+               RA_Free (pMMUHeap->psDevArena->psDeviceMemoryHeapInfo->psLocalDevMemArena, (IMG_UINTPTR_T)sSysPAddr.uiAddr, IMG_FALSE);
        }
 }
 
@@ -1308,8 +1321,9 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
        if((UINT32_MAX_VALUE - DevVAddr.uiAddr)
                < (ui32Size + pMMUHeap->ui32DataPageMask + pMMUHeap->ui32PTMask))
        {
-               /* detected overflow, clamp to highest address */
+               /* detected overflow, clamp to highest address, reserve all PDs */
                sHighDevVAddr.uiAddr = UINT32_MAX_VALUE;
+               ui32PageTableCount = 1024;
        }
        else
        {
@@ -1317,9 +1331,10 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                                                                + ui32Size
                                                                + pMMUHeap->ui32DataPageMask
                                                                + pMMUHeap->ui32PTMask;
+
+               ui32PageTableCount = sHighDevVAddr.uiAddr >> pMMUHeap->ui32PDShift;
        }
 
-       ui32PageTableCount = sHighDevVAddr.uiAddr >> pMMUHeap->ui32PDShift;
 
        /* Fix allocation of last 4MB */
        if (ui32PageTableCount == 0)
@@ -1343,10 +1358,18 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
        DevVAddr.uiAddr = DevVAddr.uiAddr & (~BRN31620_PDE_CACHE_FILL_MASK);
 
        /* Round the end address of the PD allocation to cacheline */
-       sHighDevVAddr.uiAddr = ((sHighDevVAddr.uiAddr + (BRN31620_PDE_CACHE_FILL_SIZE - 1)) & (~BRN31620_PDE_CACHE_FILL_MASK));
+       if (UINT32_MAX_VALUE - sHighDevVAddr.uiAddr < (BRN31620_PDE_CACHE_FILL_SIZE - 1))
+       {
+               sHighDevVAddr.uiAddr = UINT32_MAX_VALUE;
+               ui32PageTableCount = 1024;
+       }
+       else
+       {
+               sHighDevVAddr.uiAddr = ((sHighDevVAddr.uiAddr + (BRN31620_PDE_CACHE_FILL_SIZE - 1)) & (~BRN31620_PDE_CACHE_FILL_MASK));
+               ui32PageTableCount = sHighDevVAddr.uiAddr >> pMMUHeap->ui32PDShift;
+       }
 
        ui32PDIndex = DevVAddr.uiAddr >> pMMUHeap->ui32PDShift;
-       ui32PageTableCount = sHighDevVAddr.uiAddr >> pMMUHeap->ui32PDShift;
 
        /* Fix allocation of last 4MB */
        if (ui32PageTableCount == 0)
@@ -1371,10 +1394,11 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                {
                        ui32Flags |= PDUMP_FLAGS_CONTINUOUS;
                }
-               PDUMPCOMMENTWITHFLAGS(ui32Flags, "Alloc PTs (MMU Context ID == %u, PDBaseIndex == %u, Size == 0x%x)",
+               PDUMPCOMMENTWITHFLAGS(ui32Flags, "Alloc PTs (MMU Context ID == %u, PDBaseIndex == %u, Size == 0x%x, Shared = %s)",
                                pMMUHeap->psMMUContext->ui32PDumpMMUContextID,
                                pMMUHeap->ui32PDBaseIndex,
-                               ui32Size);
+                               ui32Size,
+                               MMU_IsHeapShared(pMMUHeap)?"True":"False");
                PDUMPCOMMENTWITHFLAGS(ui32Flags, "Alloc page table (page count == %08X)", ui32PageTableCount);
                PDUMPCOMMENTWITHFLAGS(ui32Flags, "Page directory mods (page count == %08X)", ui32PageTableCount);
        }
@@ -1424,7 +1448,7 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                if(ppsPTInfoList[i]->hPTPageOSMemHandle == IMG_NULL
                && ppsPTInfoList[i]->PTPageCpuVAddr == IMG_NULL)
                {
-                       IMG_DEV_PHYADDR sDevPAddr;
+                       IMG_DEV_PHYADDR sDevPAddr = { 0 };
 #if defined(SUPPORT_SGX_MMU_DUMMY_PAGE)
                        IMG_UINT32 *pui32Tmp;
                        IMG_UINT32 j;
@@ -1473,7 +1497,9 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                                {
                                        /* insert Page Table into all memory contexts */
                                        MMU_CONTEXT *psMMUContext = (MMU_CONTEXT*)pMMUHeap->psMMUContext->psDevInfo->pvMMUContextList;
-
+#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
+                                       PVRSRV_SGXDEV_INFO *psDevInfo = psMMUContext->psDevInfo;
+#endif
                                        while(psMMUContext)
                                        {
                                                MakeKernelPageReadWrite(psMMUContext->pvPDCpuVAddr);
@@ -1482,7 +1508,7 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                                                pui32PDEntry += ui32PDIndex;
 
                                                /* insert the page, specify the data page size and make the pde valid */
-                                               pui32PDEntry[i] = (sDevPAddr.uiAddr>>SGX_MMU_PDE_ADDR_ALIGNSHIFT)
+                                               pui32PDEntry[i] = (IMG_UINT32)(sDevPAddr.uiAddr>>SGX_MMU_PDE_ADDR_ALIGNSHIFT)
                                                                                | pMMUHeap->ui32PDEPageSizeCtrl
                                                                                | SGX_MMU_PDE_VALID;
                                                MakeKernelPageReadOnly(psMMUContext->pvPDCpuVAddr);
@@ -1492,8 +1518,16 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                                                if(psMMUContext->bPDumpActive)
                                                #endif
                                                {
-                                                       //PDUMPCOMMENT("_DeferredAllocPTs: Dumping shared PDEs on context %d (%s)", psMMUContext->ui32PDumpMMUContextID, (psMMUContext->bPDumpActive) ? "active" : "");
-                                                       PDUMPPDENTRIES(&pMMUHeap->sMMUAttrib, psMMUContext->hPDOSMemHandle, (IMG_VOID*)&pui32PDEntry[i], sizeof(IMG_UINT32), 0, IMG_FALSE, PDUMP_PD_UNIQUETAG, PDUMP_PT_UNIQUETAG);
+#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
+                                                       /*
+                                                               Any modification of the uKernel memory context
+                                                               needs to be PDumped when we're multi-process
+                                                        */
+                                                       IMG_UINT32 ui32HeapFlags = ( psMMUContext->sPDDevPAddr.uiAddr == psDevInfo->sKernelPDDevPAddr.uiAddr ) ? PDUMP_FLAGS_PERSISTENT : 0;
+#else
+                                                       IMG_UINT32 ui32HeapFlags = 0;
+#endif
+                                                       PDUMPPDENTRIES(&pMMUHeap->sMMUAttrib, psMMUContext->hPDOSMemHandle, (IMG_VOID*)&pui32PDEntry[i], sizeof(IMG_UINT32), ui32HeapFlags, IMG_FALSE, PDUMP_PD_UNIQUETAG, PDUMP_PT_UNIQUETAG);
                                                }
                                                #endif /* PDUMP */
                                                /* advance to next context */
@@ -1509,12 +1543,11 @@ _DeferredAllocPagetables(MMU_HEAP *pMMUHeap, IMG_DEV_VIRTADDR DevVAddr, IMG_UINT
                                {
                                        MakeKernelPageReadWrite(pMMUHeap->psMMUContext->pvPDCpuVAddr);
                                        /* insert Page Table into only this memory context */
-                                       pui32PDEntry[i] = (sDevPAddr.uiAddr>>SGX_MMU_PDE_ADDR_ALIGNSHIFT)
+                                       pui32PDEntry[i] = (IMG_UINT32)(sDevPAddr.uiAddr>>SGX_MMU_PDE_ADDR_ALIGNSHIFT)
                                                                        | pMMUHeap->ui32PDEPageSizeCtrl
                                                                        | SGX_MMU_PDE_VALID;
                                        MakeKernelPageReadOnly(pMMUHeap->psMMUContext->pvPDCpuVAddr);
                                        /* pdump the PD Page modifications */
-                                       //PDUMPCOMMENT("_DeferredAllocPTs: Dumping kernel PDEs on context %d (%s)", pMMUHeap->psMMUContext->ui32PDumpMMUContextID, (pMMUHeap->psMMUContext->bPDumpActive) ? "active" : "");
                                        PDUMPPDENTRIES(&pMMUHeap->sMMUAttrib, pMMUHeap->psMMUContext->hPDOSMemHandle, (IMG_VOID*)&pui32PDEntry[i], sizeof(IMG_UINT32), 0, IMG_FALSE, PDUMP_PD_UNIQUETAG, PDUMP_PT_UNIQUETAG);
                                        break;
                                }
@@ -1918,6 +1951,15 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
        }
        else
        {
+               /* 
+                  We cannot use IMG_SYS_PHYADDR here, as that is 64-bit for 32-bit PAE builds.
+                  The physical address in this call to RA_Alloc is specifically the SysPAddr 
+                  of local (card) space, and it is highly unlikely we would ever need to 
+                  support > 4GB of local (card) memory (this does assume that such local
+                  memory will be mapped into System physical memory space at a low address so
+                  that any and all local memory exists within the 4GB SYSPAddr range).
+                */
+               IMG_UINTPTR_T uiLocalPAddr;
                IMG_SYS_PHYADDR sSysPAddr;
 
                /* allocate from the device's local memory arena */
@@ -1930,12 +1972,15 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
                                        0,
                                        IMG_NULL,
                                        0,
-                                       &(sSysPAddr.uiAddr))!= IMG_TRUE)
+                                       &uiLocalPAddr)!= IMG_TRUE)
                {
                        PVR_DPF((PVR_DBG_ERROR, "MMU_Initialise: ERROR call to RA_Alloc failed"));
                        return PVRSRV_ERROR_FAILED_TO_ALLOC_VIRT_MEMORY;
                }
 
+               /* Munge the local PAddr back into the SysPAddr */
+               sSysPAddr.uiAddr = uiLocalPAddr;
+
                /* derive the CPU virtual address */
                sCpuPAddr = SysSysPAddrToCpuPAddr(sSysPAddr);
                sPDDevPAddr = SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE_SGX, sSysPAddr);
@@ -1967,12 +2012,15 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
                                                0,
                                                IMG_NULL,
                                                0,
-                                               &(sSysPAddr.uiAddr))!= IMG_TRUE)
+                                               &uiLocalPAddr)!= IMG_TRUE)
                        {
                                PVR_DPF((PVR_DBG_ERROR, "MMU_Initialise: ERROR call to RA_Alloc failed"));
                                return PVRSRV_ERROR_FAILED_TO_ALLOC_VIRT_MEMORY;
                        }
 
+                       /* Munge the local PAddr back into the SysPAddr */
+                       sSysPAddr.uiAddr = uiLocalPAddr;
+
                        /* derive the CPU virtual address */
                        sCpuPAddr = SysSysPAddrToCpuPAddr(sSysPAddr);
                        psDevInfo->sDummyPTDevPAddr = SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE_SGX, sSysPAddr);
@@ -1996,12 +2044,15 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
                                                0,
                                                IMG_NULL,
                                                0,
-                                               &(sSysPAddr.uiAddr))!= IMG_TRUE)
+                                               &uiLocalPAddr)!= IMG_TRUE)
                        {
                                PVR_DPF((PVR_DBG_ERROR, "MMU_Initialise: ERROR call to RA_Alloc failed"));
                                return PVRSRV_ERROR_FAILED_TO_ALLOC_VIRT_MEMORY;
                        }
 
+                       /* Munge the local PAddr back into the SysPAddr */
+                       sSysPAddr.uiAddr = uiLocalPAddr;
+
                        /* derive the CPU virtual address */
                        sCpuPAddr = SysSysPAddrToCpuPAddr(sSysPAddr);
                        psDevInfo->sDummyDataDevPAddr = SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE_SGX, sSysPAddr);
@@ -2031,12 +2082,15 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
                                                0,
                                                IMG_NULL,
                                                0,
-                                               &(sSysPAddr.uiAddr))!= IMG_TRUE)
+                                               &uiLocalPAddr)!= IMG_TRUE)
                        {
                                PVR_DPF((PVR_DBG_ERROR, "MMU_Initialise: ERROR call to RA_Alloc failed"));
                                return PVRSRV_ERROR_FAILED_TO_ALLOC_VIRT_MEMORY;
                        }
 
+                       /* Munge the local PAddr back into the SysPAddr */
+                       sSysPAddr.uiAddr = uiLocalPAddr;
+
                        /* derive the CPU virtual address */
                        sCpuPAddr = SysSysPAddrToCpuPAddr(sSysPAddr);
                        psDevInfo->sBRN31620DummyPageDevPAddr = SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE_SGX, sSysPAddr);
@@ -2069,12 +2123,15 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
                                                0,
                                                IMG_NULL,
                                                0,
-                                               &(sSysPAddr.uiAddr))!= IMG_TRUE)
+                                               &uiLocalPAddr)!= IMG_TRUE)
                        {
                                PVR_DPF((PVR_DBG_ERROR, "MMU_Initialise: ERROR call to RA_Alloc failed"));
                                return PVRSRV_ERROR_FAILED_TO_ALLOC_VIRT_MEMORY;
                        }
 
+                       /* Munge the local PAddr back into the SysPAddr */
+                       sSysPAddr.uiAddr = uiLocalPAddr;
+
                        /* derive the CPU virtual address */
                        sCpuPAddr = SysSysPAddrToCpuPAddr(sSysPAddr);
                        psDevInfo->sBRN31620DummyPTDevPAddr = SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE_SGX, sSysPAddr);
@@ -2123,13 +2180,7 @@ MMU_Initialise (PVRSRV_DEVICE_NODE *psDeviceNode, MMU_CONTEXT **ppsMMUContext, I
        }
 #endif /* SUPPORT_PDUMP_MULTI_PROCESS */
        /* pdump the PD malloc */
-#if IMG_ADDRSPACE_PHYSADDR_BITS == 32
-       PDUMPCOMMENT("Alloc page directory for new MMU context (PDDevPAddr == 0x%08x)",
-                       sPDDevPAddr.uiAddr);
-#else
-       PDUMPCOMMENT("Alloc page directory for new MMU context, 64-bit arch detected (PDDevPAddr == 0x%08x%08x)",
-                       sPDDevPAddr.uiHighAddr, sPDDevPAddr.uiAddr);
-#endif
+       PDUMPCOMMENT("Alloc page directory for new MMU context (PDDevPAddr == 0x" DEVPADDR_FMT ")", sPDDevPAddr.uiAddr);
        PDUMPMALLOCPAGETABLE(&psDeviceNode->sDevId, hPDOSMemHandle, 0, pvPDCpuVAddr, SGX_MMU_PAGE_SIZE, 0, PDUMP_PD_UNIQUETAG);
 #endif /* PDUMP */
 
@@ -2377,13 +2428,8 @@ MMU_Finalise (MMU_CONTEXT *psMMUContext)
        PDUMPCLEARMMUCONTEXT(PVRSRV_DEVICE_TYPE_SGX, psMMUContext->psDeviceNode->sDevId.pszPDumpDevName, psMMUContext->ui32PDumpMMUContextID, 2);
 
        /* pdump the PD free */
-#if IMG_ADDRSPACE_PHYSADDR_BITS == 32
-       PDUMPCOMMENT("Free page directory (PDDevPAddr == 0x%08x)",
+       PDUMPCOMMENT("Free page directory (PDDevPAddr == 0x" DEVPADDR_FMT ")",
                        psMMUContext->sPDDevPAddr.uiAddr);
-#else
-       PDUMPCOMMENT("Free page directory, 64-bit arch detected (PDDevPAddr == 0x%08x%08x)",
-                       psMMUContext->sPDDevPAddr.uiHighAddr, psMMUContext->sPDDevPAddr.uiAddr);
-#endif
 #endif /* PDUMP */
 
        PDUMPFREEPAGETABLE(&psMMUContext->psDeviceNode->sDevId, psMMUContext->hPDOSMemHandle, psMMUContext->pvPDCpuVAddr, SGX_MMU_PAGE_SIZE, 0, PDUMP_PT_UNIQUETAG);
@@ -2467,8 +2513,8 @@ MMU_Finalise (MMU_CONTEXT *psMMUContext)
                                                        SGX_MMU_PAGE_SIZE,
                             PVRSRV_HAP_WRITECOMBINE|PVRSRV_HAP_KERNEL_ONLY,
                                                        psMMUContext->hPDOSMemHandle);
-               /* and free the memory */
-               RA_Free (psMMUContext->psDeviceNode->psLocalDevMemArena, sSysPAddr.uiAddr, IMG_FALSE);
+               /* and free the memory, Note that the cast to IMG_UINTPTR_T is ok as we're local mem. */
+               RA_Free (psMMUContext->psDeviceNode->psLocalDevMemArena, (IMG_UINTPTR_T)sSysPAddr.uiAddr, IMG_FALSE);
 
 #if defined(SUPPORT_SGX_MMU_DUMMY_PAGE)
                /* if this is the last context free the dummy pages too */
@@ -2819,16 +2865,16 @@ MMU_UnmapPagesAndFreePTs (MMU_HEAP *psMMUHeap,
        RETURNS:
 ******************************************************************************/
 static IMG_VOID MMU_FreePageTables(IMG_PVOID pvMMUHeap,
-                                   IMG_SIZE_T ui32Start,
-                                   IMG_SIZE_T ui32End,
+                                   IMG_SIZE_T uStart,
+                                   IMG_SIZE_T uEnd,
                                    IMG_HANDLE hUniqueTag)
 {
        MMU_HEAP *pMMUHeap = (MMU_HEAP*)pvMMUHeap;
        IMG_DEV_VIRTADDR Start;
 
-       Start.uiAddr = (IMG_UINT32)ui32Start;
+       Start.uiAddr = (IMG_UINT32)uStart;
 
-       MMU_UnmapPagesAndFreePTs(pMMUHeap, Start, (IMG_UINT32)((ui32End - ui32Start) >> pMMUHeap->ui32PTShift), hUniqueTag);
+       MMU_UnmapPagesAndFreePTs(pMMUHeap, Start, (IMG_UINT32)((uEnd - uStart) >> pMMUHeap->ui32PTShift), hUniqueTag);
 }
 
 /*!
@@ -3086,7 +3132,7 @@ MMU_Alloc (MMU_HEAP *pMMUHeap,
        IMG_BOOL bStatus;
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-               "MMU_Alloc: uSize=0x%x, flags=0x%x, align=0x%x",
+               "MMU_Alloc: uSize=0x%" SIZE_T_FMT_LEN "x, flags=0x%x, align=0x%x",
                uSize, uFlags, uDevVAddrAlignment));
 
        /*
@@ -3467,7 +3513,10 @@ MMU_MapPage (MMU_HEAP *pMMUHeap,
                                                                        DevVAddr.uiAddr >> pMMUHeap->ui32PDShift,
                                                                        ui32Index ));
                        PVR_DPF((PVR_DBG_ERROR, "MMU_MapPage: Page table entry value: 0x%08X", uTmp));
-                       PVR_DPF((PVR_DBG_ERROR, "MMU_MapPage: Physical page to map: 0x%08X", DevPAddr.uiAddr));
+
+                       PVR_DPF((PVR_DBG_ERROR, "MMU_MapPage: Physical page to map: 0x" DEVPADDR_FMT,
+                                               DevPAddr.uiAddr));
+
 #if PT_DUMP
                        DumpPT(ppsPTInfoList[0]);
 #endif
@@ -3483,7 +3532,7 @@ MMU_MapPage (MMU_HEAP *pMMUHeap,
 
        MakeKernelPageReadWrite(ppsPTInfoList[0]->PTPageCpuVAddr);
        /* map in the physical page */
-       pui32Tmp[ui32Index] = ((DevPAddr.uiAddr>>SGX_MMU_PTE_ADDR_ALIGNSHIFT)
+       pui32Tmp[ui32Index] = ((IMG_UINT32)(DevPAddr.uiAddr>>SGX_MMU_PTE_ADDR_ALIGNSHIFT)
                                                & ((~pMMUHeap->ui32DataPageMask)>>SGX_MMU_PTE_ADDR_ALIGNSHIFT))
                                                | SGX_MMU_PTE_VALID
                                                | ui32MMUFlags;
@@ -3546,7 +3595,7 @@ MMU_MapScatter (MMU_HEAP *pMMUHeap,
                DevVAddr.uiAddr += pMMUHeap->ui32DataPageSize;
 
                PVR_DPF ((PVR_DBG_MESSAGE,
-                                "MMU_MapScatter: devVAddr=%08X, SysAddr=%08X, size=0x%x/0x%x",
+                                "MMU_MapScatter: devVAddr=%x, SysAddr=" SYSPADDR_FMT ", size=0x%x/0x%" SIZE_T_FMT_LEN "x",
                                  DevVAddr.uiAddr, sSysAddr.uiAddr, uCount, uSize));
        }
 
@@ -3589,7 +3638,7 @@ MMU_MapPages (MMU_HEAP *pMMUHeap,
 
        PVR_ASSERT (pMMUHeap != IMG_NULL);
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "MMU_MapPages: heap:%s, heap_id:%d devVAddr=%08X, SysPAddr=%08X, size=0x%x",
+       PVR_DPF ((PVR_DBG_MESSAGE, "MMU_MapPages: heap:%s, heap_id:%d devVAddr=%08X, SysPAddr=" SYSPADDR_FMT ", size=0x%" SIZE_T_FMT_LEN "x",
                                                                pMMUHeap->psDevArena->pszName,
                                                                pMMUHeap->psDevArena->ui32HeapID,
                                                                DevVAddr.uiAddr, 
@@ -3677,7 +3726,7 @@ MMU_MapPagesSparse (MMU_HEAP *pMMUHeap,
 
        PVR_ASSERT (pMMUHeap != IMG_NULL);
 
-       PVR_DPF ((PVR_DBG_MESSAGE, "MMU_MapPagesSparse: heap:%s, heap_id:%d devVAddr=%08X, SysPAddr=%08X, VM space=0x%x, PHYS space=0x%x",
+       PVR_DPF ((PVR_DBG_MESSAGE, "MMU_MapPagesSparse: heap:%s, heap_id:%d devVAddr=%08X, SysPAddr=" SYSPADDR_FMT ", VM space=0x%" SIZE_T_FMT_LEN "x, PHYS space=0x%x",
                                                                pMMUHeap->psDevArena->pszName,
                                                                pMMUHeap->psDevArena->ui32HeapID,
                                                                DevVAddr.uiAddr, 
@@ -3772,10 +3821,10 @@ MMU_MapShadow (MMU_HEAP          *pMMUHeap,
 #endif
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                       "MMU_MapShadow: DevVAddr:%08X, Bytes:0x%x, CPUVAddr:%08X",
+                       "MMU_MapShadow: DevVAddr:%08X, Bytes:0x%" SIZE_T_FMT_LEN "x, CPUVAddr:%p",
                        MapBaseDevVAddr.uiAddr,
                        uByteSize,
-                       (IMG_UINTPTR_T)CpuVAddr));
+                       CpuVAddr));
 
        /* set the virtual and physical advance */
        ui32VAdvance = pMMUHeap->ui32DataPageSize;
@@ -3817,9 +3866,9 @@ MMU_MapShadow (MMU_HEAP          *pMMUHeap,
                PVR_ASSERT((DevPAddr.uiAddr & pMMUHeap->ui32DataPageMask) == 0);
 
                PVR_DPF ((PVR_DBG_MESSAGE,
-                               "Offset=0x%x: CpuVAddr=%08X, CpuPAddr=%08X, DevVAddr=%08X, DevPAddr=%08X",
+                               "Offset=0x%x: CpuVAddr=%p, CpuPAddr=" CPUPADDR_FMT ", DevVAddr=%08X, DevPAddr=" DEVPADDR_FMT,
                                uOffset,
-                               (IMG_UINTPTR_T)CpuVAddr + uOffset,
+                               (IMG_PVOID)((IMG_UINTPTR_T)CpuVAddr + uOffset),
                                CpuPAddr.uiAddr,
                                MapDevVAddr.uiAddr,
                                DevPAddr.uiAddr));
@@ -3894,10 +3943,10 @@ MMU_MapShadowSparse (MMU_HEAP          *pMMUHeap,
 #endif
 
        PVR_DPF ((PVR_DBG_MESSAGE,
-                       "MMU_MapShadowSparse: DevVAddr:%08X, VM space:0x%x, CPUVAddr:%08X PHYS space:0x%x",
+                       "MMU_MapShadowSparse: DevVAddr:%08X, VM space:0x%" SIZE_T_FMT_LEN "x, CPUVAddr:%p PHYS space:0x%x",
                        MapBaseDevVAddr.uiAddr,
                        uiSizeVM,
-                       (IMG_UINTPTR_T)CpuVAddr,
+                       CpuVAddr,
                        ui32ChunkSize * ui32NumPhysChunks));
 
        /* set the virtual and physical advance */
@@ -3937,9 +3986,9 @@ MMU_MapShadowSparse (MMU_HEAP          *pMMUHeap,
                        PVR_ASSERT((DevPAddr.uiAddr & pMMUHeap->ui32DataPageMask) == 0);
        
                        PVR_DPF ((PVR_DBG_MESSAGE,
-                                       "Offset=0x%x: CpuVAddr=%08X, CpuPAddr=%08X, DevVAddr=%08X, DevPAddr=%08X",
+                                       "Offset=0x%x: CpuVAddr=%p, CpuPAddr=" CPUPADDR_FMT ", DevVAddr=%08X, DevPAddr=" DEVPADDR_FMT,
                                        uOffset,
-                                       (IMG_UINTPTR_T)CpuVAddr + uOffset,
+                                       (void *)((IMG_UINTPTR_T)CpuVAddr + uOffset),
                                        CpuPAddr.uiAddr,
                                        MapDevVAddr.uiAddr,
                                        DevPAddr.uiAddr));
@@ -4261,6 +4310,16 @@ PVRSRV_ERROR MMU_BIFResetPDAlloc(PVRSRV_SGXDEV_INFO *psDevInfo)
        {
                /* non-UMA system */
 
+               /* 
+                  We cannot use IMG_SYS_PHYADDR here, as that is 64-bit for 32-bit PAE builds.
+                  The physical address in this call to RA_Alloc is specifically the SysPAddr 
+                  of local (card) space, and it is highly unlikely we would ever need to 
+                  support > 4GB of local (card) memory (this does assume that such local
+                  memory will be mapped into System physical memory space at a low address so
+                  that any and all local memory exists within the 4GB SYSPAddr range).
+                */
+               IMG_UINTPTR_T uiLocalPAddr;
+
                if(RA_Alloc(psLocalDevMemArena,
                                        3 * SGX_MMU_PAGE_SIZE,
                                        IMG_NULL,
@@ -4270,12 +4329,15 @@ PVRSRV_ERROR MMU_BIFResetPDAlloc(PVRSRV_SGXDEV_INFO *psDevInfo)
                                        0,
                                        IMG_NULL,
                                        0,
-                                       &(sMemBlockSysPAddr.uiAddr)) != IMG_TRUE)
+                                       &uiLocalPAddr) != IMG_TRUE)
                {
                        PVR_DPF((PVR_DBG_ERROR, "MMU_BIFResetPDAlloc: ERROR call to RA_Alloc failed"));
                        return PVRSRV_ERROR_OUT_OF_MEMORY;
                }
 
+               /* Munge the local PAddr back into the SysPAddr */
+               sMemBlockSysPAddr.uiAddr = uiLocalPAddr;
+
                /* derive the CPU virtual address */
                sMemBlockCpuPAddr = SysSysPAddrToCpuPAddr(sMemBlockSysPAddr);
                pui8MemBlock = OSMapPhysToLin(sMemBlockCpuPAddr,
@@ -4342,7 +4404,8 @@ IMG_VOID MMU_BIFResetPDFree(PVRSRV_SGXDEV_INFO *psDevInfo)
                          psDevInfo->hBIFResetPDOSMemHandle);
 
                sPDSysPAddr = SysDevPAddrToSysPAddr(PVRSRV_DEVICE_TYPE_SGX, psDevInfo->sBIFResetPDDevPAddr);
-               RA_Free(psLocalDevMemArena, sPDSysPAddr.uiAddr, IMG_FALSE);
+               /* Note that the cast to IMG_UINTPTR_T is ok as we're local mem. */
+               RA_Free(psLocalDevMemArena, (IMG_UINTPTR_T)sPDSysPAddr.uiAddr, IMG_FALSE);
        }
 }
 
@@ -4421,7 +4484,7 @@ PVRSRV_ERROR MMU_MapExtSystemCacheRegs(PVRSRV_DEVICE_NODE *psDeviceNode)
        {
                IMG_CHAR                szScript[128];
 
-               sprintf(szScript, "MALLOC :EXTSYSCACHE:PA_%08X%08X %u %u 0x%08X\r\n", 0, psDevInfo->sExtSysCacheRegsDevPBase.uiAddr, SGX_MMU_PAGE_SIZE, SGX_MMU_PAGE_SIZE, psDevInfo->sExtSysCacheRegsDevPBase.uiAddr);
+               sprintf(szScript, "MALLOC :EXTSYSCACHE:PA_%08X%08X %u %u 0x%p\r\n", 0, psDevInfo->sExtSysCacheRegsDevPBase.uiAddr, SGX_MMU_PAGE_SIZE, SGX_MMU_PAGE_SIZE, psDevInfo->sExtSysCacheRegsDevPBase.uiAddr);
                PDumpOSWriteString2(szScript, PDUMP_FLAGS_CONTINUOUS);
        }
 #endif
@@ -4454,13 +4517,13 @@ PVRSRV_ERROR MMU_MapExtSystemCacheRegs(PVRSRV_DEVICE_NODE *psDeviceNode)
 
                eErr = PDumpOSBufprintf(hScript,
                                                                ui32MaxLenScript,
-                                                               "WRW :%s:PA_%08X%08X:0x%08X :%s:PA_%08X%08X:0x%08X\r\n",
+                                                               "WRW :%s:PA_%p%p:0x%08X :%s:PA_%p%08X:0x%08X\r\n",
                                                                sMMUAttrib.sDevId.pszPDumpDevName,
-                                                               (IMG_UINT32)(IMG_UINTPTR_T)PDUMP_PT_UNIQUETAG,
-                                                               (sDevPAddr.uiAddr) & ~ui32PageMask,
+                                                               PDUMP_PT_UNIQUETAG,
+                                                               (IMG_PVOID)((sDevPAddr.uiAddr) & ~ui32PageMask),
                                                                (sDevPAddr.uiAddr) & ui32PageMask,
                                                                "EXTSYSCACHE",
-                                                               (IMG_UINT32)(IMG_UINTPTR_T)PDUMP_PD_UNIQUETAG,
+                                                               PDUMP_PD_UNIQUETAG,
                                                                (ui32PTE & sMMUAttrib.ui32PDEMask) << sMMUAttrib.ui32PTEAlignShift,
                                                                ui32PTE & ~sMMUAttrib.ui32PDEMask);
                                        if(eErr != PVRSRV_OK)
@@ -4560,7 +4623,7 @@ static IMG_VOID PageTest(IMG_VOID* pMem, IMG_DEV_PHYADDR sDevPAddr)
                if (ui32WriteData != ui32ReadData)
                {
                        // Mem fault
-                       PVR_DPF ((PVR_DBG_ERROR, "Error - memory page test failed at device phys address 0x%08X", sDevPAddr.uiAddr + (n<<2) ));
+                       PVR_DPF ((PVR_DBG_ERROR, "Error - memory page test failed at device phys address 0x" DEVPADDR_FMT, sDevPAddr.uiAddr + (n<<2) ));
                        PVR_DBG_BREAK;
                        bOK = IMG_FALSE;
                }
@@ -4576,7 +4639,7 @@ static IMG_VOID PageTest(IMG_VOID* pMem, IMG_DEV_PHYADDR sDevPAddr)
                if (ui32WriteData != ui32ReadData)
                {
                        // Mem fault
-                       PVR_DPF ((PVR_DBG_ERROR, "Error - memory page test failed at device phys address 0x%08X", sDevPAddr.uiAddr + (n<<2) ));
+                       PVR_DPF ((PVR_DBG_ERROR, "Error - memory page test failed at device phys address 0x" DEVPADDR_FMT, sDevPAddr.uiAddr + (n<<2)));
                        PVR_DBG_BREAK;
                        bOK = IMG_FALSE;
                }
@@ -4584,11 +4647,11 @@ static IMG_VOID PageTest(IMG_VOID* pMem, IMG_DEV_PHYADDR sDevPAddr)
 
        if (bOK)
        {
-               PVR_DPF ((PVR_DBG_VERBOSE, "MMU Page 0x%08X is OK", sDevPAddr.uiAddr));
+               PVR_DPF ((PVR_DBG_VERBOSE, "MMU Page 0x" DEVPADDR_FMT " is OK", sDevPAddr.uiAddr));
        }
        else
        {
-               PVR_DPF ((PVR_DBG_VERBOSE, "MMU Page 0x%08X *** FAILED ***", sDevPAddr.uiAddr));
+               PVR_DPF ((PVR_DBG_VERBOSE, "MMU Page 0x" DEVPADDR_FMT " *** FAILED ***", sDevPAddr.uiAddr));
        }
 }
 #endif
index f281c4e..260a265 100644 (file)
@@ -55,28 +55,16 @@ extern "C" {
 #endif
 
 IMG_IMPORT
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSFER_SGX_KICK_KM *psKick);
-#else
 PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSFER_SGX_KICK *psKick);
-#endif
 
 #if defined(SGX_FEATURE_2D_HARDWARE)
 IMG_IMPORT
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK_KM *psKick);
-#else
 PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK *psKick);
 #endif
-#endif
 
 IMG_IMPORT
 PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                SGX_CCB_KICK_KM *psCCBKick);
-#else
                                                 SGX_CCB_KICK *psCCBKick);
-#endif
 
 IMG_IMPORT
 PVRSRV_ERROR SGXGetPhysPageAddrKM(IMG_HANDLE hDevMemHeap,
@@ -114,21 +102,12 @@ PVRSRV_ERROR SGX2DQueryBlitsCompleteKM(PVRSRV_SGXDEV_INFO         *psDevInfo,
 
 IMG_IMPORT
 PVRSRV_ERROR SGXGetInfoForSrvinitKM(IMG_HANDLE hDevHandle,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       PVRSRV_HEAP_INFO_KM *pasHeapInfo,
-                                                                       IMG_DEV_PHYADDR *psPDDevPAddr);
-#else
                                                                        SGX_BRIDGE_INFO_FOR_SRVINIT *psInitInfo);
-#endif
 
 IMG_IMPORT
 PVRSRV_ERROR DevInitSGXPart2KM(PVRSRV_PER_PROCESS_DATA *psPerProc,
                                                           IMG_HANDLE hDevHandle,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                          SGX_BRIDGE_INIT_INFO_KM *psInitInfo);
-#else
                                                           SGX_BRIDGE_INIT_INFO *psInitInfo);
-#endif
 
 /*!
  * *****************************************************************************
@@ -262,11 +241,7 @@ SGXAddSharedPBDescKM(PVRSRV_PER_PROCESS_DATA       *psPerProc,
  ********************************************************************************/
 IMG_IMPORT PVRSRV_ERROR
 SGXGetInternalDevInfoKM(IMG_HANDLE hDevCookie,
-#if defined (SUPPORT_SID_INTERFACE)
-                                               SGX_INTERNAL_DEVINFO_KM *psSGXInternalDevInfo);
-#else
                                                SGX_INTERNAL_DEVINFO *psSGXInternalDevInfo);
-#endif
 
 #if defined (__cplusplus)
 }
index b9ebab9..632ab51 100644 (file)
@@ -56,13 +56,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define SGX_KERNEL_DATA_HEAP_OFFSET            0x00000000
 #endif
 
-#if !defined(ION_HEAP_SIZE) && defined(SUPPORT_ION)
-       /* Default the Ion heap to 16MB */
-       #define ION_HEAP_SIZE                                           0x01000000
-#else
-       #define ION_HEAP_SIZE                                           0
-#endif
-
 
 #if SGX_FEATURE_ADDRESS_SPACE_SIZE == 32
 #if defined(FIX_HW_BRN_31620)
@@ -78,7 +71,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         * For hybrid PB we have to split virtual PB range between the shared
         * PB and percontext PB due to the fact we only have one heap config
         * per device.
-        * If hybrid PB is enabled we split the space acording to HYBRID_SHARED_PB_SIZE.
+        * If hybrid PB is enabled we split the space according to HYBRID_SHARED_PB_SIZE.
         * i.e. HYBRID_SHARED_PB_SIZE defines the size of the shared PB and the
         * remainder is the size of the percontext PB.
         * If hybrid PB is not enabled then we still create both heaps (helps keep
@@ -109,10 +102,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
        #define SGX_SHARED_3DPARAMETERS_HEAP_BASE                0xC0000000
-       /* Size is defiend above */
+       /* Size is defined above */
 
        #define SGX_PERCONTEXT_3DPARAMETERS_HEAP_BASE            (SGX_SHARED_3DPARAMETERS_HEAP_BASE + SGX_SHARED_3DPARAMETERS_SIZE)
-       /* Size is defiend above */
+       /* Size is defined above */
 
        #define SGX_TADATA_HEAP_BASE                             0xD0000000
        #define SGX_TADATA_HEAP_SIZE                            (0x0D000000-0x00001000)
@@ -151,16 +144,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #endif
 
        #if !defined(SUPPORT_MEMORY_TILING)
-               #if defined (SUPPORT_ION)
-                       #define SGX_GENERAL_HEAP_BASE                            0x10000000
-                       #define SGX_GENERAL_HEAP_SIZE                           (0xC2000000-ION_HEAP_SIZE-0x00001000)
-
-                       #define SGX_ION_HEAP_BASE                                       (SGX_GENERAL_HEAP_BASE+SGX_GENERAL_HEAP_SIZE+0x00001000)
-                       #define SGX_ION_HEAP_SIZE                                       (ION_HEAP_SIZE-0x00001000)
-               #else
-                       #define SGX_GENERAL_HEAP_BASE                            0x10000000
-                       #define SGX_GENERAL_HEAP_SIZE                           (0xC2000000-0x00001000)
-               #endif
+               #define SGX_GENERAL_HEAP_BASE                            0x10000000
+               #define SGX_GENERAL_HEAP_SIZE                           (0xC2000000-0x00001000)
        #else
                #include <sgx_msvdx_defs.h>
                /* Create heaps with memory tiling enabled.
@@ -185,7 +170,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         * For hybrid PB we have to split virtual PB range between the shared
         * PB and percontext PB due to the fact we only have one heap config
         * per device.
-        * If hybrid PB is enabled we split the space acording to HYBRID_SHARED_PB_SIZE.
+        * If hybrid PB is enabled we split the space according to HYBRID_SHARED_PB_SIZE.
         * i.e. HYBRID_SHARED_PB_SIZE defines the size of the shared PB and the
         * remainder is the size of the percontext PB.
         * If hybrid PB is not enabled then we still create both heaps (helps keep
@@ -216,10 +201,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
        #define SGX_SHARED_3DPARAMETERS_HEAP_BASE                0xD2000000
-       /* Size is defiend above */
+       /* Size is defined above */
 
        #define SGX_PERCONTEXT_3DPARAMETERS_HEAP_BASE            (SGX_SHARED_3DPARAMETERS_HEAP_BASE + SGX_SHARED_3DPARAMETERS_SIZE)
-       /* Size is defiend above */
+       /* Size is defined above */
 
        #define SGX_TADATA_HEAP_BASE                             0xE2000000
        #define SGX_TADATA_HEAP_SIZE                            (0x0D000000-0x00001000)
@@ -258,26 +243,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #define SGX_GENERAL_MAPPING_HEAP_SIZE           (0x01800000-0x00001000-0x00001000)
 
        #define SGX_GENERAL_HEAP_BASE                            0x01800000
-       #define SGX_GENERAL_HEAP_SIZE                           (0x07000000-ION_HEAP_SIZE-0x00001000)
+       #define SGX_GENERAL_HEAP_SIZE                           (0x07000000-0x00001000)
 
 #else
        #define SGX_GENERAL_HEAP_BASE                            0x00001000
 #if defined(SUPPORT_LARGE_GENERAL_HEAP)
-       #define SGX_GENERAL_HEAP_SIZE                           (0x0B800000-ION_HEAP_SIZE-0x00001000-0x00001000)
+       #define SGX_GENERAL_HEAP_SIZE                           (0x0B800000-0x00001000-0x00001000)
 #else
-       #define SGX_GENERAL_HEAP_SIZE                           (0x08800000-ION_HEAP_SIZE-0x00001000-0x00001000)
+       #define SGX_GENERAL_HEAP_SIZE                           (0x08800000-0x00001000-0x00001000)
 #endif
 #endif
 
-#if defined(SUPPORT_ION)
-       #define SGX_ION_HEAP_BASE                                       (SGX_GENERAL_HEAP_BASE+SGX_GENERAL_HEAP_SIZE+0x00001000)
-       #define SGX_ION_HEAP_SIZE                                       (ION_HEAP_SIZE-0x00001000)
-#endif
        /*
         * For hybrid PB we have to split virtual PB range between the shared
         * PB and percontext PB due to the fact we only have one heap config
         * per device.
-        * If hybrid PB is enabled we split the space acording to HYBRID_SHARED_PB_SIZE.
+        * If hybrid PB is enabled we split the space according to HYBRID_SHARED_PB_SIZE.
         * i.e. HYBRID_SHARED_PB_SIZE defines the size of the shared PB and the
         * remainder is the size of the percontext PB.
         * If hybrid PB is not enabled then we still create both heaps (helps keep
@@ -428,11 +409,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #error "sgxconfig.h: ERROR: SGX_VPB_TILED_HEAP overlaps SGX_3DPARAMETERS_HEAP"
        #endif
 #else
-       #if defined(SUPPORT_ION)
-               #if ((SGX_ION_HEAP_BASE + SGX_ION_HEAP_SIZE) >= SGX_SHARED_3DPARAMETERS_HEAP_BASE)
-                       #error "sgxconfig.h: ERROR: SGX_ION_HEAP overlaps SGX_3DPARAMETERS_HEAP"
-               #endif
-       #endif
        #if ((SGX_GENERAL_HEAP_BASE + SGX_GENERAL_HEAP_SIZE) >= SGX_SHARED_3DPARAMETERS_HEAP_BASE)
                #error "sgxconfig.h: ERROR: SGX_GENERAL_HEAP overlaps SGX_3DPARAMETERS_HEAP"
        #endif
index 125da09..99cb0f8 100644 (file)
@@ -149,16 +149,6 @@ typedef struct _PVRSRV_SGXDEV_INFO_
        PPVRSRV_KERNEL_MEM_INFO         psKernelHWPerfCBMemInfo;                /*!< Meminfo for hardware performace circular buffer */
        PPVRSRV_KERNEL_MEM_INFO         psKernelTASigBufferMemInfo;             /*!< Meminfo for TA signature buffer */
        PPVRSRV_KERNEL_MEM_INFO         psKernel3DSigBufferMemInfo;             /*!< Meminfo for 3D signature buffer */
-#if defined(FIX_HW_BRN_29702)
-       PPVRSRV_KERNEL_MEM_INFO psKernelCFIMemInfo;     /*!< Meminfo for cfi */
-#endif
-#if defined(FIX_HW_BRN_29823)
-       PPVRSRV_KERNEL_MEM_INFO psKernelDummyTermStreamMemInfo; /*!< Meminfo for dummy terminate stream */
-#endif
-#if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && defined(FIX_HW_BRN_31559)
-       PPVRSRV_KERNEL_MEM_INFO psKernelVDMSnapShotBufferMemInfo; /*!< Meminfo for dummy snapshot buffer */
-       PPVRSRV_KERNEL_MEM_INFO psKernelVDMCtrlStreamBufferMemInfo; /*!< Meminfo for dummy control stream */
-#endif
 #if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && \
        defined(FIX_HW_BRN_33657) && defined(SUPPORT_SECURE_33657_FIX)
        PPVRSRV_KERNEL_MEM_INFO psKernelVDMStateUpdateBufferMemInfo; /*!< Meminfo for state update buffer */
@@ -385,12 +375,6 @@ typedef struct _SGX_BRIDGE_INIT_INFO_KM_
        IMG_HANDLE      hKernelTASigBufferMemInfo;
        IMG_HANDLE      hKernel3DSigBufferMemInfo;
 
-#if defined(FIX_HW_BRN_29702)
-       IMG_HANDLE      hKernelCFIMemInfo;
-#endif
-#if defined(FIX_HW_BRN_29823)
-       IMG_HANDLE      hKernelDummyTermStreamMemInfo;
-#endif
 #if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
        IMG_HANDLE      hKernelEDMStatusBufferMemInfo;
 #endif
index 4abff88..4da1d8f 100644 (file)
@@ -68,6 +68,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "srvkm.h"
 #include "ttrace.h"
 
+IMG_UINT32 g_ui32HostIRQCountSample = 0;
+
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,7,0))
+#include <soc.h>
+#endif
+
 #if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
 
 static const IMG_CHAR *SGXUKernelStatusString(IMG_UINT32 code)
@@ -193,11 +199,7 @@ static IMG_UINT32 DeinitDevInfo(PVRSRV_SGXDEV_INFO *psDevInfo)
 ******************************************************************************/
 static PVRSRV_ERROR InitDevInfo(PVRSRV_PER_PROCESS_DATA *psPerProc,
                                                                PVRSRV_DEVICE_NODE *psDeviceNode,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                               SGX_BRIDGE_INIT_INFO_KM *psInitInfo)
-#else
                                                                SGX_BRIDGE_INIT_INFO *psInitInfo)
-#endif
 {
        PVRSRV_SGXDEV_INFO *psDevInfo = (PVRSRV_SGXDEV_INFO *)psDeviceNode->pvDevice;
        PVRSRV_ERROR            eError;
@@ -235,16 +237,6 @@ static PVRSRV_ERROR InitDevInfo(PVRSRV_PER_PROCESS_DATA *psPerProc,
 #endif
        psDevInfo->psKernelTASigBufferMemInfo = psInitInfo->hKernelTASigBufferMemInfo;
        psDevInfo->psKernel3DSigBufferMemInfo = psInitInfo->hKernel3DSigBufferMemInfo;
-#if defined(FIX_HW_BRN_29702)
-       psDevInfo->psKernelCFIMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psInitInfo->hKernelCFIMemInfo;
-#endif
-#if defined(FIX_HW_BRN_29823)
-       psDevInfo->psKernelDummyTermStreamMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psInitInfo->hKernelDummyTermStreamMemInfo;
-#endif
-#if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && defined(FIX_HW_BRN_31559)
-       psDevInfo->psKernelVDMSnapShotBufferMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psInitInfo->hKernelVDMSnapShotBufferMemInfo;
-       psDevInfo->psKernelVDMCtrlStreamBufferMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psInitInfo->hKernelVDMCtrlStreamBufferMemInfo;
-#endif
 #if defined(SGX_FEATURE_VDM_CONTEXT_SWITCH) && \
        defined(FIX_HW_BRN_33657) && defined(SUPPORT_SECURE_33657_FIX)
        psDevInfo->psKernelVDMStateUpdateBufferMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psInitInfo->hKernelVDMStateUpdateBufferMemInfo;
@@ -324,7 +316,7 @@ failed_allockernelccb:
 
 static PVRSRV_ERROR SGXRunScript(PVRSRV_SGXDEV_INFO *psDevInfo, SGX_INIT_COMMAND *psScript, IMG_UINT32 ui32NumInitCommands)
 {
-       IMG_UINT32 ui32PC;
+       IMG_UINT32 ui32PC, ui32RegVal;
        SGX_INIT_COMMAND *psComm;
 
        for (ui32PC = 0, psComm = psScript;
@@ -349,6 +341,14 @@ static PVRSRV_ERROR SGXRunScript(PVRSRV_SGXDEV_INFO *psDevInfo, SGX_INIT_COMMAND
 #endif
                                break;
                        }
+                       case SGX_INIT_OP_PRINT_HW_REG:
+                       {
+                               ui32RegVal = OSReadHWReg(psDevInfo->pvRegsBaseKM, psComm->sReadHWReg.ui32Offset);
+                               PVR_LOG(("  (SGXREG) 0x%08X : 0x%08X", psComm->sReadHWReg.ui32Offset, ui32RegVal));
+
+                               break;
+                       }
+
 #if defined(PDUMP)
                        case SGX_INIT_OP_PDUMP_HW_REG:
                        {
@@ -572,11 +572,17 @@ PVRSRV_ERROR SGXInitialise(PVRSRV_SGXDEV_INFO     *psDevInfo,
                return eError;
        }
        PDUMPCOMMENTWITHFLAGS(PDUMP_FLAGS_CONTINUOUS, "End of SGX initialisation script part 2\n");
-       if(!(cpu_is_omap3530() || cpu_is_omap3517()))
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0))
+        if(!(cpu_is_omap3530() || cpu_is_omap3517()))
+#else
+        if(!(cpu_is_omap3430() || soc_is_am35xx()))
+#endif
         {
                OSWriteHWReg(psDevInfo->pvRegsBaseKM, 0xFF08, 0x80000000);//OCP Bypass mode
         }
 
+
        /* Record the system timestamp for the microkernel */
        psSGXHostCtl->ui32HostClock = OSClockus();
 
@@ -851,11 +857,7 @@ static PVRSRV_ERROR DevInitSGXPart1 (IMG_VOID *pvDeviceNode)
 
 ******************************************************************************/
 IMG_EXPORT
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR SGXGetInfoForSrvinitKM(IMG_HANDLE hDevHandle, PVRSRV_HEAP_INFO_KM *pasHeapInfo, IMG_DEV_PHYADDR *psPDDevPAddr)
-#else
 PVRSRV_ERROR SGXGetInfoForSrvinitKM(IMG_HANDLE hDevHandle, SGX_BRIDGE_INFO_FOR_SRVINIT *psInitInfo)
-#endif
 {
        PVRSRV_DEVICE_NODE      *psDeviceNode;
        PVRSRV_SGXDEV_INFO      *psDevInfo;
@@ -866,15 +868,9 @@ PVRSRV_ERROR SGXGetInfoForSrvinitKM(IMG_HANDLE hDevHandle, SGX_BRIDGE_INFO_FOR_S
        psDeviceNode = (PVRSRV_DEVICE_NODE *)hDevHandle;
        psDevInfo = (PVRSRV_SGXDEV_INFO *)psDeviceNode->pvDevice;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       *psPDDevPAddr = psDevInfo->sKernelPDDevPAddr;
-
-       eError = PVRSRVGetDeviceMemHeapsKM(hDevHandle, pasHeapInfo);
-#else
        psInitInfo->sPDDevPAddr = psDevInfo->sKernelPDDevPAddr;
 
        eError = PVRSRVGetDeviceMemHeapsKM(hDevHandle, &psInitInfo->asHeapInfo[0]);
-#endif
        if (eError != PVRSRV_OK)
        {
                PVR_DPF((PVR_DBG_ERROR,"SGXGetInfoForSrvinit: PVRSRVGetDeviceMemHeapsKM failed (%d)", eError));
@@ -901,11 +897,7 @@ PVRSRV_ERROR SGXGetInfoForSrvinitKM(IMG_HANDLE hDevHandle, SGX_BRIDGE_INFO_FOR_S
 IMG_EXPORT
 PVRSRV_ERROR DevInitSGXPart2KM (PVRSRV_PER_PROCESS_DATA *psPerProc,
                                 IMG_HANDLE hDevHandle,
-#if defined (SUPPORT_SID_INTERFACE)
-                                SGX_BRIDGE_INIT_INFO_KM *psInitInfo)
-#else
                                 SGX_BRIDGE_INIT_INFO *psInitInfo)
-#endif
 {
        PVRSRV_DEVICE_NODE              *psDeviceNode;
        PVRSRV_SGXDEV_INFO              *psDevInfo;
@@ -1053,6 +1045,7 @@ static PVRSRV_ERROR DevDeInitSGX (IMG_VOID *pvDeviceNode)
        PVRSRV_SGXDEV_INFO                      *psDevInfo = (PVRSRV_SGXDEV_INFO*)psDeviceNode->pvDevice;
        PVRSRV_ERROR                            eError;
        IMG_UINT32                                      ui32Heap;
+       IMG_UINT32                                      ui32Count;
        DEVICE_MEMORY_HEAP_INFO         *psDeviceMemoryHeap;
        SGX_DEVICE_MAP                          *psSGXDeviceMap;
 
@@ -1161,8 +1154,19 @@ static PVRSRV_ERROR DevDeInitSGX (IMG_VOID *pvDeviceNode)
                }
        }
 #endif /* #ifdef SGX_FEATURE_HOST_PORT */
-
-
+       
+       /* Deallocate KM mem allocated for debug script commands */
+       for (ui32Count = 0; ui32Count < SGX_FEATURE_MP_CORE_COUNT_3D; ui32Count++) 
+       {
+               if(psDevInfo->sScripts.apsSGXREGDebugCommandsPart2[ui32Count])
+               {
+                       OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP,
+                                       SGX_MAX_PRINT_COMMANDS * sizeof(SGX_INIT_COMMAND),
+                                       psDevInfo->sScripts.apsSGXREGDebugCommandsPart2[ui32Count],
+                                       0);
+               }
+       }
+       
        /* DeAllocate devinfo */
        OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
                                sizeof(PVRSRV_SGXDEV_INFO),
@@ -1184,35 +1188,6 @@ static PVRSRV_ERROR DevDeInitSGX (IMG_VOID *pvDeviceNode)
 }
 
 
-#if defined(RESTRICTED_REGISTERS) && defined(SGX_FEATURE_MP)
-
-/*!
-*******************************************************************************
-
- @Function     SGXDumpMasterDebugReg
-
- @Description
-
- Dump a single SGX debug register value
-
- @Input psDevInfo - SGX device info
- @Input pszName - string used for logging
- @Input ui32RegAddr - SGX register offset
-
- @Return   IMG_VOID
-
-******************************************************************************/
-static IMG_VOID SGXDumpMasterDebugReg (PVRSRV_SGXDEV_INFO      *psDevInfo,
-                                                                IMG_CHAR                       *pszName,
-                                                                IMG_UINT32                     ui32RegAddr)
-{
-       IMG_UINT32      ui32RegVal;
-       ui32RegVal = OSReadHWReg(psDevInfo->pvRegsBaseKM, ui32RegAddr);
-       PVR_LOG(("(HYD) %s%08X", pszName, ui32RegVal));
-}
-
-#endif /* defined(RESTRICTED_REGISTERS) */
-
 /*!
 *******************************************************************************
 
@@ -1279,32 +1254,11 @@ IMG_VOID SGXDumpDebugInfo (PVRSRV_SGXDEV_INFO   *psDevInfo,
 
        if (bDumpSGXRegs)
        {
-               PVR_DPF((PVR_DBG_ERROR,"SGX Register Base Address (Linear):   0x%08X", (IMG_UINTPTR_T)psDevInfo->pvRegsBaseKM));
-               PVR_DPF((PVR_DBG_ERROR,"SGX Register Base Address (Physical): 0x%08X", psDevInfo->sRegsPhysBase.uiAddr));
+               PVR_DPF((PVR_DBG_ERROR,"SGX Register Base Address (Linear):   0x%p", psDevInfo->pvRegsBaseKM));
+               PVR_DPF((PVR_DBG_ERROR,"SGX Register Base Address (Physical): 0x" SYSPADDR_FMT, psDevInfo->sRegsPhysBase.uiAddr));
 
                SGXDumpDebugReg(psDevInfo, 0, "EUR_CR_CORE_ID:          ", EUR_CR_CORE_ID);
                SGXDumpDebugReg(psDevInfo, 0, "EUR_CR_CORE_REVISION:    ", EUR_CR_CORE_REVISION);
-#if defined(RESTRICTED_REGISTERS) && defined(SGX_FEATURE_MP)
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_BIF_INT_STAT:   ", EUR_CR_MASTER_BIF_INT_STAT);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_BIF_FAULT:      ",EUR_CR_MASTER_BIF_FAULT);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_CLKGATESTATUS2: ",EUR_CR_MASTER_CLKGATESTATUS2 );
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_PIM_STATUS: ",EUR_CR_MASTER_VDM_PIM_STATUS);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_BIF_BANK_SET:   ",EUR_CR_MASTER_BIF_BANK_SET);
-
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_EVENT_STATUS:   ",EUR_CR_MASTER_EVENT_STATUS);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_EVENT_STATUS2:  ",EUR_CR_MASTER_EVENT_STATUS2);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_MP_PRIMITIVE:   ",EUR_CR_MASTER_MP_PRIMITIVE);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_DPM_DPLIST_STATUS: ",EUR_CR_MASTER_DPM_DPLIST_STATUS);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_DPM_PROACTIVE_PIM_SPEC: ",EUR_CR_MASTER_DPM_PROACTIVE_PIM_SPEC);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_PAGE_MANAGEOP:  ",EUR_CR_MASTER_DPM_PAGE_MANAGEOP);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_CONTEXT_STORE_SNAPSHOT: ",EUR_CR_MASTER_VDM_CONTEXT_STORE_SNAPSHOT);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_CONTEXT_LOAD_STATUS: ",EUR_CR_MASTER_VDM_CONTEXT_LOAD_STATUS);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_CONTEXT_STORE_STREAM: ",EUR_CR_MASTER_VDM_CONTEXT_STORE_STREAM);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_CONTEXT_STORE_STATUS: ",EUR_CR_MASTER_VDM_CONTEXT_STORE_STATUS);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_CONTEXT_STORE_STATE0: ",EUR_CR_MASTER_VDM_CONTEXT_STORE_STATE0);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_CONTEXT_STORE_STATE1: ",EUR_CR_MASTER_VDM_CONTEXT_STORE_STATE1);
-               SGXDumpMasterDebugReg(psDevInfo, "EUR_CR_MASTER_VDM_WAIT_FOR_KICK: ",EUR_CR_MASTER_VDM_WAIT_FOR_KICK);
-#endif
                for (ui32CoreNum = 0; ui32CoreNum < SGX_FEATURE_MP_CORE_COUNT_3D; ui32CoreNum++)
                {
                        /* Dump HW event status */
@@ -1321,37 +1275,6 @@ IMG_VOID SGXDumpDebugInfo (PVRSRV_SGXDEV_INFO    *psDevInfo,
                #if defined(EUR_CR_PDS_PC_BASE)
                        SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_PDS_PC_BASE:      ", EUR_CR_PDS_PC_BASE);
                #endif
-#if defined(RESTRICTED_REGISTERS)
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_BIF_BANK_SET: ", EUR_CR_BIF_BANK_SET);
-
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_CLKGATECTL: ", EUR_CR_CLKGATECTL);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_CLKGATESTATUS: ", EUR_CR_CLKGATESTATUS);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_MTE_CTRL: ", EUR_CR_MTE_CTRL);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_EVENT_OTHER_PDS_EXEC: ", EUR_CR_EVENT_OTHER_PDS_EXEC);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_EVENT_OTHER_PDS_DATA: ", EUR_CR_EVENT_OTHER_PDS_DATA);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_EVENT_OTHER_PDS_INFO: ", EUR_CR_EVENT_OTHER_PDS_INFO);
-
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_ZLS_PAGE_THRESHOLD: ", EUR_CR_DPM_ZLS_PAGE_THRESHOLD);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_TA_GLOBAL_LIST: ", EUR_CR_DPM_TA_GLOBAL_LIST);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_STATE_CONTEXT_ID: ", EUR_CR_DPM_STATE_CONTEXT_ID);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_CONTEXT_PB_BASE: ", EUR_CR_DPM_CONTEXT_PB_BASE);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_TA_ALLOC_FREE_LIST_STATUS1: ", EUR_CR_DPM_TA_ALLOC_FREE_LIST_STATUS1);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_3D_FREE_LIST_STATUS1: ", EUR_CR_DPM_3D_FREE_LIST_STATUS1);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_TA_ALLOC_FREE_LIST_STATUS2: ", EUR_CR_DPM_TA_ALLOC_FREE_LIST_STATUS2);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_3D_FREE_LIST_STATUS2: ", EUR_CR_DPM_3D_FREE_LIST_STATUS2);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_ABORT_STATUS_MTILE: ", EUR_CR_DPM_ABORT_STATUS_MTILE);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_PAGE_STATUS: ", EUR_CR_DPM_PAGE_STATUS);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_PAGE: ", EUR_CR_DPM_PAGE);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_GLOBAL_PAGE_STATUS: ", EUR_CR_DPM_GLOBAL_PAGE_STATUS);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_VDM_CONTEXT_LOAD_STATUS: ", EUR_CR_VDM_CONTEXT_LOAD_STATUS);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_VDM_CONTEXT_STORE_STATUS: ", EUR_CR_VDM_CONTEXT_STORE_STATUS);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_VDM_TASK_KICK_STATUS: ", EUR_CR_VDM_TASK_KICK_STATUS);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_VDM_CONTEXT_STORE_STATE0: ", EUR_CR_VDM_CONTEXT_STORE_STATE0);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_VDM_CONTEXT_STORE_STATE1: ", EUR_CR_VDM_CONTEXT_STORE_STATE1);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_REQUESTING: ", EUR_CR_DPM_REQUESTING);
-                       SGXDumpDebugReg(psDevInfo, ui32CoreNum, "EUR_CR_DPM_REQUESTING: ", EUR_CR_DPM_REQUESTING);
-
-#endif
                }
 
        #if !defined(SGX_FEATURE_MULTIPLE_MEM_CONTEXTS) && !defined(FIX_HW_BRN_31620)
@@ -1448,7 +1371,25 @@ IMG_VOID SGXDumpDebugInfo (PVRSRV_SGXDEV_INFO    *psDevInfo,
                SGXMKIF_HOST_CTL        *psSGXHostCtl = psDevInfo->psSGXHostCtl;
                IMG_UINT32                      *pui32HostCtlBuffer = (IMG_UINT32 *)psSGXHostCtl;
                IMG_UINT32                      ui32LoopCounter;
-
+               
+               /* Report which defines are enabled that affect the HostCTL structure being dumped-out here */
+               {
+                       IMG_UINT32 ui32CtlFlags = 0;
+                       #if defined(PVRSRV_USSE_EDM_BREAKPOINTS)
+                       ui32CtlFlags = ui32CtlFlags | 0x0001;
+                       #endif
+                       #if defined(FIX_HW_BRN_28889)
+                       ui32CtlFlags = ui32CtlFlags | 0x0002;
+                       #endif
+                       #if defined(SUPPORT_HW_RECOVERY)
+                       ui32CtlFlags = ui32CtlFlags | 0x0004;
+                       #endif
+                       #if defined(SGX_FEATURE_EXTENDED_PERF_COUNTERS)
+                       ui32CtlFlags = ui32CtlFlags | 0x0008;
+                       #endif
+                       PVR_LOG((" Host Ctl flags= %08x", ui32CtlFlags));
+               }
+               
                if (psSGXHostCtl->ui32AssertFail != 0)
                {
                        PVR_LOG(("SGX Microkernel assert fail: 0x%08X", psSGXHostCtl->ui32AssertFail));
@@ -1461,7 +1402,8 @@ IMG_VOID SGXDumpDebugInfo (PVRSRV_SGXDEV_INFO     *psDevInfo,
                         ui32LoopCounter < sizeof(*psDevInfo->psSGXHostCtl) / sizeof(*pui32HostCtlBuffer);
                         ui32LoopCounter += 4)
                {
-                       PVR_LOG(("\t(HC-%X) 0x%08X 0x%08X 0x%08X 0x%08X", ui32LoopCounter * sizeof(*pui32HostCtlBuffer),
+                       PVR_LOG(("\t(HC-%" SIZE_T_FMT_LEN "X) 0x%08X 0x%08X 0x%08X 0x%08X", 
+                    ui32LoopCounter * sizeof(*pui32HostCtlBuffer),
                                        pui32HostCtlBuffer[ui32LoopCounter + 0], pui32HostCtlBuffer[ui32LoopCounter + 1],
                                        pui32HostCtlBuffer[ui32LoopCounter + 2], pui32HostCtlBuffer[ui32LoopCounter + 3]));
                }
@@ -1480,7 +1422,8 @@ IMG_VOID SGXDumpDebugInfo (PVRSRV_SGXDEV_INFO     *psDevInfo,
                         ui32LoopCounter < psDevInfo->psKernelSGXTA3DCtlMemInfo->uAllocSize / sizeof(*pui32TA3DCtlBuffer);
                         ui32LoopCounter += 4)
                {
-                       PVR_LOG(("\t(T3C-%X) 0x%08X 0x%08X 0x%08X 0x%08X", ui32LoopCounter * sizeof(*pui32TA3DCtlBuffer),
+                       PVR_LOG(("\t(T3C-%" SIZE_T_FMT_LEN "X) 0x%08X 0x%08X 0x%08X 0x%08X", 
+                    ui32LoopCounter * sizeof(*pui32TA3DCtlBuffer),
                                        pui32TA3DCtlBuffer[ui32LoopCounter + 0], pui32TA3DCtlBuffer[ui32LoopCounter + 1],
                                        pui32TA3DCtlBuffer[ui32LoopCounter + 2], pui32TA3DCtlBuffer[ui32LoopCounter + 3]));
                }
@@ -1581,6 +1524,7 @@ IMG_VOID HWRecoveryResetSGX (PVRSRV_DEVICE_NODE *psDeviceNode,
                                                         IMG_UINT32                     ui32CallerID)
 {
        PVRSRV_ERROR            eError;
+       IMG_UINT32                      ui32Count;
        PVRSRV_SGXDEV_INFO      *psDevInfo = (PVRSRV_SGXDEV_INFO*)psDeviceNode->pvDevice;
        SGXMKIF_HOST_CTL        *psSGXHostCtl = (SGXMKIF_HOST_CTL *)psDevInfo->psSGXHostCtl;
        
@@ -1609,6 +1553,27 @@ IMG_VOID HWRecoveryResetSGX (PVRSRV_DEVICE_NODE *psDeviceNode,
        psSGXHostCtl->ui32InterruptClearFlags |= PVRSRV_USSE_EDM_INTERRUPT_HWR;
 
        PVR_LOG(("HWRecoveryResetSGX: SGX Hardware Recovery triggered"));
+
+       /* Run SGXREGDebug scripts */
+#if defined(SGX_FEATURE_MP)
+       PVR_LOG(("(HYD)"));
+       eError = SGXRunScript(psDevInfo, psDevInfo->sScripts.asSGXREGDebugCommandsPart1, SGX_MAX_PRINT_COMMANDS);
+       if (eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR,"HWRecoveryResetSGX: SGXREGDebugCommandsPart1 SGXRunScript failed (%d)", eError));
+       }
+#endif
+
+       for (ui32Count = 0; ui32Count < SGX_FEATURE_MP_CORE_COUNT_3D; ui32Count++) 
+       {
+               PVR_LOG(("(P%u)",ui32Count));
+               eError = SGXRunScript(psDevInfo, psDevInfo->sScripts.apsSGXREGDebugCommandsPart2[ui32Count], SGX_MAX_PRINT_COMMANDS);
+               if (eError != PVRSRV_OK)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"HWRecoveryResetSGX: SGXREGDebugCommandsPart2 SGXRunScript failed (%d)", eError));
+               }
+       }
+       /* Scripts end */
        
 #if defined(SUPPORT_HWRECOVERY_TRACE_LIMIT)    
 /*
@@ -1874,6 +1839,12 @@ IMG_BOOL SGX_ISRHandler (IMG_VOID *pvData)
                        /* clear the events */
                        OSWriteHWReg(psDevInfo->pvRegsBaseKM, EUR_CR_EVENT_HOST_CLEAR, ui32EventClear);
                        OSWriteHWReg(psDevInfo->pvRegsBaseKM, EUR_CR_EVENT_HOST_CLEAR2, ui32EventClear2);
+
+                       /*
+                               Sample the current count from the uKernel _after_ we've cleared the
+                               interrupt.
+                       */
+                       g_ui32HostIRQCountSample = psDevInfo->psSGXHostCtl->ui32InterruptCount;
                }
        }
 
@@ -2120,23 +2091,6 @@ PVRSRV_ERROR SGXRegisterDevice (PVRSRV_DEVICE_NODE *psDeviceNode)
        psDeviceMemoryHeap++;/* advance to the next heap */
 #endif
 
-#if defined(SUPPORT_ION)
-       /************* Ion Heap ***************/
-       psDeviceMemoryHeap->ui32HeapID = HEAP_ID( PVRSRV_DEVICE_TYPE_SGX, SGX_ION_HEAP_ID);
-       psDeviceMemoryHeap->sDevVAddrBase.uiAddr = SGX_ION_HEAP_BASE;
-       psDeviceMemoryHeap->ui32HeapSize = SGX_ION_HEAP_SIZE;
-       psDeviceMemoryHeap->ui32Attribs = PVRSRV_HAP_WRITECOMBINE
-                                                                                                               | PVRSRV_HAP_SINGLE_PROCESS;
-       psDeviceMemoryHeap->pszName = "Ion";
-       psDeviceMemoryHeap->pszBSName = "Ion BS";
-       psDeviceMemoryHeap->DevMemHeapType = DEVICE_MEMORY_HEAP_PERCONTEXT;
-       /* specify the ion heap ID for this device */
-       psDevMemoryInfo->ui32IonHeapID = SGX_ION_HEAP_ID;
-       /* set the default (4k). System can override these as required */
-       psDeviceMemoryHeap->ui32DataPageSize = SGX_MMU_PAGE_SIZE;
-       psDeviceMemoryHeap++;/* advance to the next heap */
-#endif
-
        /************* TA data ***************/
        psDeviceMemoryHeap->ui32HeapID = HEAP_ID( PVRSRV_DEVICE_TYPE_SGX, SGX_TADATA_HEAP_ID);
        psDeviceMemoryHeap->sDevVAddrBase.uiAddr = SGX_TADATA_HEAP_BASE;
@@ -2532,8 +2486,7 @@ PVRSRV_ERROR SGXDevInitCompatCheck(PVRSRV_DEVICE_NODE *psDeviceNode)
        psSGXFeatures = &((PVRSRV_SGX_MISCINFO_INFO*)(psMemInfo->pvLinAddrKM))->sSGXFeatures;
        if( (psSGXFeatures->ui32DDKVersion !=
                ((PVRVERSION_MAJ << 16) |
-                (PVRVERSION_MIN << 8) |
-                 PVRVERSION_BRANCH) ) ||
+                (PVRVERSION_MIN << 8))) ||
                (psSGXFeatures->ui32DDKBuild != PVRVERSION_BUILD) )
        {
                PVR_LOG(("(FAIL) SGXInit: Incompatible driver DDK revision (%d)/device DDK revision (%d).",
@@ -3080,6 +3033,17 @@ PVRSRV_ERROR SGXGetMiscInfoKM(PVRSRV_SGXDEV_INFO *psDevInfo,
                        return PVRSRV_OK;
                }
 
+               case SGX_MISC_INFO_REQUEST_CLOCKSPEED_SLCSIZE:
+               {
+                       psMiscInfo->uData.sQueryClockSpeedSLCSize.ui32SGXClockSpeed = SYS_SGX_CLOCK_SPEED;
+#if defined(SGX_FEATURE_SYSTEM_CACHE) && defined(SYS_SGX_SLC_SIZE)
+                       psMiscInfo->uData.sQueryClockSpeedSLCSize.ui32SGXSLCSize = SYS_SGX_SLC_SIZE;
+#else
+                       psMiscInfo->uData.sQueryClockSpeedSLCSize.ui32SGXSLCSize = 0;
+#endif /* defined(SGX_FEATURE_SYSTEM_CACHE) && defined(SYS_SGX_SLC_SIZE) */
+                       return PVRSRV_OK;
+               }
+
                case SGX_MISC_INFO_REQUEST_ACTIVEPOWER:
                {
                        psMiscInfo->uData.sActivePower.ui32NumActivePowerEvents = psDevInfo->psSGXHostCtl->ui32NumActivePowerEvents;
@@ -3148,24 +3112,27 @@ PVRSRV_ERROR SGXGetMiscInfoKM(PVRSRV_SGXDEV_INFO        *psDevInfo,
 
                        psSGXFeatures->ui32DDKVersion =
                                (PVRVERSION_MAJ << 16) |
-                               (PVRVERSION_MIN << 8) |
-                               PVRVERSION_BRANCH;
+                               (PVRVERSION_MIN << 8);
                        psSGXFeatures->ui32DDKBuild = PVRVERSION_BUILD;
 
                        /* Also report the kernel module build options -- used in SGXConnectionCheck() */
                        psSGXFeatures->ui32BuildOptions = (SGX_BUILD_OPTIONS);
 
-#if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
-                       /* Report the EDM status buffer location in memory */
-                       psSGXFeatures->sDevVAEDMStatusBuffer = psDevInfo->psKernelEDMStatusBufferMemInfo->sDevVAddr;
-                       psSGXFeatures->pvEDMStatusBuffer = psDevInfo->psKernelEDMStatusBufferMemInfo->pvLinAddrKM;
-#endif
-
                        /* Copy SGX features into misc info struct, to return to client */
                        psMiscInfo->uData.sSGXFeatures = *psSGXFeatures;
                        return PVRSRV_OK;
                }
 
+#if defined(PVRSRV_USSE_EDM_STATUS_DEBUG)
+               case SGX_MISC_INFO_REQUEST_EDM_STATUS_BUFFER_INFO:
+               {
+                       /* Report the EDM status buffer location in memory */
+                       psMiscInfo->uData.sEDMStatusBufferInfo.sDevVAEDMStatusBuffer = psDevInfo->psKernelEDMStatusBufferMemInfo->sDevVAddr;
+                       psMiscInfo->uData.sEDMStatusBufferInfo.pvEDMStatusBuffer = psDevInfo->psKernelEDMStatusBufferMemInfo->pvLinAddrKM;
+                       return PVRSRV_OK;
+               }
+#endif
+
 #if defined(SUPPORT_SGX_EDM_MEMORY_DEBUG)
                case SGX_MISC_INFO_REQUEST_MEMREAD:
                case SGX_MISC_INFO_REQUEST_MEMCOPY:
@@ -3331,6 +3298,14 @@ PVRSRV_ERROR SGXGetMiscInfoKM(PVRSRV_SGXDEV_INFO *psDevInfo,
 
                case SGX_MISC_INFO_DUMP_DEBUG_INFO_FORCE_REGS:
                {
+                       if(!OSProcHasPrivSrvInit())
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "Insufficient privileges to dump SGX "
+                                                                               "debug info with registers"));
+
+                               return PVRSRV_ERROR_INVALID_MISCINFO;
+                       }
+
                        PVR_LOG(("User requested SGX debug info"));
 
                        /* Dump SGX debug data to the kernel log. */
index 584f538..a83242c 100644 (file)
@@ -53,6 +53,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sgxutils.h"
 #include "ttrace.h"
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include "pvr_sync.h"
+#endif
+
 /*!
 ******************************************************************************
 
@@ -68,11 +72,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 ******************************************************************************/
 IMG_EXPORT
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK_KM *psCCBKick)
-#else
 PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
-#endif
 {
        PVRSRV_ERROR eError;
        PVRSRV_KERNEL_SYNC_INFO *psSyncInfo;
@@ -239,7 +239,41 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
        }
 #else /* SUPPORT_SGX_GENERALISED_SYNCOBJECTS */
        /* texture dependencies */
-       psTACmd->ui32NumSrcSyncs = psCCBKick->ui32NumSrcSyncs;
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       eError = PVRSyncPatchCCBKickSyncInfos(psCCBKick->ahSrcKernelSyncInfo,
+                                                                                 psTACmd->asSrcSyncs,
+                                                                                 &psCCBKick->ui32NumSrcSyncs);
+       if(eError != PVRSRV_OK)
+       {
+               /* We didn't kick yet, or perform PDUMP processing, so we should
+                * be able to trivially roll back any changes made to the sync
+                * data. If we don't do this, we'll wedge services cleanup.
+                */
+
+               if (psCCBKick->h3DSyncInfo != IMG_NULL)
+               {
+                       psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psCCBKick->h3DSyncInfo;
+                       psSyncInfo->psSyncData->ui32ReadOpsPending--;
+               }
+
+               if (psCCBKick->hTASyncInfo != IMG_NULL)
+               {
+                       psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psCCBKick->hTASyncInfo;
+                       psSyncInfo->psSyncData->ui32ReadOpsPending--;
+               }
+
+               if (psCCBKick->hTA3DSyncInfo && psCCBKick->bTADependency)
+               {
+                       psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psCCBKick->hTA3DSyncInfo;
+                       psSyncInfo->psSyncData->ui32WriteOpsPending--;
+               }
+
+               PVR_DPF((PVR_DBG_ERROR, "SGXDoKickKM: PVRSyncPatchCCBKickSyncInfos failed."));
+               PVR_TTRACE(PVRSRV_TRACE_GROUP_KICK, PVRSRV_TRACE_CLASS_FUNCTION_EXIT,
+                                  KICK_TOKEN_DOKICK);
+               return eError;
+       }
+#else /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
        for (i=0; i<psCCBKick->ui32NumSrcSyncs; i++)
        {
                psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *) psCCBKick->ahSrcKernelSyncInfo[i];
@@ -255,7 +289,9 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                /* Copy ui32WriteOpsPending snapshot into the CCB. */
                psTACmd->asSrcSyncs[i].ui32WriteOpsPendingVal = psSyncInfo->psSyncData->ui32WriteOpsPending;
        }
-#endif/* SUPPORT_SGX_GENERALISED_SYNCOBJECTS */
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
+       psTACmd->ui32NumSrcSyncs = psCCBKick->ui32NumSrcSyncs;
+#endif /* defined(SUPPORT_SGX_GENERALISED_SYNCOBJECTS) */
 
        if (psCCBKick->bFirstKickOrResume && psCCBKick->ui32NumDstSyncObjects > 0)
        {
@@ -322,31 +358,6 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                                                         0,
                                                         MAKEUNIQUETAG(psHWDstSyncListMemInfo));
 
-                                       if ((psSyncInfo->psSyncData->ui32LastOpDumpVal == 0) &&
-                                               (psSyncInfo->psSyncData->ui32LastReadOpDumpVal == 0))
-                                       {
-                                               /*
-                                               * Init the ROpsComplete value to 0.
-                                               */
-                                               PDUMPCOMMENT("Init RT ROpsComplete\r\n");
-                                               PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
-                                                       psSyncInfo->psSyncDataMemInfoKM,
-                                                       offsetof(PVRSRV_SYNC_DATA, ui32ReadOpsComplete),
-                                                       sizeof(psSyncInfo->psSyncData->ui32ReadOpsComplete),
-                                                       0,
-                                                       MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                                               /*
-                                               * Init the WOpsComplete value to 0.
-                                               */
-                                               PDUMPCOMMENT("Init RT WOpsComplete\r\n");
-                                                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
-                                                               psSyncInfo->psSyncDataMemInfoKM,
-                                                               offsetof(PVRSRV_SYNC_DATA, ui32WriteOpsComplete),
-                                                               sizeof(psSyncInfo->psSyncData->ui32WriteOpsComplete),
-                                                               0,
-                                                               MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                                       }
-
                                        psSyncInfo->psSyncData->ui32LastOpDumpVal++;
 
                                        ui32ModifiedValue = psSyncInfo->psSyncData->ui32LastOpDumpVal - 1;
@@ -420,31 +431,6 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                        IMG_UINT32      ui32ModifiedValue;
                        psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *) psCCBKick->ahTASrcKernelSyncInfo[i];
 
-                       if ((psSyncInfo->psSyncData->ui32LastOpDumpVal == 0) &&
-                               (psSyncInfo->psSyncData->ui32LastReadOpDumpVal == 0))
-                       {
-                               /*
-                               * Init the ROpsComplete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT TA-SRC ROpsComplete\r\n", i);
-                               PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
-                                       psSyncInfo->psSyncDataMemInfoKM,
-                                       offsetof(PVRSRV_SYNC_DATA, ui32ReadOpsComplete),
-                                       sizeof(psSyncInfo->psSyncData->ui32ReadOpsComplete),
-                                       0,
-                                       MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                               /*
-                               * Init the WOpsComplete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT TA-SRC WOpsComplete\r\n");
-                                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
-                                               psSyncInfo->psSyncDataMemInfoKM,
-                                               offsetof(PVRSRV_SYNC_DATA, ui32WriteOpsComplete),
-                                               sizeof(psSyncInfo->psSyncData->ui32WriteOpsComplete),
-                                               0,
-                                               MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                       }
-
                        psSyncInfo->psSyncData->ui32LastReadOpDumpVal++;
 
                        ui32ModifiedValue = psSyncInfo->psSyncData->ui32LastReadOpDumpVal - 1;
@@ -475,31 +461,6 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                        IMG_UINT32      ui32ModifiedValue;
                        psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *) psCCBKick->ahTADstKernelSyncInfo[i];
 
-                       if ((psSyncInfo->psSyncData->ui32LastOpDumpVal == 0) &&
-                               (psSyncInfo->psSyncData->ui32LastReadOpDumpVal == 0))
-                       {
-                               /*
-                                * Init the ROpsComplete value to 0.
-                                */
-                               PDUMPCOMMENT("Init RT TA-DST ROpsComplete\r\n", i);
-                               PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
-                                       psSyncInfo->psSyncDataMemInfoKM,
-                                       offsetof(PVRSRV_SYNC_DATA, ui32ReadOpsComplete),
-                                       sizeof(psSyncInfo->psSyncData->ui32ReadOpsComplete),
-                                       0,
-                                       MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                               /*
-                                * Init the WOpsComplete value to 0.
-                                */
-                               PDUMPCOMMENT("Init RT TA-DST WOpsComplete\r\n");
-                                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
-                                               psSyncInfo->psSyncDataMemInfoKM,
-                                               offsetof(PVRSRV_SYNC_DATA, ui32WriteOpsComplete),
-                                               sizeof(psSyncInfo->psSyncData->ui32WriteOpsComplete),
-                                               0,
-                                               MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                       }
-
                        psSyncInfo->psSyncData->ui32LastOpDumpVal++;
 
                        ui32ModifiedValue = psSyncInfo->psSyncData->ui32LastOpDumpVal - 1;
@@ -530,31 +491,6 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                        IMG_UINT32      ui32ModifiedValue;
                        psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *) psCCBKick->ah3DSrcKernelSyncInfo[i];
 
-                       if ((psSyncInfo->psSyncData->ui32LastOpDumpVal == 0) &&
-                               (psSyncInfo->psSyncData->ui32LastReadOpDumpVal == 0))
-                       {
-                               /*
-                               * Init the ROpsComplete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT 3D-SRC ROpsComplete\r\n", i);
-                               PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
-                                       psSyncInfo->psSyncDataMemInfoKM,
-                                       offsetof(PVRSRV_SYNC_DATA, ui32ReadOpsComplete),
-                                       sizeof(psSyncInfo->psSyncData->ui32ReadOpsComplete),
-                                       0,
-                                       MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                               /*
-                               * Init the WOpsComplete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT 3D-SRC WOpsComplete\r\n");
-                                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
-                                               psSyncInfo->psSyncDataMemInfoKM,
-                                               offsetof(PVRSRV_SYNC_DATA, ui32WriteOpsComplete),
-                                               sizeof(psSyncInfo->psSyncData->ui32WriteOpsComplete),
-                                               0,
-                                               MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                       }
-
                        psSyncInfo->psSyncData->ui32LastReadOpDumpVal++;
 
                        ui32ModifiedValue = psSyncInfo->psSyncData->ui32LastReadOpDumpVal - 1;
@@ -585,41 +521,6 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                        IMG_UINT32      ui32ModifiedValue;
                        psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *) psCCBKick->ahSrcKernelSyncInfo[i];
 
-                       if ((psSyncInfo->psSyncData->ui32LastOpDumpVal == 0) &&
-                               (psSyncInfo->psSyncData->ui32LastReadOpDumpVal == 0))
-                       {
-                               /*
-                               * Init the ROpsComplete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT ROpsComplete\r\n");
-                               PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
-                                       psSyncInfo->psSyncDataMemInfoKM,
-                                       offsetof(PVRSRV_SYNC_DATA, ui32ReadOpsComplete),
-                                       sizeof(psSyncInfo->psSyncData->ui32ReadOpsComplete),
-                                       0,
-                                       MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                               /*
-                               * Init the WOpsComplete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT WOpsComplete\r\n");
-                                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
-                                               psSyncInfo->psSyncDataMemInfoKM,
-                                               offsetof(PVRSRV_SYNC_DATA, ui32WriteOpsComplete),
-                                               sizeof(psSyncInfo->psSyncData->ui32WriteOpsComplete),
-                                               0,
-                                               MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                               /*
-                               * Init the ROps2Complete value to 0.
-                               */
-                               PDUMPCOMMENT("Init RT WOpsComplete\r\n");
-                                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
-                                               psSyncInfo->psSyncDataMemInfoKM,
-                                               offsetof(PVRSRV_SYNC_DATA, ui32ReadOps2Complete),
-                                               sizeof(psSyncInfo->psSyncData->ui32ReadOps2Complete),
-                                               0,
-                                               MAKEUNIQUETAG(psSyncInfo->psSyncDataMemInfoKM));
-                       }
-
                        psSyncInfo->psSyncData->ui32LastReadOpDumpVal++;
 
                        ui32ModifiedValue = psSyncInfo->psSyncData->ui32LastReadOpDumpVal - 1;
@@ -645,6 +546,25 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                                MAKEUNIQUETAG(psCCBMemInfo));
                }
 
+               if (psCCBKick->hTA3DSyncInfo != IMG_NULL)
+               {
+                       psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psCCBKick->hTA3DSyncInfo;
+
+                       PDUMPCOMMENT("Modify TA/3D dependency WOpPendingVal\r\n");
+
+                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
+                                       psCCBMemInfo,
+                                       psCCBKick->ui32CCBDumpWOff + offsetof(SGXMKIF_CMDTA_SHARED, sTA3DDependency.ui32WriteOpsPendingVal),
+                                       sizeof(IMG_UINT32),
+                                       0,
+                                       MAKEUNIQUETAG(psCCBMemInfo));
+                       
+                       if (psCCBKick->bTADependency)
+                       {
+                               psSyncInfo->psSyncData->ui32LastOpDumpVal++;
+                       }
+               }
+
                if (psCCBKick->hTASyncInfo != IMG_NULL)
                {
                        psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psCCBKick->hTASyncInfo;
@@ -657,6 +577,16 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                                        sizeof(IMG_UINT32),
                                        0,
                                        MAKEUNIQUETAG(psCCBMemInfo));
+
+                       PDUMPCOMMENT("Modify TA/TQ WOpPendingVal\r\n");
+
+                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
+                                       psCCBMemInfo,
+                                       psCCBKick->ui32CCBDumpWOff + offsetof(SGXMKIF_CMDTA_SHARED, ui32TATQSyncWriteOpsPendingVal),
+                                       sizeof(IMG_UINT32),
+                                       0,
+                                       MAKEUNIQUETAG(psCCBMemInfo));
+
                        psSyncInfo->psSyncData->ui32LastReadOpDumpVal++;
                }
 
@@ -672,6 +602,16 @@ PVRSRV_ERROR SGXDoKickKM(IMG_HANDLE hDevHandle, SGX_CCB_KICK *psCCBKick)
                                        sizeof(IMG_UINT32),
                                        0,
                                        MAKEUNIQUETAG(psCCBMemInfo));
+
+                       PDUMPCOMMENT("Modify 3D/TQ WOpPendingVal\r\n");
+
+                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastOpDumpVal,
+                                       psCCBMemInfo,
+                                       psCCBKick->ui32CCBDumpWOff + offsetof(SGXMKIF_CMDTA_SHARED, ui323DTQSyncWriteOpsPendingVal),
+                                       sizeof(IMG_UINT32),
+                                       0,
+                                       MAKEUNIQUETAG(psCCBMemInfo));
+
                        psSyncInfo->psSyncData->ui32LastReadOpDumpVal++;
                }
 
index d2549bb..1b807c0 100644 (file)
@@ -48,6 +48,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sgxutils.h"
 #include "pdump_km.h"
 
+extern IMG_UINT32 g_ui32HostIRQCountSample;
 
 #if defined(SUPPORT_HW_RECOVERY)
 static PVRSRV_ERROR SGXAddTimer(PVRSRV_DEVICE_NODE             *psDeviceNode,
@@ -366,6 +367,20 @@ PVRSRV_ERROR SGXPrePowerState (IMG_HANDLE                          hDevHandle,
                                        MAKEUNIQUETAG(psDevInfo->psKernelSGXHostCtlMemInfo));
                #endif /* PDUMP */
 
+               /* Wait for the pending ukernel to host interrupts to come back. */
+               #if !defined(NO_HARDWARE)
+//             if (PollForValueKM(&g_ui32HostIRQCountSample,
+//                                                     psDevInfo->psSGXHostCtl->ui32InterruptCount,
+//                                                     0xffffffff,
+//                                                     MAX_HW_TIME_US,
+//                                                     MAX_HW_TIME_US/WAIT_TRY_COUNT,
+//                                                     IMG_FALSE) != PVRSRV_OK)
+//             {
+//                     PVR_DPF((PVR_DBG_ERROR,"SGXPrePowerState: Wait for pending interrupts failed."));
+//                     SGXDumpDebugInfo(psDevInfo, IMG_FALSE);
+//                     PVR_DBG_BREAK;
+//             }
+               #endif /* NO_HARDWARE */
 #if defined(SGX_FEATURE_MP)
                ui32CoresEnabled = ((OSReadHWReg(psDevInfo->pvRegsBaseKM, EUR_CR_MASTER_CORE) & EUR_CR_MASTER_CORE_ENABLE_MASK) >> EUR_CR_MASTER_CORE_ENABLE_SHIFT) + 1;
 #else
@@ -541,6 +556,18 @@ PVRSRV_ERROR SGXPreClockSpeedChange (IMG_HANDLE                            hDevHandle,
                                return eError;
                        }
                }
+               else
+               {
+                       #if defined(SUPPORT_HW_RECOVERY)
+                       PVRSRV_ERROR    eError;
+
+                       eError = OSDisableTimer(psDevInfo->hTimer);
+                       if (eError != PVRSRV_OK)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR,"SGXStartTimer : Failed to enable host timer"));
+                       }
+                       #endif /* SUPPORT_HW_RECOVERY */
+               }
        }
 
        PVR_DPF((PVR_DBG_MESSAGE,"SGXPreClockSpeedChange: SGX clock speed was %uHz",
index dcdefae..e539df6 100644 (file)
@@ -191,7 +191,7 @@ static IMG_VOID SGXResetSetupBIFContexts(PVRSRV_SGXDEV_INFO *psDevInfo,
                ui32EDMDirListReg = EUR_CR_BIF_DIR_LIST_BASE1 + 4 * (SGX_BIF_DIR_LIST_INDEX_EDM - 1);
                #endif /* SGX_BIF_DIR_LIST_INDEX_EDM */
 
-               ui32RegVal = psDevInfo->sKernelPDDevPAddr.uiAddr >> SGX_MMU_PDE_ADDR_ALIGNSHIFT;
+               ui32RegVal = (IMG_UINT32)(psDevInfo->sKernelPDDevPAddr.uiAddr >> SGX_MMU_PDE_ADDR_ALIGNSHIFT);
                
 #if defined(FIX_HW_BRN_28011)
                OSWriteHWReg(psDevInfo->pvRegsBaseKM, EUR_CR_BIF_DIR_LIST_BASE0, ui32RegVal);
@@ -506,6 +506,16 @@ IMG_VOID SGXReset(PVRSRV_SGXDEV_INFO       *psDevInfo,
        /* enable 36bit addressing mode if the MMU supports it*/
        OSWriteHWReg(psDevInfo->pvRegsBaseKM, EUR_CR_BIF_36BIT_ADDRESSING, EUR_CR_BIF_36BIT_ADDRESSING_ENABLE_MASK);
        PDUMPREGWITHFLAGS(SGX_PDUMPREG_NAME, EUR_CR_BIF_36BIT_ADDRESSING, EUR_CR_BIF_36BIT_ADDRESSING_ENABLE_MASK, ui32PDUMPFlags);
+#else
+       #if defined(EUR_CR_BIF_36BIT_ADDRESSING)
+               OSWriteHWReg(psDevInfo->pvRegsBaseKM, 
+                               EUR_CR_BIF_36BIT_ADDRESSING, 
+                               0);
+               PDUMPREGWITHFLAGS(SGX_PDUMPREG_NAME, 
+                               EUR_CR_BIF_36BIT_ADDRESSING, 
+                               0, 
+                               ui32PDUMPFlags);
+       #endif
 #endif
 
        SGXResetInitBIFContexts(psDevInfo, ui32PDUMPFlags);
@@ -589,11 +599,11 @@ IMG_VOID SGXReset(PVRSRV_SGXDEV_INFO      *psDevInfo,
                        SGXResetSoftReset(psDevInfo, IMG_TRUE, ui32PDUMPFlags, IMG_FALSE);
 
                        /* Map in the dummy page. */
-                       psDevInfo->pui32BIFResetPD[ui32PDIndex] = (psDevInfo->sBIFResetPTDevPAddr.uiAddr
+                       psDevInfo->pui32BIFResetPD[ui32PDIndex] = (IMG_UINT32)(psDevInfo->sBIFResetPTDevPAddr.uiAddr
                                                                                                        >>SGX_MMU_PDE_ADDR_ALIGNSHIFT)
                                                                                                        | SGX_MMU_PDE_PAGE_SIZE_4K
                                                                                                        | SGX_MMU_PDE_VALID;
-                       psDevInfo->pui32BIFResetPT[ui32PTIndex] = (psDevInfo->sBIFResetPageDevPAddr.uiAddr
+                       psDevInfo->pui32BIFResetPT[ui32PTIndex] = (IMG_UINT32)(psDevInfo->sBIFResetPageDevPAddr.uiAddr
                                                                                                        >>SGX_MMU_PTE_ADDR_ALIGNSHIFT)
                                                                                                        | SGX_MMU_PTE_VALID;
 
index 81f3b07..0dece84 100644 (file)
@@ -58,11 +58,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sgxutils.h"
 #include "ttrace.h"
 
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSFER_SGX_KICK_KM *psKick)
-#else
-IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSFER_SGX_KICK *psKick)
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include "pvr_sync.h"
 #endif
+
+IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSFER_SGX_KICK *psKick)
 {
        PVRSRV_KERNEL_MEM_INFO          *psCCBMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psKick->hCCBMemInfo;
        SGXMKIF_COMMAND                         sCommand = {0};
@@ -210,9 +210,6 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSF
                }
        }
 
-       psSharedTransferCmd->ui32NumSrcSyncs = ui32RealSrcSyncNum; 
-       psSharedTransferCmd->ui32NumDstSyncs = ui32RealDstSyncNum; 
-
        if ((psKick->ui32Flags & SGXMKIF_TQFLAGS_KEEPPENDING) == 0UL)
        {
                IMG_UINT32 i = 0;
@@ -282,12 +279,90 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSF
                                psSyncInfo->psSyncData->ui32WriteOpsPending++;
                        }
                }
+
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+               if (ui32RealDstSyncNum < SGX_MAX_TRANSFER_SYNC_OPS - 2 && psKick->iFenceFd > 0)
+               {
+                       IMG_HANDLE ahSyncInfo[SGX_MAX_SRC_SYNCS_TA];
+                       PVRSRV_DEVICE_SYNC_OBJECT *apsDevSyncs = &psSharedTransferCmd->asDstSyncs[ui32RealDstSyncNum];
+                       IMG_UINT32 ui32NumSrcSyncs = 1;
+                       IMG_UINT32 i;
+                       ahSyncInfo[0] = (IMG_HANDLE)(psKick->iFenceFd - 1);
+
+                       eError = PVRSyncPatchTransferSyncInfos(ahSyncInfo, apsDevSyncs, &ui32NumSrcSyncs);
+                       if (eError != PVRSRV_OK)
+                       {
+                               /* We didn't kick yet, or perform PDUMP processing, so we should
+                                * be able to trivially roll back any changes made to the sync
+                                * data. If we don't do this, we'll wedge services cleanup.
+                                */
+
+                               for (loop = 0; loop < psKick->ui32NumDstSync; loop++)
+                               {
+                                       if (abDstSyncEnable[loop])
+                                       {
+                                               psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psKick->ahDstSyncInfo[loop];
+                                               psSyncInfo->psSyncData->ui32WriteOpsPending--;
+                                       }
+                               }
+
+                               for (loop = 0; loop < psKick->ui32NumSrcSync; loop++)
+                               {
+                                       if (abSrcSyncEnable[loop])
+                                       {
+                                               psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psKick->ahSrcSyncInfo[loop];
+                                               psSyncInfo->psSyncData->ui32ReadOpsPending--;
+                                       }
+                               }
+
+                               if (psKick->h3DSyncInfo != IMG_NULL)
+                               {
+                                       psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psKick->h3DSyncInfo;
+                                       psSyncInfo->psSyncData->ui32WriteOpsPending++;
+                               }
+
+                               if (psKick->hTASyncInfo != IMG_NULL)
+                               {
+                                       psSyncInfo = (PVRSRV_KERNEL_SYNC_INFO *)psKick->hTASyncInfo;
+                                       psSyncInfo->psSyncData->ui32WriteOpsPending--;
+                               }
+
+                               PVR_DPF((PVR_DBG_ERROR, "SGXSubmitTransferKM: PVRSyncPatchCCBKickSyncInfos failed."));
+                               PVR_TTRACE(PVRSRV_TRACE_GROUP_TRANSFER, PVRSRV_TRACE_CLASS_FUNCTION_EXIT,
+                                                  TRANSFER_TOKEN_SUBMIT);
+                               return eError;
+                       }
+
+                       /* Find a free dst sync to slot in our extra sync */
+                       for (loop = 0; loop < psKick->ui32NumDstSync; loop++)
+                       {
+                               if (abDstSyncEnable[loop])
+                                       break;
+                       }
+
+                       /* We shouldn't be in this code path if ui32RealDstSyncNum
+                        * didn't allow for at least two free synchronization slots.
+                        */
+                       PVR_ASSERT(loop + ui32NumSrcSyncs <= SGX_MAX_TRANSFER_SYNC_OPS);
+
+                       /* Slot in the extra dst syncs */
+                       for (i = 0; i < ui32NumSrcSyncs; i++)
+                       {
+                               psKick->ahDstSyncInfo[loop + i] = ahSyncInfo[i];
+                               abDstSyncEnable[loop + i] = IMG_TRUE;
+                               psKick->ui32NumDstSync++;
+                               ui32RealDstSyncNum++;
+                       }
+               }
+#endif /* defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) */
        }
 
+       psSharedTransferCmd->ui32NumSrcSyncs = ui32RealSrcSyncNum; 
+       psSharedTransferCmd->ui32NumDstSyncs = ui32RealDstSyncNum; 
+
 #if defined(PDUMP)
-       if ((PDumpIsCaptureFrameKM()
-       || ((psKick->ui32PDumpFlags & PDUMP_FLAGS_CONTINUOUS) != 0)) 
-       &&  (bPersistentProcess == IMG_FALSE) )
+       if (PDumpIsCaptureFrameKM()
+       || ((psKick->ui32PDumpFlags & PDUMP_FLAGS_CONTINUOUS) != 0))
        {
                PDUMPCOMMENT("Shared part of transfer command\r\n");
                PDUMPMEM(psSharedTransferCmd,
@@ -398,6 +473,14 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSF
                                        psKick->ui32PDumpFlags,
                                        MAKEUNIQUETAG(psCCBMemInfo));
 
+                       PDUMPCOMMENT("Tweak TA/TQ surface read op in transfer cmd\r\n");
+                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
+                                       psCCBMemInfo,
+                                       psKick->ui32CCBDumpWOff + (IMG_UINT32)(offsetof(SGXMKIF_TRANSFERCMD_SHARED, ui32TASyncReadOpsPendingVal)),
+                                       sizeof(psSyncInfo->psSyncData->ui32LastReadOpDumpVal),
+                                       psKick->ui32PDumpFlags,
+                                       MAKEUNIQUETAG(psCCBMemInfo));
+
                        psSyncInfo->psSyncData->ui32LastOpDumpVal++;
                }
 
@@ -413,6 +496,14 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSF
                                        psKick->ui32PDumpFlags,
                                        MAKEUNIQUETAG(psCCBMemInfo));
 
+                       PDUMPCOMMENT("Tweak 3D/TQ surface read op in transfer cmd\r\n");
+                       PDUMPMEM(&psSyncInfo->psSyncData->ui32LastReadOpDumpVal,
+                                       psCCBMemInfo,
+                                       psKick->ui32CCBDumpWOff + (IMG_UINT32)(offsetof(SGXMKIF_TRANSFERCMD_SHARED, ui323DSyncReadOpsPendingVal)),
+                                       sizeof(psSyncInfo->psSyncData->ui32LastReadOpDumpVal),
+                                       psKick->ui32PDumpFlags,
+                                       MAKEUNIQUETAG(psCCBMemInfo));
+
                        psSyncInfo->psSyncData->ui32LastOpDumpVal++;
                }
        }
@@ -529,11 +620,7 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmitTransferKM(IMG_HANDLE hDevHandle, PVRSRV_TRANSF
 }
 
 #if defined(SGX_FEATURE_2D_HARDWARE)
-#if defined (SUPPORT_SID_INTERFACE)
-IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK_KM *psKick)
-#else
 IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK *psKick)
-#endif
                                            
 {
        PVRSRV_KERNEL_MEM_INFO  *psCCBMemInfo = (PVRSRV_KERNEL_MEM_INFO *)psKick->hCCBMemInfo;
@@ -543,21 +630,6 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
        PVRSRV_ERROR eError;
        IMG_UINT32 i;
        IMG_HANDLE hDevMemContext = IMG_NULL;
-#if defined(PDUMP)
-       IMG_BOOL bPersistentProcess = IMG_FALSE;
-       /*
-        *      For persistent processes, the HW kicks should not go into the
-        *      extended init phase; only keep memory transactions from the
-        *      window system which are necessary to run the client app.
-        */
-       {
-               PVRSRV_PER_PROCESS_DATA* psPerProc = PVRSRVFindPerProcessData();
-               if(psPerProc != IMG_NULL)
-               {
-                       bPersistentProcess = psPerProc->bPDumpPersistent;
-               }
-       }
-#endif /* PDUMP */
 #if defined(FIX_HW_BRN_31620)
        hDevMemContext = psKick->hDevMemContext;
 #endif
@@ -571,8 +643,6 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
        /* PRQA S 3305 1 */
        ps2DCmd =  CCB_DATA_FROM_OFFSET(SGXMKIF_2DCMD_SHARED, psCCBMemInfo, psKick, ui32SharedCmdCCBOffset);
 
-       OSMemSet(ps2DCmd, 0, sizeof(*ps2DCmd));
-
        /* Command needs to be synchronised with the TA? */
        if (psKick->hTASyncInfo != IMG_NULL)
        {
@@ -584,6 +654,11 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
                ps2DCmd->sTASyncData.sWriteOpsCompleteDevVAddr  = psSyncInfo->sWriteOpsCompleteDevVAddr;
                ps2DCmd->sTASyncData.sReadOpsCompleteDevVAddr   = psSyncInfo->sReadOpsCompleteDevVAddr;
        }
+       else
+       {
+               ps2DCmd->sTASyncData.sWriteOpsCompleteDevVAddr.uiAddr = 0;
+               ps2DCmd->sTASyncData.sReadOpsCompleteDevVAddr.uiAddr = 0;
+       }
 
        /* Command needs to be synchronised with the 3D? */
        if (psKick->h3DSyncInfo != IMG_NULL)
@@ -596,6 +671,11 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
                ps2DCmd->s3DSyncData.sWriteOpsCompleteDevVAddr = psSyncInfo->sWriteOpsCompleteDevVAddr;
                ps2DCmd->s3DSyncData.sReadOpsCompleteDevVAddr = psSyncInfo->sReadOpsCompleteDevVAddr;
        }
+       else
+       {
+               ps2DCmd->s3DSyncData.sWriteOpsCompleteDevVAddr.uiAddr = 0;
+               ps2DCmd->s3DSyncData.sReadOpsCompleteDevVAddr.uiAddr = 0;
+       }
 
        /*
         * We allow the first source and destination sync objects to be the
@@ -604,6 +684,7 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
         * values from the objects.
         */
        ps2DCmd->ui32NumSrcSync = psKick->ui32NumSrcSync;
+
        for (i = 0; i < psKick->ui32NumSrcSync; i++)
        {
                psSyncInfo = psKick->ahSrcSyncInfo[i];
@@ -626,6 +707,15 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
                ps2DCmd->sDstSyncData.sWriteOpsCompleteDevVAddr = psSyncInfo->sWriteOpsCompleteDevVAddr;
                ps2DCmd->sDstSyncData.sReadOpsCompleteDevVAddr = psSyncInfo->sReadOpsCompleteDevVAddr;
                ps2DCmd->sDstSyncData.sReadOps2CompleteDevVAddr = psSyncInfo->sReadOps2CompleteDevVAddr;
+
+               /* We can do this immediately as we only have one */
+               psSyncInfo->psSyncData->ui32WriteOpsPending++;
+       }
+       else
+       {
+               ps2DCmd->sDstSyncData.sWriteOpsCompleteDevVAddr.uiAddr = 0;
+               ps2DCmd->sDstSyncData.sReadOpsCompleteDevVAddr.uiAddr = 0;
+               ps2DCmd->sDstSyncData.sReadOps2CompleteDevVAddr.uiAddr = 0;
        }
 
        /* Read/Write ops pending updates, delayed from above */
@@ -635,16 +725,9 @@ IMG_EXPORT PVRSRV_ERROR SGXSubmit2DKM(IMG_HANDLE hDevHandle, PVRSRV_2D_SGX_KICK
                psSyncInfo->psSyncData->ui32ReadOpsPending++;
        }
 
-       if (psKick->hDstSyncInfo != IMG_NULL)
-       {
-               psSyncInfo = psKick->hDstSyncInfo;
-               psSyncInfo->psSyncData->ui32WriteOpsPending++;
-       }
-
 #if defined(PDUMP)
        if ((PDumpIsCaptureFrameKM()
-       || ((psKick->ui32PDumpFlags & PDUMP_FLAGS_CONTINUOUS) != 0))
-       &&  (bPersistentProcess == IMG_FALSE) )
+       || ((psKick->ui32PDumpFlags & PDUMP_FLAGS_CONTINUOUS) != 0)))
        {
                /* Pdump the command from the per context CCB */
                PDUMPCOMMENT("Shared part of 2D command\r\n");
index bb45433..47765b8 100644 (file)
@@ -57,6 +57,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "pvr_debug.h"
 #include "sgxutils.h"
 #include "ttrace.h"
+#include "sgxmmu.h"
 
 #ifdef __linux__
 #include <linux/kernel.h>      // sprintf
@@ -287,7 +288,11 @@ PVRSRV_ERROR SGXScheduleCCBCommand(PVRSRV_DEVICE_NODE      *psDeviceNode,
 #if defined(PDUMP)
        IMG_VOID *pvDumpCommand;
        IMG_BOOL bPDumpIsSuspended = PDumpIsSuspended();
-       IMG_BOOL bPersistentProcess = IMG_FALSE;
+#if defined(SUPPORT_PDUMP_MULTI_PROCESS)
+       IMG_BOOL bPDumpActive = _PDumpIsProcessActive();
+#else
+       IMG_BOOL bPDumpActive = IMG_TRUE;
+#endif
 #else
        PVR_UNREFERENCED_PARAMETER(ui32CallerID);
        PVR_UNREFERENCED_PARAMETER(ui32PDumpFlags);
@@ -425,20 +430,6 @@ PVRSRV_ERROR SGXScheduleCCBCommand(PVRSRV_DEVICE_NODE      *psDeviceNode,
                }
        }
 #endif
-#if defined(PDUMP)
-       /*
-        *      For persistent processes, the HW kicks should not go into the
-        *      extended init phase; only keep memory transactions from the
-        *      window system which are necessary to run the client app.
-        */
-       {
-               PVRSRV_PER_PROCESS_DATA* psPerProc = PVRSRVFindPerProcessData();
-               if(psPerProc != IMG_NULL)
-               {
-                       bPersistentProcess = psPerProc->bPDumpPersistent;
-               }
-       }
-#endif /* PDUMP */
        psKernelCCB = psDevInfo->psKernelCCBInfo;
 
        psSGXCommand = SGXAcquireKernelCCBSlot(psKernelCCB);
@@ -499,7 +490,7 @@ PVRSRV_ERROR SGXScheduleCCBCommand(PVRSRV_DEVICE_NODE       *psDeviceNode,
 
 #if defined(PDUMP)
        if ((ui32CallerID != ISR_ID) && (bPDumpIsSuspended == IMG_FALSE) &&
-               (bPersistentProcess == IMG_FALSE) )
+               (bPDumpActive == IMG_TRUE) )
        {
                /* Poll for space in the CCB. */
                PDUMPCOMMENTWITHFLAGS(ui32PDumpFlags, "Poll for space in the Kernel CCB\r\n");
@@ -562,7 +553,7 @@ PVRSRV_ERROR SGXScheduleCCBCommand(PVRSRV_DEVICE_NODE       *psDeviceNode,
 
 #if defined(PDUMP)
        if ((ui32CallerID != ISR_ID) && (bPDumpIsSuspended == IMG_FALSE) &&
-               (bPersistentProcess == IMG_FALSE) )
+               (bPDumpActive == IMG_TRUE) )
        {
        #if defined(FIX_HW_BRN_26620) && defined(SGX_FEATURE_SYSTEM_CACHE) && !defined(SGX_BYPASS_SYSTEM_CACHE)
                PDUMPCOMMENTWITHFLAGS(ui32PDumpFlags, "Poll for previous Kernel CCB CMD to be read\r\n");
@@ -807,11 +798,7 @@ IMG_BOOL SGXIsDevicePowered(PVRSRV_DEVICE_NODE *psDeviceNode)
 ******************************************************************************/
 IMG_EXPORT
 PVRSRV_ERROR SGXGetInternalDevInfoKM(IMG_HANDLE hDevCookie,
-#if defined (SUPPORT_SID_INTERFACE)
-                                                                       SGX_INTERNAL_DEVINFO_KM *psSGXInternalDevInfo)
-#else
                                                                        SGX_INTERNAL_DEVINFO *psSGXInternalDevInfo)
-#endif
 {
        PVRSRV_SGXDEV_INFO *psDevInfo = (PVRSRV_SGXDEV_INFO *)((PVRSRV_DEVICE_NODE *)hDevCookie)->pvDevice;
 
@@ -1090,6 +1077,7 @@ IMG_HANDLE SGXRegisterHWRenderContextKM(IMG_HANDLE                                hDeviceNode,
     IMG_UINT8 *pSrc;
     IMG_UINT8 *pDst;
        PRESMAN_ITEM psResItem;
+       IMG_UINT32 ui32PDDevPAddrInDirListFormat;
 
        eError = OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
                                                sizeof(SGX_HW_RENDER_CONTEXT_CLEANUP),
@@ -1155,17 +1143,23 @@ IMG_HANDLE SGXRegisterHWRenderContextKM(IMG_HANDLE                              hDeviceNode,
     psMMUContext = BM_GetMMUContextFromMemContext(hDevMemContextInt);
     sPDDevPAddr = psDeviceNode->pfnMMUGetPDDevPAddr(psMMUContext);
 
+       /* 
+          The PDDevPAddr needs to be shifted-down, as the uKernel expects it in the
+          format it will be inserted into the DirList registers in.
+       */
+       ui32PDDevPAddrInDirListFormat = (IMG_UINT32)(sPDDevPAddr.uiAddr >> SGX_MMU_PTE_ADDR_ALIGNSHIFT);
+
     /* 
        patch-in the Page-Directory Device-Physical address. Note that this is
        copied-in one byte at a time, as we have no guarantee that the usermode-
        provided ui32OffsetToPDDevPAddr is a validly-aligned address for the
        current CPU architecture.
      */
-    pSrc = (IMG_UINT8 *)&sPDDevPAddr;
+       pSrc = (IMG_UINT8 *)&ui32PDDevPAddrInDirListFormat;
     pDst = (IMG_UINT8 *)psCleanup->psHWRenderContextMemInfo->pvLinAddrKM;
     pDst += ui32OffsetToPDDevPAddr;
 
-    for (iPtrByte = 0; iPtrByte < sizeof(IMG_DEV_PHYADDR); iPtrByte++)
+    for (iPtrByte = 0; iPtrByte < sizeof(ui32PDDevPAddrInDirListFormat); iPtrByte++)
     {
         pDst[iPtrByte] = pSrc[iPtrByte];
     }
@@ -1270,6 +1264,7 @@ IMG_HANDLE SGXRegisterHWTransferContextKM(IMG_HANDLE                              hDeviceNode,
     IMG_UINT8 *pSrc;
     IMG_UINT8 *pDst;
        PRESMAN_ITEM psResItem;
+       IMG_UINT32 ui32PDDevPAddrInDirListFormat;
 
        eError = OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
                                                sizeof(SGX_HW_TRANSFER_CONTEXT_CLEANUP),
@@ -1286,6 +1281,7 @@ IMG_HANDLE SGXRegisterHWTransferContextKM(IMG_HANDLE                              hDeviceNode,
        psDevMemoryInfo = &psDeviceNode->sDevMemoryInfo;
     psHeapInfo = &psDevMemoryInfo->psDeviceMemoryHeap[SGX_KERNEL_DATA_HEAP_ID];
 
+       PDUMPCOMMENTWITHFLAGS(PDUMP_FLAGS_CONTINUOUS, "Allocate HW Transfer context");
     eError = PVRSRVAllocDeviceMemKM(hDeviceNode,
                                psPerProc,
                                psHeapInfo->hDevMemHeap,
@@ -1335,17 +1331,23 @@ IMG_HANDLE SGXRegisterHWTransferContextKM(IMG_HANDLE                            hDeviceNode,
     psMMUContext = BM_GetMMUContextFromMemContext(hDevMemContextInt);
     sPDDevPAddr = psDeviceNode->pfnMMUGetPDDevPAddr(psMMUContext);
 
+       /* 
+          The PDDevPAddr needs to be shifted-down, as the uKernel expects it in the
+          format it will be inserted into the DirList registers in.
+       */
+       ui32PDDevPAddrInDirListFormat = (IMG_UINT32)(sPDDevPAddr.uiAddr >> SGX_MMU_PTE_ADDR_ALIGNSHIFT);
+
     /* 
        patch-in the Page-Directory Device-Physical address. Note that this is
        copied-in one byte at a time, as we have no guarantee that the usermode-
        provided ui32OffsetToPDDevPAddr is a validly-aligned address for the
        current CPU architecture.
      */
-    pSrc = (IMG_UINT8 *)&sPDDevPAddr;
+       pSrc = (IMG_UINT8 *)&ui32PDDevPAddrInDirListFormat;
     pDst = (IMG_UINT8 *)psCleanup->psHWTransferContextMemInfo->pvLinAddrKM;
     pDst += ui32OffsetToPDDevPAddr;
 
-    for (iPtrByte = 0; iPtrByte < sizeof(IMG_DEV_PHYADDR); iPtrByte++)
+    for (iPtrByte = 0; iPtrByte < sizeof(ui32PDDevPAddrInDirListFormat); iPtrByte++)
     {
         pDst[iPtrByte] = pSrc[iPtrByte];
     }
@@ -1603,6 +1605,7 @@ IMG_HANDLE SGXRegisterHW2DContextKM(IMG_HANDLE                            hDeviceNode,
     IMG_UINT8 *pSrc;
     IMG_UINT8 *pDst;
        PRESMAN_ITEM psResItem;
+       IMG_UINT32 ui32PDDevPAddrInDirListFormat;
 
        eError = OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP,
                                                sizeof(SGX_HW_2D_CONTEXT_CLEANUP),
@@ -1667,17 +1670,23 @@ IMG_HANDLE SGXRegisterHW2DContextKM(IMG_HANDLE                          hDeviceNode,
     psMMUContext = BM_GetMMUContextFromMemContext(hDevMemContextInt);
     sPDDevPAddr = psDeviceNode->pfnMMUGetPDDevPAddr(psMMUContext);
 
+       /* 
+          The PDDevPAddr needs to be shifted-down, as the uKernel expects it in the
+          format it will be inserted into the DirList registers in.
+       */
+       ui32PDDevPAddrInDirListFormat = sPDDevPAddr.uiAddr >> SGX_MMU_PTE_ADDR_ALIGNSHIFT;
+
     /* 
        patch-in the Page-Directory Device-Physical address. Note that this is
        copied-in one byte at a time, as we have no guarantee that the usermode-
        provided ui32OffsetToPDDevPAddr is a validly-aligned address for the
        current CPU architecture.
      */
-    pSrc = (IMG_UINT8 *)&sPDDevPAddr;
+       pSrc = (IMG_UINT8 *)&ui32PDDevPAddrInDirListFormat;
     pDst = (IMG_UINT8 *)psCleanup->psHW2DContextMemInfo->pvLinAddrKM;
     pDst += ui32OffsetToPDDevPAddr;
 
-    for (iPtrByte = 0; iPtrByte < sizeof(IMG_DEV_PHYADDR); iPtrByte++)
+    for (iPtrByte = 0; iPtrByte < sizeof(ui32PDDevPAddrInDirListFormat); iPtrByte++)
     {
         pDst[iPtrByte] = pSrc[iPtrByte];
     }
@@ -1846,8 +1855,8 @@ PVRSRV_ERROR SGX2DQueryBlitsCompleteKM(PVRSRV_SGXDEV_INFO *psDevInfo,
        {
                PVRSRV_SYNC_DATA *psSyncData = psSyncInfo->psSyncData;
 
-               PVR_TRACE(("SGX2DQueryBlitsCompleteKM: Syncinfo: 0x%x, Syncdata: 0x%x",
-                               (IMG_UINTPTR_T)psSyncInfo, (IMG_UINTPTR_T)psSyncData));
+               PVR_TRACE(("SGX2DQueryBlitsCompleteKM: Syncinfo: 0x%p, Syncdata: 0x%p",
+                               psSyncInfo, psSyncData));
 
                PVR_TRACE(("SGX2DQueryBlitsCompleteKM: Read ops complete: %d, Read ops pending: %d", psSyncData->ui32ReadOpsComplete, psSyncData->ui32ReadOpsPending));
                PVR_TRACE(("SGX2DQueryBlitsCompleteKM: Write ops complete: %d, Write ops pending: %d", psSyncData->ui32WriteOpsComplete, psSyncData->ui32WriteOpsPending));
index a2a47a8..20ddd56 100644 (file)
@@ -82,6 +82,11 @@ pvrsrvkm-y += \
        services4/srvkm/env/linux/ion.o
 endif
 
+ifeq ($(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC),1)
+pvrsrvkm-y += \
+       services4/srvkm/env/linux/pvr_sync.o
+endif
+
 ifeq ($(TTRACE),1)
 pvrsrvkm-y += \
        services4/srvkm/common/ttrace.o
@@ -153,7 +158,7 @@ pvrsrvkm-y += \
  services4/srvkm/env/linux/pvr_drm.o
 
 ccflags-y += \
- -I$(KERNELDIR)/include/drm \
+ -Iinclude/drm \
  -I$(TOP)/services4/include/env/linux \
 
 ifeq ($(PVR_DRI_DRM_NOT_PCI),1)
index 8a37a7f..bdc7e0b 100644 (file)
@@ -56,7 +56,7 @@ typedef struct _PVRSRV_ENV_PER_PROCESS_DATA_
 #if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
        struct list_head sDRMAuthListHead;
 #endif
-#if defined (SUPPORT_ION)
+#if defined(SUPPORT_ION)
        struct ion_client *psIONClient;
        IMG_CHAR azIonClientName[ION_CLIENT_NAME_SIZE];
 #endif
index b70a79d..fae33dc 100644 (file)
@@ -49,7 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <asm/io.h>
 #include <asm/page.h>
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
 #include <asm/system.h>
 #endif
 #include <linux/mm.h>
@@ -396,7 +396,7 @@ PVRSRV_ERROR LinuxEventObjectWait(IMG_HANDLE hOSEventObject, IMG_UINT32 ui32MSTi
 
                ui32TimeOutJiffies = (IMG_UINT32)schedule_timeout((IMG_INT32)ui32TimeOutJiffies);
                
-               LinuxLockMutex(&gPVRSRVLock);
+               LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 #if defined(DEBUG)
                psLinuxEventObject->ui32Stats++;
 #endif                 
diff --git a/services4/srvkm/env/linux/ion.c b/services4/srvkm/env/linux/ion.c
new file mode 100644 (file)
index 0000000..2b7e955
--- /dev/null
@@ -0,0 +1,423 @@
+/*************************************************************************/ /*!
+@Title          Ion driver inter-operability code.
+@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.
+*/ /**************************************************************************/
+
+#include "ion.h"
+
+/* Three possible configurations:
+ *
+ *  - !SUPPORT_ION && CONFIG_ION_OMAP
+ *    This is ion inter-op, not real ion support.
+ *
+ *  - SUPPORT_ION && CONFIG_ION_OMAP
+ *    Real ion support, but sharing with an SOC ion device. We need
+ *    to co-share the heaps too.
+ *
+ *  - SUPPORT_ION && !CONFIG_ION_OMAP
+ *    "Reference" ion implementation. Creates its own ion device
+ *    and heaps for the driver to use.
+ */
+
+#if !defined(SUPPORT_ION) && defined(CONFIG_ION_OMAP)
+
+/* Legacy ion inter-op mode */
+
+#include "services.h"
+#include "servicesint.h"
+#include "mutex.h"
+#include "lock.h"
+#include "mm.h"
+#include "handle.h"
+#include "perproc.h"
+#include "env_perproc.h"
+#include "private_data.h"
+#include "pvr_debug.h"
+
+#include <linux/module.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+
+extern struct ion_client *gpsIONClient;
+
+void PVRSRVExportFDToIONHandles(int fd, struct ion_client **client,
+                                                               struct ion_handle *handles[2])
+{
+       PVRSRV_FILE_PRIVATE_DATA *psPrivateData;
+       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo;
+       LinuxMemArea *psLinuxMemArea;
+       PVRSRV_ERROR eError;
+       struct file *psFile;
+
+       /* Take the bridge mutex so the handle won't be freed underneath us */
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
+
+       psFile = fget(fd);
+       if(!psFile)
+               goto err_unlock;
+
+       psPrivateData = psFile->private_data;
+       if(!psPrivateData)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: struct file* has no private_data; "
+                                                               "invalid export handle", __func__));
+               goto err_fput;
+       }
+
+       eError = PVRSRVLookupHandle(KERNEL_HANDLE_BASE,
+                                                               (IMG_PVOID *)&psKernelMemInfo,
+                                                               psPrivateData->hKernelMemInfo,
+                                                               PVRSRV_HANDLE_TYPE_MEM_INFO);
+       if(eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: Failed to look up MEM_INFO handle",
+                                                               __func__));
+               goto err_fput;
+       }
+
+       psLinuxMemArea = (LinuxMemArea *)psKernelMemInfo->sMemBlk.hOSMemHandle;
+       BUG_ON(psLinuxMemArea == IMG_NULL);
+
+       if(psLinuxMemArea->eAreaType != LINUX_MEM_AREA_ION)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: Valid handle, but not an ION buffer",
+                                                               __func__));
+               goto err_fput;
+       }
+
+       handles[0] = psLinuxMemArea->uData.sIONTilerAlloc.psIONHandle[0];
+       handles[1] = psLinuxMemArea->uData.sIONTilerAlloc.psIONHandle[1];
+       if(client)
+               *client = gpsIONClient;
+
+err_fput:
+       fput(psFile);
+err_unlock:
+       /* Allow PVRSRV clients to communicate with srvkm again */
+       LinuxUnLockMutex(&gPVRSRVLock);
+}
+
+struct ion_handle *
+PVRSRVExportFDToIONHandle(int fd, struct ion_client **client)
+{
+       struct ion_handle *psHandles[2] = { IMG_NULL, IMG_NULL };
+       PVRSRVExportFDToIONHandles(fd, client, psHandles);
+       return psHandles[0];
+}
+
+EXPORT_SYMBOL(PVRSRVExportFDToIONHandles);
+EXPORT_SYMBOL(PVRSRVExportFDToIONHandle);
+
+#endif /* !defined(SUPPORT_ION) && defined(CONFIG_ION_OMAP) */
+
+#if defined(SUPPORT_ION)
+
+#include <linux/scatterlist.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+
+#if defined(CONFIG_ION_OMAP)
+
+/* Real ion with sharing */
+
+extern struct ion_device *omap_ion_device;
+struct ion_device *gpsIonDev;
+
+PVRSRV_ERROR IonInit(IMG_VOID)
+{
+       gpsIonDev = omap_ion_device;
+       return PVRSRV_OK;
+}
+
+IMG_VOID IonDeinit(IMG_VOID)
+{
+       gpsIonDev = IMG_NULL;
+}
+
+#else /* defined(CONFIG_ION_OMAP) */
+
+/* "Reference" ion implementation */
+
+#include "../drivers/gpu/ion/ion_priv.h"
+
+static struct ion_heap **gapsIonHeaps;
+struct ion_device *gpsIonDev;
+
+static struct ion_platform_data gsGenericConfig =
+{
+       .nr = 2,
+       .heaps =
+       {
+               {
+                       .type = ION_HEAP_TYPE_SYSTEM_CONTIG,
+                       .name = "System contig",
+                       .id   = ION_HEAP_TYPE_SYSTEM_CONTIG,
+               },
+               {
+                       .type = ION_HEAP_TYPE_SYSTEM,
+                       .name = "System",
+                       .id   = ION_HEAP_TYPE_SYSTEM,
+               }
+       }
+};
+
+PVRSRV_ERROR IonInit(IMG_VOID)
+{
+       int uiHeapCount = gsGenericConfig.nr;
+       int uiError;
+       int i;
+
+       gapsIonHeaps = kzalloc(sizeof(struct ion_heap *) * uiHeapCount, GFP_KERNEL);
+       /* Create the ion devicenode */
+       gpsIonDev = ion_device_create(NULL);
+       if (IS_ERR_OR_NULL(gpsIonDev)) {
+               kfree(gapsIonHeaps);
+               return PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+
+       /* Register all the heaps */
+       for (i = 0; i < gsGenericConfig.nr; i++)
+       {
+               struct ion_platform_heap *psPlatHeapData = &gsGenericConfig.heaps[i];
+
+               gapsIonHeaps[i] = ion_heap_create(psPlatHeapData);
+               if (IS_ERR_OR_NULL(gapsIonHeaps[i]))
+               {
+                       uiError = PTR_ERR(gapsIonHeaps[i]);
+                       goto failHeapCreate;
+               }
+               ion_device_add_heap(gpsIonDev, gapsIonHeaps[i]);
+       }
+
+       return PVRSRV_OK;
+failHeapCreate:
+       for (i = 0; i < uiHeapCount; i++)
+       {
+               if (gapsIonHeaps[i])
+               {
+                               ion_heap_destroy(gapsIonHeaps[i]);
+               }
+       }
+       kfree(gapsIonHeaps);
+       return PVRSRV_ERROR_OUT_OF_MEMORY;
+}
+
+IMG_VOID IonDeinit(IMG_VOID)
+{
+       int uiHeapCount = gsGenericConfig.nr;
+       int i;
+
+       for (i = 0; i < uiHeapCount; i++)
+       {
+               if (gapsIonHeaps[i])
+               {
+                               ion_heap_destroy(gapsIonHeaps[i]);
+               }
+       }
+       kfree(gapsIonHeaps);
+       ion_device_destroy(gpsIonDev);
+}
+
+#endif /* defined(CONFIG_ION_OMAP) */
+
+#define MAX_IMPORT_ION_FDS 3
+
+typedef struct _ION_IMPORT_DATA_
+{
+       /* ion client handles are imported into */
+       struct ion_client *psIonClient;
+
+       /* Number of ion handles represented by this import */
+       IMG_UINT32 ui32NumIonHandles;
+
+       /* Array of ion handles in use by services */
+       struct ion_handle *apsIonHandle[MAX_IMPORT_ION_FDS];
+
+       /* Array of physical addresses represented by these buffers */
+       IMG_SYS_PHYADDR *psSysPhysAddr;
+
+       /* If ui32NumBuffers is 1 and ion_map_kernel() is implemented by the
+        * allocator, this may be non-NULL. Otherwise it will be NULL.
+        */
+       IMG_PVOID pvKernAddr0;
+}
+ION_IMPORT_DATA;
+
+PVRSRV_ERROR IonImportBufferAndAcquirePhysAddr(IMG_HANDLE hIonDev,
+                                                                                          IMG_UINT32 ui32NumFDs,
+                                                                                          IMG_INT32  *pai32BufferFDs,
+                                                                                          IMG_UINT32 *pui32PageCount,
+                                                                                          IMG_SYS_PHYADDR **ppsSysPhysAddr,
+                                                                                          IMG_PVOID  *ppvKernAddr0,
+                                                                                          IMG_HANDLE *phPriv,
+                                                                                          IMG_HANDLE *phUnique)
+{
+       struct scatterlist *psTemp, *psScatterList[MAX_IMPORT_ION_FDS] = {};
+       PVRSRV_ERROR eError = PVRSRV_ERROR_OUT_OF_MEMORY;
+       struct ion_client *psIonClient = hIonDev;
+       IMG_UINT32 i, k, ui32PageCount = 0;
+       ION_IMPORT_DATA *psImportData;
+
+       if(ui32NumFDs > MAX_IMPORT_ION_FDS)
+       {
+               printk(KERN_ERR "%s: More ion export fds passed in than supported "
+                                               "(%d provided, %d max)", __func__, ui32NumFDs,
+                                               MAX_IMPORT_ION_FDS);
+               return PVRSRV_ERROR_INVALID_PARAMS;
+       }
+
+       psImportData = kzalloc(sizeof(ION_IMPORT_DATA), GFP_KERNEL);
+       if (psImportData == NULL)
+       {
+               goto exitFailKMallocImportData;
+       }
+
+       /* Set up import data for free call */
+       psImportData->psIonClient = psIonClient;
+       psImportData->ui32NumIonHandles = ui32NumFDs;
+
+       for(i = 0; i < ui32NumFDs; i++)
+       {
+               int fd = (int)pai32BufferFDs[i];
+
+               psImportData->apsIonHandle[i] = ion_import_fd(psIonClient, fd);
+               if (psImportData->apsIonHandle[i] == IMG_NULL)
+               {
+                       eError = PVRSRV_ERROR_BAD_MAPPING;
+                       goto exitFailImport;
+               }
+
+               psScatterList[i] = ion_map_dma(psIonClient, psImportData->apsIonHandle[i]);
+               if (psScatterList[i] == NULL)
+               {
+                       eError = PVRSRV_ERROR_INVALID_PARAMS;
+                       goto exitFailImport;
+               }
+
+               for(psTemp = psScatterList[i]; psTemp; psTemp = sg_next(psTemp))
+               {
+                       IMG_UINT32 j;
+                       for (j = 0; j < psTemp->length; j += PAGE_SIZE)
+                       {
+                               ui32PageCount++;
+                       }
+               }
+       }
+
+       BUG_ON(ui32PageCount == 0);
+
+       psImportData->psSysPhysAddr = kmalloc(sizeof(IMG_SYS_PHYADDR) * ui32PageCount, GFP_KERNEL);
+       if (psImportData->psSysPhysAddr == NULL)
+       {
+               goto exitFailImport;
+       }
+
+       for(i = 0, k = 0; i < ui32NumFDs; i++)
+       {
+               for(psTemp = psScatterList[i]; psTemp; psTemp = sg_next(psTemp))
+               {
+                       IMG_UINT32 j;
+                       for (j = 0; j < psTemp->length; j += PAGE_SIZE)
+                       {
+                               psImportData->psSysPhysAddr[k].uiAddr = sg_phys(psTemp) + j;
+                               k++;
+                       }
+               }
+       }
+
+       *pui32PageCount = ui32PageCount;
+       *ppsSysPhysAddr = psImportData->psSysPhysAddr;
+
+       if(ui32NumFDs == 1)
+       {
+               IMG_PVOID pvKernAddr0;
+
+               pvKernAddr0 = ion_map_kernel(psIonClient, psImportData->apsIonHandle[0]);
+               if (IS_ERR(pvKernAddr0))
+               {
+                       pvKernAddr0 = IMG_NULL;
+               }
+
+               psImportData->pvKernAddr0 = pvKernAddr0;
+               *ppvKernAddr0 = pvKernAddr0;
+       }
+       else
+       {
+               *ppvKernAddr0 = NULL;
+       }
+
+       *phPriv = psImportData;
+       *phUnique = (IMG_HANDLE)psImportData->psSysPhysAddr[0].uiAddr;
+
+       return PVRSRV_OK;
+
+exitFailImport:
+       for(i = 0; psImportData->apsIonHandle[i] != NULL; i++)
+       {
+               if(psScatterList[i])
+                       ion_unmap_dma(psIonClient, psImportData->apsIonHandle[i]);
+               ion_free(psIonClient, psImportData->apsIonHandle[i]);
+       }
+       kfree(psImportData);
+exitFailKMallocImportData:
+       return eError;
+}
+
+IMG_VOID IonUnimportBufferAndReleasePhysAddr(IMG_HANDLE hPriv)
+{
+       ION_IMPORT_DATA *psImportData = hPriv;
+       IMG_UINT32 i;
+
+       if (psImportData->pvKernAddr0)
+       {
+               ion_unmap_kernel(psImportData->psIonClient, psImportData->apsIonHandle[0]);
+       }
+
+       for(i = 0; i < psImportData->ui32NumIonHandles; i++)
+       {
+               ion_unmap_dma(psImportData->psIonClient, psImportData->apsIonHandle[i]);
+               ion_free(psImportData->psIonClient, psImportData->apsIonHandle[i]);
+       }
+
+       kfree(psImportData->psSysPhysAddr);
+       kfree(psImportData);
+}
+
+#endif /* defined(SUPPORT_ION) */
diff --git a/services4/srvkm/env/linux/ion.h b/services4/srvkm/env/linux/ion.h
new file mode 100644 (file)
index 0000000..ba55a93
--- /dev/null
@@ -0,0 +1,83 @@
+/*************************************************************************/ /*!
+@Title          Ion driver inter-operability code.
+@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.
+*/ /**************************************************************************/
+
+#ifndef __IMG_LINUX_ION_H__
+#define __IMG_LINUX_ION_H__
+
+#include <linux/ion.h>
+#if defined (CONFIG_ION_OMAP)
+#include <linux/omap_ion.h>
+#endif
+#if defined (SUPPORT_ION)
+#include "img_types.h"
+#include "servicesext.h"
+#endif
+
+#if !defined(SUPPORT_ION) && defined(CONFIG_ION_OMAP)
+
+void PVRSRVExportFDToIONHandles(int fd, struct ion_client **client,
+                                                               struct ion_handle *handles[2]);
+
+struct ion_handle *PVRSRVExportFDToIONHandle(int fd,
+                                                                                        struct ion_client **client);
+
+#endif /* !defined(SUPPORT_ION) && defined(CONFIG_ION_OMAP) */
+
+#if defined(SUPPORT_ION)
+
+PVRSRV_ERROR IonInit(IMG_VOID);
+
+IMG_VOID IonDeinit(IMG_VOID);
+
+PVRSRV_ERROR IonImportBufferAndAcquirePhysAddr(IMG_HANDLE hIonDev,
+                                                                                          IMG_UINT32 ui32NumFDs,
+                                                                                          IMG_INT32  *pi32BufferFDs,
+                                                                                          IMG_UINT32 *pui32PageCount,
+                                                                                          IMG_SYS_PHYADDR **ppsSysPhysAddr,
+                                                                                          IMG_PVOID *ppvKernAddr0,
+                                                                                          IMG_HANDLE *phPriv,
+                                                                                          IMG_HANDLE *phUnique);
+
+IMG_VOID IonUnimportBufferAndReleasePhysAddr(IMG_HANDLE hPriv);
+
+#endif /* defined(SUPPORT_ION) */
+
+#endif /* __IMG_LINUX_ION_H__ */
index 23ae762..ea8850b 100644 (file)
@@ -89,6 +89,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #include "lists.h"
 #endif
 
+/* Decide whether or not DevMem allocs need __GFP_DMA32 */
+#ifndef SGX_FEATURE_36BIT_MMU
+#      ifdef CONFIG_ZONE_DMA32
+#              if defined CONFIG_X86_PAE || defined CONFIG_ARM_LPAE || defined CONFIG_64BIT
+#                      define PVR_USE_DMA32_FOR_DEVMEM_ALLOCS
+#              endif
+#      endif
+#endif
+
 /*
  * The page pool entry count is an atomic int so that the shrinker function
  * can return it even when we can't take the lock that protects the page pool
@@ -114,11 +123,11 @@ typedef enum {
 typedef struct _DEBUG_MEM_ALLOC_REC
 {
     DEBUG_MEM_ALLOC_TYPE    eAllocType;
-       IMG_VOID                                *pvKey; /* Some unique value (private to the eAllocType) */
+       IMG_UINTPTR_T                   uiKey; /* Some unique value (private to the eAllocType) */
     IMG_VOID                *pvCpuVAddr;
-    IMG_UINT32              ulCpuPAddr;
+    IMG_CPU_PHYADDR         sCpuPAddr;
     IMG_VOID                *pvPrivateData;
-       IMG_UINT32                              ui32Bytes;
+       IMG_SIZE_T                              uiBytes;
        pid_t                                   pid;
     IMG_CHAR                *pszFileName;
     IMG_UINT32              ui32Line;
@@ -154,15 +163,15 @@ static IMG_UINT32 g_IOMemWaterMark;
 static IMG_UINT32 g_IOMemHighWaterMark;
 
 static IMG_VOID DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE eAllocType,
-                                       IMG_VOID *pvKey,
+                                       IMG_UINTPTR_T uiKey,
                                        IMG_VOID *pvCpuVAddr,
-                                       IMG_UINT32 ulCpuPAddr,
+                                       IMG_CPU_PHYADDR sCpuPAddr,
                                        IMG_VOID *pvPrivateData,
-                                       IMG_UINT32 ui32Bytes,
+                                       IMG_SIZE_T uiBytes,
                                        IMG_CHAR *pszFileName,
                                        IMG_UINT32 ui32Line);
 
-static IMG_VOID DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE eAllocType, IMG_VOID *pvKey, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
+static IMG_VOID DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE eAllocType, IMG_UINTPTR_T uiKey, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
 
 static IMG_CHAR *DebugMemAllocRecordTypeToString(DEBUG_MEM_ALLOC_TYPE eAllocType);
 
@@ -232,8 +241,8 @@ static LIST_HEAD(g_sPagePoolList);
 static int g_iPagePoolMaxEntries;
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
-static IMG_VOID ReservePages(IMG_VOID *pvAddress, IMG_UINT32 ui32Length);
-static IMG_VOID UnreservePages(IMG_VOID *pvAddress, IMG_UINT32 ui32Length);
+static IMG_VOID ReservePages(IMG_VOID *pvAddress, IMG_SIZE_T uiLength);
+static IMG_VOID UnreservePages(IMG_VOID *pvAddress, IMG_SIZE_T uiLength);
 #endif
 
 static LinuxMemArea *LinuxMemAreaStructAlloc(IMG_VOID);
@@ -258,19 +267,22 @@ CanFreeToPool(LinuxMemArea *psLinuxMemArea)
 }
 
 IMG_VOID *
-_KMallocWrapper(IMG_UINT32 ui32ByteSize, gfp_t uFlags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
+_KMallocWrapper(IMG_SIZE_T uiByteSize, gfp_t uFlags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
     IMG_VOID *pvRet;
-    pvRet = kmalloc(ui32ByteSize, uFlags);
+    pvRet = kmalloc(uiByteSize, uFlags);
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     if (pvRet)
     {
+               IMG_CPU_PHYADDR sCpuPAddr;
+               sCpuPAddr.uiAddr = 0;
+
         DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_KMALLOC,
+                               (IMG_UINTPTR_T)pvRet,
                                pvRet,
-                               pvRet,
-                               0,
+                               sCpuPAddr,
                                NULL,
-                               ui32ByteSize,
+                               uiByteSize,
                                pszFileName,
                                ui32Line
                               );
@@ -287,7 +299,11 @@ IMG_VOID
 _KFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_KMALLOC, pvCpuVAddr, pszFileName,  ui32Line);
+    DebugMemAllocRecordRemove(
+                       DEBUG_MEM_ALLOC_TYPE_KMALLOC, 
+                       (IMG_UINTPTR_T)pvCpuVAddr, 
+                       pszFileName,  
+                       ui32Line);
 #else
     PVR_UNREFERENCED_PARAMETER(pszFileName);
     PVR_UNREFERENCED_PARAMETER(ui32Line);
@@ -299,11 +315,11 @@ _KFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
 static IMG_VOID
 DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE eAllocType,
-                       IMG_VOID *pvKey,
+                       IMG_UINTPTR_T uiKey,
                        IMG_VOID *pvCpuVAddr,
-                       IMG_UINT32 ulCpuPAddr,
+                       IMG_CPU_PHYADDR sCpuPAddr,
                        IMG_VOID *pvPrivateData,
-                       IMG_UINT32 ui32Bytes,
+                       IMG_SIZE_T uiBytes,
                        IMG_CHAR *pszFileName,
                        IMG_UINT32 ui32Line)
 {
@@ -314,18 +330,18 @@ DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE eAllocType,
     psRecord = kmalloc(sizeof(DEBUG_MEM_ALLOC_REC), GFP_KERNEL);
 
     psRecord->eAllocType = eAllocType;
-    psRecord->pvKey = pvKey;
+    psRecord->uiKey = uiKey;
     psRecord->pvCpuVAddr = pvCpuVAddr;
-    psRecord->ulCpuPAddr = ulCpuPAddr;
+    psRecord->sCpuPAddr.uiAddr = sCpuPAddr.uiAddr;
     psRecord->pvPrivateData = pvPrivateData;
     psRecord->pid = OSGetCurrentProcessIDKM();
-    psRecord->ui32Bytes = ui32Bytes;
+    psRecord->uiBytes = uiBytes;
     psRecord->pszFileName = pszFileName;
     psRecord->ui32Line = ui32Line;
     
        List_DEBUG_MEM_ALLOC_REC_Insert(&g_MemoryRecords, psRecord);
     
-    g_WaterMarkData[eAllocType] += ui32Bytes;
+    g_WaterMarkData[eAllocType] += uiBytes;
     if (g_WaterMarkData[eAllocType] > g_HighWaterMarkData[eAllocType])
     {
         g_HighWaterMarkData[eAllocType] = g_WaterMarkData[eAllocType];
@@ -336,20 +352,20 @@ DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE eAllocType,
        || eAllocType == DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES
        || eAllocType == DEBUG_MEM_ALLOC_TYPE_KMEM_CACHE)
     {
-       IMG_UINT32 ui32SysRAMTrueWaterMark;
+               IMG_SIZE_T uSysRAMTrueWaterMark;
 
-        g_SysRAMWaterMark += ui32Bytes;
-       ui32SysRAMTrueWaterMark = SysRAMTrueWaterMark();
+        g_SysRAMWaterMark += uiBytes;
+               uSysRAMTrueWaterMark = SysRAMTrueWaterMark();
 
-        if (ui32SysRAMTrueWaterMark > g_SysRAMHighWaterMark)
+        if (uSysRAMTrueWaterMark > g_SysRAMHighWaterMark)
         {
-            g_SysRAMHighWaterMark = ui32SysRAMTrueWaterMark;
+            g_SysRAMHighWaterMark = uSysRAMTrueWaterMark;
         }
     }
     else if (eAllocType == DEBUG_MEM_ALLOC_TYPE_IOREMAP
             || eAllocType == DEBUG_MEM_ALLOC_TYPE_IO)
     {
-        g_IOMemWaterMark += ui32Bytes;
+        g_IOMemWaterMark += uiBytes;
         if (g_IOMemWaterMark > g_IOMemHighWaterMark)
         {
             g_IOMemHighWaterMark = g_IOMemWaterMark;
@@ -363,28 +379,28 @@ DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE eAllocType,
 static IMG_BOOL DebugMemAllocRecordRemove_AnyVaCb(DEBUG_MEM_ALLOC_REC *psCurrentRecord, va_list va)
 {
        DEBUG_MEM_ALLOC_TYPE eAllocType;
-       IMG_VOID *pvKey;
+       IMG_UINTPTR_T uiKey;
        
        eAllocType = va_arg(va, DEBUG_MEM_ALLOC_TYPE);
-       pvKey = va_arg(va, IMG_VOID*);
+       uiKey = va_arg(va, IMG_UINTPTR_T);
 
        if (psCurrentRecord->eAllocType == eAllocType
-               && psCurrentRecord->pvKey == pvKey)
+               && psCurrentRecord->uiKey == uiKey)
        {
                eAllocType = psCurrentRecord->eAllocType;
-               g_WaterMarkData[eAllocType] -= psCurrentRecord->ui32Bytes;
+               g_WaterMarkData[eAllocType] -= psCurrentRecord->uiBytes;
                
                if (eAllocType == DEBUG_MEM_ALLOC_TYPE_KMALLOC
                   || eAllocType == DEBUG_MEM_ALLOC_TYPE_VMALLOC
                   || eAllocType == DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES
                   || eAllocType == DEBUG_MEM_ALLOC_TYPE_KMEM_CACHE)
                {
-                       g_SysRAMWaterMark -= psCurrentRecord->ui32Bytes;
+                       g_SysRAMWaterMark -= psCurrentRecord->uiBytes;
                }
                else if (eAllocType == DEBUG_MEM_ALLOC_TYPE_IOREMAP
                                || eAllocType == DEBUG_MEM_ALLOC_TYPE_IO)
                {
-                       g_IOMemWaterMark -= psCurrentRecord->ui32Bytes;
+                       g_IOMemWaterMark -= psCurrentRecord->uiBytes;
                }
                
                List_DEBUG_MEM_ALLOC_REC_Remove(psCurrentRecord);
@@ -400,7 +416,7 @@ static IMG_BOOL DebugMemAllocRecordRemove_AnyVaCb(DEBUG_MEM_ALLOC_REC *psCurrent
 
 
 static IMG_VOID
-DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE eAllocType, IMG_VOID *pvKey, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
+DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE eAllocType, IMG_UINTPTR_T uiKey, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
 /*    DEBUG_MEM_ALLOC_REC **ppsCurrentRecord;*/
 
@@ -410,10 +426,10 @@ DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE eAllocType, IMG_VOID *pvKey, IMG_
        if (!List_DEBUG_MEM_ALLOC_REC_IMG_BOOL_Any_va(g_MemoryRecords,
                                                                                                DebugMemAllocRecordRemove_AnyVaCb,
                                                                                                eAllocType,
-                                                                                               pvKey))
+                                                                                               uiKey))
        {
-               PVR_DPF((PVR_DBG_ERROR, "%s: couldn't find an entry for type=%s with pvKey=%p (called from %s, line %d\n",
-               __FUNCTION__, DebugMemAllocRecordTypeToString(eAllocType), pvKey,
+               PVR_DPF((PVR_DBG_ERROR, "%s: couldn't find an entry for type=%s with uiKey=" UINTPTR_FMT " (called from %s, line %d\n",
+               __FUNCTION__, DebugMemAllocRecordTypeToString(eAllocType), uiKey,
                pszFileName, ui32Line));
        }
 
@@ -470,31 +486,43 @@ AllocFlagsToPGProt(pgprot_t *pPGProtFlags, IMG_UINT32 ui32AllocFlags)
 }
 
 IMG_VOID *
-_VMallocWrapper(IMG_UINT32 ui32Bytes,
+_VMallocWrapper(IMG_SIZE_T uiBytes,
                 IMG_UINT32 ui32AllocFlags,
                 IMG_CHAR *pszFileName,
                 IMG_UINT32 ui32Line)
 {
     pgprot_t PGProtFlags;
     IMG_VOID *pvRet;
+       gfp_t gfp_mask; 
     
     if (!AllocFlagsToPGProt(&PGProtFlags, ui32AllocFlags))
     {
             return NULL;
     }
 
+       gfp_mask = GFP_KERNEL;
+
+#if defined(PVR_USE_DMA32_FOR_DEVMEM_ALLOCS)
+       gfp_mask |= __GFP_DMA32;
+#else
+       gfp_mask |= __GFP_HIGHMEM;
+#endif
+
        /* Allocate virtually contiguous pages */
-    pvRet = __vmalloc(ui32Bytes, GFP_KERNEL | __GFP_HIGHMEM, PGProtFlags);
+    pvRet = __vmalloc(uiBytes, gfp_mask, PGProtFlags);
     
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     if (pvRet)
     {
+               IMG_CPU_PHYADDR sCpuPAddr;
+               sCpuPAddr.uiAddr = 0;
+
         DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_VMALLOC,
+                               (IMG_UINTPTR_T)pvRet,
                                pvRet,
-                               pvRet,
-                               0,
+                               sCpuPAddr,
                                NULL,
-                               PAGE_ALIGN(ui32Bytes),
+                               PAGE_ALIGN(uiBytes),
                                pszFileName,
                                ui32Line
                               );
@@ -512,7 +540,11 @@ IMG_VOID
 _VFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_VMALLOC, pvCpuVAddr, pszFileName, ui32Line);
+    DebugMemAllocRecordRemove(
+                       DEBUG_MEM_ALLOC_TYPE_VMALLOC, 
+                       (IMG_UINTPTR_T)pvCpuVAddr, 
+                       pszFileName, 
+                       ui32Line);
 #else
     PVR_UNREFERENCED_PARAMETER(pszFileName);
     PVR_UNREFERENCED_PARAMETER(ui32Line);
@@ -538,10 +570,13 @@ _VMapWrapper(struct page **ppsPageList, IMG_UINT32 ui32NumPages, IMG_UINT32 ui32
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     if (pvRet)
     {
+               IMG_CPU_PHYADDR sCpuPAddr;
+               sCpuPAddr.uiAddr = 0;
+
         DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_VMAP,
+                               (IMG_UINTPTR_T)pvRet,
                                pvRet,
-                               pvRet,
-                               0,
+                               sCpuPAddr,
                                NULL,
                                PAGES_TO_BYTES(ui32NumPages),
                                pszFileName,
@@ -557,9 +592,9 @@ _VMapWrapper(struct page **ppsPageList, IMG_UINT32 ui32NumPages, IMG_UINT32 ui32
 }
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-#define VMapWrapper(ppsPageList, ui32Bytes, ui32AllocFlags) _VMapWrapper(ppsPageList, ui32Bytes, ui32AllocFlags, __FILE__, __LINE__)
+#define VMapWrapper(ppsPageList, uBytes, ui32AllocFlags) _VMapWrapper(ppsPageList, uBytes, ui32AllocFlags, __FILE__, __LINE__)
 #else
-#define VMapWrapper(ppsPageList, ui32Bytes, ui32AllocFlags) _VMapWrapper(ppsPageList, ui32Bytes, ui32AllocFlags, NULL, 0)
+#define VMapWrapper(ppsPageList, uBytes, ui32AllocFlags) _VMapWrapper(ppsPageList, uBytes, ui32AllocFlags, NULL, 0)
 #endif
 
 
@@ -567,7 +602,8 @@ static IMG_VOID
 _VUnmapWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_VMAP, pvCpuVAddr, pszFileName, ui32Line);
+    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_VMAP,
+                                                         (IMG_UINTPTR_T)pvCpuVAddr, pszFileName, ui32Line);
 #else
     PVR_UNREFERENCED_PARAMETER(pszFileName);
     PVR_UNREFERENCED_PARAMETER(ui32Line);
@@ -588,7 +624,11 @@ IMG_VOID
 _KMemCacheFreeWrapper(LinuxKMemCache *psCache, IMG_VOID *pvObject, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_KMEM_CACHE, pvObject, pszFileName, ui32Line);
+    DebugMemAllocRecordRemove(
+                       DEBUG_MEM_ALLOC_TYPE_KMEM_CACHE, 
+                       (IMG_UINTPTR_T)pvObject, 
+                       pszFileName, 
+                       ui32Line);
 #else
     PVR_UNREFERENCED_PARAMETER(pszFileName);
     PVR_UNREFERENCED_PARAMETER(ui32Line);
@@ -626,13 +666,22 @@ static struct page *
 AllocPageFromLinux(void)
 {
        struct page *psPage;
+       gfp_t gfp_mask; 
 
-        psPage = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, 0);
-        if (!psPage)
-        {
-            return NULL;
+       gfp_mask = GFP_KERNEL;
 
-        }
+#if defined(PVR_USE_DMA32_FOR_DEVMEM_ALLOCS)
+       gfp_mask |= __GFP_DMA32;
+#else
+       gfp_mask |= __GFP_HIGHMEM;
+#endif
+
+       psPage = alloc_pages(gfp_mask, 0);
+       if (!psPage)
+       {
+               return NULL;
+
+       }
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
        /* Reserve those pages to allow them to be re-mapped to user space */
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))               
@@ -885,6 +934,10 @@ AllocPages(IMG_UINT32 ui32AreaFlags, struct page ***pppsPageList, IMG_HANDLE *ph
     PVRSRV_ERROR eError;
     IMG_BOOL bFromPagePool = IMG_FALSE;
 
+#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
+       IMG_CPU_PHYADDR sCpuPAddr;
+#endif
+
     eError = OSAllocMem(0, sizeof(*ppsPageList) * ui32NumPages, (IMG_VOID **)&ppsPageList, &hBlockPageList,
                                                        "Array of pages");
     if (eError != PVRSRV_OK)
@@ -907,10 +960,12 @@ AllocPages(IMG_UINT32 ui32AreaFlags, struct page ***pppsPageList, IMG_HANDLE *ph
     *phBlockPageList = hBlockPageList;
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
+       sCpuPAddr.uiAddr = 0;
+
     DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES,
-                           ppsPageList,
-                           0,
+                           (IMG_UINTPTR_T)ppsPageList,
                            0,
+                           sCpuPAddr,
                            NULL,
                            PAGES_TO_BYTES(ui32NumPages),
                            "unknown",
@@ -943,7 +998,11 @@ FreePages(IMG_BOOL bToPagePool, struct page **ppsPageList, IMG_HANDLE hBlockPage
     }
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES, ppsPageList, __FILE__, __LINE__);
+    DebugMemAllocRecordRemove(
+                       DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES, 
+                       (IMG_UINTPTR_T)ppsPageList, 
+                       __FILE__, 
+                       __LINE__);
 #endif
 
     (IMG_VOID) OSFreeMem(0, sizeof(*ppsPageList) * ui32NumPages, ppsPageList, hBlockPageList);
@@ -951,7 +1010,7 @@ FreePages(IMG_BOOL bToPagePool, struct page **ppsPageList, IMG_HANDLE hBlockPage
 
 
 LinuxMemArea *
-NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
+NewVMallocLinuxMemArea(IMG_SIZE_T uBytes, IMG_UINT32 ui32AreaFlags)
 {
     LinuxMemArea *psLinuxMemArea = NULL;
     IMG_VOID *pvCpuVAddr;
@@ -969,7 +1028,7 @@ NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
     }
 
 #if defined(PVR_LINUX_MEM_AREA_USE_VMAP)
-    ui32NumPages = RANGE_TO_PAGES(ui32Bytes);
+    ui32NumPages = RANGE_TO_PAGES(uBytes);
 
     if (!AllocPages(ui32AreaFlags, &ppsPageList, &hBlockPageList, ui32NumPages, &bFromPagePool))
     {
@@ -978,7 +1037,7 @@ NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
 
     pvCpuVAddr = VMapWrapper(ppsPageList, ui32NumPages, ui32AreaFlags);
 #else  /* defined(PVR_LINUX_MEM_AREA_USE_VMAP) */
-    pvCpuVAddr = VMallocWrapper(ui32Bytes, ui32AreaFlags);
+    pvCpuVAddr = VMallocWrapper(uBytes, ui32AreaFlags);
     if (!pvCpuVAddr)
     {
         goto failed;
@@ -986,7 +1045,7 @@ NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
 /* PG_reserved was deprecated in linux-2.6.15 */
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
     /* Reserve those pages to allow them to be re-mapped to user space */
-    ReservePages(pvCpuVAddr, ui32Bytes);
+    ReservePages(pvCpuVAddr, uBytes);
 #endif
 #endif /* defined(PVR_LINUX_MEM_AREA_USE_VMAP) */ 
 
@@ -996,7 +1055,7 @@ NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
     psLinuxMemArea->uData.sVmalloc.ppsPageList = ppsPageList;
     psLinuxMemArea->uData.sVmalloc.hBlockPageList = hBlockPageList;
 #endif
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = ui32AreaFlags;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
 
@@ -1021,7 +1080,7 @@ NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
      */
     if (AreaIsUncached(ui32AreaFlags) && !bFromPagePool)
     {
-        OSInvalidateCPUCacheRangeKM(psLinuxMemArea, 0, pvCpuVAddr, ui32Bytes);
+        OSInvalidateCPUCacheRangeKM(psLinuxMemArea, 0, pvCpuVAddr, uBytes);
     }
 
     return psLinuxMemArea;
@@ -1066,7 +1125,7 @@ FreeVMallocLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 #if defined(PVR_LINUX_MEM_AREA_USE_VMAP)
     VUnmapWrapper(psLinuxMemArea->uData.sVmalloc.pvVmallocAddress);
 
-    ui32NumPages = RANGE_TO_PAGES(psLinuxMemArea->ui32ByteSize);
+    ui32NumPages = RANGE_TO_PAGES(psLinuxMemArea->uiByteSize);
     ppsPageList = psLinuxMemArea->uData.sVmalloc.ppsPageList;
     hBlockPageList = psLinuxMemArea->uData.sVmalloc.hBlockPageList;
     
@@ -1075,7 +1134,7 @@ FreeVMallocLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 /* PG_reserved was deprecated in linux-2.6.15 */
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
     UnreservePages(psLinuxMemArea->uData.sVmalloc.pvVmallocAddress,
-                    psLinuxMemArea->ui32ByteSize);
+                    psLinuxMemArea->uiByteSize);
 #endif
 
     VFreeWrapper(psLinuxMemArea->uData.sVmalloc.pvVmallocAddress);
@@ -1089,10 +1148,10 @@ FreeVMallocLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 /* Reserve pages of memory in order that they're not automatically
    deallocated after the last user reference dies. */
 static IMG_VOID
-ReservePages(IMG_VOID *pvAddress, IMG_UINT32 ui32Length)
+ReservePages(IMG_VOID *pvAddress, IMG_SIZE_T uLength)
 {
        IMG_VOID *pvPage;
-       IMG_VOID *pvEnd = pvAddress + ui32Length;
+       IMG_VOID *pvEnd = pvAddress + uLength;
 
        for(pvPage = pvAddress; pvPage < pvEnd;  pvPage += PAGE_SIZE)
        {
@@ -1107,10 +1166,10 @@ ReservePages(IMG_VOID *pvAddress, IMG_UINT32 ui32Length)
 
 /* Un-reserve pages of memory in order that they can be freed. */
 static IMG_VOID
-UnreservePages(IMG_VOID *pvAddress, IMG_UINT32 ui32Length)
+UnreservePages(IMG_VOID *pvAddress, IMG_SIZE_T uLength)
 {
        IMG_VOID *pvPage;
-       IMG_VOID *pvEnd = pvAddress + ui32Length;
+       IMG_VOID *pvEnd = pvAddress + uLength;
 
        for(pvPage = pvAddress; pvPage < pvEnd;  pvPage += PAGE_SIZE)
        {
@@ -1126,7 +1185,7 @@ UnreservePages(IMG_VOID *pvAddress, IMG_UINT32 ui32Length)
 
 IMG_VOID *
 _IORemapWrapper(IMG_CPU_PHYADDR BasePAddr,
-               IMG_UINT32 ui32Bytes,
+               IMG_SIZE_T uBytes,
                IMG_UINT32 ui32MappingFlags,
                IMG_CHAR *pszFileName,
                IMG_UINT32 ui32Line)
@@ -1136,13 +1195,13 @@ _IORemapWrapper(IMG_CPU_PHYADDR BasePAddr,
     switch (ui32MappingFlags & PVRSRV_HAP_CACHETYPE_MASK)
     {
         case PVRSRV_HAP_CACHED:
-           pvIORemapCookie = (IMG_VOID *)IOREMAP(BasePAddr.uiAddr, ui32Bytes);
+           pvIORemapCookie = (IMG_VOID *)IOREMAP(BasePAddr.uiAddr, uBytes);
             break;
         case PVRSRV_HAP_WRITECOMBINE:
-           pvIORemapCookie = (IMG_VOID *)IOREMAP_WC(BasePAddr.uiAddr, ui32Bytes);
+           pvIORemapCookie = (IMG_VOID *)IOREMAP_WC(BasePAddr.uiAddr, uBytes);
             break;
         case PVRSRV_HAP_UNCACHED:
-            pvIORemapCookie = (IMG_VOID *)IOREMAP_UC(BasePAddr.uiAddr, ui32Bytes);
+            pvIORemapCookie = (IMG_VOID *)IOREMAP_UC(BasePAddr.uiAddr, uBytes);
             break;
         default:
             PVR_DPF((PVR_DBG_ERROR, "IORemapWrapper: unknown mapping flags"));
@@ -1153,11 +1212,11 @@ _IORemapWrapper(IMG_CPU_PHYADDR BasePAddr,
     if (pvIORemapCookie)
     {
         DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_IOREMAP,
+                               (IMG_UINTPTR_T)pvIORemapCookie,
                                pvIORemapCookie,
-                               pvIORemapCookie,
-                               BasePAddr.uiAddr,
+                               BasePAddr,
                                NULL,
-                               ui32Bytes,
+                               uBytes,
                                pszFileName,
                                ui32Line
                               );
@@ -1175,7 +1234,11 @@ IMG_VOID
 _IOUnmapWrapper(IMG_VOID *pvIORemapCookie, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line)
 {
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_IOREMAP, pvIORemapCookie, pszFileName, ui32Line);
+    DebugMemAllocRecordRemove(
+                       DEBUG_MEM_ALLOC_TYPE_IOREMAP, 
+                       (IMG_UINTPTR_T)pvIORemapCookie, 
+                       pszFileName, 
+                       ui32Line);
 #else
     PVR_UNREFERENCED_PARAMETER(pszFileName);
     PVR_UNREFERENCED_PARAMETER(ui32Line);
@@ -1186,7 +1249,7 @@ _IOUnmapWrapper(IMG_VOID *pvIORemapCookie, IMG_CHAR *pszFileName, IMG_UINT32 ui3
 
 LinuxMemArea *
 NewIORemapLinuxMemArea(IMG_CPU_PHYADDR BasePAddr,
-                       IMG_UINT32 ui32Bytes,
+                       IMG_SIZE_T uBytes,
                        IMG_UINT32 ui32AreaFlags)
 {
     LinuxMemArea *psLinuxMemArea;
@@ -1198,7 +1261,7 @@ NewIORemapLinuxMemArea(IMG_CPU_PHYADDR BasePAddr,
         return NULL;
     }
 
-    pvIORemapCookie = IORemapWrapper(BasePAddr, ui32Bytes, ui32AreaFlags);
+    pvIORemapCookie = IORemapWrapper(BasePAddr, uBytes, ui32AreaFlags);
     if (!pvIORemapCookie)
     {
         LinuxMemAreaStructFree(psLinuxMemArea);
@@ -1208,7 +1271,7 @@ NewIORemapLinuxMemArea(IMG_CPU_PHYADDR BasePAddr,
     psLinuxMemArea->eAreaType = LINUX_MEM_AREA_IOREMAP;
     psLinuxMemArea->uData.sIORemap.pvIORemapCookie = pvIORemapCookie;
     psLinuxMemArea->uData.sIORemap.CPUPhysAddr = BasePAddr;
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = ui32AreaFlags;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
 
@@ -1247,11 +1310,11 @@ FreeIORemapLinuxMemArea(LinuxMemArea *psLinuxMemArea)
  * using memory wrapping, which ends up creating an external KV memory area.
  */
 static IMG_BOOL
-TreatExternalPagesAsContiguous(IMG_SYS_PHYADDR *psSysPhysAddr, IMG_UINT32 ui32Bytes, IMG_BOOL bPhysContig)
+TreatExternalPagesAsContiguous(IMG_SYS_PHYADDR *psSysPhysAddr, IMG_SIZE_T uBytes, IMG_BOOL bPhysContig)
 {
        IMG_UINT32 ui32;
        IMG_UINT32 ui32AddrChk;
-       IMG_UINT32 ui32NumPages = RANGE_TO_PAGES(ui32Bytes);
+       IMG_UINT32 ui32NumPages = RANGE_TO_PAGES(uBytes);
 
        /*
         * If bPhysContig is IMG_TRUE, we must assume psSysPhysAddr points
@@ -1288,7 +1351,7 @@ TreatExternalPagesAsContiguous(IMG_SYS_PHYADDR *psSysPhysAddr, IMG_UINT32 ui32By
 }
 #endif
 
-LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_UINT32 ui32Bytes, IMG_BOOL bPhysContig, IMG_UINT32 ui32AreaFlags)
+LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_SIZE_T uBytes, IMG_BOOL bPhysContig, IMG_UINT32 ui32AreaFlags)
 {
     LinuxMemArea *psLinuxMemArea;
 
@@ -1302,7 +1365,7 @@ LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *p
     psLinuxMemArea->uData.sExternalKV.pvExternalKV = pvCPUVAddr;
     psLinuxMemArea->uData.sExternalKV.bPhysContig =
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
-       (bPhysContig || TreatExternalPagesAsContiguous(pBasePAddr, ui32Bytes, bPhysContig))
+       (bPhysContig || TreatExternalPagesAsContiguous(pBasePAddr, uiBytes, bPhysContig))
                                                     ? IMG_TRUE : IMG_FALSE;
 #else
        bPhysContig;
@@ -1315,7 +1378,7 @@ LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *p
     {
        psLinuxMemArea->uData.sExternalKV.uPhysAddr.pSysPhysAddr = pBasePAddr;
     }
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = ui32AreaFlags;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
 
@@ -1342,7 +1405,7 @@ FreeExternalKVLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 
 LinuxMemArea *
 NewIOLinuxMemArea(IMG_CPU_PHYADDR BasePAddr,
-                  IMG_UINT32 ui32Bytes,
+                  IMG_SIZE_T uBytes,
                   IMG_UINT32 ui32AreaFlags)
 {
     LinuxMemArea *psLinuxMemArea = LinuxMemAreaStructAlloc();
@@ -1354,17 +1417,17 @@ NewIOLinuxMemArea(IMG_CPU_PHYADDR BasePAddr,
     /* Nothing to activly do. We just keep a record of the physical range. */
     psLinuxMemArea->eAreaType = LINUX_MEM_AREA_IO;
     psLinuxMemArea->uData.sIO.CPUPhysAddr.uiAddr = BasePAddr.uiAddr;
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = ui32AreaFlags;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_IO,
-                           (IMG_VOID *)BasePAddr.uiAddr,
-                           0,
                            BasePAddr.uiAddr,
+                           0,
+                           BasePAddr,
                            NULL,
-                           ui32Bytes,
+                           uBytes,
                            "unknown",
                            0
                           );
@@ -1389,7 +1452,9 @@ FreeIOLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_IO,
-                              (IMG_VOID *)psLinuxMemArea->uData.sIO.CPUPhysAddr.uiAddr, __FILE__, __LINE__);
+                              psLinuxMemArea->uData.sIO.CPUPhysAddr.uiAddr,
+                                                         __FILE__, 
+                                                         __LINE__);
 #endif
 
     /* Nothing more to do than free the LinuxMemArea struct */
@@ -1399,7 +1464,7 @@ FreeIOLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 
 
 LinuxMemArea *
-NewAllocPagesLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
+NewAllocPagesLinuxMemArea(IMG_SIZE_T uBytes, IMG_UINT32 ui32AreaFlags)
 {
     LinuxMemArea *psLinuxMemArea;
     IMG_UINT32 ui32NumPages;
@@ -1413,7 +1478,7 @@ NewAllocPagesLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
         goto failed_area_alloc;
     }
     
-    ui32NumPages = RANGE_TO_PAGES(ui32Bytes);
+    ui32NumPages = RANGE_TO_PAGES(uBytes);
 
     if (!AllocPages(ui32AreaFlags, &ppsPageList, &hBlockPageList, ui32NumPages, &bFromPagePool))
     {
@@ -1423,7 +1488,7 @@ NewAllocPagesLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags)
     psLinuxMemArea->eAreaType = LINUX_MEM_AREA_ALLOC_PAGES;
     psLinuxMemArea->uData.sPageList.ppsPageList = ppsPageList;
     psLinuxMemArea->uData.sPageList.hBlockPageList = hBlockPageList;
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = ui32AreaFlags;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
 
@@ -1459,7 +1524,7 @@ FreeAllocPagesLinuxMemArea(LinuxMemArea *psLinuxMemArea)
     DebugLinuxMemAreaRecordRemove(psLinuxMemArea);
 #endif
     
-    ui32NumPages = RANGE_TO_PAGES(psLinuxMemArea->ui32ByteSize);
+    ui32NumPages = RANGE_TO_PAGES(psLinuxMemArea->uiByteSize);
     ppsPageList = psLinuxMemArea->uData.sPageList.ppsPageList;
     hBlockPageList = psLinuxMemArea->uData.sPageList.hBlockPageList;
     
@@ -1478,10 +1543,10 @@ FreeAllocPagesLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 extern struct ion_client *gpsIONClient;
 
 LinuxMemArea *
-NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
-                   IMG_PVOID pvPrivData, IMG_UINT32 ui32PrivDataLength)
+NewIONLinuxMemArea(IMG_SIZE_T uBytes, IMG_UINT32 ui32AreaFlags,
+                   IMG_PVOID pvPrivData, IMG_SIZE_T uiPrivDataLength)
 {
-    const IMG_UINT32 ui32AllocDataLen =
+    const IMG_SIZE_T uiAllocDataLen =
         offsetof(struct omap_ion_tiler_alloc_data, handle);
     struct omap_ion_tiler_alloc_data asAllocData[2] = {};
     u32 *pu32PageAddrs[2] = { NULL, NULL };
@@ -1503,16 +1568,16 @@ NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
      * were given by this ui32AllocDataLen, and check it's 1 or 2.
      * Otherwise abort.
      */
-    BUG_ON(ui32PrivDataLength != ui32AllocDataLen &&
-           ui32PrivDataLength != ui32AllocDataLen * 2);
-    ui32NumHandlesPerFd = ui32PrivDataLength / ui32AllocDataLen;
+    BUG_ON(uiPrivDataLength != uiAllocDataLen &&
+           uiPrivDataLength != uiAllocDataLen * 2);
+    ui32NumHandlesPerFd = uiPrivDataLength / uiAllocDataLen;
 
     /* Shuffle the alloc data into separate Y & UV bits and
      * make two separate allocations via the tiler.
      */
     for(i = 0; i < ui32NumHandlesPerFd; i++)
     {
-           memcpy(&asAllocData[i], &pbPrivData[i * ui32AllocDataLen], ui32AllocDataLen);
+           memcpy(&asAllocData[i], &pbPrivData[i * uiAllocDataLen], uiAllocDataLen);
 
         if (omap_ion_tiler_alloc(gpsIONClient, &asAllocData[i]) < 0)
         {
@@ -1531,7 +1596,7 @@ NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
     /* Assume the user-allocator has already done the tiler math and that the
      * number of tiler pages allocated matches any other allocation type.
      */
-    BUG_ON(ui32Bytes != (iNumPages[0] + iNumPages[1]) * PAGE_SIZE);
+    BUG_ON(uBytes != (iNumPages[0] + iNumPages[1]) * PAGE_SIZE);
     BUG_ON(sizeof(IMG_CPU_PHYADDR) != sizeof(int));
 
     /* Glue the page lists together */
@@ -1548,11 +1613,11 @@ NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_ION,
-                           asAllocData[0].handle,
-                           0,
+                           (IMG_UINTPTR_T)asAllocData[0].handle,
                            0,
+                           (IMG_CPU_PHYADDR){0},
                            NULL,
-                           PAGE_ALIGN(ui32Bytes),
+                           PAGE_ALIGN(uBytes),
                            "unknown",
                            0
                           );
@@ -1563,7 +1628,7 @@ NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
 
     psLinuxMemArea->eAreaType = LINUX_MEM_AREA_ION;
     psLinuxMemArea->uData.sIONTilerAlloc.pCPUPhysAddrs = pCPUPhysAddrs;
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = ui32AreaFlags;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
 
@@ -1595,7 +1660,7 @@ FreeIONLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
     DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_ION,
-                              psLinuxMemArea->uData.sIONTilerAlloc.psIONHandle[0],
+                              (IMG_UINTPTR_T)psLinuxMemArea->uData.sIONTilerAlloc.psIONHandle[0],
                               __FILE__, __LINE__);
 #endif
 
@@ -1618,27 +1683,27 @@ FreeIONLinuxMemArea(LinuxMemArea *psLinuxMemArea)
 
 struct page*
 LinuxMemAreaOffsetToPage(LinuxMemArea *psLinuxMemArea,
-                         IMG_UINT32 ui32ByteOffset)
+                         IMG_UINTPTR_T uByteOffset)
 {
-    IMG_UINT32 ui32PageIndex;
+    IMG_UINTPTR_T uPageIndex;
     IMG_CHAR *pui8Addr;
 
     switch (psLinuxMemArea->eAreaType)
     {
         case LINUX_MEM_AREA_ALLOC_PAGES:
-            ui32PageIndex = PHYS_TO_PFN(ui32ByteOffset);
-            return psLinuxMemArea->uData.sPageList.ppsPageList[ui32PageIndex];
+            uPageIndex = PHYS_TO_PFN(uByteOffset);
+            return psLinuxMemArea->uData.sPageList.ppsPageList[uPageIndex];
  
         case LINUX_MEM_AREA_VMALLOC:
             pui8Addr = psLinuxMemArea->uData.sVmalloc.pvVmallocAddress;
-            pui8Addr += ui32ByteOffset;
+            pui8Addr += uByteOffset;
             return vmalloc_to_page(pui8Addr);
  
         case LINUX_MEM_AREA_SUB_ALLOC:
             /* PRQA S 3670 3 */ /* ignore recursive warning */
             return LinuxMemAreaOffsetToPage(psLinuxMemArea->uData.sSubAlloc.psParentLinuxMemArea,
-                                            psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset
-                                             + ui32ByteOffset);
+                                            psLinuxMemArea->uData.sSubAlloc.uiByteOffset
+                                             + uByteOffset);
         default:
             PVR_DPF((PVR_DBG_ERROR,
                     "%s: Unsupported request for struct page from LinuxMemArea with type=%s",
@@ -1683,14 +1748,19 @@ _KMemCacheAllocWrapper(LinuxKMemCache *psCache,
                       IMG_UINT32 ui32Line)
 {
     IMG_VOID *pvRet;
-    
+
+#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
+       IMG_CPU_PHYADDR sCpuPAddr;
+#endif
+
     pvRet = kmem_cache_zalloc(psCache, Flags);
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
+       sCpuPAddr.uiAddr = 0;
     DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_KMEM_CACHE,
+                           (IMG_UINTPTR_T)pvRet,
                            pvRet,
-                           pvRet,
-                           0,
+                           sCpuPAddr,
                            psCache,
                            kmem_cache_size(psCache),
                            pszFileName,
@@ -1707,12 +1777,12 @@ _KMemCacheAllocWrapper(LinuxKMemCache *psCache,
 
 LinuxMemArea *
 NewSubLinuxMemArea(LinuxMemArea *psParentLinuxMemArea,
-                   IMG_UINT32 ui32ByteOffset,
-                   IMG_UINT32 ui32Bytes)
+                   IMG_UINTPTR_T uiByteOffset,
+                   IMG_SIZE_T uBytes)
 {
     LinuxMemArea *psLinuxMemArea;
     
-    PVR_ASSERT((ui32ByteOffset+ui32Bytes) <= psParentLinuxMemArea->ui32ByteSize);
+    PVR_ASSERT((uiByteOffset + uBytes) <= psParentLinuxMemArea->uiByteSize);
     
     psLinuxMemArea = LinuxMemAreaStructAlloc();
     if (!psLinuxMemArea)
@@ -1722,8 +1792,8 @@ NewSubLinuxMemArea(LinuxMemArea *psParentLinuxMemArea,
     
     psLinuxMemArea->eAreaType = LINUX_MEM_AREA_SUB_ALLOC;
     psLinuxMemArea->uData.sSubAlloc.psParentLinuxMemArea = psParentLinuxMemArea;
-    psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset = ui32ByteOffset;
-    psLinuxMemArea->ui32ByteSize = ui32Bytes;
+    psLinuxMemArea->uData.sSubAlloc.uiByteOffset = uiByteOffset;
+    psLinuxMemArea->uiByteSize = uBytes;
     psLinuxMemArea->ui32AreaFlags = psParentLinuxMemArea->ui32AreaFlags;
     psLinuxMemArea->bNeedsCacheInvalidate = psParentLinuxMemArea->bNeedsCacheInvalidate;
     INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList);
@@ -1825,7 +1895,7 @@ DebugLinuxMemAreaRecordAdd(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32Flags)
 
     if (psLinuxMemArea->eAreaType != LINUX_MEM_AREA_SUB_ALLOC)
     {
-        g_LinuxMemAreaWaterMark += psLinuxMemArea->ui32ByteSize;
+        g_LinuxMemAreaWaterMark += psLinuxMemArea->uiByteSize;
         if (g_LinuxMemAreaWaterMark > g_LinuxMemAreaHighWaterMark)
         {
             g_LinuxMemAreaHighWaterMark = g_LinuxMemAreaWaterMark;
@@ -1911,7 +1981,7 @@ DebugLinuxMemAreaRecordRemove(LinuxMemArea *psLinuxMemArea)
 
     if (psLinuxMemArea->eAreaType != LINUX_MEM_AREA_SUB_ALLOC)
     {
-        g_LinuxMemAreaWaterMark -= psLinuxMemArea->ui32ByteSize;
+        g_LinuxMemAreaWaterMark -= psLinuxMemArea->uiByteSize;
     }
     g_LinuxMemAreaCount--;
 
@@ -1955,7 +2025,7 @@ LinuxMemAreaToCpuVAddr(LinuxMemArea *psLinuxMemArea)
             {
                 return NULL;
             }
-            return pAddr + psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset;
+            return pAddr + psLinuxMemArea->uData.sSubAlloc.uiByteOffset;
         }
         default:
             return NULL;
@@ -1964,7 +2034,7 @@ LinuxMemAreaToCpuVAddr(LinuxMemArea *psLinuxMemArea)
 
 
 IMG_CPU_PHYADDR
-LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset)
+LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINTPTR_T uiByteOffset)
 {
     IMG_CPU_PHYADDR CpuPAddr;
     
@@ -1975,7 +2045,7 @@ LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset)
         case LINUX_MEM_AREA_IOREMAP:
         {
             CpuPAddr = psLinuxMemArea->uData.sIORemap.CPUPhysAddr;
-            CpuPAddr.uiAddr += ui32ByteOffset;
+            CpuPAddr.uiAddr += uiByteOffset;
             break;
         }
        case LINUX_MEM_AREA_EXTERNAL_KV:
@@ -1983,22 +2053,22 @@ LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset)
            if (psLinuxMemArea->uData.sExternalKV.bPhysContig)
            {
                CpuPAddr = SysSysPAddrToCpuPAddr(psLinuxMemArea->uData.sExternalKV.uPhysAddr.SysPhysAddr);
-               CpuPAddr.uiAddr += ui32ByteOffset;
+               CpuPAddr.uiAddr += uiByteOffset;
            }
            else
            {
-               IMG_UINT32 ui32PageIndex = PHYS_TO_PFN(ui32ByteOffset);
-               IMG_SYS_PHYADDR SysPAddr = psLinuxMemArea->uData.sExternalKV.uPhysAddr.pSysPhysAddr[ui32PageIndex];
+               IMG_UINTPTR_T uiPageIndex = PHYS_TO_PFN(uiByteOffset);
+               IMG_SYS_PHYADDR SysPAddr = psLinuxMemArea->uData.sExternalKV.uPhysAddr.pSysPhysAddr[uiPageIndex];
 
                CpuPAddr = SysSysPAddrToCpuPAddr(SysPAddr);
-                CpuPAddr.uiAddr += ADDR_TO_PAGE_OFFSET(ui32ByteOffset);
+                CpuPAddr.uiAddr += ADDR_TO_PAGE_OFFSET(uiByteOffset);
            }
             break;
        }
         case LINUX_MEM_AREA_IO:
         {
             CpuPAddr = psLinuxMemArea->uData.sIO.CPUPhysAddr;
-            CpuPAddr.uiAddr += ui32ByteOffset;
+            CpuPAddr.uiAddr += uiByteOffset;
             break;
         }
         case LINUX_MEM_AREA_VMALLOC:
@@ -2006,32 +2076,32 @@ LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset)
             IMG_CHAR *pCpuVAddr;
             pCpuVAddr =
                 (IMG_CHAR *)psLinuxMemArea->uData.sVmalloc.pvVmallocAddress;
-            pCpuVAddr += ui32ByteOffset;
+            pCpuVAddr += uiByteOffset;
             CpuPAddr.uiAddr = VMallocToPhys(pCpuVAddr);
             break;
         }
         case LINUX_MEM_AREA_ION:
         {
-            IMG_UINT32 ui32PageIndex = PHYS_TO_PFN(ui32ByteOffset);
-            CpuPAddr = psLinuxMemArea->uData.sIONTilerAlloc.pCPUPhysAddrs[ui32PageIndex];
-            CpuPAddr.uiAddr += ADDR_TO_PAGE_OFFSET(ui32ByteOffset);
+            IMG_UINTPTR_T uiPageIndex = PHYS_TO_PFN(uiByteOffset);
+            CpuPAddr = psLinuxMemArea->uData.sIONTilerAlloc.pCPUPhysAddrs[uiPageIndex];
+            CpuPAddr.uiAddr += ADDR_TO_PAGE_OFFSET(uiByteOffset);
             break;
         }
         case LINUX_MEM_AREA_ALLOC_PAGES:
         {
             struct page *page;
-            IMG_UINT32 ui32PageIndex = PHYS_TO_PFN(ui32ByteOffset);
-            page = psLinuxMemArea->uData.sPageList.ppsPageList[ui32PageIndex];
+            IMG_UINTPTR_T uiPageIndex = PHYS_TO_PFN(uiByteOffset);
+            page = psLinuxMemArea->uData.sPageList.ppsPageList[uiPageIndex];
             CpuPAddr.uiAddr = page_to_phys(page);
-            CpuPAddr.uiAddr += ADDR_TO_PAGE_OFFSET(ui32ByteOffset);
+            CpuPAddr.uiAddr += ADDR_TO_PAGE_OFFSET(uiByteOffset);
             break;
         }
         case LINUX_MEM_AREA_SUB_ALLOC:
         {
             CpuPAddr =
                 OSMemHandleToCpuPAddr(psLinuxMemArea->uData.sSubAlloc.psParentLinuxMemArea,
-                                      psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset
-                                        + ui32ByteOffset);
+                                      psLinuxMemArea->uData.sSubAlloc.uiByteOffset
+                                        + uiByteOffset);
             break;
         }
         default:
@@ -2204,14 +2274,14 @@ static void ProcSeqShowMemArea(struct seq_file *sfile,void* el)
 
         seq_printf(sfile,
 #if !defined(DEBUG_LINUX_XML_PROC_FILES)
-                       "%8p       %-24s %8p %08x %-8d %-5u %08x=(%s)\n",
+                       "%p       %-24s %p " CPUPADDR_FMT " %" SIZE_T_FMT_LEN "u %-5u %08x=(%s)\n",
 #else
                        "<linux_mem_area>\n"
-                       "\t<pointer>%8p</pointer>\n"
+                       "\t<pointer>%p</pointer>\n"
                        "\t<type>%s</type>\n"
-                       "\t<cpu_virtual>%8p</cpu_virtual>\n"
-                       "\t<cpu_physical>%08x</cpu_physical>\n"
-                       "\t<bytes>%d</bytes>\n"
+                       "\t<cpu_virtual>%p</cpu_virtual>\n"
+                       "\t<cpu_physical>" CPUPADDR_FMT "</cpu_physical>\n"
+                       "\t<bytes>%" SIZE_T_FMT_LEN "d</bytes>\n"
                        "\t<pid>%u</pid>\n"
                        "\t<flags>%08x</flags>\n"
                        "\t<flags_string>%s</flags_string>\n"
@@ -2221,7 +2291,7 @@ static void ProcSeqShowMemArea(struct seq_file *sfile,void* el)
                        LinuxMemAreaTypeToString(psRecord->psLinuxMemArea->eAreaType),
                        LinuxMemAreaToCpuVAddr(psRecord->psLinuxMemArea),
                        LinuxMemAreaToCpuPAddr(psRecord->psLinuxMemArea,0).uiAddr,
-                       psRecord->psLinuxMemArea->ui32ByteSize,
+                       psRecord->psLinuxMemArea->uiByteSize,
                        psRecord->pid,
                        psRecord->ui32Flags,
                        HAPFlagsToString(psRecord->ui32Flags)
@@ -2452,13 +2522,13 @@ static void ProcSeqShowMemoryRecords(struct seq_file *sfile,void* el)
     {
                seq_printf(sfile,
 #if !defined(DEBUG_LINUX_XML_PROC_FILES)
-                           "%-16s %-8p %08x %-10d %-5d %-10s %s:%d\n",
+                           "%-16s %p " CPUPADDR_FMT " %" SIZE_T_FMT_LEN "u %-5d %-10s %s:%d\n",
 #else
                            "<allocation>\n"
                            "\t<type>%s</type>\n"
-                           "\t<cpu_virtual>%-8p</cpu_virtual>\n"
-                           "\t<cpu_physical>%08x</cpu_physical>\n"
-                           "\t<bytes>%d</bytes>\n"
+                           "\t<cpu_virtual>%p</cpu_virtual>\n"
+                           "\t<cpu_physical>" CPUPADDR_FMT "</cpu_physical>\n"
+                           "\t<bytes>%" SIZE_T_FMT_LEN "u</bytes>\n"
                            "\t<pid>%d</pid>\n"
                            "\t<private>%s</private>\n"
                            "\t<filename>%s</filename>\n"
@@ -2467,8 +2537,8 @@ static void ProcSeqShowMemoryRecords(struct seq_file *sfile,void* el)
 #endif
                            DebugMemAllocRecordTypeToString(psRecord->eAllocType),
                            psRecord->pvCpuVAddr,
-                           psRecord->ulCpuPAddr,
-                           psRecord->ui32Bytes,
+                           psRecord->sCpuPAddr.uiAddr,
+                           psRecord->uiBytes,
                            psRecord->pid,
                            "NULL",
                            psRecord->pszFileName,
@@ -2478,13 +2548,13 @@ static void ProcSeqShowMemoryRecords(struct seq_file *sfile,void* el)
     {
                seq_printf(sfile,
 #if !defined(DEBUG_LINUX_XML_PROC_FILES)
-                           "%-16s %-8p %08x %-10d %-5d %-10s %s:%d\n",
+                           "%-16s %p " CPUPADDR_FMT " %" SIZE_T_FMT_LEN "u %-5d %-10s %s:%d\n",
 #else
                            "<allocation>\n"
                            "\t<type>%s</type>\n"
-                           "\t<cpu_virtual>%-8p</cpu_virtual>\n"
-                           "\t<cpu_physical>%08x</cpu_physical>\n"
-                           "\t<bytes>%d</bytes>\n"
+                           "\t<cpu_virtual>%p</cpu_virtual>\n"
+                           "\t<cpu_physical>" CPUPADDR_FMT "</cpu_physical>\n"
+                           "\t<bytes>%" SIZE_T_FMT_LEN "u</bytes>\n"
                            "\t<pid>%d</pid>\n"
                            "\t<private>%s</private>\n"
                            "\t<filename>%s</filename>\n"
@@ -2493,8 +2563,8 @@ static void ProcSeqShowMemoryRecords(struct seq_file *sfile,void* el)
 #endif
                            DebugMemAllocRecordTypeToString(psRecord->eAllocType),
                            psRecord->pvCpuVAddr,
-                           psRecord->ulCpuPAddr,
-                           psRecord->ui32Bytes,
+                           psRecord->sCpuPAddr.uiAddr,
+                           psRecord->uiBytes,
                            psRecord->pid,
                            KMemCacheNameWrapper(psRecord->pvPrivateData),
                            psRecord->pszFileName,
@@ -2584,11 +2654,11 @@ static IMG_VOID LinuxMMCleanup_MemAreas_ForEachCb(DEBUG_LINUX_MEM_AREA_REC *psCu
        LinuxMemArea *psLinuxMemArea;
 
        psLinuxMemArea = psCurrentRecord->psLinuxMemArea;
-       PVR_DPF((PVR_DBG_ERROR, "%s: BUG!: Cleaning up Linux memory area (%p), type=%s, size=%d bytes",
+       PVR_DPF((PVR_DBG_ERROR, "%s: BUG!: Cleaning up Linux memory area (%p), type=%s, size=%"SIZE_T_FMT_LEN"d bytes",
                                __FUNCTION__,
                                psCurrentRecord->psLinuxMemArea,
                                LinuxMemAreaTypeToString(psCurrentRecord->psLinuxMemArea->eAreaType),
-                               psCurrentRecord->psLinuxMemArea->ui32ByteSize));
+                               psCurrentRecord->psLinuxMemArea->uiByteSize));
        /* Note this will also remove psCurrentRecord from g_LinuxMemAreaRecords
         * but that's ok since we have already got a pointer to the next area. */
        LinuxMemAreaDeepFree(psLinuxMemArea);
@@ -2605,12 +2675,12 @@ static IMG_VOID LinuxMMCleanup_MemRecords_ForEachVa(DEBUG_MEM_ALLOC_REC *psCurre
        PVR_DPF((PVR_DBG_ERROR, "%s: BUG!: Cleaning up memory: "
                                                        "type=%s "
                                                        "CpuVAddr=%p "
-                                                       "CpuPAddr=0x%08x, "
+                                                       "CpuPAddr=0x" CPUPADDR_FMT ", "
                                                        "allocated @ file=%s,line=%d",
                        __FUNCTION__,
                        DebugMemAllocRecordTypeToString(psCurrentRecord->eAllocType),
                        psCurrentRecord->pvCpuVAddr,
-                       psCurrentRecord->ulCpuPAddr,
+                       psCurrentRecord->sCpuPAddr.uiAddr,
                        psCurrentRecord->pszFileName,
                        psCurrentRecord->ui32Line));
        switch (psCurrentRecord->eAllocType)
@@ -2623,13 +2693,13 @@ static IMG_VOID LinuxMMCleanup_MemRecords_ForEachVa(DEBUG_MEM_ALLOC_REC *psCurre
                        break;
                case DEBUG_MEM_ALLOC_TYPE_IO:
                        /* Nothing needed except to free the record */
-                       DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_IO, psCurrentRecord->pvKey, __FILE__, __LINE__);
+                       DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_IO, psCurrentRecord->uiKey, __FILE__, __LINE__);
                        break;
                case DEBUG_MEM_ALLOC_TYPE_VMALLOC:
                        VFreeWrapper(psCurrentRecord->pvCpuVAddr);
                        break;
                case DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES:
-                       DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES, psCurrentRecord->pvKey, __FILE__, __LINE__);
+                       DebugMemAllocRecordRemove(DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES, psCurrentRecord->uiKey, __FILE__, __LINE__);
                        break;
                case DEBUG_MEM_ALLOC_TYPE_KMEM_CACHE:
                        KMemCacheFreeWrapper(psCurrentRecord->pvPrivateData, psCurrentRecord->pvCpuVAddr);
index d414306..0c690ee 100644 (file)
@@ -88,7 +88,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 #endif
 
-static inline IMG_UINT32 VMallocToPhys(IMG_VOID *pCpuVAddr)
+static inline IMG_UINTPTR_T VMallocToPhys(IMG_VOID *pCpuVAddr)
 {
        return (page_to_phys(vmalloc_to_page(pCpuVAddr)) + ADDR_TO_PAGE_OFFSET(pCpuVAddr));
                
@@ -173,11 +173,11 @@ struct _LinuxMemArea {
             /* Note: The memory this represents is _not_ implicitly
              * page aligned, neither is its size */
             LinuxMemArea *psParentLinuxMemArea;
-            IMG_UINT32 ui32ByteOffset;
+            IMG_UINTPTR_T uiByteOffset;
         }sSubAlloc;
     }uData;
 
-    IMG_UINT32 ui32ByteSize;           /* Size of memory area */
+    IMG_SIZE_T uiByteSize;                 /* Size of memory area */
 
     IMG_UINT32 ui32AreaFlags;          /* Flags passed at creation time */
 
@@ -239,16 +239,16 @@ IMG_VOID LinuxMMCleanup(IMG_VOID);
  *        They can also be used as more concise replacements for OSAllocMem
  *        in Linux specific code.
  *
- * @param ui32ByteSize  
+ * @param uByteSize  
  *
  * @return 
  ******************************************************************************/
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-#define KMallocWrapper(ui32ByteSize, uFlags) _KMallocWrapper(ui32ByteSize, uFlags, __FILE__, __LINE__)
+#define KMallocWrapper(uByteSize, uFlags) _KMallocWrapper(uByteSize, uFlags, __FILE__, __LINE__)
 #else
-#define KMallocWrapper(ui32ByteSize, uFlags) _KMallocWrapper(ui32ByteSize, uFlags, NULL, 0)
+#define KMallocWrapper(uByteSize, uFlags) _KMallocWrapper(uByteSize, uFlags, NULL, 0)
 #endif
-IMG_VOID *_KMallocWrapper(IMG_UINT32 ui32ByteSize, gfp_t uFlags, IMG_CHAR *szFileName, IMG_UINT32 ui32Line);
+IMG_VOID *_KMallocWrapper(IMG_SIZE_T uByteSize, gfp_t uFlags, IMG_CHAR *szFileName, IMG_UINT32 ui32Line);
 
 
 /*!
@@ -271,17 +271,17 @@ IMG_VOID _KFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 u
  *******************************************************************************
  * @brief 
  *
- * @param ui32Bytes  
+ * @param uBytes  
  * @param ui32AllocFlags  
  *
  * @return 
  ******************************************************************************/
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-#define VMallocWrapper(ui32Bytes, ui32AllocFlags) _VMallocWrapper(ui32Bytes, ui32AllocFlags, __FILE__, __LINE__)
+#define VMallocWrapper(uiBytes, ui32AllocFlags) _VMallocWrapper(uiBytes, ui32AllocFlags, __FILE__, __LINE__)
 #else
-#define VMallocWrapper(ui32Bytes, ui32AllocFlags) _VMallocWrapper(ui32Bytes, ui32AllocFlags, NULL, 0)
+#define VMallocWrapper(uiBytes, ui32AllocFlags) _VMallocWrapper(uiBytes, ui32AllocFlags, NULL, 0)
 #endif
-IMG_VOID *_VMallocWrapper(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AllocFlags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
+IMG_VOID *_VMallocWrapper(IMG_SIZE_T uiBytes, IMG_UINT32 ui32AllocFlags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
 
 
 /*!
@@ -304,12 +304,12 @@ IMG_VOID _VFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 u
  *******************************************************************************
  * @brief Allocates virtually contiguous pages
  *
- * @param ui32Bytes  number of bytes to reserve
+ * @param uBytes  number of bytes to reserve
  * @param ui32AreaFlags  Heap caching and mapping Flags
  *
  * @return Page-aligned address of virtual allocation or NULL on error
  ******************************************************************************/
-LinuxMemArea *NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
+LinuxMemArea *NewVMallocLinuxMemArea(IMG_SIZE_T uBytes, IMG_UINT32 ui32AreaFlags);
 
 
 /*!
@@ -327,20 +327,20 @@ IMG_VOID FreeVMallocLinuxMemArea(LinuxMemArea *psLinuxMemArea);
  * @brief Reserve physical IO memory and create a CPU virtual mapping for it
  *
  * @param BasePAddr 
- * @param ui32Bytes  
+ * @param uiBytes  
  * @param ui32MappingFlags  
  *
  * @return 
  ******************************************************************************/
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-#define IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags) \
-    _IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags, __FILE__, __LINE__)
+#define IORemapWrapper(BasePAddr, uiBytes, ui32MappingFlags) \
+    _IORemapWrapper(BasePAddr, uiBytes, ui32MappingFlags, __FILE__, __LINE__)
 #else
-#define IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags) \
-    _IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags, NULL, 0)
+#define IORemapWrapper(BasePAddr, uiBytes, ui32MappingFlags) \
+    _IORemapWrapper(BasePAddr, uiBytes, ui32MappingFlags, NULL, 0)
 #endif
 IMG_VOID *_IORemapWrapper(IMG_CPU_PHYADDR BasePAddr,
-                          IMG_UINT32 ui32Bytes,
+                          IMG_SIZE_T uiBytes,
                           IMG_UINT32 ui32MappingFlags,
                           IMG_CHAR *pszFileName,
                           IMG_UINT32 ui32Line);
@@ -351,12 +351,12 @@ IMG_VOID *_IORemapWrapper(IMG_CPU_PHYADDR BasePAddr,
  * @brief Reserve physical IO memory and create a CPU virtual mapping for it
  *
  * @param BasePAddr  
- * @param ui32Bytes  
+ * @param uiBytes  
  * @param ui32AreaFlags  Heap caching and mapping Flags
  *
  * @return 
  ******************************************************************************/
-LinuxMemArea *NewIORemapLinuxMemArea(IMG_CPU_PHYADDR BasePAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
+LinuxMemArea *NewIORemapLinuxMemArea(IMG_CPU_PHYADDR BasePAddr, IMG_SIZE_T uiBytes, IMG_UINT32 ui32AreaFlags);
 
 
 /*!
@@ -376,12 +376,12 @@ IMG_VOID FreeIORemapLinuxMemArea(LinuxMemArea *psLinuxMemArea);
  * @param pBasePAddr  
  * @param pvCPUVAddr  
  * @param bPhysContig
- * @param ui32Bytes  
+ * @param uBytes  
  * @param ui32AreaFlags  Heap caching and mapping Flags
  *
  * @return 
  ******************************************************************************/
-LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_UINT32 ui32Bytes, IMG_BOOL bPhysContig, IMG_UINT32 ui32AreaFlags);
+LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_SIZE_T uBytes, IMG_BOOL bPhysContig, IMG_UINT32 ui32AreaFlags);
 
 
 /*!
@@ -418,11 +418,11 @@ IMG_VOID _IOUnmapWrapper(IMG_VOID *pvIORemapCookie, IMG_CHAR *pszFileName, IMG_U
  * @brief 
  *
  * @param psLinuxMemArea  
- * @param ui32ByteOffset  
+ * @param uByteOffset  
  *
  * @return 
  ******************************************************************************/
-struct page *LinuxMemAreaOffsetToPage(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset);
+struct page *LinuxMemAreaOffsetToPage(LinuxMemArea *psLinuxMemArea, IMG_UINTPTR_T uByteOffset);
 
 
 /*!
@@ -504,12 +504,12 @@ const IMG_CHAR *KMemCacheNameWrapper(LinuxKMemCache *psCache);
  * @brief 
  *
  * @param BasePAddr  
- * @param ui32Bytes  
+ * @param uiBytes  
  * @param ui32AreaFlags  Heap caching and mapping Flags
  *
  * @return 
  ******************************************************************************/
-LinuxMemArea *NewIOLinuxMemArea(IMG_CPU_PHYADDR BasePAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
+LinuxMemArea *NewIOLinuxMemArea(IMG_CPU_PHYADDR BasePAddr, IMG_SIZE_T uiBytes, IMG_UINT32 ui32AreaFlags);
 
 
 /*!
@@ -527,12 +527,12 @@ IMG_VOID FreeIOLinuxMemArea(LinuxMemArea *psLinuxMemArea);
  *******************************************************************************
  * @brief 
  *
- * @param ui32Bytes  
+ * @param uiBytes  
  * @param ui32AreaFlags  E.g Heap caching and mapping Flags
  *
  * @return 
  ******************************************************************************/
-LinuxMemArea *NewAllocPagesLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
+LinuxMemArea *NewAllocPagesLinuxMemArea(IMG_SIZE_T uiBytes, IMG_UINT32 ui32AreaFlags);
 
 
 /*!
@@ -552,14 +552,14 @@ IMG_VOID FreeAllocPagesLinuxMemArea(LinuxMemArea *psLinuxMemArea);
  *******************************************************************************
  * @brief 
  *
- * @param ui32Bytes  
+ * @param uiBytes  
  * @param ui32AreaFlags  E.g Heap caching and mapping Flags
  *
  * @return 
  ******************************************************************************/
 LinuxMemArea *
-NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
-                   IMG_PVOID pvPrivData, IMG_UINT32 ui32PrivDataLength);
+NewIONLinuxMemArea(IMG_SIZE_T uiBytes, IMG_UINT32 ui32AreaFlags,
+                   IMG_PVOID pvPrivData, IMG_SIZE_T uiPrivDataLength);
 
 
 /*!
@@ -575,13 +575,13 @@ IMG_VOID FreeIONLinuxMemArea(LinuxMemArea *psLinuxMemArea);
 #else /* defined(CONFIG_ION_OMAP) */
 
 static inline LinuxMemArea *
-NewIONLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags,
-                   IMG_PVOID pvPrivData, IMG_UINT32 ui32PrivDataLength)
+NewIONLinuxMemArea(IMG_SIZE_T uBytes, IMG_UINT32 ui32AreaFlags,
+                   IMG_PVOID pvPrivData, IMG_SIZE_T uPrivDataLength)
 {
-    PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+    PVR_UNREFERENCED_PARAMETER(uBytes);
     PVR_UNREFERENCED_PARAMETER(ui32AreaFlags);
     PVR_UNREFERENCED_PARAMETER(pvPrivData);
-    PVR_UNREFERENCED_PARAMETER(ui32PrivDataLength);
+    PVR_UNREFERENCED_PARAMETER(uPrivDataLength);
     BUG();
     return IMG_NULL;
 }
@@ -600,14 +600,14 @@ static inline IMG_VOID FreeIONLinuxMemArea(LinuxMemArea *psLinuxMemArea)
  * @brief 
  *
  * @param psParentLinuxMemArea  
- * @param ui32ByteOffset
- * @param ui32Bytes
+ * @param uByteOffset
+ * @param uBytes
  *
  * @return 
  ******************************************************************************/
 LinuxMemArea *NewSubLinuxMemArea(LinuxMemArea *psParentLinuxMemArea,
-                                 IMG_UINT32 ui32ByteOffset,
-                                 IMG_UINT32 ui32Bytes);
+                                 IMG_UINTPTR_T uByteOffset,
+                                 IMG_SIZE_T uBytes);
 
 
 /*!
@@ -651,14 +651,14 @@ IMG_VOID *LinuxMemAreaToCpuVAddr(LinuxMemArea *psLinuxMemArea);
  * @brief 
  *
  * @param psLinuxMemArea  
- * @param ui32ByteOffset  
+ * @param uByteOffset  
  *
  * @return 
  ******************************************************************************/
-IMG_CPU_PHYADDR LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset);
+IMG_CPU_PHYADDR LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINTPTR_T uByteOffset);
 
 
-#define         LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32ByteOffset) PHYS_TO_PFN(LinuxMemAreaToCpuPAddr(psLinuxMemArea, ui32ByteOffset).uiAddr)
+#define         LinuxMemAreaToCpuPFN(psLinuxMemArea, uByteOffset) PHYS_TO_PFN(LinuxMemAreaToCpuPAddr(psLinuxMemArea, uByteOffset).uiAddr)
 
 /*!
  *******************************************************************************
index ef725e2..9cb3330 100644 (file)
@@ -69,6 +69,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <drm/drmP.h>
 #endif
 
+#ifdef CONFIG_ARCH_OMAP5
+#ifdef CONFIG_DSSCOMP
+#include <../drivers/staging/omapdrm/omap_dmm_tiler.h>
+#endif
+#endif
+
 #include "services_headers.h"
 
 #include "pvrmmap.h"
@@ -85,7 +91,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "pvr_drm.h"
 #endif
 
-#if !defined(PVR_SECURE_HANDLES) && !defined (SUPPORT_SID_INTERFACE)
+#if !defined(PVR_SECURE_HANDLES)
 #error "The mmap code requires PVR_SECURE_HANDLES"
 #endif
 
@@ -108,7 +114,7 @@ static LIST_HEAD(g_sMMapAreaList);
 static LIST_HEAD(g_sMMapOffsetStructList);
 #if defined(DEBUG_LINUX_MMAP_AREAS)
 static IMG_UINT32 g_ui32RegisteredAreas = 0;
-static IMG_UINT32 g_ui32TotalByteSize = 0;
+static IMG_SIZE_T g_uiTotalByteSize = 0;
 #endif
 
 
@@ -201,14 +207,10 @@ MMapOffsetToHandle(IMG_UINT32 pfn)
 }
 #endif
 
-static inline IMG_UINT32
-#if defined (SUPPORT_SID_INTERFACE)
-HandleToMMapOffset(IMG_SID hHandle)
-#else
+static inline IMG_UINTPTR_T
 HandleToMMapOffset(IMG_HANDLE hHandle)
-#endif
 {
-       IMG_UINT32 ulHandle = (IMG_UINT32)hHandle;
+       IMG_UINTPTR_T ulHandle = (IMG_UINTPTR_T)hHandle;
 
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
        if (PFNIsSpecial(ulHandle))
@@ -255,7 +257,7 @@ GetCurrentThreadID(IMG_VOID)
  * mmap data.
  */
 static PKV_OFFSET_STRUCT
-CreateOffsetStruct(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
+CreateOffsetStruct(LinuxMemArea *psLinuxMemArea, IMG_UINTPTR_T uiOffset, IMG_SIZE_T uiRealByteSize)
 {
     PKV_OFFSET_STRUCT psOffsetStruct;
 #if defined(DEBUG) || defined(DEBUG_LINUX_MMAP_AREAS)
@@ -279,11 +281,11 @@ CreateOffsetStruct(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32Offset, IMG_UINT
         return IMG_NULL;
     }
     
-    psOffsetStruct->ui32MMapOffset = ui32Offset;
+    psOffsetStruct->uiMMapOffset = uiOffset;
 
     psOffsetStruct->psLinuxMemArea = psLinuxMemArea;
 
-    psOffsetStruct->ui32RealByteSize = ui32RealByteSize;
+    psOffsetStruct->uiRealByteSize = uiRealByteSize;
 
     /*
      * We store the TID in case two threads within a process
@@ -327,7 +329,8 @@ DestroyOffsetStruct(PKV_OFFSET_STRUCT psOffsetStruct)
 
 #ifdef DEBUG
     PVR_DPF((PVR_DBG_MESSAGE, "%s: Table entry: "
-             "psLinuxMemArea=%p, CpuPAddr=0x%08X", __FUNCTION__,
+             "psLinuxMemArea=%p, CpuPAddr=0x" CPUPADDR_FMT, 
+                        __FUNCTION__,
              psOffsetStruct->psLinuxMemArea,
              CpuPAddr.uiAddr));
 #endif
@@ -349,18 +352,18 @@ DestroyOffsetStruct(PKV_OFFSET_STRUCT psOffsetStruct)
  */
 static inline IMG_VOID
 DetermineUsersSizeAndByteOffset(LinuxMemArea *psLinuxMemArea,
-                               IMG_UINT32 *pui32RealByteSize,
-                               IMG_UINT32 *pui32ByteOffset)
+                               IMG_SIZE_T *puiRealByteSize,
+                               IMG_UINTPTR_T *puiByteOffset)
 {
-    IMG_UINT32 ui32PageAlignmentOffset;
+    IMG_UINTPTR_T uiPageAlignmentOffset;
     IMG_CPU_PHYADDR CpuPAddr;
     
     CpuPAddr = LinuxMemAreaToCpuPAddr(psLinuxMemArea, 0);
-    ui32PageAlignmentOffset = ADDR_TO_PAGE_OFFSET(CpuPAddr.uiAddr);
+    uiPageAlignmentOffset = ADDR_TO_PAGE_OFFSET(CpuPAddr.uiAddr);
     
-    *pui32ByteOffset = ui32PageAlignmentOffset;
+    *puiByteOffset = uiPageAlignmentOffset;
 
-    *pui32RealByteSize = PAGE_ALIGN(psLinuxMemArea->ui32ByteSize + ui32PageAlignmentOffset);
+    *puiRealByteSize = PAGE_ALIGN(psLinuxMemArea->uiByteSize + uiPageAlignmentOffset);
 }
 
 
@@ -376,16 +379,16 @@ DetermineUsersSizeAndByteOffset(LinuxMemArea *psLinuxMemArea,
 
  @input psPerProc : Per-process data.
  @input hMHandle : Memory handle.
- @input pui32MMapOffset : pointer to location for returned mmap offset.
- @input pui32ByteOffset : pointer to location for returned byte offset.
- @input pui32RealByteSize : pointer to location for returned real byte size.
- @input pui32UserVaddr : pointer to location for returned user mode address.
+ @input puiMMapOffset : pointer to location for returned mmap offset.
+ @input puiByteOffset : pointer to location for returned byte offset.
+ @input puiRealByteSize : pointer to location for returned real byte size.
+ @input puiUserVaddr : pointer to location for returned user mode address.
 
- @output pui32MMapOffset : points to mmap offset to be used in mmap2 sys call.
- @output pui32ByteOffset : points to byte offset of start of memory
+ @output puiMMapOffset : points to mmap offset to be used in mmap2 sys call.
+ @output puiByteOffset : points to byte offset of start of memory
                           within mapped area returned by mmap2.
- @output pui32RealByteSize : points to size of area to be mapped.
- @output pui32UserVAddr : points to user mode address of start of
+ @output puiRealByteSize : points to size of area to be mapped.
+ @output puiUserVAddr : points to user mode address of start of
                          mapping, or 0 if it hasn't been mapped yet.
 
  @Return PVRSRV_ERROR : PVRSRV_OK, or error code.
@@ -393,33 +396,25 @@ DetermineUsersSizeAndByteOffset(LinuxMemArea *psLinuxMemArea,
  ******************************************************************************/
 PVRSRV_ERROR
 PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
-#if defined (SUPPORT_SID_INTERFACE)
-                             IMG_SID     hMHandle,
-#else
                              IMG_HANDLE hMHandle,
-#endif
-                             IMG_UINT32 *pui32MMapOffset,
-                             IMG_UINT32 *pui32ByteOffset,
-                             IMG_UINT32 *pui32RealByteSize,
-                             IMG_UINT32 *pui32UserVAddr)
+                             IMG_UINTPTR_T *puiMMapOffset,
+                             IMG_UINTPTR_T *puiByteOffset,
+                             IMG_SIZE_T *puiRealByteSize,
+                             IMG_UINTPTR_T *puiUserVAddr)
 {
     LinuxMemArea *psLinuxMemArea;
     PKV_OFFSET_STRUCT psOffsetStruct;
     IMG_HANDLE hOSMemHandle;
     PVRSRV_ERROR eError;
 
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
     PVR_ASSERT(PVRSRVGetMaxHandle(psPerProc->psHandleBase) <= MAX_MMAP_HANDLE);
 
     eError = PVRSRVLookupOSMemHandle(psPerProc->psHandleBase, &hOSMemHandle, hMHandle);
     if (eError != PVRSRV_OK)
     {
-#if defined (SUPPORT_SID_INTERFACE)
-        PVR_DPF((PVR_DBG_ERROR, "%s: Lookup of handle %x failed", __FUNCTION__, hMHandle));
-#else
         PVR_DPF((PVR_DBG_ERROR, "%s: Lookup of handle %p failed", __FUNCTION__, hMHandle));
-#endif
 
         goto exit_unlock;
     }
@@ -429,14 +424,14 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
        /* Sparse mappings have to ask the BM for the virtual size */
        if (psLinuxMemArea->hBMHandle)
        {
-               *pui32RealByteSize = BM_GetVirtualSize(psLinuxMemArea->hBMHandle);
-               *pui32ByteOffset = 0;
+               *puiRealByteSize = BM_GetVirtualSize(psLinuxMemArea->hBMHandle);
+               *puiByteOffset = 0;
        }
        else
        {
                DetermineUsersSizeAndByteOffset(psLinuxMemArea,
-                                                                               pui32RealByteSize,
-                                                                               pui32ByteOffset);
+                                                                               puiRealByteSize,
+                                                                               puiByteOffset);
        }
 
     /* Check whether this memory area has already been mapped */
@@ -446,7 +441,7 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
         {
                        if (!psLinuxMemArea->hBMHandle)
                        {
-                               PVR_ASSERT(*pui32RealByteSize == psOffsetStruct->ui32RealByteSize);
+                               PVR_ASSERT(*puiRealByteSize == psOffsetStruct->uiRealByteSize);
                        }
           /*
            * User mode locking is required to stop two threads racing to
@@ -456,8 +451,8 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
            * Without locking, both threads may attempt the mmap,
            * and one of them will fail.
            */
-          *pui32MMapOffset = psOffsetStruct->ui32MMapOffset;
-          *pui32UserVAddr = psOffsetStruct->ui32UserVAddr;
+          *puiMMapOffset = psOffsetStruct->uiMMapOffset;
+          *puiUserVAddr = psOffsetStruct->uiUserVAddr;
           PVRSRVOffsetStructIncRef(psOffsetStruct);
 
           eError = PVRSRV_OK;
@@ -466,24 +461,24 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
     }
 
     /* Memory area won't have been mapped yet */
-    *pui32UserVAddr = 0;
+    *puiUserVAddr = 0;
 
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
     if (LinuxMemAreaUsesPhysicalMap(psLinuxMemArea))
     {
-        *pui32MMapOffset = LinuxMemAreaToCpuPFN(psLinuxMemArea, 0);
-        PVR_ASSERT(PFNIsPhysical(*pui32MMapOffset));
+        *puiMMapOffset = LinuxMemAreaToCpuPFN(psLinuxMemArea, 0);
+        PVR_ASSERT(PFNIsPhysical(*puiMMapOffset));
     }
     else
 #endif
     {
-        *pui32MMapOffset = HandleToMMapOffset(hMHandle);
+        *puiMMapOffset = HandleToMMapOffset(hMHandle);
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
-        PVR_ASSERT(PFNIsSpecial(*pui32MMapOffset));
+        PVR_ASSERT(PFNIsSpecial(*puiMMapOffset));
 #endif
     }
 
-    psOffsetStruct = CreateOffsetStruct(psLinuxMemArea, *pui32MMapOffset, *pui32RealByteSize);
+    psOffsetStruct = CreateOffsetStruct(psLinuxMemArea, *puiMMapOffset, *puiRealByteSize);
     if (psOffsetStruct == IMG_NULL)
     {
         eError = PVRSRV_ERROR_OUT_OF_MEMORY;
@@ -506,7 +501,7 @@ PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
           is done in the mmap2() syscall, as it expects the pgoff
           argument to be in units of 4,096 bytes irrespective of
           page size */
-       *pui32MMapOffset = *pui32MMapOffset << (PAGE_SHIFT - 12);
+       *puiMMapOffset = *puiMMapOffset << (PAGE_SHIFT - 12);
 
 exit_unlock:
     LinuxUnLockMutex(&g_sMMapMutex);
@@ -527,26 +522,22 @@ exit_unlock:
  @input psPerProc : Per-process data.
  @input hMHandle : Memory handle.
  @input pbMUnmap : pointer to location for munmap flag.
- @input pui32UserVAddr : pointer to location for user mode address of mapping.
- @input pui32ByteSize : pointer to location for size of mapping.
+ @input puiUserVAddr : pointer to location for user mode address of mapping.
+ @input puiByteSize : pointer to location for size of mapping.
 
  @Output pbMUnmap : points to flag that indicates whether an munmap is
                    required.
- @output pui32UserVAddr : points to user mode address to munmap.
+ @output puiUserVAddr : points to user mode address to munmap.
 
  @Return PVRSRV_ERROR : PVRSRV_OK, or error code.
 
  ******************************************************************************/
 PVRSRV_ERROR
 PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
-#if defined (SUPPORT_SID_INTERFACE)
-                               IMG_SID   hMHandle,
-#else
                                IMG_HANDLE hMHandle,
-#endif
                                IMG_BOOL *pbMUnmap,
-                               IMG_UINT32 *pui32RealByteSize,
-                                IMG_UINT32 *pui32UserVAddr)
+                               IMG_SIZE_T *puiRealByteSize,
+                IMG_UINTPTR_T *puiUserVAddr)
 {
     LinuxMemArea *psLinuxMemArea;
     PKV_OFFSET_STRUCT psOffsetStruct;
@@ -554,18 +545,14 @@ PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
     PVRSRV_ERROR eError;
     IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
 
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
     PVR_ASSERT(PVRSRVGetMaxHandle(psPerProc->psHandleBase) <= MAX_MMAP_HANDLE);
 
     eError = PVRSRVLookupOSMemHandle(psPerProc->psHandleBase, &hOSMemHandle, hMHandle);
     if (eError != PVRSRV_OK)
     {
-#if defined (SUPPORT_SID_INTERFACE)
-       PVR_DPF((PVR_DBG_ERROR, "%s: Lookup of handle %x failed", __FUNCTION__, hMHandle));
-#else
        PVR_DPF((PVR_DBG_ERROR, "%s: Lookup of handle %p failed", __FUNCTION__, hMHandle));
-#endif
 
        goto exit_unlock;
     }
@@ -586,10 +573,10 @@ PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
 
            PVRSRVOffsetStructDecRef(psOffsetStruct);
 
-           *pbMUnmap = (IMG_BOOL)((psOffsetStruct->ui32RefCount == 0) && (psOffsetStruct->ui32UserVAddr != 0));
+           *pbMUnmap = (IMG_BOOL)((psOffsetStruct->ui32RefCount == 0) && (psOffsetStruct->uiUserVAddr != 0));
 
-           *pui32UserVAddr = (*pbMUnmap) ? psOffsetStruct->ui32UserVAddr : 0;
-           *pui32RealByteSize = (*pbMUnmap) ? psOffsetStruct->ui32RealByteSize : 0;
+           *puiUserVAddr = (*pbMUnmap) ? psOffsetStruct->uiUserVAddr : 0;
+           *puiRealByteSize = (*pbMUnmap) ? psOffsetStruct->uiRealByteSize : 0;
 
            eError = PVRSRV_OK;
            goto exit_unlock;
@@ -597,11 +584,7 @@ PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
     }
 
     /* MMap data not found */
-#if defined (SUPPORT_SID_INTERFACE)
-    PVR_DPF((PVR_DBG_ERROR, "%s: Mapping data not found for handle %x (memory area %p)", __FUNCTION__, hMHandle, psLinuxMemArea));
-#else
     PVR_DPF((PVR_DBG_ERROR, "%s: Mapping data not found for handle %p (memory area %p)", __FUNCTION__, hMHandle, psLinuxMemArea));
-#endif
 
     eError =  PVRSRV_ERROR_MAPPING_NOT_FOUND;
 
@@ -612,7 +595,7 @@ exit_unlock:
 }
 
 static inline PKV_OFFSET_STRUCT
-FindOffsetStructByOffset(IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
+FindOffsetStructByOffset(IMG_UINTPTR_T uiOffset, IMG_SIZE_T uiRealByteSize)
 {
     PKV_OFFSET_STRUCT psOffsetStruct;
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
@@ -622,7 +605,7 @@ FindOffsetStructByOffset(IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
 
     list_for_each_entry(psOffsetStruct, &g_sMMapOffsetStructList, sMMapItem)
     {
-        if (ui32Offset == psOffsetStruct->ui32MMapOffset && ui32RealByteSize == psOffsetStruct->ui32RealByteSize && psOffsetStruct->ui32PID == ui32PID)
+        if (uiOffset == psOffsetStruct->uiMMapOffset && uiRealByteSize == psOffsetStruct->uiRealByteSize && psOffsetStruct->ui32PID == ui32PID)
         {
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
            /*
@@ -630,7 +613,7 @@ FindOffsetStructByOffset(IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
             * as different threads may be mapping different memory areas
             * with the same offset.
             */
-           if (!PFNIsPhysical(ui32Offset) || psOffsetStruct->ui32TID == ui32TID)
+           if (!PFNIsPhysical(uiOffset) || psOffsetStruct->ui32TID == ui32TID)
 #endif
            {
                return psOffsetStruct;
@@ -650,11 +633,11 @@ FindOffsetStructByOffset(IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
 static IMG_BOOL
 DoMapToUser(LinuxMemArea *psLinuxMemArea,
             struct vm_area_struct* ps_vma,
-            IMG_UINT32 ui32ByteOffset)
+            IMG_UINTPTR_T uiByteOffset)
 {
-    IMG_UINT32 ui32ByteSize;
+    IMG_SIZE_T uiByteSize;
 
-       if ((psLinuxMemArea->hBMHandle) && (ui32ByteOffset != 0))
+       if ((psLinuxMemArea->hBMHandle) && (uiByteOffset != 0))
        {
                /* Partial mapping of sparse allocations should never happen */
                return IMG_FALSE;
@@ -664,15 +647,15 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
     {
         return DoMapToUser(LinuxMemAreaRoot(psLinuxMemArea),           /* PRQA S 3670 */ /* allow recursion */
                     ps_vma,
-                    psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset + ui32ByteOffset);
+                    psLinuxMemArea->uData.sSubAlloc.uiByteOffset + uiByteOffset);
     }
 
     /*
      * Note that ui32ByteSize may be larger than the size of the memory
      * area being mapped, as the former is a multiple of the page size.
      */
-    ui32ByteSize = ps_vma->vm_end - ps_vma->vm_start;
-    PVR_ASSERT(ADDR_TO_PAGE_OFFSET(ui32ByteSize) == 0);
+    uiByteSize = ps_vma->vm_end - ps_vma->vm_start;
+    PVR_ASSERT(ADDR_TO_PAGE_OFFSET(uiByteSize) == 0);
 
 #if defined (__sparc__)
     /*
@@ -687,10 +670,10 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
     if (PFNIsPhysical(ps_vma->vm_pgoff))
     {
-       IMG_INT result;
+               IMG_INT result;
 
-       PVR_ASSERT(LinuxMemAreaPhysIsContig(psLinuxMemArea));
-       PVR_ASSERT(LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32ByteOffset) == ps_vma->vm_pgoff);
+               PVR_ASSERT(LinuxMemAreaPhysIsContig(psLinuxMemArea));
+               PVR_ASSERT(LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32ByteOffset) == ps_vma->vm_pgoff);
         /*
         * Since the memory is contiguous, we can map the whole range in one
         * go .
@@ -698,7 +681,7 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
 
        PVR_ASSERT(psLinuxMemArea->hBMHandle == IMG_NULL);
 
-       result = IO_REMAP_PFN_RANGE(ps_vma, ps_vma->vm_start, ps_vma->vm_pgoff, ui32ByteSize, ps_vma->vm_page_prot);
+       result = IO_REMAP_PFN_RANGE(ps_vma, ps_vma->vm_start, ps_vma->vm_pgoff, uiByteSize, ps_vma->vm_page_prot);
 
         if(result == 0)
         {
@@ -710,7 +693,7 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
 #endif
 
     {
-        /*
+       /*
          * Memory may be non-contiguous, so we map the range page,
         * by page.  Since VM_PFNMAP mappings are assumed to be physically
         * contiguous, we can't legally use REMAP_PFN_RANGE (that is, we
@@ -720,22 +703,22 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
         * finding the page structure corresponding to each page, or
         * if mixed maps are supported (VM_MIXEDMAP), vm_insert_mixed.
         */
-        IMG_UINT32 ulVMAPos;
-       IMG_UINT32 ui32ByteEnd = ui32ByteOffset + ui32ByteSize;
-       IMG_UINT32 ui32PA;
-       IMG_UINT32 ui32AdjustedPA = ui32ByteOffset;
+        IMG_UINTPTR_T ulVMAPos;
+       IMG_UINTPTR_T uiByteEnd = uiByteOffset + uiByteSize;
+       IMG_UINTPTR_T uiPA;
+       IMG_UINTPTR_T uiAdjustedPA = uiByteOffset;
 #if defined(PVR_MAKE_ALL_PFNS_SPECIAL)
-       IMG_BOOL bMixedMap = IMG_FALSE;
+               IMG_BOOL bMixedMap = IMG_FALSE;
 #endif
        /* First pass, validate the page frame numbers */
-       for(ui32PA = ui32ByteOffset; ui32PA < ui32ByteEnd; ui32PA += PAGE_SIZE)
+       for(uiPA = uiByteOffset; uiPA < uiByteEnd; uiPA += PAGE_SIZE)
        {
-               IMG_UINT32 pfn;
+               IMG_UINTPTR_T pfn;
            IMG_BOOL bMapPage = IMG_TRUE;
 
                if (psLinuxMemArea->hBMHandle)
                {
-                       if (!BM_MapPageAtOffset(psLinuxMemArea->hBMHandle, ui32PA))
+                       if (!BM_MapPageAtOffset(psLinuxMemArea->hBMHandle, uiPA))
                        {
                                bMapPage = IMG_FALSE;
                        }
@@ -743,39 +726,43 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
 
                if (bMapPage)
                {
-                       pfn =  LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32AdjustedPA);
+                       pfn =  LinuxMemAreaToCpuPFN(psLinuxMemArea, uiAdjustedPA);
                        if (!pfn_valid(pfn))
                        {
 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
-                                       PVR_DPF((PVR_DBG_ERROR,"%s: Error - PFN invalid: 0x%x", __FUNCTION__, pfn));
+                                       PVR_DPF((PVR_DBG_ERROR,"%s: Error - PFN invalid: 0x" UINTPTR_FMT, __FUNCTION__, pfn));
                                        return IMG_FALSE;
 #else
                        bMixedMap = IMG_TRUE;
 #endif
                        }
-                       ui32AdjustedPA += PAGE_SIZE;
+                   else if (0 == page_count(pfn_to_page(pfn)))
+                   {
+                       bMixedMap = IMG_TRUE;
+                   }
+                       uiAdjustedPA += PAGE_SIZE;
                }
        }
 
 #if defined(PVR_MAKE_ALL_PFNS_SPECIAL)
-       if (bMixedMap)
-       {
-            ps_vma->vm_flags |= VM_MIXEDMAP;
-       }
+               if (bMixedMap)
+               {
+                       ps_vma->vm_flags |= VM_MIXEDMAP;
+               }
 #endif
        /* Second pass, get the page structures and insert the pages */
         ulVMAPos = ps_vma->vm_start;
-        ui32AdjustedPA = ui32ByteOffset;
-       for(ui32PA = ui32ByteOffset; ui32PA < ui32ByteEnd; ui32PA += PAGE_SIZE)
+        uiAdjustedPA = uiByteOffset;
+       for(uiPA = uiByteOffset; uiPA < uiByteEnd; uiPA += PAGE_SIZE)
        {
-           IMG_UINT32 pfn;
+           IMG_UINTPTR_T pfn;
            IMG_INT result;
            IMG_BOOL bMapPage = IMG_TRUE;
 
                if (psLinuxMemArea->hBMHandle)
                {
                        /* We have a sparse allocation, check if this page should be mapped */
-                       if (!BM_MapPageAtOffset(psLinuxMemArea->hBMHandle, ui32PA))
+                       if (!BM_MapPageAtOffset(psLinuxMemArea->hBMHandle, uiPA))
                        {
                                bMapPage = IMG_FALSE;
                        }
@@ -783,7 +770,7 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
 
                if (bMapPage)
                {
-                       pfn =  LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32AdjustedPA);
+                       pfn =  LinuxMemAreaToCpuPFN(psLinuxMemArea, uiAdjustedPA);
 
 #if defined(PVR_MAKE_ALL_PFNS_SPECIAL)
                    if (bMixedMap)
@@ -798,7 +785,7 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
                    else
 #endif
                    {
-                       struct page *psPage;
+                               struct page *psPage;
        
                        PVR_ASSERT(pfn_valid(pfn));
        
@@ -811,11 +798,11 @@ DoMapToUser(LinuxMemArea *psLinuxMemArea,
                            return IMG_FALSE;
                        }
                    }
-                   ui32AdjustedPA += PAGE_SIZE;
+                   uiAdjustedPA += PAGE_SIZE;
+                       }
+               ulVMAPos += PAGE_SIZE;
                }
-        ulVMAPos += PAGE_SIZE;
-    }
-    }
+       }
 
     return IMG_TRUE;
 }
@@ -840,11 +827,11 @@ MMapVOpenNoLock(struct vm_area_struct* ps_vma)
 #if defined(DEBUG_LINUX_MMAP_AREAS)
 
     PVR_DPF((PVR_DBG_MESSAGE,
-             "%s: psLinuxMemArea 0x%p, KVAddress 0x%p MMapOffset %d, ui32Mapped %d",
+             "%s: psLinuxMemArea 0x%p, KVAddress 0x%p MMapOffset " UINTPTR_FMT ", ui32Mapped %d",
              __FUNCTION__,
              psOffsetStruct->psLinuxMemArea,
              LinuxMemAreaToCpuVAddr(psOffsetStruct->psLinuxMemArea),
-             psOffsetStruct->ui32MMapOffset,
+             psOffsetStruct->uiMMapOffset,
              psOffsetStruct->ui32Mapped));
 #endif
 }
@@ -856,7 +843,7 @@ MMapVOpenNoLock(struct vm_area_struct* ps_vma)
 static void
 MMapVOpen(struct vm_area_struct* ps_vma)
 {
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
     MMapVOpenNoLock(ps_vma);
 
@@ -872,11 +859,11 @@ MMapVCloseNoLock(struct vm_area_struct* ps_vma)
 
 #if defined(DEBUG_LINUX_MMAP_AREAS)
     PVR_DPF((PVR_DBG_MESSAGE,
-             "%s: psLinuxMemArea %p, CpuVAddr %p ui32MMapOffset %d, ui32Mapped %d",
+             "%s: psLinuxMemArea %p, CpuVAddr %p uiMMapOffset " UINTPTR_FMT ", ui32Mapped %d",
              __FUNCTION__,
              psOffsetStruct->psLinuxMemArea,
              LinuxMemAreaToCpuVAddr(psOffsetStruct->psLinuxMemArea),
-             psOffsetStruct->ui32MMapOffset,
+             psOffsetStruct->uiMMapOffset,
              psOffsetStruct->ui32Mapped));
 #endif
 
@@ -886,7 +873,13 @@ MMapVCloseNoLock(struct vm_area_struct* ps_vma)
     {
        if (psOffsetStruct->ui32RefCount != 0)
        {
-               PVR_DPF((PVR_DBG_MESSAGE, "%s: psOffsetStruct %p has non-zero reference count (ui32RefCount = %u). User mode address of start of mapping: 0x%x", __FUNCTION__, psOffsetStruct, psOffsetStruct->ui32RefCount, psOffsetStruct->ui32UserVAddr));
+               PVR_DPF((
+              PVR_DBG_MESSAGE, 
+              "%s: psOffsetStruct %p has non-zero reference count (ui32RefCount = %u). User mode address of start of mapping: 0x" UINTPTR_FMT, 
+              __FUNCTION__, 
+              psOffsetStruct, 
+              psOffsetStruct->ui32RefCount, 
+              psOffsetStruct->uiUserVAddr));
        }
 
        DestroyOffsetStruct(psOffsetStruct);
@@ -901,7 +894,7 @@ MMapVCloseNoLock(struct vm_area_struct* ps_vma)
 static void
 MMapVClose(struct vm_area_struct* ps_vma)
 {
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
     MMapVCloseNoLock(ps_vma);
 
@@ -923,13 +916,13 @@ static int MMapVAccess(struct vm_area_struct *ps_vma, unsigned long addr,
        int iRetVal = -EINVAL;
        IMG_VOID *pvKernelAddr;
 
-       LinuxLockMutex(&g_sMMapMutex);
+       LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
        psOffsetStruct = (PKV_OFFSET_STRUCT)ps_vma->vm_private_data;
        psLinuxMemArea = psOffsetStruct->psLinuxMemArea;
        ulOffset = addr - ps_vma->vm_start;
 
-    if (ulOffset+len > psLinuxMemArea->ui32ByteSize)
+    if (ulOffset+len > psLinuxMemArea->uiByteSize)
                /* Out of range. We shouldn't get here, because the kernel will do
                   the necessary checks before calling access_process_vm. */
                goto exit_unlock;
@@ -943,7 +936,7 @@ static int MMapVAccess(struct vm_area_struct *ps_vma, unsigned long addr,
        }
        else
        {
-               IMG_UINT32 pfn, ui32OffsetInPage;
+               IMG_UINTPTR_T pfn, uiOffsetInPage;
                struct page *page;
 
                pfn = LinuxMemAreaToCpuPFN(psLinuxMemArea, ulOffset);
@@ -952,14 +945,14 @@ static int MMapVAccess(struct vm_area_struct *ps_vma, unsigned long addr,
                        goto exit_unlock;
 
                page = pfn_to_page(pfn);
-               ui32OffsetInPage = ADDR_TO_PAGE_OFFSET(ulOffset);
+               uiOffsetInPage = ADDR_TO_PAGE_OFFSET(ulOffset);
 
-               if (ui32OffsetInPage+len > PAGE_SIZE)
+               if (uiOffsetInPage + len > PAGE_SIZE)
                        /* The region crosses a page boundary */
                        goto exit_unlock;
 
                pvKernelAddr = kmap(page);
-               memcpy(buf, pvKernelAddr+ui32OffsetInPage, len);
+               memcpy(buf, pvKernelAddr + uiOffsetInPage, len);
                kunmap(page);
 
                iRetVal = len;
@@ -1001,34 +994,35 @@ PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
 {
     LinuxMemArea *psFlushMemArea = IMG_NULL;
     PKV_OFFSET_STRUCT psOffsetStruct;
-    IMG_UINT32 ui32ByteSize;
+    IMG_SIZE_T uiByteSize;
     IMG_VOID *pvBase = IMG_NULL;
     int iRetVal = 0;
-    IMG_UINT32 ui32ByteOffset = 0;     /* Keep compiler happy */
-    IMG_UINT32 ui32FlushSize = 0;
+    IMG_UINTPTR_T uiByteOffset = 0;    /* Keep compiler happy */
+    IMG_SIZE_T uiFlushSize = 0;
 
     PVR_UNREFERENCED_PARAMETER(pFile);
 
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
     
-    ui32ByteSize = ps_vma->vm_end - ps_vma->vm_start;
+    uiByteSize = ps_vma->vm_end - ps_vma->vm_start;
     
-    PVR_DPF((PVR_DBG_MESSAGE, "%s: Received mmap(2) request with ui32MMapOffset 0x%08lx,"
-                              " and ui32ByteSize %d(0x%08x)",
+    PVR_DPF((PVR_DBG_MESSAGE, "%s: Received mmap(2) request with ui32MMapOffset 0x" UINTPTR_FMT ","
+                              " and uiByteSize %" SIZE_T_FMT_LEN "u(0x%" SIZE_T_FMT_LEN "x)",
             __FUNCTION__,
             ps_vma->vm_pgoff,
-            ui32ByteSize, ui32ByteSize));
+            uiByteSize, 
+            uiByteSize));
    
-    psOffsetStruct = FindOffsetStructByOffset(ps_vma->vm_pgoff, ui32ByteSize);
+    psOffsetStruct = FindOffsetStructByOffset(ps_vma->vm_pgoff, uiByteSize);
 
     if (psOffsetStruct == IMG_NULL)
     {
 #if defined(SUPPORT_DRI_DRM)
-        LinuxUnLockMutex(&g_sMMapMutex);
+               LinuxUnLockMutex(&g_sMMapMutex);
 
 #if !defined(SUPPORT_DRI_DRM_EXT)
-        /* Pass unknown requests onto the DRM module */
-        return drm_mmap(pFile, ps_vma);
+               /* Pass unknown requests onto the DRM module */
+               return drm_mmap(pFile, ps_vma);
 #else
         /*
          * Indicate to caller that the request is not for us.
@@ -1064,7 +1058,12 @@ PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
     PVR_DPF((PVR_DBG_MESSAGE, "%s: Mapped psLinuxMemArea 0x%p\n",
          __FUNCTION__, psOffsetStruct->psLinuxMemArea));
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
     ps_vma->vm_flags |= VM_RESERVED;
+#else
+    ps_vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; /* Don't swap */
+#endif
+
     ps_vma->vm_flags |= VM_IO;
 
     /*
@@ -1094,7 +1093,33 @@ PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
             iRetVal = -EINVAL;
            goto unlock_and_return;
     }
-    
+
+#ifdef CONFIG_ARCH_OMAP5
+    {
+       IMG_BOOL bModPageProt = IMG_FALSE;
+
+       /* In OMAP5, the Cortex A15 no longer masks an issue with the L2
+        * interconnect. Write-combined access to the TILER aperture will
+        * generate SIGBUS / "non-line fetch abort" errors due to L2
+        * interconnect bus accesses. The workaround is to use a shared
+        * device access.
+        */
+
+       bModPageProt |= (psOffsetStruct->psLinuxMemArea->eAreaType == LINUX_MEM_AREA_ION);
+
+#ifdef CONFIG_DSSCOMP
+       bModPageProt |= is_tiler_addr(LinuxMemAreaToCpuPAddr(psOffsetStruct->psLinuxMemArea, 0).uiAddr);
+#endif /* CONFIG_DSSCOMP */ 
+
+       if (bModPageProt)
+       {
+               ps_vma->vm_page_prot = __pgprot_modify(ps_vma->vm_page_prot,
+                                              L_PTE_MT_MASK,
+                                              L_PTE_MT_DEV_SHARED);
+       }
+    }
+#endif /* CONFIG_ARCH_OMAP5 */
+
     /* Install open and close handlers for ref-counting */
     ps_vma->vm_ops = &MMapIOOps;
     
@@ -1104,9 +1129,9 @@ PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
         goto unlock_and_return;
     }
     
-    PVR_ASSERT(psOffsetStruct->ui32UserVAddr == 0);
+    PVR_ASSERT(psOffsetStruct->uiUserVAddr == 0);
 
-    psOffsetStruct->ui32UserVAddr = ps_vma->vm_start;
+    psOffsetStruct->uiUserVAddr = ps_vma->vm_start;
 
     /* Compute the flush region (if necessary) inside the mmap mutex */
     if(psOffsetStruct->psLinuxMemArea->bNeedsCacheInvalidate)
@@ -1117,19 +1142,19 @@ PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
                if (psFlushMemArea->hBMHandle)
                {
                        pvBase = (IMG_VOID *)ps_vma->vm_start;
-                       ui32ByteOffset = 0;
-                       ui32FlushSize = BM_GetVirtualSize(psFlushMemArea->hBMHandle);
+                       uiByteOffset = 0;
+                       uiFlushSize = BM_GetVirtualSize(psFlushMemArea->hBMHandle);
                }
                else
                {
-               IMG_UINT32 ui32DummyByteSize;
+                       IMG_SIZE_T uiDummyByteSize;
 
                DetermineUsersSizeAndByteOffset(psFlushMemArea,
-                                               &ui32DummyByteSize,
-                                               &ui32ByteOffset);
+                                               &uiDummyByteSize,
+                                               &uiByteOffset);
        
-               pvBase = (IMG_VOID *)ps_vma->vm_start + ui32ByteOffset;
-               ui32FlushSize = psFlushMemArea->ui32ByteSize;
+               pvBase = (IMG_VOID *)ps_vma->vm_start + uiByteOffset;
+               uiFlushSize = psFlushMemArea->uiByteSize;
                }
 
         psFlushMemArea->bNeedsCacheInvalidate = IMG_FALSE;
@@ -1138,8 +1163,8 @@ PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
     /* Call the open routine to increment the usage count */
     MMapVOpenNoLock(ps_vma);
 
-    PVR_DPF((PVR_DBG_MESSAGE, "%s: Mapped area at offset 0x%08lx\n",
-             __FUNCTION__, ps_vma->vm_pgoff));
+    PVR_DPF((PVR_DBG_MESSAGE, "%s: Mapped area at offset 0x" UINTPTR_FMT "\n",
+             __FUNCTION__, (IMG_UINTPTR_T)ps_vma->vm_pgoff));
 
 unlock_and_return:
     if (iRetVal != 0 && psOffsetStruct != IMG_NULL)
@@ -1151,8 +1176,8 @@ unlock_and_return:
 
     if(psFlushMemArea)
     {
-        OSInvalidateCPUCacheRangeKM(psFlushMemArea, ui32ByteOffset, pvBase,
-                                                                       ui32FlushSize);
+        OSInvalidateCPUCacheRangeKM(psFlushMemArea, uiByteOffset, pvBase,
+                                                                       uiFlushSize);
     }
 
     return iRetVal;
@@ -1172,7 +1197,7 @@ static void ProcSeqStartstopMMapRegistations(struct seq_file *sfile,IMG_BOOL sta
 {
        if(start) 
        {
-           LinuxLockMutex(&g_sMMapMutex);              
+           LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);                
        }
        else
        {
@@ -1242,15 +1267,15 @@ static void ProcSeqShowMMapRegistrations(struct seq_file *sfile, void *el)
 {
        KV_OFFSET_STRUCT *psOffsetStruct = (KV_OFFSET_STRUCT*)el;
     LinuxMemArea *psLinuxMemArea;
-       IMG_UINT32 ui32RealByteSize;
-       IMG_UINT32 ui32ByteOffset;
+       IMG_SIZE_T uiRealByteSize;
+       IMG_UINTPTR_T uiByteOffset;
 
        if(el == PVR_PROC_SEQ_START_TOKEN) 
        {
         seq_printf( sfile,
 #if !defined(DEBUG_LINUX_XML_PROC_FILES)
                                                  "Allocations registered for mmap: %u\n"
-                          "In total these areas correspond to %u bytes\n"
+                          "In total these areas correspond to %" SIZE_T_FMT_LEN "u bytes\n"
                           "psLinuxMemArea "
                                                  "UserVAddr "
                                                  "KernelVAddr "
@@ -1262,11 +1287,11 @@ static void ProcSeqShowMMapRegistrations(struct seq_file *sfile, void *el)
 #else
                           "<mmap_header>\n"
                           "\t<count>%u</count>\n"
-                          "\t<bytes>%u</bytes>\n"
+                          "\t<bytes>%" SIZE_T_FMT_LEN "u</bytes>\n"
                           "</mmap_header>\n",
 #endif
                                                  g_ui32RegisteredAreas,
-                          g_ui32TotalByteSize
+                          g_uiTotalByteSize
                           );
                return;
        }
@@ -1274,20 +1299,20 @@ static void ProcSeqShowMMapRegistrations(struct seq_file *sfile, void *el)
        psLinuxMemArea = psOffsetStruct->psLinuxMemArea;
 
        DetermineUsersSizeAndByteOffset(psLinuxMemArea,
-                                                                       &ui32RealByteSize,
-                                                                       &ui32ByteOffset);
+                                                                       &uiRealByteSize,
+                                                                       &uiByteOffset);
 
        seq_printf( sfile,
 #if !defined(DEBUG_LINUX_XML_PROC_FILES)
-                                               "%-8p       %08x %-8p %08x %08x   %-8d   %-24s %-5u %-8s %08x(%s)\n",
+                                               "%p       %p %p " CPUPADDR_FMT " " UINTPTR_FMT "   %" SIZE_T_FMT_LEN "u   %-24s %-5u %-8s %08x(%s)\n",
 #else
                         "<mmap_record>\n"
-                                               "\t<pointer>%-8p</pointer>\n"
-                        "\t<user_virtual>%-8x</user_virtual>\n"
-                        "\t<kernel_virtual>%-8p</kernel_virtual>\n"
-                        "\t<cpu_physical>%08x</cpu_physical>\n"
-                        "\t<mmap_offset>%08x</mmap_offset>\n"
-                        "\t<bytes>%-8d</bytes>\n"
+                                               "\t<pointer>%p</pointer>\n"
+                        "\t<user_virtual>%p</user_virtual>\n"
+                        "\t<kernel_virtual>%p</kernel_virtual>\n"
+                        "\t<cpu_physical>" CPUPADDR_FMT "</cpu_physical>\n"
+                        "\t<mmap_offset>" UINTPTR_FMT "</mmap_offset>\n"
+                        "\t<bytes>%" SIZE_T_FMT_LEN "u</bytes>\n"
                         "\t<linux_mem_area_type>%-24s</linux_mem_area_type>\n"
                         "\t<pid>%-5u</pid>\n"
                         "\t<name>%-8s</name>\n"
@@ -1296,11 +1321,11 @@ static void ProcSeqShowMMapRegistrations(struct seq_file *sfile, void *el)
                         "</mmap_record>\n",
 #endif
                         psLinuxMemArea,
-                                               psOffsetStruct->ui32UserVAddr + ui32ByteOffset,
+                                               (IMG_PVOID)(psOffsetStruct->uiUserVAddr + uiByteOffset),
                                                LinuxMemAreaToCpuVAddr(psLinuxMemArea),
                         LinuxMemAreaToCpuPAddr(psLinuxMemArea,0).uiAddr,
-                                               psOffsetStruct->ui32MMapOffset,
-                                               psLinuxMemArea->ui32ByteSize,
+                                               (IMG_UINTPTR_T)psOffsetStruct->uiMMapOffset,
+                                               psLinuxMemArea->uiByteSize,
                         LinuxMemAreaTypeToString(psLinuxMemArea->eAreaType),
                                                psOffsetStruct->ui32PID,
                                                psOffsetStruct->pszName,
@@ -1333,7 +1358,7 @@ PVRMMapRegisterArea(LinuxMemArea *psLinuxMemArea)
     const IMG_CHAR *pszName = LinuxMemAreaTypeToString(LinuxMemAreaRootType(psLinuxMemArea));
 #endif
 
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
 #if defined(DEBUG) || defined(DEBUG_LINUX_MMAP_AREAS)
     PVR_DPF((PVR_DBG_MESSAGE,
@@ -1365,7 +1390,7 @@ PVRMMapRegisterArea(LinuxMemArea *psLinuxMemArea)
      */
     if (psLinuxMemArea->eAreaType != LINUX_MEM_AREA_SUB_ALLOC)
     {
-        g_ui32TotalByteSize += psLinuxMemArea->ui32ByteSize;
+        g_uiTotalByteSize += psLinuxMemArea->uiByteSize;
     }
 #endif
 
@@ -1398,7 +1423,7 @@ PVRMMapRemoveRegisteredArea(LinuxMemArea *psLinuxMemArea)
     PVRSRV_ERROR eError;
     PKV_OFFSET_STRUCT psOffsetStruct, psTmpOffsetStruct;
 
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
     PVR_ASSERT(psLinuxMemArea->bMMapRegistered);
 
@@ -1436,7 +1461,7 @@ PVRMMapRemoveRegisteredArea(LinuxMemArea *psLinuxMemArea)
     g_ui32RegisteredAreas--;
     if (psLinuxMemArea->eAreaType != LINUX_MEM_AREA_SUB_ALLOC)
     {
-        g_ui32TotalByteSize -= psLinuxMemArea->ui32ByteSize;
+        g_uiTotalByteSize -= psLinuxMemArea->uiByteSize;
     }
 #endif
 
@@ -1491,7 +1516,7 @@ LinuxMMapPerProcessDisconnect(PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc)
 
     PVR_UNREFERENCED_PARAMETER(psEnvPerProc);
 
-    LinuxLockMutex(&g_sMMapMutex);
+    LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
     list_for_each_entry_safe(psOffsetStruct, psTmpOffsetStruct, &g_sMMapOffsetStructList, sMMapItem)
     {
index 7140c13..72640e3 100644 (file)
@@ -77,9 +77,9 @@ typedef struct KV_OFFSET_STRUCT_TAG
      * contiguous), or it may represent the secure handle associated
      * with the area.
      */
-    IMG_UINT32                  ui32MMapOffset;
-    
-    IMG_UINT32                 ui32RealByteSize;
+    IMG_UINTPTR_T       uiMMapOffset;
+
+    IMG_SIZE_T                 uiRealByteSize;
 
     /* Memory area associated with this offset structure */
     LinuxMemArea                *psLinuxMemArea;
@@ -107,7 +107,7 @@ typedef struct KV_OFFSET_STRUCT_TAG
      * User mode address of start of mapping.  This is not necessarily the
      * first user mode address of the memory area.
      */
-    IMG_UINT32                 ui32UserVAddr;
+    IMG_UINTPTR_T              uiUserVAddr;
 
     /* Extra entries to support proc filesystem debug info */
 #if defined(DEBUG_LINUX_MMAP_AREAS)
@@ -187,15 +187,11 @@ PVRSRV_ERROR PVRMMapRemoveRegisteredArea(LinuxMemArea *psLinuxMemArea);
  * @Return PVRSRV_ERROR
  ******************************************************************************/
 PVRSRV_ERROR PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
-#if defined (SUPPORT_SID_INTERFACE)
-                                          IMG_SID     hMHandle,
-#else
                                           IMG_HANDLE hMHandle,
-#endif
-                                          IMG_UINT32 *pui32MMapOffset,
-                                          IMG_UINT32 *pui32ByteOffset,
-                                          IMG_UINT32 *pui32RealByteSize,
-                                          IMG_UINT32 *pui32UserVAddr);
+                                          IMG_UINTPTR_T *puiMMapOffset,
+                                          IMG_UINTPTR_T *puiByteOffset,
+                                          IMG_SIZE_T *puiRealByteSize,
+                                          IMG_UINTPTR_T *puiUserVAddr);
 
 /*!
  *******************************************************************************
@@ -214,14 +210,10 @@ PVRSRV_ERROR PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
  ******************************************************************************/
 PVRSRV_ERROR
 PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
-#if defined (SUPPORT_SID_INTERFACE)
-                               IMG_SID   hMHandle,
-#else
                                IMG_HANDLE hMHandle,
-#endif
                                IMG_BOOL *pbMUnmap,
-                               IMG_UINT32 *pui32RealByteSize,
-                                IMG_UINT32 *pui32UserVAddr);
+                               IMG_SIZE_T *puiRealByteSize,
+                IMG_UINTPTR_T *puiUserVAddr);
 
 /*!
  *******************************************************************************
index ea4b5e3..668dc2d 100644 (file)
@@ -129,6 +129,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "lock.h"
 #include "linkage.h"
 #include "buffer_manager.h"
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include "pvr_sync.h"
+#endif
 
 #if defined(SUPPORT_DRI_DRM)
 #include "pvr_drm.h"
@@ -139,7 +142,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 #if defined(PVR_LDM_MODULE)
 //#define      DRVNAME         PVR_LDM_DRIVER_REGISTRATION_NAME
-#define        DRVNAME         PVRSRV_MODNAME  
+#define DRVNAME                PVRSRV_MODNAME
 #endif
 #define DEVNAME                PVRSRV_MODNAME
 
@@ -166,7 +169,6 @@ MODULE_PARM_DESC(gPVRDebugLevel, "Sets the level of debug output (default 0x7)")
 #include <linux/omap_ion.h>
 extern struct ion_device *omap_ion_device;
 struct ion_client *gpsIONClient;
-EXPORT_SYMBOL(gpsIONClient);
 #endif /* defined(CONFIG_ION_OMAP) */
 
 /* PRQA S 3207 2 */ /* ignore 'not used' warning */
@@ -215,6 +217,39 @@ IMG_UINT32 gui32ReleasePID;
 static IMG_UINT32 gPVRPowerLevel;
 #endif
 
+static int PVRSRVIONClientCreate(void)
+{
+#if defined(CONFIG_ION_OMAP)
+       gpsIONClient = ion_client_create(omap_ion_device,
+                                                                        1 << OMAP_ION_HEAP_TYPE_TILER,
+                                                                        "pvr");
+       if (IS_ERR_OR_NULL(gpsIONClient))
+       {
+               int err;
+
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVDriverProbe: Couldn't create ion client"));
+
+               err = PTR_ERR(gpsIONClient);
+               gpsIONClient = IMG_NULL;
+
+               return err;
+       }
+#endif /* defined(CONFIG_ION_OMAP) */
+
+       return 0;
+}
+
+static void PVRSRVIONClientDestroy(void)
+{
+#if defined(CONFIG_ION_OMAP)
+       if (gpsIONClient != NULL)
+       {
+               ion_client_destroy(gpsIONClient);
+               gpsIONClient = IMG_NULL;
+       }
+#endif
+}
+
 #if defined(PVR_LDM_MODULE)
 
 #if defined(PVR_LDM_PLATFORM_MODULE)
@@ -289,10 +324,10 @@ LDM_DEV *gpsPVRLDMDev;
 
 #if defined(MODULE) && defined(PVR_LDM_PLATFORM_MODULE) && \
        !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
+#if !defined(PM_RUNTIME_SUPPORT)
 static void PVRSRVDeviceRelease(struct device unref__ *pDevice)
 {
 }
-
 static struct platform_device powervr_device = {
        .name                   = DEVNAME,
        .id                             = -1,
@@ -301,6 +336,7 @@ static struct platform_device powervr_device = {
        }
 };
 #endif
+#endif
 
 /*!
 ******************************************************************************
@@ -354,19 +390,7 @@ static int __devinit PVRSRVDriverProbe(LDM_DEV *pDevice, const struct pci_device
                }
        }
 
-#if defined(CONFIG_ION_OMAP)
-       gpsIONClient = ion_client_create(omap_ion_device,
-                                                                        1 << ION_HEAP_TYPE_CARVEOUT |
-                                                                        1 << OMAP_ION_HEAP_TYPE_TILER,
-                                                                        "pvr");
-       if (IS_ERR_OR_NULL(gpsIONClient))
-       {
-               PVR_DPF((PVR_DBG_ERROR, "PVRSRVDriverProbe: Couldn't create ion client"));
-               return PTR_ERR(gpsIONClient);
-       }
-#endif /* defined(CONFIG_ION_OMAP) */
-
-       return 0;
+       return PVRSRVIONClientCreate();
 }
 
 
@@ -400,10 +424,7 @@ static void __devexit PVRSRVDriverRemove(LDM_DEV *pDevice)
 
        PVR_TRACE(("PVRSRVDriverRemove(pDevice=%p)", pDevice));
 
-#if defined(CONFIG_ION_OMAP)
-       ion_client_destroy(gpsIONClient);
-       gpsIONClient = IMG_NULL;
-#endif
+       PVRSRVIONClientDestroy();
 
        SysAcquireData(&psSysData);
        
@@ -479,7 +500,7 @@ PVR_MOD_STATIC void PVRSRVDriverShutdown(LDM_DEV *pDevice)
                 * processes trying to use the driver after it has been
                 * shutdown.
                 */
-               LinuxLockMutex(&gPVRSRVLock);
+               LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
                (void) PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D3);
        }
@@ -540,7 +561,7 @@ PVR_MOD_STATIC int PVRSRVDriverSuspend(LDM_DEV *pDevice, pm_message_t state)
 
        if (!bDriverIsSuspended && !bDriverIsShutdown)
        {
-               LinuxLockMutex(&gPVRSRVLock);
+               LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
                if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D3) == PVRSRV_OK)
                {
@@ -731,7 +752,7 @@ static int PVRSRVOpen(struct inode unref__ * pInode, struct file *pFile)
        PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc;
 #endif
 
-       LinuxLockMutex(&gPVRSRVLock);
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
        ui32PID = OSGetCurrentProcessIDKM();
 
@@ -756,11 +777,7 @@ static int PVRSRVOpen(struct inode unref__ * pInode, struct file *pFile)
        if(eError != PVRSRV_OK)
                goto err_unlock;
 
-#if defined (SUPPORT_SID_INTERFACE)
-       psPrivateData->hKernelMemInfo = 0;
-#else
        psPrivateData->hKernelMemInfo = NULL;
-#endif
 #if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
        psPrivateData->psDRMFile = pFile;
 
@@ -802,7 +819,7 @@ static int PVRSRVRelease(struct inode unref__ * pInode, struct file *pFile)
        PVRSRV_FILE_PRIVATE_DATA *psPrivateData;
        int err = 0;
 
-       LinuxLockMutex(&gPVRSRVLock);
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
 #if defined(SUPPORT_DRI_DRM)
        psPrivateData = (PVRSRV_FILE_PRIVATE_DATA *)pvPrivData;
@@ -922,6 +939,8 @@ static int __init PVRCore_Init(void)
        struct device *psDev;
 #endif
 
+
+
 #if !defined(SUPPORT_DRI_DRM)
        /*
         * Must come before attempting to print anything via Services.
@@ -957,6 +976,7 @@ static int __init PVRCore_Init(void)
        }
 
        LinuxBridgeInit();
+       
 
        PVRMMapInit();
 
@@ -971,6 +991,7 @@ static int __init PVRCore_Init(void)
        }
 
 #if defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
+#if !defined(PM_RUNTIME_SUPPORT)
        if ((error = platform_device_register(&powervr_device)) != 0)
        {
                platform_driver_unregister(&powervr_driver);
@@ -980,6 +1001,7 @@ static int __init PVRCore_Init(void)
                goto init_failed;
        }
 #endif
+#endif
 #endif /* PVR_LDM_PLATFORM_MODULE */
 
 #if defined(PVR_LDM_PCI_MODULE)
@@ -1008,6 +1030,12 @@ static int __init PVRCore_Init(void)
 #endif
                goto init_failed;
        }
+
+       error = PVRSRVIONClientCreate();
+       if (error != 0)
+       {
+               goto sys_deinit;
+       }
 #endif /* !defined(PVR_LDM_MODULE) */
 
 #if !defined(SUPPORT_DRI_DRM)
@@ -1051,6 +1079,9 @@ static int __init PVRCore_Init(void)
 #endif /* defined(PVR_LDM_DEVICE_CLASS) */
 #endif /* !defined(SUPPORT_DRI_DRM) */
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       PVRSyncDeviceInit();
+#endif
        return 0;
 
 #if !defined(SUPPORT_DRI_DRM)
@@ -1060,6 +1091,8 @@ destroy_class:
 unregister_device:
        unregister_chrdev((IMG_UINT)AssignedMajorNumber, DEVNAME);
 #endif
+#endif
+#if !defined(PVR_LDM_MODULE) || !defined(SUPPORT_DRI_DRM)
 sys_deinit:
 #endif
 #if defined(PVR_LDM_MODULE)
@@ -1069,12 +1102,16 @@ sys_deinit:
 
 #if defined (PVR_LDM_PLATFORM_MODULE)
 #if defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
+#if !defined(PM_RUNTIME_SUPPORT)
        platform_device_unregister(&powervr_device);
+#endif
 #endif
        platform_driver_unregister(&powervr_driver);
 #endif
 
 #else  /* defined(PVR_LDM_MODULE) */
+       PVRSRVIONClientDestroy();
+
        /* LDM drivers call SysDeinitialise during PVRSRVDriverRemove */
        {
                SYS_DATA *psSysData;
@@ -1138,6 +1175,10 @@ static void __exit PVRCore_Cleanup(void)
        SysAcquireData(&psSysData);
 #endif
 
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       PVRSyncDeviceDeInit();
+#endif
+
 #if !defined(SUPPORT_DRI_DRM)
 
 #if defined(PVR_LDM_DEVICE_CLASS)
@@ -1167,7 +1208,9 @@ static void __exit PVRCore_Cleanup(void)
 
 #if defined (PVR_LDM_PLATFORM_MODULE)
 #if defined(MODULE) && !defined(PVR_USE_PRE_REGISTERED_PLATFORM_DEV)
+#if !defined(PM_RUNTIME_SUPPORT)
        platform_device_unregister(&powervr_device);
+#endif
 #endif
        platform_driver_unregister(&powervr_driver);
 #endif
@@ -1182,6 +1225,8 @@ static void __exit PVRCore_Cleanup(void)
                }
        }
 #endif
+       PVRSRVIONClientDestroy();
+
        /* LDM drivers call SysDeinitialise during PVRSRVDriverRemove */
        (void) SysDeinitialise(psSysData);
 #endif /* defined(PVR_LDM_MODULE) */
index 2cd666f..56422d6 100644 (file)
@@ -66,6 +66,11 @@ IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
     mutex_lock(psPVRSRVMutex);
 }
 
+IMG_VOID LinuxLockMutexNested(PVRSRV_LINUX_MUTEX *psPVRSRVMutex, unsigned int uiLockClass)
+{
+       mutex_lock_nested(psPVRSRVMutex, uiLockClass);
+}
+
 PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
 {
     if(mutex_lock_interruptible(psPVRSRVMutex) == -EINTR)
@@ -109,6 +114,11 @@ IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
     atomic_dec(&psPVRSRVMutex->Count);
 }
 
+IMG_VOID LinuxLockMutexNested(PVRSRV_LINUX_MUTEX *psPVRSRVMutex, unsigned int uiLockClass)
+{
+       LinuxLockMutex(psPVRSRVMutex);
+}
+
 PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
 {
     if(down_interruptible(&psPVRSRVMutex->sSemaphore) == -EINTR)
@@ -131,7 +141,7 @@ IMG_INT32 LinuxTryLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
         atomic_dec(&psPVRSRVMutex->Count);
     }
 
-    return Status;
+    return Status == 0;
 }
 
 IMG_VOID LinuxUnLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
index c590da1..816cf4a 100644 (file)
@@ -72,11 +72,18 @@ typedef struct {
 
 #endif
 
+enum PVRSRV_MUTEX_LOCK_CLASS
+{
+       PVRSRV_LOCK_CLASS_BRIDGE,
+       PVRSRV_LOCK_CLASS_MMAP,
+};
 
 extern IMG_VOID LinuxInitMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex);
 
 extern IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex);
 
+extern IMG_VOID LinuxLockMutexNested(PVRSRV_LINUX_MUTEX *psPVRSRVMutex, unsigned int uiLockClass);
+
 extern PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex);
 
 extern IMG_INT32 LinuxTryLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex);
index 891598c..31e0dac 100644 (file)
@@ -64,7 +64,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #if defined(__arm__) || defined(__sh__)
                #define PGPROT_WC(pv)   pgprot_writecombine(pv)
        #else
-               #if defined(__i386__) || defined(__mips__)
+               #if defined(__i386__) || defined(__x86_64) || defined(__mips__)
                        #define PGPROT_WC(pv)   pgprot_noncached(pv)
                #else
                        #define PGPROT_WC(pv)   pgprot_noncached(pv)
index 8b9bf4f..09fe10b 100644 (file)
@@ -49,7 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <asm/io.h>
 #include <asm/page.h>
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
 #include <asm/system.h>
 #endif
 #include <asm/cacheflush.h>
@@ -89,23 +89,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "linkage.h"
 #include "pvr_uaccess.h"
 #include "lock.h"
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+#include "pvr_sync.h"
+#endif
 
 #if defined (SUPPORT_ION)
 #include "ion.h"
 #endif
 
-#if defined (CONFIG_X86_PAE)
-#error Physical Address Extension not supported with the driver
-#endif
-
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
 #define ON_EACH_CPU(func, info, wait) on_each_cpu(func, info, wait)
 #else
 #define ON_EACH_CPU(func, info, wait) on_each_cpu(func, info, 0, wait)
 #endif
 
-#if 0
-#if defined(PVR_LINUX_USING_WORKQUEUES) && !defined(CONFIG_PREEMPT)
+//#if defined(PVR_LINUX_USING_WORKQUEUES) && !defined(CONFIG_PREEMPT)
 /* 
  * Services spins at certain points waiting for events (e.g. swap
  * chain destrucion).  If those events rely on workqueues running,
@@ -113,9 +111,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * Removing the need for CONFIG_PREEMPT will require adding preemption
  * points at various points in Services.
  */
-#error "A preemptible Linux kernel is required when using workqueues"
-#endif
-#endif
+//#error "A preemptible Linux kernel is required when using workqueues"
+//#endif
 
 #if defined(EMULATOR)
 #define EVENT_OBJECT_TIMEOUT_MS                (2000)
@@ -124,21 +121,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif /* EMULATOR */
 
 #if !defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID *ppvCpuVAddr, IMG_HANDLE *phBlockAlloc)
+PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uiSize, IMG_PVOID *ppvCpuVAddr, IMG_HANDLE *phBlockAlloc)
 #else
-PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID *ppvCpuVAddr, IMG_HANDLE *phBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line)
+PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uiSize, IMG_PVOID *ppvCpuVAddr, IMG_HANDLE *phBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line)
 #endif
 {
     PVR_UNREFERENCED_PARAMETER(ui32Flags);
     PVR_UNREFERENCED_PARAMETER(phBlockAlloc);
 
-    if (ui32Size > PAGE_SIZE)
+    if (uiSize > PAGE_SIZE)
     {
         /* Try to allocate the memory using vmalloc */
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-        *ppvCpuVAddr = _VMallocWrapper(ui32Size, PVRSRV_HAP_CACHED, pszFilename, ui32Line);
+        *ppvCpuVAddr = _VMallocWrapper(uiSize, PVRSRV_HAP_CACHED, pszFilename, ui32Line);
 #else
-        *ppvCpuVAddr = VMallocWrapper(ui32Size, PVRSRV_HAP_CACHED);
+        *ppvCpuVAddr = VMallocWrapper(uiSize, PVRSRV_HAP_CACHED);
 #endif
         if (*ppvCpuVAddr)
         {
@@ -147,9 +144,9 @@ PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOI
     }
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    *ppvCpuVAddr = _KMallocWrapper(ui32Size, GFP_KERNEL | __GFP_NOWARN, pszFilename, ui32Line);
+    *ppvCpuVAddr = _KMallocWrapper(uiSize, GFP_KERNEL | __GFP_NOWARN, pszFilename, ui32Line);
 #else
-    *ppvCpuVAddr = KMallocWrapper(ui32Size, GFP_KERNEL | __GFP_NOWARN);
+    *ppvCpuVAddr = KMallocWrapper(uiSize, GFP_KERNEL | __GFP_NOWARN);
 #endif
     if (!*ppvCpuVAddr)
     {
@@ -170,13 +167,13 @@ static inline int is_vmalloc_addr(const void *pvCpuVAddr)
 #endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24)) */
 
 #if !defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID pvCpuVAddr, IMG_HANDLE hBlockAlloc)
+PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uiSize, IMG_PVOID pvCpuVAddr, IMG_HANDLE hBlockAlloc)
 #else
-PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID pvCpuVAddr, IMG_HANDLE hBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line)
+PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uiSize, IMG_PVOID pvCpuVAddr, IMG_HANDLE hBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line)
 #endif
 {      
     PVR_UNREFERENCED_PARAMETER(ui32Flags);
-    PVR_UNREFERENCED_PARAMETER(ui32Size);
+    PVR_UNREFERENCED_PARAMETER(uiSize);
     PVR_UNREFERENCED_PARAMETER(hBlockAlloc);
 
     if (is_vmalloc_addr(pvCpuVAddr))
@@ -202,7 +199,7 @@ PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID
 
 PVRSRV_ERROR
 OSAllocPages_Impl(IMG_UINT32 ui32AllocFlags,
-                                 IMG_UINT32 ui32Size,
+                                 IMG_SIZE_T uiSize,
                                  IMG_UINT32 ui32PageSize,
                                  IMG_PVOID pvPrivData,
                                  IMG_UINT32 ui32PrivDataLength,
@@ -229,7 +226,7 @@ OSAllocPages_Impl(IMG_UINT32 ui32AllocFlags,
         /* We'll only see HAP_SINGLE_PROCESS with MEM_ION */
         BUG_ON((ui32AllocFlags & PVRSRV_HAP_MAPTYPE_MASK) != PVRSRV_HAP_SINGLE_PROCESS);
 
-        psLinuxMemArea = NewIONLinuxMemArea(ui32Size, ui32AllocFlags,
+        psLinuxMemArea = NewIONLinuxMemArea(uiSize, ui32AllocFlags,
                                                                                        pvPrivData, ui32PrivDataLength);
         if(!psLinuxMemArea)
         {
@@ -244,7 +241,7 @@ OSAllocPages_Impl(IMG_UINT32 ui32AllocFlags,
     {
         case PVRSRV_HAP_KERNEL_ONLY:
         {
-            psLinuxMemArea = NewVMallocLinuxMemArea(ui32Size, ui32AllocFlags);
+            psLinuxMemArea = NewVMallocLinuxMemArea(uiSize, ui32AllocFlags);
             if(!psLinuxMemArea)
             {
                 return PVRSRV_ERROR_OUT_OF_MEMORY;
@@ -256,7 +253,7 @@ OSAllocPages_Impl(IMG_UINT32 ui32AllocFlags,
             /* Currently PVRSRV_HAP_SINGLE_PROCESS implies that we dont need a
              * kernel virtual mapping, but will need a user space virtual mapping */
 
-            psLinuxMemArea = NewAllocPagesLinuxMemArea(ui32Size, ui32AllocFlags);
+            psLinuxMemArea = NewAllocPagesLinuxMemArea(uiSize, ui32AllocFlags);
             if(!psLinuxMemArea)
             {
                 return PVRSRV_ERROR_OUT_OF_MEMORY;
@@ -280,7 +277,7 @@ OSAllocPages_Impl(IMG_UINT32 ui32AllocFlags,
              * VIPT architectures. */
             ui32AllocFlags &= ~PVRSRV_HAP_CACHED;
 #endif
-            psLinuxMemArea = NewVMallocLinuxMemArea(ui32Size, ui32AllocFlags);
+            psLinuxMemArea = NewVMallocLinuxMemArea(uiSize, ui32AllocFlags);
             if(!psLinuxMemArea)
             {
                 return PVRSRV_ERROR_OUT_OF_MEMORY;
@@ -315,12 +312,12 @@ ExitSkipSwitch:
 
 
 PVRSRV_ERROR
-OSFreePages(IMG_UINT32 ui32AllocFlags, IMG_UINT32 ui32Bytes, IMG_VOID *pvCpuVAddr, IMG_HANDLE hOSMemHandle)
+OSFreePages(IMG_UINT32 ui32AllocFlags, IMG_SIZE_T uiBytes, IMG_VOID *pvCpuVAddr, IMG_HANDLE hOSMemHandle)
 {   
     LinuxMemArea *psLinuxMemArea;
     PVRSRV_ERROR eError;
     
-    PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+    PVR_UNREFERENCED_PARAMETER(uiBytes);
     PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
     
     psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
@@ -335,9 +332,9 @@ OSFreePages(IMG_UINT32 ui32AllocFlags, IMG_UINT32 ui32Bytes, IMG_VOID *pvCpuVAdd
             if (eError != PVRSRV_OK)
             {
                 PVR_DPF((PVR_DBG_ERROR,
-                         "OSFreePages(ui32AllocFlags=0x%08X, ui32Bytes=%d, "
+                         "OSFreePages(ui32AllocFlags=0x%08X, ui32Bytes=%" SIZE_T_FMT_LEN "u, "
                                         "pvCpuVAddr=%p, hOSMemHandle=%p) FAILED!",
-                         ui32AllocFlags, ui32Bytes, pvCpuVAddr, hOSMemHandle));
+                         ui32AllocFlags, uiBytes, pvCpuVAddr, hOSMemHandle));
                 return eError;
             }
             break;
@@ -355,8 +352,8 @@ OSFreePages(IMG_UINT32 ui32AllocFlags, IMG_UINT32 ui32Bytes, IMG_VOID *pvCpuVAdd
 
 PVRSRV_ERROR
 OSGetSubMemHandle(IMG_HANDLE hOSMemHandle,
-                  IMG_UINT32 ui32ByteOffset,
-                  IMG_UINT32 ui32Bytes,
+                  IMG_UINTPTR_T uiByteOffset,
+                  IMG_SIZE_T uiBytes,
                   IMG_UINT32 ui32Flags,
                   IMG_HANDLE *phOSMemHandleRet)
 {
@@ -365,7 +362,7 @@ OSGetSubMemHandle(IMG_HANDLE hOSMemHandle,
 
     psParentLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
     
-    psLinuxMemArea = NewSubLinuxMemArea(psParentLinuxMemArea, ui32ByteOffset, ui32Bytes);
+    psLinuxMemArea = NewSubLinuxMemArea(psParentLinuxMemArea, uiByteOffset, uiBytes);
     if(!psLinuxMemArea)
     {
         *phOSMemHandleRet = NULL;
@@ -417,11 +414,11 @@ OSReleaseSubMemHandle(IMG_VOID *hOSMemHandle, IMG_UINT32 ui32Flags)
 
 
 IMG_CPU_PHYADDR
-OSMemHandleToCpuPAddr(IMG_VOID *hOSMemHandle, IMG_UINT32 ui32ByteOffset)
+OSMemHandleToCpuPAddr(IMG_VOID *hOSMemHandle, IMG_UINTPTR_T uiByteOffset)
 {
     PVR_ASSERT(hOSMemHandle);
 
-    return LinuxMemAreaToCpuPAddr(hOSMemHandle, ui32ByteOffset);
+    return LinuxMemAreaToCpuPAddr(hOSMemHandle, uiByteOffset);
 }
 
 
@@ -452,7 +449,7 @@ IMG_BOOL OSMemHandleIsPhysContig(IMG_VOID *hOSMemHandle)
  @Return  none
 
 ******************************************************************************/
-IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
+IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_SIZE_T uiSize)
 {
 #if defined(USE_UNOPTIMISED_MEMCPY)
     IMG_UINT8 *Src,*Dst;
@@ -460,12 +457,12 @@ IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
 
     Src=(IMG_UINT8 *)pvSrc;
     Dst=(IMG_UINT8 *)pvDst;
-    for(i=0;i<ui32Size;i++)
+    for(i=0;i<uiSize;i++)
     {
         Dst[i]=Src[i];
     }
 #else
-    memcpy(pvDst, pvSrc, ui32Size);
+    memcpy(pvDst, pvSrc, uiSize);
 #endif
 }
 
@@ -486,19 +483,19 @@ IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
  @Return   IMG_VOID
 
 ******************************************************************************/
-IMG_VOID OSMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_UINT32 ui32Size)
+IMG_VOID OSMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_SIZE_T uiSize)
 {
 #if defined(USE_UNOPTIMISED_MEMSET)
     IMG_UINT8 *Buff;
     IMG_INT i;
 
     Buff=(IMG_UINT8 *)pvDest;
-    for(i=0;i<ui32Size;i++)
+    for(i=0;i<uiSize;i++)
     {
         Buff[i]=ui8Value;
     }
 #else
-    memset(pvDest, (IMG_INT) ui8Value, (size_t) ui32Size);
+    memset(pvDest, (IMG_INT) ui8Value, (size_t) uiSize);
 #endif
 }
 
@@ -518,13 +515,13 @@ IMG_CHAR *OSStringCopy(IMG_CHAR *pszDest, const IMG_CHAR *pszSrc)
  @Function     OSSNPrintf
  @Description snprintf
 ******************************************************************************/
-IMG_INT32 OSSNPrintf(IMG_CHAR *pStr, IMG_UINT32 ui32Size, const IMG_CHAR *pszFormat, ...)
+IMG_INT32 OSSNPrintf(IMG_CHAR *pStr, IMG_SIZE_T uiSize, const IMG_CHAR *pszFormat, ...)
 {
     va_list argList;
     IMG_INT32 iCount;
 
     va_start(argList, pszFormat);
-    iCount = vsnprintf(pStr, (size_t)ui32Size, pszFormat, argList);
+    iCount = vsnprintf(pStr, (size_t)uiSize, pszFormat, argList);
     va_end(argList);
 
     return iCount;
@@ -1123,6 +1120,10 @@ static void MISRWrapper(
        SYS_DATA *psSysData  = (SYS_DATA *)psEnvData->pvMISRData;
 
        PVRSRVMISR(psSysData);
+
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       PVRSyncUpdateAllSyncs();
+#endif
 }
 
 
@@ -1629,7 +1630,7 @@ IMG_CPU_PHYADDR OSMapLinToCPUPhys(IMG_HANDLE hOSMemHandle,
  ******************************************************************************/
 IMG_VOID *
 OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr,
-               IMG_UINT32 ui32Bytes,
+               IMG_SIZE_T uiBytes,
                IMG_UINT32 ui32MappingFlags,
                IMG_HANDLE *phOSMemHandle)
 {
@@ -1643,7 +1644,7 @@ OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr,
        if(phOSMemHandle == IMG_NULL)
        {
                IMG_VOID *pvIORemapCookie;
-               pvIORemapCookie = IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags);
+               pvIORemapCookie = IORemapWrapper(BasePAddr, uiBytes, ui32MappingFlags);
                if(pvIORemapCookie == IMG_NULL)
                {
                    return IMG_NULL;
@@ -1652,7 +1653,7 @@ OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr,
        }
        else
        {
-               LinuxMemArea *psLinuxMemArea = NewIORemapLinuxMemArea(BasePAddr, ui32Bytes, ui32MappingFlags);
+               LinuxMemArea *psLinuxMemArea = NewIORemapLinuxMemArea(BasePAddr, uiBytes, ui32MappingFlags);
 
                if(psLinuxMemArea == IMG_NULL)
                {
@@ -1678,9 +1679,9 @@ OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr,
  @Return TRUE on success, else FALSE
 ******************************************************************************/
 IMG_BOOL
-OSUnMapPhysToLin(IMG_VOID *pvLinAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32MappingFlags, IMG_HANDLE hOSMemHandle)
+OSUnMapPhysToLin(IMG_VOID *pvLinAddr, IMG_SIZE_T uiBytes, IMG_UINT32 ui32MappingFlags, IMG_HANDLE hOSMemHandle)
 {
-    PVR_UNREFERENCED_PARAMETER(ui32Bytes);     
+    PVR_UNREFERENCED_PARAMETER(uiBytes);       
 
     if(ui32MappingFlags & PVRSRV_HAP_KERNEL_ONLY)
     {
@@ -1794,19 +1795,19 @@ RegisterExternalMem(IMG_SYS_PHYADDR *pBasePAddr,
 PVRSRV_ERROR
 OSRegisterMem(IMG_CPU_PHYADDR BasePAddr,
               IMG_VOID *pvCPUVAddr,
-              IMG_UINT32 ui32Bytes,
+              IMG_SIZE_T uiBytes,
               IMG_UINT32 ui32MappingFlags,
               IMG_HANDLE *phOSMemHandle)
 {
     IMG_SYS_PHYADDR SysPAddr = SysCpuPAddrToSysPAddr(BasePAddr);
 
-    return RegisterExternalMem(&SysPAddr, pvCPUVAddr, ui32Bytes, IMG_TRUE, ui32MappingFlags, phOSMemHandle);
+    return RegisterExternalMem(&SysPAddr, pvCPUVAddr, uiBytes, IMG_TRUE, ui32MappingFlags, phOSMemHandle);
 }
 
 
-PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32MappingFlags, IMG_HANDLE *phOSMemHandle)
+PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_SIZE_T uiBytes, IMG_UINT32 ui32MappingFlags, IMG_HANDLE *phOSMemHandle)
 {
-    return RegisterExternalMem(pBasePAddr, pvCPUVAddr, ui32Bytes, IMG_FALSE, ui32MappingFlags, phOSMemHandle);
+    return RegisterExternalMem(pBasePAddr, pvCPUVAddr, uiBytes, IMG_FALSE, ui32MappingFlags, phOSMemHandle);
 }
 
 
@@ -1818,7 +1819,7 @@ PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPU
 ******************************************************************************/
 PVRSRV_ERROR
 OSUnRegisterMem (IMG_VOID *pvCpuVAddr,
-                IMG_UINT32 ui32Bytes,
+                IMG_SIZE_T uiBytes,
                 IMG_UINT32 ui32MappingFlags,
                 IMG_HANDLE hOSMemHandle)
 {
@@ -1826,7 +1827,7 @@ OSUnRegisterMem (IMG_VOID *pvCpuVAddr,
     PVRSRV_ERROR eError;
 
     PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
-    PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+    PVR_UNREFERENCED_PARAMETER(uiBytes);
 
     switch(ui32MappingFlags & PVRSRV_HAP_MAPTYPE_MASK)
     {
@@ -1838,8 +1839,8 @@ OSUnRegisterMem (IMG_VOID *pvCpuVAddr,
             eError = PVRMMapRemoveRegisteredArea(psLinuxMemArea);
             if (eError != PVRSRV_OK)
             {
-                 PVR_DPF((PVR_DBG_ERROR, "%s(%p, %d, 0x%08X, %p) FAILED!",
-                          __FUNCTION__, pvCpuVAddr, ui32Bytes,
+                 PVR_DPF((PVR_DBG_ERROR, "%s(%p, %" SIZE_T_FMT_LEN "u, 0x%08X, %p) FAILED!",
+                          __FUNCTION__, pvCpuVAddr, uiBytes,
                           ui32MappingFlags, hOSMemHandle));
                 return eError;
             }
@@ -1857,9 +1858,9 @@ OSUnRegisterMem (IMG_VOID *pvCpuVAddr,
     return PVRSRV_OK;
 }
 
-PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
+PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr, IMG_SIZE_T uiBytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
 {
-    return OSUnRegisterMem(pvCpuVAddr, ui32Bytes, ui32Flags, hOSMemHandle);
+    return OSUnRegisterMem(pvCpuVAddr, uiBytes, ui32Flags, hOSMemHandle);
 }
 
 /*!
@@ -1872,7 +1873,7 @@ PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr, IMG_UINT32 ui32Bytes
 ******************************************************************************/
 PVRSRV_ERROR
 OSReservePhys(IMG_CPU_PHYADDR BasePAddr,
-              IMG_UINT32 ui32Bytes,
+              IMG_SIZE_T uiBytes,
               IMG_UINT32 ui32MappingFlags,
               IMG_HANDLE hBMHandle,
               IMG_VOID **ppvCpuVAddr,
@@ -1898,7 +1899,7 @@ OSReservePhys(IMG_CPU_PHYADDR BasePAddr,
              * mapping is required for the allocation and no user virtual
              * mappings are allowed: Note these eat into our limited kernel
              * virtual address space */
-            psLinuxMemArea = NewIORemapLinuxMemArea(BasePAddr, ui32Bytes, ui32MappingFlags);
+            psLinuxMemArea = NewIORemapLinuxMemArea(BasePAddr, uiBytes, ui32MappingFlags);
             if(!psLinuxMemArea)
             {
                 return PVRSRV_ERROR_BAD_MAPPING;
@@ -1909,7 +1910,7 @@ OSReservePhys(IMG_CPU_PHYADDR BasePAddr,
         {
             /* Currently this implies that we dont need a kernel virtual
              * mapping, but will need a user space virtual mapping */
-            psLinuxMemArea = NewIOLinuxMemArea(BasePAddr, ui32Bytes, ui32MappingFlags);
+            psLinuxMemArea = NewIOLinuxMemArea(BasePAddr, uiBytes, ui32MappingFlags);
             if(!psLinuxMemArea)
             {
                 return PVRSRV_ERROR_BAD_MAPPING;
@@ -1933,7 +1934,7 @@ OSReservePhys(IMG_CPU_PHYADDR BasePAddr,
              */
             ui32MappingFlags &= ~PVRSRV_HAP_CACHED;
 #endif
-            psLinuxMemArea = NewIORemapLinuxMemArea(BasePAddr, ui32Bytes, ui32MappingFlags);
+            psLinuxMemArea = NewIORemapLinuxMemArea(BasePAddr, uiBytes, ui32MappingFlags);
             if(!psLinuxMemArea)
             {
                 return PVRSRV_ERROR_BAD_MAPPING;
@@ -1974,7 +1975,7 @@ OSReservePhys(IMG_CPU_PHYADDR BasePAddr,
 ******************************************************************************/
 PVRSRV_ERROR
 OSUnReservePhys(IMG_VOID *pvCpuVAddr,
-                IMG_UINT32 ui32Bytes,
+                IMG_SIZE_T uiBytes,
                 IMG_UINT32 ui32MappingFlags,
                 IMG_HANDLE hOSMemHandle)
 {
@@ -1982,7 +1983,7 @@ OSUnReservePhys(IMG_VOID *pvCpuVAddr,
     PVRSRV_ERROR eError;
 
     PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
-    PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+    PVR_UNREFERENCED_PARAMETER(uiBytes);
 
     psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
     
@@ -1996,8 +1997,8 @@ OSUnReservePhys(IMG_VOID *pvCpuVAddr,
             eError = PVRMMapRemoveRegisteredArea(psLinuxMemArea);
             if (eError != PVRSRV_OK)
             {
-                 PVR_DPF((PVR_DBG_ERROR, "%s(%p, %d, 0x%08X, %p) FAILED!",
-                          __FUNCTION__, pvCpuVAddr, ui32Bytes,
+                 PVR_DPF((PVR_DBG_ERROR, "%s(%p, %" SIZE_T_FMT_LEN "u, 0x%08X, %p) FAILED!",
+                          __FUNCTION__, pvCpuVAddr, uiBytes,
                           ui32MappingFlags, hOSMemHandle));
                 return eError;
             }
@@ -2024,10 +2025,10 @@ OSUnReservePhys(IMG_VOID *pvCpuVAddr,
  @Output    ppvLinAddr - pointer to variable that will receive the linear address of buffer
  @Return PVRSRV_OK if allocation successed else returns PVRSRV_ERROR_OUT_OF_MEMORY
  **************************************************************************/
-PVRSRV_ERROR OSBaseAllocContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR *pvLinAddr, IMG_CPU_PHYADDR *psPhysAddr)
+PVRSRV_ERROR OSBaseAllocContigMemory(IMG_SIZE_T uiSize, IMG_CPU_VIRTADDR *pvLinAddr, IMG_CPU_PHYADDR *psPhysAddr)
 {
 #if !defined(NO_HARDWARE)
-    PVR_UNREFERENCED_PARAMETER(ui32Size);
+    PVR_UNREFERENCED_PARAMETER(uiSize);
     PVR_UNREFERENCED_PARAMETER(pvLinAddr);
     PVR_UNREFERENCED_PARAMETER(psPhysAddr);
     PVR_DPF((PVR_DBG_ERROR, "%s: Not available", __FUNCTION__));
@@ -2044,9 +2045,9 @@ PVRSRV_ERROR OSBaseAllocContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR *pvLi
     IMG_VOID *pvKernLinAddr;
 
 #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-    pvKernLinAddr = _KMallocWrapper(ui32Size, GFP_KERNEL, __FILE__, __LINE__);
+    pvKernLinAddr = _KMallocWrapper(uiSize, GFP_KERNEL, __FILE__, __LINE__);
 #else
-    pvKernLinAddr = KMallocWrapper(ui32Size, GFP_KERNEL);
+    pvKernLinAddr = KMallocWrapper(uiSize, GFP_KERNEL);
 #endif
     if (!pvKernLinAddr)
     {
@@ -2068,16 +2069,16 @@ PVRSRV_ERROR OSBaseAllocContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR *pvLi
  @Description Frees memory allocated with OSBaseAllocContigMemory
  @Input     LinAddr - pointer to buffer allocated with OSBaseAllocContigMemory
  **************************************************************************/
-PVRSRV_ERROR OSBaseFreeContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR pvLinAddr, IMG_CPU_PHYADDR psPhysAddr)
+PVRSRV_ERROR OSBaseFreeContigMemory(IMG_SIZE_T uiSize, IMG_CPU_VIRTADDR pvLinAddr, IMG_CPU_PHYADDR psPhysAddr)
 {
 #if !defined(NO_HARDWARE)
-    PVR_UNREFERENCED_PARAMETER(ui32Size);
+    PVR_UNREFERENCED_PARAMETER(uiSize);
     PVR_UNREFERENCED_PARAMETER(pvLinAddr);
     PVR_UNREFERENCED_PARAMETER(psPhysAddr.uiAddr);
 
     PVR_DPF((PVR_DBG_WARNING, "%s: Not available", __FUNCTION__));
 #else
-    PVR_UNREFERENCED_PARAMETER(ui32Size);
+    PVR_UNREFERENCED_PARAMETER(uiSize);
     PVR_UNREFERENCED_PARAMETER(psPhysAddr.uiAddr);
 
     KFreeWrapper(pvLinAddr);
@@ -2688,9 +2689,9 @@ static void OSTimerCallbackBody(TIMER_CALLBACK_DATA *psTimerCBData)
  @Return   NONE
 
 ******************************************************************************/
-static IMG_VOID OSTimerCallbackWrapper(IMG_UINT32 ui32Data)
+static IMG_VOID OSTimerCallbackWrapper(IMG_UINTPTR_T uiData)
 {
-    TIMER_CALLBACK_DATA        *psTimerCBData = (TIMER_CALLBACK_DATA*)ui32Data;
+    TIMER_CALLBACK_DATA        *psTimerCBData = (TIMER_CALLBACK_DATA*)uiData;
     
 #if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES) || defined(PVR_LINUX_TIMERS_USING_SHARED_WORKQUEUE)
     int res;
@@ -2740,7 +2741,7 @@ static void OSTimerWorkQueueCallBack(struct work_struct *psWork)
 IMG_HANDLE OSAddTimer(PFN_TIMER_FUNC pfnTimerFunc, IMG_VOID *pvData, IMG_UINT32 ui32MsTimeout)
 {
     TIMER_CALLBACK_DATA        *psTimerCBData;
-    IMG_UINT32         ui32i;
+    IMG_UINTPTR_T              ui;
 #if !(defined(PVR_LINUX_TIMERS_USING_WORKQUEUES) || defined(PVR_LINUX_TIMERS_USING_SHARED_WORKQUEUE))
     unsigned long              ulLockFlags;
 #endif
@@ -2758,9 +2759,9 @@ IMG_HANDLE OSAddTimer(PFN_TIMER_FUNC pfnTimerFunc, IMG_VOID *pvData, IMG_UINT32
 #else
     spin_lock_irqsave(&sTimerStructLock, ulLockFlags);
 #endif
-    for (ui32i = 0; ui32i < OS_MAX_TIMERS; ui32i++)
+    for (ui = 0; ui < OS_MAX_TIMERS; ui++)
     {
-        psTimerCBData = &sTimers[ui32i];
+        psTimerCBData = &sTimers[ui];
         if (!psTimerCBData->bInUse)
         {
             psTimerCBData->bInUse = IMG_TRUE;
@@ -2772,7 +2773,7 @@ IMG_HANDLE OSAddTimer(PFN_TIMER_FUNC pfnTimerFunc, IMG_VOID *pvData, IMG_UINT32
 #else
     spin_unlock_irqrestore(&sTimerStructLock, ulLockFlags);
 #endif
-    if (ui32i >= OS_MAX_TIMERS)
+    if (ui >= OS_MAX_TIMERS)
     {
         PVR_DPF((PVR_DBG_ERROR, "OSAddTimer: all timers are in use"));         
         return IMG_NULL;       
@@ -2796,19 +2797,19 @@ IMG_HANDLE OSAddTimer(PFN_TIMER_FUNC pfnTimerFunc, IMG_VOID *pvData, IMG_UINT32
     /* setup timer object */
     /* PRQA S 0307,0563 1 */ /* ignore warning about inconpartible ptr casting */
     psTimerCBData->sTimer.function = (IMG_VOID *)OSTimerCallbackWrapper;
-    psTimerCBData->sTimer.data = (IMG_UINT32)psTimerCBData;
+    psTimerCBData->sTimer.data = (IMG_UINTPTR_T)psTimerCBData;
     
-    return (IMG_HANDLE)(ui32i + 1);
+    return (IMG_HANDLE)(ui + 1);
 }
 
 
 static inline TIMER_CALLBACK_DATA *GetTimerStructure(IMG_HANDLE hTimer)
 {
-    IMG_UINT32 ui32i = ((IMG_UINT32)hTimer) - 1;
+    IMG_UINTPTR_T ui = ((IMG_UINTPTR_T)hTimer) - 1;
 
-    PVR_ASSERT(ui32i < OS_MAX_TIMERS);
+    PVR_ASSERT(ui < OS_MAX_TIMERS);
 
-    return &sTimers[ui32i];
+    return &sTimers[ui];
 }
 
 /*!
@@ -2942,11 +2943,7 @@ PVRSRV_ERROR OSDisableTimer (IMG_HANDLE hTimer)
  @Return   PVRSRV_ERROR  : 
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR OSEventObjectCreateKM(const IMG_CHAR *pszName, PVRSRV_EVENTOBJECT_KM *psEventObject)
-#else
 PVRSRV_ERROR OSEventObjectCreateKM(const IMG_CHAR *pszName, PVRSRV_EVENTOBJECT *psEventObject)
-#endif
 {
 
     PVRSRV_ERROR eError = PVRSRV_OK;
@@ -2962,11 +2959,7 @@ PVRSRV_ERROR OSEventObjectCreateKM(const IMG_CHAR *pszName, PVRSRV_EVENTOBJECT *
         {
             /* autogenerate a name */  
             static IMG_UINT16 ui16NameIndex = 0;                       
-#if defined (SUPPORT_SID_INTERFACE)
-            snprintf(psEventObject->szName, EVENTOBJNAME_MAXLENGTH, "PVRSRV_EVENTOBJECT_KM_%d", ui16NameIndex++);
-#else
             snprintf(psEventObject->szName, EVENTOBJNAME_MAXLENGTH, "PVRSRV_EVENTOBJECT_%d", ui16NameIndex++);
-#endif
         }
         
         if(LinuxEventObjectListCreate(&psEventObject->hOSEventKM) != PVRSRV_OK)
@@ -3000,11 +2993,7 @@ PVRSRV_ERROR OSEventObjectCreateKM(const IMG_CHAR *pszName, PVRSRV_EVENTOBJECT *
  @Return   PVRSRV_ERROR  : 
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR OSEventObjectDestroyKM(PVRSRV_EVENTOBJECT_KM *psEventObject)
-#else
 PVRSRV_ERROR OSEventObjectDestroyKM(PVRSRV_EVENTOBJECT *psEventObject)
-#endif
 {
     PVRSRV_ERROR eError = PVRSRV_OK;
 
@@ -3075,11 +3064,7 @@ PVRSRV_ERROR OSEventObjectWaitKM(IMG_HANDLE hOSEventKM)
  @Return   PVRSRV_ERROR  : 
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR OSEventObjectOpenKM(PVRSRV_EVENTOBJECT_KM *psEventObject,
-#else
 PVRSRV_ERROR OSEventObjectOpenKM(PVRSRV_EVENTOBJECT *psEventObject,
-#endif
                                             IMG_HANDLE *phOSEvent)
 {
     PVRSRV_ERROR eError = PVRSRV_OK;
@@ -3118,11 +3103,7 @@ PVRSRV_ERROR OSEventObjectOpenKM(PVRSRV_EVENTOBJECT *psEventObject,
  @Return   PVRSRV_ERROR  : 
 
 ******************************************************************************/
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR OSEventObjectCloseKM(PVRSRV_EVENTOBJECT_KM *psEventObject,
-#else
 PVRSRV_ERROR OSEventObjectCloseKM(PVRSRV_EVENTOBJECT *psEventObject,
-#endif
                                             IMG_HANDLE hOSEventKM)
 {
     PVRSRV_ERROR eError = PVRSRV_OK;
@@ -3217,11 +3198,11 @@ IMG_BOOL OSProcHasPrivSrvInit(IMG_VOID)
 PVRSRV_ERROR OSCopyToUser(IMG_PVOID pvProcess, 
                           IMG_VOID *pvDest, 
                           IMG_VOID *pvSrc, 
-                          IMG_UINT32 ui32Bytes)
+                          IMG_SIZE_T uiBytes)
 {
     PVR_UNREFERENCED_PARAMETER(pvProcess);
 
-    if(pvr_copy_to_user(pvDest, pvSrc, ui32Bytes)==0)
+    if(pvr_copy_to_user(pvDest, pvSrc, uiBytes)==0)
         return PVRSRV_OK;
     else
         return PVRSRV_ERROR_FAILED_TO_COPY_VIRT_MEMORY;
@@ -3248,11 +3229,11 @@ PVRSRV_ERROR OSCopyToUser(IMG_PVOID pvProcess,
 PVRSRV_ERROR OSCopyFromUser( IMG_PVOID pvProcess, 
                              IMG_VOID *pvDest, 
                              IMG_VOID *pvSrc, 
-                             IMG_UINT32 ui32Bytes)
+                             IMG_SIZE_T uiBytes)
 {
     PVR_UNREFERENCED_PARAMETER(pvProcess);
 
-    if(pvr_copy_from_user(pvDest, pvSrc, ui32Bytes)==0)
+    if(pvr_copy_from_user(pvDest, pvSrc, uiBytes)==0)
         return PVRSRV_OK;
     else
         return PVRSRV_ERROR_FAILED_TO_COPY_VIRT_MEMORY;
@@ -3276,7 +3257,7 @@ PVRSRV_ERROR OSCopyFromUser( IMG_PVOID pvProcess,
  @Return   IMG_BOOL :
 
 ******************************************************************************/
-IMG_BOOL OSAccessOK(IMG_VERIFY_TEST eVerification, IMG_VOID *pvUserPtr, IMG_UINT32 ui32Bytes)
+IMG_BOOL OSAccessOK(IMG_VERIFY_TEST eVerification, IMG_VOID *pvUserPtr, IMG_SIZE_T uiBytes)
 {
     IMG_INT linuxType;
 
@@ -3290,7 +3271,7 @@ IMG_BOOL OSAccessOK(IMG_VERIFY_TEST eVerification, IMG_VOID *pvUserPtr, IMG_UINT
         linuxType = VERIFY_WRITE;
     }
 
-    return access_ok(linuxType, pvUserPtr, ui32Bytes);
+    return access_ok(linuxType, pvUserPtr, uiBytes);
 }
 
 typedef enum _eWrapMemType_
@@ -3309,8 +3290,8 @@ typedef struct _sWrapMemInfo_
     IMG_SYS_PHYADDR *psPhysAddr;
     IMG_INT iPageOffset;
 #if defined(DEBUG)
-    IMG_UINT32 ulStartAddr;
-    IMG_UINT32 ulBeyondEndAddr;
+    IMG_UINTPTR_T uStartAddr;
+    IMG_UINTPTR_T uBeyondEndAddr;
     struct vm_area_struct *psVMArea;
 #endif
 } sWrapMemInfo;
@@ -3329,16 +3310,16 @@ typedef struct _sWrapMemInfo_
  and must be writable.  A get_page is done on the returned page structure.
  
  @Input    psVMArea - pointer to VM area structure
-       ulCPUVAddr - CPU virtual address
-       pulPFN - Pointer to returned PFN.
+       uCPUVAddr - CPU virtual address
+       pui32PFN - Pointer to returned PFN.
        ppsPAge - Pointer to returned page structure pointer.
 
- @Output   *pulPFN - Set to PFN
+ @Output   *pui32PFN - Set to PFN
           *ppsPage - Pointer to the page structure if present, else NULL.
  @Return   IMG_TRUE if PFN lookup was succesful.
 
 ******************************************************************************/
-static IMG_BOOL CPUVAddrToPFN(struct vm_area_struct *psVMArea, IMG_UINT32 ulCPUVAddr, IMG_UINT32 *pulPFN, struct page **ppsPage)
+static IMG_BOOL CPUVAddrToPFN(struct vm_area_struct *psVMArea, IMG_UINTPTR_T uCPUVAddr, IMG_UINT32 *pui32PFN, struct page **ppsPage)
 {
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,10))
     pgd_t *psPGD;
@@ -3349,31 +3330,31 @@ static IMG_BOOL CPUVAddrToPFN(struct vm_area_struct *psVMArea, IMG_UINT32 ulCPUV
     spinlock_t *psPTLock;
     IMG_BOOL bRet = IMG_FALSE;
 
-    *pulPFN = 0;
+    *pui32PFN = 0;
     *ppsPage = NULL;
 
-    psPGD = pgd_offset(psMM, ulCPUVAddr);
+    psPGD = pgd_offset(psMM, uCPUVAddr);
     if (pgd_none(*psPGD) || pgd_bad(*psPGD))
         return bRet;
 
-    psPUD = pud_offset(psPGD, ulCPUVAddr);
+    psPUD = pud_offset(psPGD, uCPUVAddr);
     if (pud_none(*psPUD) || pud_bad(*psPUD))
         return bRet;
 
-    psPMD = pmd_offset(psPUD, ulCPUVAddr);
+    psPMD = pmd_offset(psPUD, uCPUVAddr);
     if (pmd_none(*psPMD) || pmd_bad(*psPMD))
         return bRet;
 
-    psPTE = (pte_t *)pte_offset_map_lock(psMM, psPMD, ulCPUVAddr, &psPTLock);
+    psPTE = (pte_t *)pte_offset_map_lock(psMM, psPMD, uCPUVAddr, &psPTLock);
 
     if ((pte_none(*psPTE) == 0) && (pte_present(*psPTE) != 0) && (pte_write(*psPTE) != 0))
     {
-        *pulPFN = pte_pfn(*psPTE);
+        *pui32PFN = pte_pfn(*psPTE);
        bRet = IMG_TRUE;
 
-        if (pfn_valid(*pulPFN))
+        if (pfn_valid(*pui32PFN))
         {
-            *ppsPage = pfn_to_page(*pulPFN);
+            *ppsPage = pfn_to_page(*pui32PFN);
 
             get_page(*ppsPage);
         }
@@ -3480,7 +3461,7 @@ PVRSRV_ERROR OSReleasePhysPageAddr(IMG_HANDLE hOSWrapMem)
     return PVRSRV_OK;
 }
 
-#if defined(CONFIG_TI_TILER)
+#if defined(CONFIG_TI_TILER) || defined(CONFIG_DRM_OMAP_DMM_TILER)
 
 static IMG_UINT32 CPUAddrToTilerPhy(IMG_UINT32 uiAddr)
 {
@@ -3488,12 +3469,17 @@ static IMG_UINT32 CPUAddrToTilerPhy(IMG_UINT32 uiAddr)
        pte_t *ptep, pte;
        pgd_t *pgd;
        pmd_t *pmd;
+       pud_t *pud;
 
        pgd = pgd_offset(current->mm, uiAddr);
        if (pgd_none(*pgd) || pgd_bad(*pgd))
                goto err_out;
 
-       pmd = pmd_offset(pgd, uiAddr);
+       pud = pud_offset(pgd, uiAddr);
+       if (pud_none(*pud) || pud_bad(*pud))
+               goto err_out;
+
+       pmd = pmd_offset(pud, uiAddr);
        if (pmd_none(*pmd) || pmd_bad(*pmd))
                goto err_out;
 
@@ -3521,7 +3507,7 @@ err_out:
        return ui32PhysAddr;
 }
 
-#endif /* defined(CONFIG_TI_TILER) */
+#endif /* defined(CONFIG_TI_TILER) && defined(CONFIG_DRM_OMAP_DMM_TILER) */
 
 /*!
 ******************************************************************************
@@ -3534,17 +3520,17 @@ err_out:
 
 ******************************************************************************/
 PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr, 
-                                    IMG_UINT32 ui32Bytes, 
+                                    IMG_SIZE_T uiBytes, 
                                     IMG_SYS_PHYADDR *psSysPAddr,
                                     IMG_HANDLE *phOSWrapMem)
 {
-    IMG_UINT32 ulStartAddrOrig = (IMG_UINT32) pvCPUVAddr;
-    IMG_UINT32 ulAddrRangeOrig = (IMG_UINT32) ui32Bytes;
-    IMG_UINT32 ulBeyondEndAddrOrig = ulStartAddrOrig + ulAddrRangeOrig;
-    IMG_UINT32 ulStartAddr;
-    IMG_UINT32 ulAddrRange;
-    IMG_UINT32 ulBeyondEndAddr;
-    IMG_UINT32 ulAddr;
+    IMG_UINTPTR_T uStartAddrOrig = (IMG_UINTPTR_T) pvCPUVAddr;
+    IMG_SIZE_T uAddrRangeOrig = uiBytes;
+    IMG_UINTPTR_T uBeyondEndAddrOrig = uStartAddrOrig + uAddrRangeOrig;
+    IMG_UINTPTR_T uStartAddr;
+    IMG_SIZE_T uAddrRange;
+    IMG_UINTPTR_T uBeyondEndAddr;
+    IMG_UINTPTR_T uAddr;
     IMG_INT i;
     struct vm_area_struct *psVMArea;
     sWrapMemInfo *psInfo = NULL;
@@ -3554,19 +3540,19 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
     PVRSRV_ERROR eError = PVRSRV_ERROR_OUT_OF_MEMORY;
 
     /* Align start and end addresses to page boundaries */
-    ulStartAddr = ulStartAddrOrig & PAGE_MASK;
-    ulBeyondEndAddr = PAGE_ALIGN(ulBeyondEndAddrOrig);
-    ulAddrRange = ulBeyondEndAddr - ulStartAddr;
+    uStartAddr = uStartAddrOrig & PAGE_MASK;
+    uBeyondEndAddr = PAGE_ALIGN(uBeyondEndAddrOrig);
+    uAddrRange = uBeyondEndAddr - uStartAddr;
 
     /*
      * Check for address range calculation overflow, and attempts to wrap
      * zero bytes.
      */
-    if (ulBeyondEndAddr <= ulStartAddr)
+    if (uBeyondEndAddr <= uStartAddr)
     {
         PVR_DPF((PVR_DBG_ERROR,
-            "OSAcquirePhysPageAddr: Invalid address range (start %x, length %x)",
-               ulStartAddrOrig, ulAddrRangeOrig));
+            "OSAcquirePhysPageAddr: Invalid address range (start " UINTPTR_FMT  ", length %" SIZE_T_FMT_LEN "x)",
+               uStartAddrOrig, uAddrRangeOrig));
         goto error;
     }
 
@@ -3581,12 +3567,12 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
     memset(psInfo, 0, sizeof(*psInfo));
 
 #if defined(DEBUG)
-    psInfo->ulStartAddr = ulStartAddrOrig;
-    psInfo->ulBeyondEndAddr = ulBeyondEndAddrOrig;
+    psInfo->uStartAddr = uStartAddrOrig;
+    psInfo->uBeyondEndAddr = uBeyondEndAddrOrig;
 #endif
 
-    psInfo->iNumPages = (IMG_INT)(ulAddrRange >> PAGE_SHIFT);
-    psInfo->iPageOffset = (IMG_INT)(ulStartAddrOrig & ~PAGE_MASK);
+    psInfo->iNumPages = (IMG_INT)(uAddrRange >> PAGE_SHIFT);
+    psInfo->iPageOffset = (IMG_INT)(uStartAddrOrig & ~PAGE_MASK);
 
     /* Allocate physical address array */
     psInfo->psPhysAddr = kmalloc((size_t)psInfo->iNumPages * sizeof(*psInfo->psPhysAddr), GFP_KERNEL);
@@ -3619,7 +3605,7 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
     bMMapSemHeld = IMG_TRUE;
 
     /* Get page list */
-    psInfo->iNumPagesMapped = get_user_pages(current, current->mm, ulStartAddr, psInfo->iNumPages, 1, 0, psInfo->ppsPages, NULL);
+    psInfo->iNumPagesMapped = get_user_pages(current, current->mm, uStartAddr, psInfo->iNumPages, 1, 0, psInfo->ppsPages, NULL);
 
     if (psInfo->iNumPagesMapped >= 0)
     {
@@ -3635,14 +3621,14 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
         for (i = 0; i < psInfo->iNumPages; i++)
         {
             IMG_CPU_PHYADDR CPUPhysAddr;
-           IMG_UINT32 ulPFN;
+                       IMG_UINT32 ui32PFN;
 
-            ulPFN = page_to_pfn(psInfo->ppsPages[i]);
-            CPUPhysAddr.uiAddr = ulPFN << PAGE_SHIFT;
-           if ((CPUPhysAddr.uiAddr >> PAGE_SHIFT) != ulPFN)
+            ui32PFN = page_to_pfn(psInfo->ppsPages[i]);
+            CPUPhysAddr.uiAddr = ui32PFN << PAGE_SHIFT;
+           if ((CPUPhysAddr.uiAddr >> PAGE_SHIFT) != ui32PFN)
            {
                 PVR_DPF((PVR_DBG_ERROR,
-                   "OSAcquirePhysPageAddr: Page frame number out of range (%x)", ulPFN));
+                   "OSAcquirePhysPageAddr: Page frame number out of range (%x)", ui32PFN));
 
                    goto error;
            }
@@ -3670,11 +3656,12 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
     /* Set the mapping type to aid clean up */
     psInfo->eType = WRAP_TYPE_FIND_VMA;
 
-    psVMArea = find_vma(current->mm, ulStartAddrOrig);
+    psVMArea = find_vma(current->mm, uStartAddrOrig);
     if (psVMArea == NULL)
     {
         PVR_DPF((PVR_DBG_ERROR,
-            "OSAcquirePhysPageAddr: Couldn't find memory region containing start address %x", ulStartAddrOrig));
+            "OSAcquirePhysPageAddr: Couldn't find memory region containing start address " UINTPTR_FMT, 
+            uStartAddrOrig));
         
         goto error;
     }
@@ -3686,23 +3673,29 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
      * find_vma locates a region with an end point past a given
      * virtual address.  So check the address is actually in the region.
      */
-    if (ulStartAddrOrig < psVMArea->vm_start)
+    if (uStartAddrOrig < psVMArea->vm_start)
     {
         PVR_DPF((PVR_DBG_ERROR,
-            "OSAcquirePhysPageAddr: Start address %x is outside of the region returned by find_vma", ulStartAddrOrig));
+            "OSAcquirePhysPageAddr: Start address " UINTPTR_FMT " is outside of the region returned by find_vma", 
+            uStartAddrOrig));
         goto error;
     }
 
     /* Now check the end address is in range */
-    if (ulBeyondEndAddrOrig > psVMArea->vm_end)
+    if (uBeyondEndAddrOrig > psVMArea->vm_end)
     {
         PVR_DPF((PVR_DBG_ERROR,
-            "OSAcquirePhysPageAddr: End address %x is outside of the region returned by find_vma", ulBeyondEndAddrOrig));
+            "OSAcquirePhysPageAddr: End address " UINTPTR_FMT " is outside of the region returned by find_vma", uBeyondEndAddrOrig));
         goto error;
     }
 
     /* Does the region represent memory mapped I/O? */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0))
     if ((psVMArea->vm_flags & (VM_IO | VM_RESERVED)) != (VM_IO | VM_RESERVED))
+#else
+    if ((psVMArea->vm_flags & (VM_IO | VM_DONTEXPAND | VM_DONTDUMP)) != (VM_IO | VM_DONTEXPAND | VM_DONTDUMP))
+#endif
+
     {
         PVR_DPF((PVR_DBG_ERROR,
             "OSAcquirePhysPageAddr: Memory region does not represent memory mapped I/O (VMA flags: 0x%lx)", psVMArea->vm_flags));
@@ -3717,14 +3710,14 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
         goto error;
     }
 
-    for (ulAddr = ulStartAddrOrig, i = 0; ulAddr < ulBeyondEndAddrOrig; ulAddr += PAGE_SIZE, i++)
+    for (uAddr = uStartAddrOrig, i = 0; uAddr < uBeyondEndAddrOrig; uAddr += PAGE_SIZE, i++)
     {
        IMG_CPU_PHYADDR CPUPhysAddr;
-       IMG_UINT32 ulPFN = 0;
+       IMG_UINT32 ui32PFN = 0;
 
        PVR_ASSERT(i < psInfo->iNumPages);
 
-       if (!CPUVAddrToPFN(psVMArea, ulAddr, &ulPFN, &psInfo->ppsPages[i]))
+       if (!CPUVAddrToPFN(psVMArea, uAddr, &ui32PFN, &psInfo->ppsPages[i]))
        {
             PVR_DPF((PVR_DBG_ERROR,
               "OSAcquirePhysPageAddr: Invalid CPU virtual address"));
@@ -3733,9 +3726,9 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
        }
        if (psInfo->ppsPages[i] == NULL)
        {
-#if defined(CONFIG_TI_TILER)
+#if defined(CONFIG_TI_TILER) || defined(CONFIG_DRM_OMAP_DMM_TILER)
                /* This could be tiler memory.*/
-               IMG_UINT32 ui32TilerAddr = CPUAddrToTilerPhy(ulAddr);
+               IMG_UINT32 ui32TilerAddr = CPUAddrToTilerPhy(uAddr);
                if (ui32TilerAddr)
                {
                        bHavePageStructs = IMG_TRUE;
@@ -3744,7 +3737,7 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
                        psSysPAddr[i].uiAddr = ui32TilerAddr;
                        continue;
                }
-#endif /* defined(CONFIG_TI_TILER) */
+#endif /* defined(CONFIG_TI_TILER) || defined(CONFIG_DRM_OMAP_DMM_TILER) */
 
            bHaveNoPageStructs = IMG_TRUE;
        }
@@ -3754,14 +3747,14 @@ PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID *pvCPUVAddr,
 
            psInfo->iNumPagesMapped++;
 
-           PVR_ASSERT(ulPFN == page_to_pfn(psInfo->ppsPages[i]));
+           PVR_ASSERT(ui32PFN == page_to_pfn(psInfo->ppsPages[i]));
        }
 
-        CPUPhysAddr.uiAddr = ulPFN << PAGE_SHIFT;
-       if ((CPUPhysAddr.uiAddr >> PAGE_SHIFT) != ulPFN)
+        CPUPhysAddr.uiAddr = ui32PFN << PAGE_SHIFT;
+       if ((CPUPhysAddr.uiAddr >> PAGE_SHIFT) != ui32PFN)
        {
                 PVR_DPF((PVR_DBG_ERROR,
-                   "OSAcquirePhysPageAddr: Page frame number out of range (%x)", ulPFN));
+                   "OSAcquirePhysPageAddr: Page frame number out of range (%x)", ui32PFN));
 
                    goto error;
        }
@@ -3839,19 +3832,23 @@ typedef void (*OuterCacheOp_t)(unsigned long ulStart, unsigned long ulEnd);
 
 #if defined(CONFIG_OUTER_CACHE)
 
+/* 
+       Note: use IMG_CPU_PHYADDR to return CPU Phys Addresses, and not just 'unsigned long',
+       as this is not big enough to hold physical addresses on 32-bit PAE devices.
+*/
 typedef IMG_BOOL (*MemAreaToPhys_t)(LinuxMemArea *psLinuxMemArea,
                                                                                 IMG_VOID *pvRangeAddrStart,
                                                                                 IMG_UINT32 ui32PageNumOffset,
                                                                                 IMG_UINT32 ui32PageNum,
-                                                                                unsigned long *pulStart);
+                                                                                IMG_CPU_PHYADDR *psStart);
 
 static IMG_BOOL VMallocAreaToPhys(LinuxMemArea *psLinuxMemArea,
                                                                  IMG_VOID *pvRangeAddrStart,
                                                                  IMG_UINT32 ui32PageNumOffset,
                                                                  IMG_UINT32 ui32PageNum,
-                                                                 unsigned long *pulStart)
+                                                                 IMG_CPU_PHYADDR *psStart)
 {
-       *pulStart = vmalloc_to_pfn(pvRangeAddrStart + ui32PageNum * PAGE_SIZE) << PAGE_SHIFT;
+       psStart->uiAddr = vmalloc_to_pfn(pvRangeAddrStart + ui32PageNum * PAGE_SIZE) << PAGE_SHIFT;
        return IMG_TRUE;
 }
 
@@ -3859,13 +3856,11 @@ static IMG_BOOL ExternalKVAreaToPhys(LinuxMemArea *psLinuxMemArea,
                                                                         IMG_VOID *pvRangeAddrStart,
                                                                         IMG_UINT32 ui32PageNumOffset,
                                                                         IMG_UINT32 ui32PageNum,
-                                                                        unsigned long *pulStart)
+                                                                        IMG_CPU_PHYADDR *psStart)
 {
        IMG_SYS_PHYADDR SysPAddr;
-       IMG_CPU_PHYADDR CpuPAddr;
        SysPAddr = psLinuxMemArea->uData.sExternalKV.uPhysAddr.pSysPhysAddr[ui32PageNumOffset + ui32PageNum];
-       CpuPAddr = SysSysPAddrToCpuPAddr(SysPAddr);
-       *pulStart = CpuPAddr.uiAddr;
+       *psStart = SysSysPAddrToCpuPAddr(SysPAddr);
        return IMG_TRUE;
 }
 
@@ -3873,12 +3868,12 @@ static IMG_BOOL AllocPagesAreaToPhys(LinuxMemArea *psLinuxMemArea,
                                                                         IMG_VOID *pvRangeAddrStart,
                                                                         IMG_UINT32 ui32PageNumOffset,
                                                                         IMG_UINT32 ui32PageNum,
-                                                                        unsigned long *pulStart)
+                                                                        IMG_CPU_PHYADDR *psStart)
 {
        struct page *pPage;
 
        pPage = psLinuxMemArea->uData.sPageList.ppsPageList[ui32PageNumOffset + ui32PageNum];
-       *pulStart = page_to_pfn(pPage) << PAGE_SHIFT;
+       psStart->uiAddr = page_to_pfn(pPage) << PAGE_SHIFT;
        return IMG_TRUE;
 }
 
@@ -3886,7 +3881,7 @@ static IMG_BOOL AllocPagesSparseAreaToPhys(LinuxMemArea *psLinuxMemArea,
                                                                                   IMG_VOID *pvRangeAddrStart,
                                                                                   IMG_UINT32 ui32PageNumOffset,
                                                                                   IMG_UINT32 ui32PageNum,
-                                                                                  unsigned long *pulStart)
+                                                                                  IMG_CPU_PHYADDR *psStart)
 {
        IMG_UINT32 ui32VirtOffset = (ui32PageNumOffset + ui32PageNum) << PAGE_SHIFT;
        IMG_UINT32 ui32PhysOffset;
@@ -3896,7 +3891,7 @@ static IMG_BOOL AllocPagesSparseAreaToPhys(LinuxMemArea *psLinuxMemArea,
        {
                PVR_ASSERT(ui32PhysOffset <= ui32VirtOffset);
                pPage = psLinuxMemArea->uData.sPageList.ppsPageList[ui32PhysOffset >> PAGE_SHIFT];
-               *pulStart = page_to_pfn(pPage) << PAGE_SHIFT;
+               psStart->uiAddr = page_to_pfn(pPage) << PAGE_SHIFT;
                return IMG_TRUE;
        }
 
@@ -3908,11 +3903,9 @@ static IMG_BOOL IONAreaToPhys(LinuxMemArea *psLinuxMemArea,
                                                          IMG_VOID *pvRangeAddrStart,
                                                          IMG_UINT32 ui32PageNumOffset,
                                                          IMG_UINT32 ui32PageNum,
-                                                         unsigned long *pulStart)
+                                                         IMG_CPU_PHYADDR *psStart)
 {
-       IMG_CPU_PHYADDR CpuPAddr;
-       CpuPAddr = psLinuxMemArea->uData.sIONTilerAlloc.pCPUPhysAddrs[ui32PageNumOffset + ui32PageNum];
-       *pulStart = CpuPAddr.uiAddr;
+       *psStart = psLinuxMemArea->uData.sIONTilerAlloc.pCPUPhysAddrs[ui32PageNumOffset + ui32PageNum];;
        return IMG_TRUE;
 }
 
@@ -3936,11 +3929,11 @@ IMG_VOID *FindMMapBaseVAddr(struct list_head *psMMapOffsetStructList,
                if(OSGetCurrentProcessIDKM() != psOffsetStruct->ui32PID)
                        continue;
 
-               pvMinVAddr = (IMG_VOID *)psOffsetStruct->ui32UserVAddr;
+               pvMinVAddr = (IMG_VOID *)psOffsetStruct->uiUserVAddr;
 
                /* Within permissible range */
                if(pvRangeAddrStart >= pvMinVAddr &&
-                  ui32Length <= psOffsetStruct->ui32RealByteSize)
+                  ui32Length <= psOffsetStruct->uiRealByteSize)
                        return pvMinVAddr;
        }
 
@@ -3964,7 +3957,7 @@ static inline void DoInnerCacheOp(IMG_HANDLE hOSMemHandle,
        else
        {
                IMG_UINT32 ui32ByteRemain = ui32Length;
-               IMG_UINT32 ui32BytesToDo = PAGE_SIZE - (((IMG_UINT32) pvRangeAddrStart) & (~PAGE_MASK));
+               IMG_UINT32 ui32BytesToDo = PAGE_SIZE - (((IMG_UINTPTR_T) pvRangeAddrStart) & (~PAGE_MASK));
                IMG_UINT8 *pbDo = (IMG_UINT8 *) pvRangeAddrStart;
        
                while(ui32ByteRemain)
@@ -3984,26 +3977,27 @@ static
 IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                                                         IMG_UINT32 ui32ByteOffset,
                                                         IMG_VOID *pvRangeAddrStart,
-                                                        IMG_UINT32 ui32Length,
+                                                        IMG_SIZE_T uiLength,
                                                         InnerCacheOp_t pfnInnerCacheOp,
                                                         OuterCacheOp_t pfnOuterCacheOp)
 {
        LinuxMemArea *psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-       IMG_UINT32 ui32AreaLength, ui32AreaOffset = 0;
+       IMG_SIZE_T uiAreaLength = 0;
+    IMG_UINTPTR_T uiAreaOffset = 0;
        struct list_head *psMMapOffsetStructList;
        IMG_VOID *pvMinVAddr;
 
 #if defined(CONFIG_OUTER_CACHE)
        MemAreaToPhys_t pfnMemAreaToPhys = IMG_NULL;
-       IMG_UINT32 ui32PageNumOffset = 0;
+       IMG_UINTPTR_T uPageNumOffset = 0;
 #endif
 
        PVR_ASSERT(psLinuxMemArea != IMG_NULL);
 
-       LinuxLockMutex(&g_sMMapMutex);
+       LinuxLockMutexNested(&g_sMMapMutex, PVRSRV_LOCK_CLASS_MMAP);
 
        psMMapOffsetStructList = &psLinuxMemArea->sMMapOffsetStructList;
-       ui32AreaLength = psLinuxMemArea->ui32ByteSize;
+       uiAreaLength = psLinuxMemArea->uiByteSize;
 
        /*
                Don't check the length in the case of sparse mappings as
@@ -4011,12 +4005,12 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
        */
        if (!psLinuxMemArea->hBMHandle)
        {
-               PVR_ASSERT(ui32Length <= ui32AreaLength);
+               PVR_ASSERT(uiLength <= uiAreaLength);
        }
 
        if(psLinuxMemArea->eAreaType == LINUX_MEM_AREA_SUB_ALLOC)
        {
-               ui32AreaOffset = psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset;
+               uiAreaOffset = psLinuxMemArea->uData.sSubAlloc.uiByteOffset;
                psLinuxMemArea = psLinuxMemArea->uData.sSubAlloc.psParentLinuxMemArea;
        }
 
@@ -4029,7 +4023,7 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                {
                        if(is_vmalloc_addr(pvRangeAddrStart))
                        {
-                               pvMinVAddr = psLinuxMemArea->uData.sVmalloc.pvVmallocAddress + ui32AreaOffset;
+                               pvMinVAddr = psLinuxMemArea->uData.sVmalloc.pvVmallocAddress + uiAreaOffset;
 
                                /* Outside permissible range */
                                if(pvRangeAddrStart < pvMinVAddr)
@@ -4038,7 +4032,7 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                                DoInnerCacheOp(hOSMemHandle,
                                                           ui32ByteOffset,
                                                           pvRangeAddrStart,
-                                                          ui32Length,
+                                                          uiLength,
                                                           pfnInnerCacheOp);
                        }
                        else
@@ -4049,14 +4043,14 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                                 */
 
                                pvMinVAddr = FindMMapBaseVAddr(psMMapOffsetStructList,
-                                                                                          pvRangeAddrStart, ui32Length);
+                                                                                          pvRangeAddrStart, uiLength);
                                if(!pvMinVAddr)
                                        goto err_blocked;
 
                                DoInnerCacheOp(hOSMemHandle,
                                                           ui32ByteOffset,
                                                           pvRangeAddrStart,
-                                                          ui32Length,
+                                                          uiLength,
                                                           pfnInnerCacheOp);
 
 #if defined(CONFIG_OUTER_CACHE)
@@ -4069,7 +4063,7 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                                 * affected physical pages for outer cache flushing.
                                 */
                                pvRangeAddrStart = psLinuxMemArea->uData.sVmalloc.pvVmallocAddress +
-                                                                  (ui32AreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr);
+                                                                  (uiAreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr);
                        }
 
                        pfnMemAreaToPhys = VMallocAreaToPhys;
@@ -4100,18 +4094,18 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                        }
 
                        pvMinVAddr = FindMMapBaseVAddr(psMMapOffsetStructList,
-                                                                                  pvRangeAddrStart, ui32Length);
+                                                                                  pvRangeAddrStart, uiLength);
                        if(!pvMinVAddr)
                                goto err_blocked;
 
                        DoInnerCacheOp(hOSMemHandle,
                                                   ui32ByteOffset,
                                                   pvRangeAddrStart,
-                                                  ui32Length,
+                                                  uiLength,
                                                   pfnInnerCacheOp);
 
 #if defined(CONFIG_OUTER_CACHE)
-                       ui32PageNumOffset = ((ui32AreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr)) >> PAGE_SHIFT;
+                       uPageNumOffset = ((uiAreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr)) >> PAGE_SHIFT;
                        pfnMemAreaToPhys = ExternalKVAreaToPhys;
 #endif
                        break;
@@ -4120,18 +4114,18 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                case LINUX_MEM_AREA_ION:
                {
                        pvMinVAddr = FindMMapBaseVAddr(psMMapOffsetStructList,
-                                                                                  pvRangeAddrStart, ui32Length);
+                                                                                  pvRangeAddrStart, uiLength);
                        if(!pvMinVAddr)
                                goto err_blocked;
 
                        DoInnerCacheOp(hOSMemHandle,
                                                   ui32ByteOffset,
                                                   pvRangeAddrStart,
-                                                  ui32Length,
+                                                  uiLength,
                                                   pfnInnerCacheOp);
 
 #if defined(CONFIG_OUTER_CACHE)
-                       ui32PageNumOffset = ((ui32AreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr)) >> PAGE_SHIFT;
+                       uPageNumOffset = ((uiAreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr)) >> PAGE_SHIFT;
                        pfnMemAreaToPhys = IONAreaToPhys;
 #endif
                        break;
@@ -4140,18 +4134,18 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                case LINUX_MEM_AREA_ALLOC_PAGES:
                {
                        pvMinVAddr = FindMMapBaseVAddr(psMMapOffsetStructList,
-                                                                                  pvRangeAddrStart, ui32Length);
+                                                                                  pvRangeAddrStart, uiLength);
                        if(!pvMinVAddr)
                                goto err_blocked;
 
                        DoInnerCacheOp(hOSMemHandle,
                                                   ui32ByteOffset,
                                                   pvRangeAddrStart,
-                                                  ui32Length,
+                                                  uiLength,
                                                   pfnInnerCacheOp);
 
 #if defined(CONFIG_OUTER_CACHE)
-                       ui32PageNumOffset = ((ui32AreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr)) >> PAGE_SHIFT;
+                       uPageNumOffset = ((uiAreaOffset & PAGE_MASK) + (pvRangeAddrStart - pvMinVAddr)) >> PAGE_SHIFT;
                        if (psLinuxMemArea->hBMHandle)
                        {
                                pfnMemAreaToPhys = AllocPagesSparseAreaToPhys;
@@ -4175,12 +4169,13 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
 
        /* Outer caches need some more work, to get a list of physical addresses */
        {
-               unsigned long ulStart, ulEnd, ulLength, ulStartOffset, ulEndOffset;
+               IMG_CPU_PHYADDR sStart, sEnd;
+               unsigned long ulLength, ulStartOffset, ulEndOffset;
                IMG_UINT32 i, ui32NumPages;
                IMG_BOOL bValidPage;
 
                /* Length and offsets of flush region WRT page alignment */
-               ulLength = (unsigned long)ui32Length;
+               ulLength = (unsigned long)uiLength;
                ulStartOffset = ((unsigned long)pvRangeAddrStart) & (PAGE_SIZE - 1);
                ulEndOffset = ((unsigned long)pvRangeAddrStart + ulLength) & (PAGE_SIZE - 1);
 
@@ -4190,18 +4185,18 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
                for(i = 0; i < ui32NumPages; i++)
                {
                        bValidPage = pfnMemAreaToPhys(psLinuxMemArea, pvRangeAddrStart,
-                                                                          ui32PageNumOffset, i, &ulStart);
+                                                                          uPageNumOffset, i, &sStart);
                        if (bValidPage)
                        {
-                               ulEnd = ulStart + PAGE_SIZE;
+                               sEnd.uiAddr = sStart.uiAddr + PAGE_SIZE;
        
                                if(i == ui32NumPages - 1 && ulEndOffset != 0)
-                                       ulEnd = ulStart + ulEndOffset;
+                                       sEnd.uiAddr = sStart.uiAddr + ulEndOffset;
        
                                if(i == 0)
-                                       ulStart += ulStartOffset;
+                                       sStart.uiAddr += ulStartOffset;
        
-                               pfnOuterCacheOp(ulStart, ulEnd);
+                               pfnOuterCacheOp(sStart.uiAddr, sEnd.uiAddr);
                        }
                }
        }
@@ -4212,13 +4207,13 @@ IMG_BOOL CheckExecuteCacheOp(IMG_HANDLE hOSMemHandle,
 err_blocked:
        PVR_DPF((PVR_DBG_WARNING, "%s: Blocked cache op on virtual range "
                                                          "%p-%p (type %d)", __func__,
-                        pvRangeAddrStart, pvRangeAddrStart + ui32Length,
+                        pvRangeAddrStart, pvRangeAddrStart + uiLength,
                         psLinuxMemArea->eAreaType));
        LinuxUnLockMutex(&g_sMMapMutex);
        return IMG_FALSE;
 }
 
-#if defined(__i386__)
+#if defined(__i386__) || defined (__x86_64__)
 
 #define ROUND_UP(x,a) (((x) + (a) - 1) & ~((a) - 1))
 
@@ -4286,7 +4281,7 @@ IMG_BOOL OSInvalidateCPUCacheRangeKM(IMG_HANDLE hOSMemHandle,
                                                           x86_flush_cache_range, IMG_NULL);
 }
 
-#else /* defined(__i386__) */
+#else /* defined(__i386__) || defined(__x86_64__) */
 
 #if defined(__arm__)
 
@@ -4530,7 +4525,7 @@ IMG_VOID OSReleaseBridgeLock(IMG_VOID)
 
 IMG_VOID OSReacquireBridgeLock(IMG_VOID)
 {
-       LinuxLockMutex(&gPVRSRVLock);
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 }
 
 typedef struct _OSTime
@@ -4548,7 +4543,7 @@ PVRSRV_ERROR OSTimeCreateWithUSOffset(IMG_PVOID *pvRet, IMG_UINT32 ui32USOffset)
                return PVRSRV_ERROR_OUT_OF_MEMORY;
        }
 
-       psOSTime->ulTime = usecs_to_jiffies(jiffies_to_usecs(jiffies) + ui32USOffset);
+       psOSTime->ulTime = jiffies + usecs_to_jiffies(ui32USOffset);
        *pvRet = psOSTime;
        return PVRSRV_OK;
 }
index a22b461..465f410 100644 (file)
@@ -44,11 +44,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "env_perproc.h"
 #include "proc.h"
-#if defined (SUPPORT_ION)
-#include "linux/ion.h"
 
-extern struct ion_device *psIonDev;
+#if defined (SUPPORT_ION)
+#include "ion.h"
+extern struct ion_device *gpsIonDev;
 #endif
+
 extern IMG_UINT32 gui32ReleasePID;
 
 PVRSRV_ERROR OSPerProcessPrivateDataInit(IMG_HANDLE *phOsPrivateData)
@@ -83,13 +84,19 @@ PVRSRV_ERROR OSPerProcessPrivateDataInit(IMG_HANDLE *phOsPrivateData)
        /* Linked list of PVRSRV_FILE_PRIVATE_DATA structures */
        INIT_LIST_HEAD(&psEnvPerProc->sDRMAuthListHead);
 #endif
+
 #if defined(SUPPORT_ION)
        OSSNPrintf(psEnvPerProc->azIonClientName, ION_CLIENT_NAME_SIZE, "pvr_ion_client-%d", OSGetCurrentProcessIDKM());
        psEnvPerProc->psIONClient =
-               ion_client_create(psIonDev,
-                                                 1 << ION_HEAP_TYPE_SYSTEM_CONTIG |
-                                                 1 << ION_HEAP_TYPE_SYSTEM,
-                                                 psEnvPerProc->azIonClientName);
+               ion_client_create(gpsIonDev,
+#if defined(CONFIG_ION_OMAP)
+                                                 /*1 << ION_HEAP_TYPE_SYSTEM_CONTIG |*/
+                                                   1 << ION_HEAP_TYPE_SYSTEM
+                                                 | 1 << OMAP_ION_HEAP_TYPE_TILER
+#else /* defined(CONFIG_ION_OMAP) */
+                                                 -1
+#endif /* defined(CONFIG_ION_OMAP) */
+                                                 , psEnvPerProc->azIonClientName);
  
        if (IS_ERR_OR_NULL(psEnvPerProc->psIONClient))
        {
@@ -97,7 +104,8 @@ PVRSRV_ERROR OSPerProcessPrivateDataInit(IMG_HANDLE *phOsPrivateData)
                                                                "ion client for per process data"));
                return PVRSRV_ERROR_OUT_OF_MEMORY;
        }
-#endif /* SUPPORT_ION */
+#endif /* defined(SUPPORT_ION) */
+
        return PVRSRV_OK;
 }
 
index 0124737..548e8dc 100644 (file)
@@ -62,6 +62,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <linux/kernel.h> // sprintf
 #include <linux/string.h> // strncpy, strlen
+#include <linux/mutex.h>
 
 static IMG_BOOL PDumpWriteString2              (IMG_CHAR * pszString, IMG_UINT32 ui32Flags);
 static IMG_BOOL PDumpWriteILock                        (PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32Count, IMG_UINT32 ui32Flags);
@@ -80,7 +81,8 @@ static atomic_t gsPDumpSuspended = ATOMIC_INIT(0);
 
 static PDBGKM_SERVICE_TABLE gpfnDbgDrv = IMG_NULL;
 
-
+DEFINE_MUTEX(sPDumpLock);
+DEFINE_MUTEX(sPDumpMsgLock);
 
 IMG_CHAR *pszStreamName[PDUMP_NUM_STREAMS] = { "ParamStream2",
                                                                                                "ScriptStream2",
@@ -391,7 +393,7 @@ IMG_VOID PDumpOSCPUVAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType,
 IMG_VOID PDumpOSCPUVAddrToPhysPages(IMG_HANDLE hOSMemHandle,
                IMG_UINT32 ui32Offset,
                IMG_PUINT8 pui8LinAddr,
-               IMG_UINT32 ui32DataPageMask,
+               IMG_UINTPTR_T ui32DataPageMask,
                IMG_UINT32 *pui32PageOffset)
 {
        if(hOSMemHandle)
@@ -411,7 +413,7 @@ IMG_VOID PDumpOSCPUVAddrToPhysPages(IMG_HANDLE hOSMemHandle,
                PVR_UNREFERENCED_PARAMETER(hOSMemHandle);
                PVR_UNREFERENCED_PARAMETER(ui32Offset);
 
-               *pui32PageOffset = ((IMG_UINT32)pui8LinAddr & ui32DataPageMask);
+               *pui32PageOffset = ((IMG_UINTPTR_T)pui8LinAddr & ui32DataPageMask);
        }
 }
 
@@ -724,7 +726,7 @@ static IMG_BOOL PDumpWriteILock(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_U
        IMG_UINT32 ui32Written = 0;
        if ((psStream == IMG_NULL) || PDumpSuspended() || ((ui32Flags & PDUMP_FLAGS_NEVER) != 0))
        {
-               PVR_DPF((PVR_DBG_MESSAGE, "PDumpWriteILock: Failed to write 0x%x bytes to stream 0x%x", ui32Count, (IMG_UINT32)psStream));
+               PVR_DPF((PVR_DBG_MESSAGE, "PDumpWriteILock: Failed to write 0x%x bytes to stream 0x%p", ui32Count, psStream));
                return IMG_TRUE;
        }
 
@@ -797,6 +799,55 @@ IMG_VOID PDumpResumeKM(IMG_VOID)
        atomic_dec(&gsPDumpSuspended);
 }
 
+/* Set to 1 if you want to debug PDump locking issues */
+#define DEBUG_PDUMP_LOCKS 0
+
+#if DEBUG_PDUMP_LOCKS
+static IMG_UINT32 ui32Count=0;
+static IMG_UINT32 aui32LockLine[2] = {0};
+static IMG_UINT32 aui32UnlockLine[2] = {0};
+static IMG_UINT32 ui32LockLineCount = 0;
+static IMG_UINT32 ui32UnlockLineCount = 0;
+#endif
+
+IMG_VOID PDumpOSLock(IMG_UINT32 ui32Line)
+{
+#if DEBUG_PDUMP_LOCKS
+       aui32LockLine[ui32LockLineCount++ % 2] = ui32Line;
+       ui32Count++;
+       if (ui32Count == 2)
+       {
+               IMG_UINT32 i;
+               printk(KERN_ERR "Double lock\n");
+               dump_stack();
+               for (i=0;i<2;i++)
+               {
+                       printk(KERN_ERR "Lock[%d] = %d, Unlock[%d] = %d\n", i, aui32LockLine[i],i, aui32UnlockLine[i]);
+               }
+       }
+#endif
+       mutex_lock(&sPDumpLock);
+}
+
+IMG_VOID PDumpOSUnlock(IMG_UINT32 ui32Line)
+{
+       mutex_unlock(&sPDumpLock);
+#if DEBUG_PDUMP_LOCKS
+       aui32UnlockLine[ui32UnlockLineCount++ % 2] = ui32Line;
+       ui32Count--;
+#endif
+}
+
+IMG_VOID PDumpOSLockMessageBuffer(IMG_VOID)
+{
+       mutex_lock(&sPDumpMsgLock);
+}
+
+IMG_VOID PDumpOSUnlockMessageBuffer(IMG_VOID)
+{
+       mutex_unlock(&sPDumpMsgLock);
+}
+
 #endif /* #if defined (PDUMP) */
 #endif /* #if defined (SUPPORT_SGX) */
 /*****************************************************************************
index 6b09705..e2a6c74 100644 (file)
@@ -64,11 +64,7 @@ typedef struct
        IMG_UINT32 ui32OpenPID;
 
        /* Global kernel MemInfo handle */
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID hKernelMemInfo;
-#else
        IMG_HANDLE hKernelMemInfo;
-#endif
 
 #if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
        /* The private data is on a list in the per-process data structure */
index bc2a554..fa5e1b2 100644 (file)
@@ -44,7 +44,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __SERVICES_PROC_H__
 #define __SERVICES_PROC_H__
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0))
 #include <asm/system.h>                // va_list etc
+#endif
 #include <linux/proc_fs.h>     // read_proc_t etc
 #include <linux/seq_file.h> // seq_file
 
index 5d1ad8c..f366d15 100644 (file)
@@ -95,7 +95,7 @@ static void ProcSeqStartstopBridgeStats(struct seq_file *sfile,IMG_BOOL start);
 extern PVRSRV_LINUX_MUTEX gPVRSRVLock;
 
 #if defined(SUPPORT_MEMINFO_IDS)
-static IMG_UINT64 ui64Stamp;
+IMG_UINT64 g_ui64MemInfoID;
 #endif /* defined(SUPPORT_MEMINFO_IDS) */
 
 PVRSRV_ERROR
@@ -141,7 +141,7 @@ static void ProcSeqStartstopBridgeStats(struct seq_file *sfile,IMG_BOOL start)
 {
        if(start) 
        {
-               LinuxLockMutex(&gPVRSRVLock);
+               LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
        }
        else
        {
@@ -253,7 +253,7 @@ PVRSRV_BridgeDispatchKM(struct file *pFile, unsigned int unref__ ioctlCmd, unsig
        PVRSRV_PER_PROCESS_DATA *psPerProc;
        IMG_INT err = -EFAULT;
 
-       LinuxLockMutex(&gPVRSRVLock);
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
 #if defined(SUPPORT_DRI_DRM)
        psBridgePackageKM = (PVRSRV_BRIDGE_PACKAGE *)arg;
@@ -474,7 +474,7 @@ PVRSRV_BridgeDispatchKM(struct file *pFile, unsigned int unref__ ioctlCmd, unsig
 
                        psPrivateData->hKernelMemInfo = hMemInfo;
 #if defined(SUPPORT_MEMINFO_IDS)
-                       psPrivateData->ui64Stamp = ++ui64Stamp;
+                       psPrivateData->ui64Stamp = ++g_ui64MemInfoID;
 
                        psKernelMemInfo->ui64Stamp = psPrivateData->ui64Stamp;
                        if (pvr_put_user(psPrivateData->ui64Stamp, &psExportDeviceMemOUT->ui64Stamp) != 0)
@@ -505,7 +505,7 @@ PVRSRV_BridgeDispatchKM(struct file *pFile, unsigned int unref__ ioctlCmd, unsig
                {
                        PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY *psDeviceClassMemoryOUT =
                                (PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY *)psBridgePackageKM->pvParamOut;
-                       if (pvr_put_user(++ui64Stamp, &psDeviceClassMemoryOUT->sClientMemInfo.ui64Stamp) != 0)
+                       if (pvr_put_user(++g_ui64MemInfoID, &psDeviceClassMemoryOUT->sClientMemInfo.ui64Stamp) != 0)
                        {
                                err = -EFAULT;
                                goto unlock_and_return;
index 28b814f..098f0c0 100644 (file)
@@ -338,7 +338,7 @@ PVRDRMUnprivCmd(struct drm_device *dev, void *arg, struct drm_file *pFile)
 {
        int ret = 0;
 
-       LinuxLockMutex(&gPVRSRVLock);
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
        if (arg == NULL)
        {
@@ -373,7 +373,7 @@ PVRDRM_Display_ioctl(struct drm_device *dev, void *arg, struct drm_file *pFile)
 {
        int res;
 
-       LinuxLockMutex(&gPVRSRVLock);
+       LinuxLockMutexNested(&gPVRSRVLock, PVRSRV_LOCK_CLASS_BRIDGE);
 
        res = PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Ioctl)(dev, arg, pFile);
 
@@ -389,7 +389,11 @@ PVRSRVPciProbe(struct pci_dev *dev, const struct pci_device_id *id)
 {
        PVR_TRACE(("PVRSRVPciProbe"));
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36))
+       return drm_get_pci_dev(dev, id, &sPVRDrmDriver);
+#else
        return drm_get_dev(dev, id, &sPVRDrmDriver);
+#endif
 }
 
 static void
@@ -467,6 +471,24 @@ static PVRSRV_DRM_PLUGIN sPVRDrmPlugin =
        .ioctl_start = 0
 };
 #else  /* defined(SUPPORT_DRI_DRM_PLUGIN) */
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
+static const struct file_operations sPVRFileOps = 
+{
+       .owner = THIS_MODULE,
+       .open = drm_open,
+#if defined(PVR_DRI_DRM_USE_POST_CLOSE)
+       .release = drm_release,
+#else
+       .release = PVRSRVDrmRelease,
+#endif
+       PVR_DRM_FOPS_IOCTL = drm_ioctl,
+       .mmap = PVRMMap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+};
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) */
+
 static struct drm_driver sPVRDrmDriver = 
 {
 #if defined(PVR_OLD_STYLE_DRM_PLATFORM_DEV)
@@ -490,6 +512,9 @@ static struct drm_driver sPVRDrmDriver =
        .get_reg_ofs = drm_core_get_reg_ofs,
 #endif
        .ioctls = sPVRDrmIoctls,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
+       .fops = &sPVRFileOps,
+#else
        .fops = 
        {
                .owner = THIS_MODULE,
@@ -504,6 +529,7 @@ static struct drm_driver sPVRDrmDriver =
                .poll = drm_poll,
                .fasync = drm_fasync,
        },
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) */
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39))
 #if defined(PVR_OLD_STYLE_DRM_PLATFORM_DEV)
        .platform_driver =
@@ -549,6 +575,8 @@ static struct pci_driver sPVRPCIDriver =
 #if defined(SUPPORT_DRM_MODESET)
                .probe = PVRSRVPciProbe,
                .remove = PVRSRVPciRemove,
+               .suspend = PVRSRVDriverSuspend,
+               .resume = PVRSRVDriverResume,
 #endif
 };
 #endif
index 711e356..92f721e 100644 (file)
@@ -167,13 +167,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define SGX_CORE_REV    SGX_CORE_REV_HEAD
        #endif
 
-       #if SGX_CORE_REV == 101
-               #define FIX_HW_BRN_25499/* Workaround in sgx featuredefs */
-               #define FIX_HW_BRN_25503/* Workaround in code (services) */
-               #define FIX_HW_BRN_26620/* Workaround in services (srvkm) */
-               #define FIX_HW_BRN_28011/* Workaround in services (srvkm) */
-               #define FIX_HW_BRN_34028/* Workaround in services (srvkm) */
-       #else
        #if SGX_CORE_REV == 110
                #define FIX_HW_BRN_25503/* Workaround in code (services) */
                #define FIX_HW_BRN_26620/* Workaround in services (srvkm) */
@@ -201,7 +194,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #endif
        #endif
        #endif
-       #endif
        /* signal that the Core Version has a valid definition */
        #define SGX_CORE_DEFINED
 #endif
@@ -224,9 +216,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define FIX_HW_BRN_31272/* workaround in services (srvclient) and uKernel */
                #define FIX_HW_BRN_31278/* disabled prefetching in MMU */
                #define FIX_HW_BRN_31542/* workaround in uKernel and Services */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31620/* workaround in services */
                #define FIX_HW_BRN_31780/* workaround in uKernel */
                #define FIX_HW_BRN_32044 /* workaround in uKernel, services and client drivers */
@@ -243,9 +232,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         #define FIX_HW_BRN_31195/* workaround in services */
                #define FIX_HW_BRN_31272/* workaround in services (srvclient) and uKernel */
                #define FIX_HW_BRN_31278/* disabled prefetching in MMU */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31542/* workaround in uKernel and Services */
                #define FIX_HW_BRN_31671/* workaround in uKernel */             
                #define FIX_HW_BRN_31780/* workaround in uKernel */
@@ -260,9 +246,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #else
        #if SGX_CORE_REV == 141
                #define FIX_HW_BRN_29954/* turns off regbank split feature */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31671 /* workaround in uKernel */
                #define FIX_HW_BRN_31780/* workaround in uKernel */
                #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING) && defined(SGX_FEATURE_MP)
@@ -273,9 +256,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #else
        #if SGX_CORE_REV == 142
                #define FIX_HW_BRN_29954/* turns off regbank split feature */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31671 /* workaround in uKernel */
                #define FIX_HW_BRN_31780/* workaround in uKernel */
                #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING) && defined(SGX_FEATURE_MP)
@@ -291,9 +271,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define FIX_HW_BRN_31272/* workaround in services (srvclient) and uKernel */
                #define FIX_HW_BRN_31278/* disabled prefetching in MMU */
                #define FIX_HW_BRN_31542/* workaround in uKernel and Services */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31620/* workaround in services */
                #define FIX_HW_BRN_31780/* workaround in uKernel */
                #define FIX_HW_BRN_32044 /* workaround in uKernel, services and client drivers */
@@ -307,9 +284,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #else
        #if SGX_CORE_REV == 213
                #define FIX_HW_BRN_31272/* workaround in services (srvclient) and uKernel */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31671 /* workaround in uKernel */
                #define FIX_HW_BRN_31780/* workaround in uKernel */
                #define FIX_HW_BRN_32085 /* workaround in services: prefetch fix applied, investigating PT based fix */
@@ -330,13 +304,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING) && defined(SGX_FEATURE_MP)
                        #define FIX_HW_BRN_33657/* workaround in ukernel*/
                #endif
-       #define FIX_HW_BRN_36513 /* workaround in uKernel and Services */
+               #define FIX_HW_BRN_36513 /* workaround in uKernel and Services */
        #else
        #if SGX_CORE_REV == 303
                #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING) && defined(SGX_FEATURE_MP)
                        #define FIX_HW_BRN_33657/* workaround in ukernel*/
                #endif
-       #define FIX_HW_BRN_36513 /* workaround in uKernel and Services */
+               #define FIX_HW_BRN_36513 /* workaround in uKernel and Services */
        #else
        #if SGX_CORE_REV == SGX_CORE_REV_HEAD
                #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING) && defined(SGX_FEATURE_MP)
@@ -372,9 +346,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define FIX_HW_BRN_31195/* workaround in services */
                #define FIX_HW_BRN_31272/* workaround in services (srvclient) and uKernel */
                #define FIX_HW_BRN_31278/* disabled prefetching in MMU */
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31542 /* workaround in uKernel and Services */
                #define FIX_HW_BRN_31620/* workaround in services */
                #define FIX_HW_BRN_31671 /* workaround in uKernel */
@@ -388,9 +359,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define FIX_HW_BRN_36513 /* workaround in uKernel and Services */
        #else   
        #if SGX_CORE_REV == 105
-               #if defined(SGX_FEATURE_MP)
-                       #define FIX_HW_BRN_31559/* workaround in services and uKernel */
-               #endif
                #define FIX_HW_BRN_31780/* workaround in uKernel */
                #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING) && defined(SGX_FEATURE_MP)
                        #define FIX_HW_BRN_33657/* workaround in ukernel*/
@@ -449,11 +417,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define SGX_CORE_REV    SGX_CORE_REV_HEAD
        #endif
 
-       #if SGX_CORE_REV == 109
-               #define FIX_HW_BRN_29702/* Workaround in services */
-               #define FIX_HW_BRN_29823/* Workaround in services */
-               #define FIX_HW_BRN_31939/* workaround in uKernel */
-       #else
        #if SGX_CORE_REV == 10131
        #else
        #if SGX_CORE_REV == 1014
@@ -468,7 +431,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #endif
        #endif
        #endif
-       #endif
        /* signal that the Core Version has a valid definition */
        #define SGX_CORE_DEFINED
 #endif
index 3e3a116..dfbc28b 100644 (file)
@@ -104,7 +104,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define SGX_FEATURE_MASTER_VDM_CONTEXT_SWITCH
                #endif
                #define SGX_FEATURE_SLAVE_VDM_CONTEXT_SWITCH
-               #define SGX_FEATURE_SW_ISP_CONTEXT_SWITCH
        #endif
 #else
 #if defined(SGX544)
@@ -122,8 +121,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //     #define SGX_FEATURE_DATA_BREAKPOINTS
 //    #define SGX_FEATURE_PERPIPE_BKPT_REGS
 //    #define SGX_FEATURE_PERPIPE_BKPT_REGS_NUMPIPES          (2)
-//     #define SGX_FEATURE_2D_HARDWARE
-//     #define SGX_FEATURE_PTLA
+       #if defined(SGX_FEATURE_MP)
+               #define SGX_FEATURE_2D_HARDWARE
+               #define SGX_FEATURE_PTLA
+       #endif
        #define SGX_FEATURE_EXTENDED_PERF_COUNTERS
        #define SGX_FEATURE_EDM_VERTEX_PDSADDR_FULL_RANGE
        #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING)
@@ -131,7 +132,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define SGX_FEATURE_MASTER_VDM_CONTEXT_SWITCH
                #define SGX_FEATURE_SLAVE_VDM_CONTEXT_SWITCH
                #endif
-               #define SGX_FEATURE_SW_ISP_CONTEXT_SWITCH
        #endif
 #else
 #if defined(SGX545)
@@ -160,9 +160,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        #define SGX_FEATURE_BIF_WIDE_TILING_AND_4K_ADDRESS
        #define SGX_FEATURE_MULTI_EVENT_KICK
        #define SGX_FEATURE_EDM_VERTEX_PDSADDR_FULL_RANGE
-       #if defined(SUPPORT_SGX_LOW_LATENCY_SCHEDULING)
-               #define SGX_FEATURE_SW_ISP_CONTEXT_SWITCH
-       #endif
 #else
 #if defined(SGX554)
        #define SGX_CORE_FRIENDLY_NAME                                                  "SGX554"
@@ -188,7 +185,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
                #define SGX_FEATURE_MASTER_VDM_CONTEXT_SWITCH
                #endif
                #define SGX_FEATURE_SLAVE_VDM_CONTEXT_SWITCH
-               #define SGX_FEATURE_SW_ISP_CONTEXT_SWITCH
        #endif
 #endif
 #endif
index 510f47d..49d023e 100644 (file)
@@ -335,8 +335,8 @@ BM_Alloc (IMG_HANDLE                        hDevMemHeap,
  */
 IMG_BOOL
 BM_Wrap (      IMG_HANDLE hDevMemHeap,
-                   IMG_SIZE_T ui32Size,
-                       IMG_SIZE_T ui32Offset,
+                   IMG_SIZE_T uSize,
+                       IMG_SIZE_T uOffset,
                        IMG_BOOL bPhysContig,
                        IMG_SYS_PHYADDR *psSysAddr,
                        IMG_VOID *pvCPUVAddr,
@@ -608,6 +608,7 @@ IMG_VOID _BM_XProcIndexReleaseDebug(const IMG_CHAR *pszFile, IMG_INT iLine, IMG_
 IMG_VOID _BM_XProcIndexAcquire(IMG_UINT32 ui32Index);
 IMG_VOID _BM_XProcIndexRelease(IMG_UINT32 ui32Index);
 
+
 #define BM_XProcIndexAcquire(x) \
        _BM_XProcIndexAcquire( x)
 #define BM_XProcIndexRelease(x) \
diff --git a/services4/srvkm/include/devicemem.h b/services4/srvkm/include/devicemem.h
new file mode 100644 (file)
index 0000000..00f8fe1
--- /dev/null
@@ -0,0 +1,52 @@
+/*************************************************************************/ /*!
+@Title          KM internal device memory functions
+@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.
+*/ /**************************************************************************/
+
+#include "img_defs.h"
+#include "img_types.h"
+#include "servicesext.h"
+
+#ifndef __DEVICEMEM_H__
+#define __DEVICEMEM_H__
+
+PVRSRV_ERROR IMG_CALLCONV PVRSRVInitDeviceMem(IMG_VOID);
+IMG_VOID IMG_CALLCONV PVRSRVDeInitDeviceMem(IMG_VOID);
+
+#endif /* __DEVICEMEM_H__ */
index 157d209..f636073 100644 (file)
@@ -230,30 +230,11 @@ typedef enum
 struct _PVRSRV_HANDLE_BASE_;
 typedef struct _PVRSRV_HANDLE_BASE_ PVRSRV_HANDLE_BASE;
 
-#if defined (PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)
+#if defined(PVR_SECURE_HANDLES)
 extern PVRSRV_HANDLE_BASE *gpsKernelHandleBase;
 
 #define        KERNEL_HANDLE_BASE (gpsKernelHandleBase)
 
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR PVRSRVAllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag);
-
-PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_SID hParent);
-
-PVRSRV_ERROR PVRSRVFindHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType);
-
-PVRSRV_ERROR PVRSRVLookupHandleAnyType(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, PVRSRV_HANDLE_TYPE *peType, IMG_SID hHandle);
-
-PVRSRV_ERROR PVRSRVLookupHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType);
-
-PVRSRV_ERROR PVRSRVLookupSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType, IMG_SID hAncestor);
-
-PVRSRV_ERROR PVRSRVGetParentHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID *phParent, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType);
-
-PVRSRV_ERROR PVRSRVLookupAndReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType);
-
-PVRSRV_ERROR PVRSRVReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_SID hHandle, PVRSRV_HANDLE_TYPE eType);
-#else
 PVRSRV_ERROR PVRSRVAllocHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag);
 
 PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE *phHandle, IMG_VOID *pvData, PVRSRV_HANDLE_TYPE eType, PVRSRV_HANDLE_ALLOC_FLAG eFlag, IMG_HANDLE hParent);
@@ -271,7 +252,6 @@ PVRSRV_ERROR PVRSRVGetParentHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *phPare
 PVRSRV_ERROR PVRSRVLookupAndReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_PVOID *ppvData, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType);
 
 PVRSRV_ERROR PVRSRVReleaseHandle(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE hHandle, PVRSRV_HANDLE_TYPE eType);
-#endif /* #if defined (SUPPORT_SID_INTERFACE) */
 
 PVRSRV_ERROR PVRSRVNewHandleBatch(PVRSRV_HANDLE_BASE *psBase, IMG_UINT32 ui32BatchSize);
 
@@ -295,7 +275,7 @@ PVRSRV_ERROR PVRSRVHandleInit(IMG_VOID);
 
 PVRSRV_ERROR PVRSRVHandleDeInit(IMG_VOID);
 
-#else  /* #if defined (PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)*/
+#else  /* #if defined (PVR_SECURE_HANDLES) */
 
 #define KERNEL_HANDLE_BASE IMG_NULL
 
@@ -543,7 +523,7 @@ PVRSRV_ERROR PVRSRVHandleDeInit(IMG_VOID)
        return PVRSRV_OK;
 }
 
-#endif /* #if defined (PVR_SECURE_HANDLES) || defined (SUPPORT_SID_INTERFACE)*/
+#endif /* #if defined (PVR_SECURE_HANDLES) */
 
 /*
  * Versions of PVRSRVAllocHandle and PVRSRVAllocSubHandle with no return
index b08985f..900430e 100644 (file)
@@ -54,7 +54,6 @@ extern "C" {
 #if defined(__linux__) && defined(__KERNEL__)
 #include <linux/hardirq.h>
 #include <linux/string.h>
-#include <asm/system.h>
 #if defined(__arm__)
 #include <asm/memory.h>
 #endif
@@ -87,7 +86,7 @@ extern "C" {
 
 
 IMG_UINT32 OSClockus(IMG_VOID);
-IMG_SIZE_T OSGetPageSize(IMG_VOID);
+IMG_UINT32 OSGetPageSize(IMG_VOID);
 PVRSRV_ERROR OSInstallDeviceLISR(IMG_VOID *pvSysData,
                                                                 IMG_UINT32 ui32Irq,
                                                                 IMG_CHAR *pszISRName,
@@ -98,12 +97,12 @@ PVRSRV_ERROR OSUninstallSystemLISR(IMG_VOID *pvSysData);
 PVRSRV_ERROR OSInstallMISR(IMG_VOID *pvSysData);
 PVRSRV_ERROR OSUninstallMISR(IMG_VOID *pvSysData);
 IMG_CPU_PHYADDR OSMapLinToCPUPhys(IMG_HANDLE, IMG_VOID* pvLinAddr);
-IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_SIZE_T ui32Size);
-IMG_VOID *OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE *phOSMemHandle);
-IMG_BOOL OSUnMapPhysToLin(IMG_VOID *pvLinAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle);
+IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_SIZE_T uiSize);
+IMG_VOID *OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_HANDLE *phOSMemHandle);
+IMG_BOOL OSUnMapPhysToLin(IMG_VOID *pvLinAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle);
 
-PVRSRV_ERROR OSReservePhys(IMG_CPU_PHYADDR BasePAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hBMHandle, IMG_VOID **ppvCpuVAddr, IMG_HANDLE *phOSMemHandle);
-PVRSRV_ERROR OSUnReservePhys(IMG_VOID *pvCpuVAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle);
+PVRSRV_ERROR OSReservePhys(IMG_CPU_PHYADDR BasePAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_HANDLE hBMHandle, IMG_VOID **ppvCpuVAddr, IMG_HANDLE *phOSMemHandle);
+PVRSRV_ERROR OSUnReservePhys(IMG_VOID *pvCpuVAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle);
 
 /* Some terminology:
  *
@@ -193,11 +192,11 @@ static INLINE IMG_BOOL OSInvalidateCPUCacheRangeKM(IMG_HANDLE hOSMemHandle,
 #if defined(__linux__) || defined(__QNXNTO__)
 PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr,
                                                                        IMG_VOID *pvCpuVAddr, 
-                                                                       IMG_SIZE_T ui32Bytes,
+                                                                       IMG_SIZE_T uBytes,
                                                                        IMG_UINT32 ui32Flags, 
                                                                        IMG_HANDLE *phOSMemHandle);
 PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr,
-                                                                       IMG_SIZE_T ui32Bytes,
+                                                                       IMG_SIZE_T uBytes,
                                                                        IMG_UINT32 ui32Flags,
                                                                        IMG_HANDLE hOSMemHandle);
 #else  /* defined(__linux__) */
@@ -206,7 +205,7 @@ PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr,
 #endif
 static INLINE PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr,
                                                                                                        IMG_VOID *pvCpuVAddr,
-                                                                                                       IMG_SIZE_T ui32Bytes,
+                                                                                                       IMG_SIZE_T uBytes,
                                                                                                        IMG_UINT32 ui32Flags,
                                                                                                        IMG_HANDLE *phOSMemHandle)
 {
@@ -223,7 +222,7 @@ static INLINE PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr,
 #pragma inline(OSUnRegisterDiscontigMem)
 #endif
 static INLINE PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr,
-                                                                                                       IMG_SIZE_T ui32Bytes,
+                                                                                                       IMG_SIZE_T uBytes,
                                                                                                        IMG_UINT32 ui32Flags,
                                                                                                        IMG_HANDLE hOSMemHandle)
 {
@@ -241,11 +240,11 @@ static INLINE PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr,
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(OSReserveDiscontigPhys)
 #endif
-static INLINE PVRSRV_ERROR OSReserveDiscontigPhys(IMG_SYS_PHYADDR *pBasePAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_VOID **ppvCpuVAddr, IMG_HANDLE *phOSMemHandle)
+static INLINE PVRSRV_ERROR OSReserveDiscontigPhys(IMG_SYS_PHYADDR *pBasePAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_VOID **ppvCpuVAddr, IMG_HANDLE *phOSMemHandle)
 {
 #if defined(__linux__) || defined(__QNXNTO__) 
        *ppvCpuVAddr = IMG_NULL;
-       return OSRegisterDiscontigMem(pBasePAddr, *ppvCpuVAddr, ui32Bytes, ui32Flags, phOSMemHandle);   
+       return OSRegisterDiscontigMem(pBasePAddr, *ppvCpuVAddr, uBytes, ui32Flags, phOSMemHandle);      
 #else
        extern IMG_CPU_PHYADDR SysSysPAddrToCpuPAddr(IMG_SYS_PHYADDR SysPAddr);
 
@@ -258,14 +257,14 @@ static INLINE PVRSRV_ERROR OSReserveDiscontigPhys(IMG_SYS_PHYADDR *pBasePAddr, I
         * 4. We don't need to unmap
         */
 
-       return OSReservePhys(SysSysPAddrToCpuPAddr(pBasePAddr[0]), ui32Bytes, ui32Flags, IMG_NULL, ppvCpuVAddr, phOSMemHandle);
+       return OSReservePhys(SysSysPAddrToCpuPAddr(pBasePAddr[0]), uBytes, ui32Flags, IMG_NULL, ppvCpuVAddr, phOSMemHandle);
 #endif 
 }
 
-static INLINE PVRSRV_ERROR OSUnReserveDiscontigPhys(IMG_VOID *pvCpuVAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
+static INLINE PVRSRV_ERROR OSUnReserveDiscontigPhys(IMG_VOID *pvCpuVAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
 {
 #if defined(__linux__) || defined(__QNXNTO__) 
-       OSUnRegisterDiscontigMem(pvCpuVAddr, ui32Bytes, ui32Flags, hOSMemHandle);
+       OSUnRegisterDiscontigMem(pvCpuVAddr, uBytes, ui32Flags, hOSMemHandle);
 #endif
        /* We don't need to unmap */
        return PVRSRV_OK;
@@ -276,10 +275,10 @@ static INLINE PVRSRV_ERROR OSUnReserveDiscontigPhys(IMG_VOID *pvCpuVAddr, IMG_SI
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(OSReserveDiscontigPhys)
 #endif
-static INLINE PVRSRV_ERROR OSReserveDiscontigPhys(IMG_SYS_PHYADDR *pBasePAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_VOID **ppvCpuVAddr, IMG_HANDLE *phOSMemHandle)
+static INLINE PVRSRV_ERROR OSReserveDiscontigPhys(IMG_SYS_PHYADDR *pBasePAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_VOID **ppvCpuVAddr, IMG_HANDLE *phOSMemHandle)
 {
        PVR_UNREFERENCED_PARAMETER(pBasePAddr);
-       PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+       PVR_UNREFERENCED_PARAMETER(uBytes);
        PVR_UNREFERENCED_PARAMETER(ui32Flags);
        PVR_UNREFERENCED_PARAMETER(ppvCpuVAddr);
        PVR_UNREFERENCED_PARAMETER(phOSMemHandle);
@@ -290,10 +289,10 @@ static INLINE PVRSRV_ERROR OSReserveDiscontigPhys(IMG_SYS_PHYADDR *pBasePAddr, I
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(OSUnReserveDiscontigPhys)
 #endif
-static INLINE PVRSRV_ERROR OSUnReserveDiscontigPhys(IMG_VOID *pvCpuVAddr, IMG_SIZE_T ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
+static INLINE PVRSRV_ERROR OSUnReserveDiscontigPhys(IMG_VOID *pvCpuVAddr, IMG_SIZE_T uBytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
 {
        PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
-       PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+       PVR_UNREFERENCED_PARAMETER(uBytes);
        PVR_UNREFERENCED_PARAMETER(ui32Flags);
        PVR_UNREFERENCED_PARAMETER(hOSMemHandle);
 
@@ -303,11 +302,11 @@ static INLINE PVRSRV_ERROR OSUnReserveDiscontigPhys(IMG_VOID *pvCpuVAddr, IMG_SI
 
 PVRSRV_ERROR OSRegisterMem(IMG_CPU_PHYADDR BasePAddr,
                                                        IMG_VOID *pvCpuVAddr,
-                                                       IMG_SIZE_T ui32Bytes,
+                                                       IMG_SIZE_T uBytes,
                                                        IMG_UINT32 ui32Flags,
                                                        IMG_HANDLE *phOSMemHandle);
 PVRSRV_ERROR OSUnRegisterMem(IMG_VOID *pvCpuVAddr,
-                                                       IMG_SIZE_T ui32Bytes,
+                                                       IMG_SIZE_T uBytes,
                                                        IMG_UINT32 ui32Flags,
                                                        IMG_HANDLE hOSMemHandle);
 
@@ -315,8 +314,8 @@ PVRSRV_ERROR OSUnRegisterMem(IMG_VOID *pvCpuVAddr,
 
 #if defined(__linux__) || defined(__QNXNTO__)
 PVRSRV_ERROR OSGetSubMemHandle(IMG_HANDLE hOSMemHandle,
-                                                          IMG_UINTPTR_T ui32ByteOffset,
-                                                          IMG_SIZE_T ui32Bytes,
+                                                          IMG_UINTPTR_T uByteOffset,
+                                                          IMG_SIZE_T uBytes,
                                                           IMG_UINT32 ui32Flags,
                                                           IMG_HANDLE *phOSMemHandleRet);
 PVRSRV_ERROR OSReleaseSubMemHandle(IMG_HANDLE hOSMemHandle, IMG_UINT32 ui32Flags);
@@ -325,13 +324,13 @@ PVRSRV_ERROR OSReleaseSubMemHandle(IMG_HANDLE hOSMemHandle, IMG_UINT32 ui32Flags
 #pragma inline(OSGetSubMemHandle)
 #endif
 static INLINE PVRSRV_ERROR OSGetSubMemHandle(IMG_HANDLE hOSMemHandle,
-                                                                                        IMG_UINTPTR_T ui32ByteOffset,
-                                                                                        IMG_SIZE_T ui32Bytes,
+                                                                                        IMG_UINTPTR_T uByteOffset,
+                                                                                        IMG_SIZE_T uBytes,
                                                                                         IMG_UINT32 ui32Flags,
                                                                                         IMG_HANDLE *phOSMemHandleRet)
 {
-       PVR_UNREFERENCED_PARAMETER(ui32ByteOffset);
-       PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+       PVR_UNREFERENCED_PARAMETER(uByteOffset);
+       PVR_UNREFERENCED_PARAMETER(uBytes);
        PVR_UNREFERENCED_PARAMETER(ui32Flags);
 
        *phOSMemHandleRet = hOSMemHandle;
@@ -348,11 +347,11 @@ static INLINE PVRSRV_ERROR OSReleaseSubMemHandle(IMG_HANDLE hOSMemHandle, IMG_UI
 
 IMG_UINT32 OSGetCurrentProcessIDKM(IMG_VOID);
 IMG_UINTPTR_T OSGetCurrentThreadID( IMG_VOID );
-IMG_VOID OSMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_SIZE_T ui32Size);
+IMG_VOID OSMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_SIZE_T uSize);
 
-PVRSRV_ERROR OSAllocPages_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T ui32Size, IMG_UINT32 ui32PageSize,
+PVRSRV_ERROR OSAllocPages_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uSize, IMG_UINT32 ui32PageSize,
                                                           IMG_PVOID pvPrivData, IMG_UINT32 ui32PrivDataLength, IMG_HANDLE hBMHandle, IMG_PVOID *ppvLinAddr, IMG_HANDLE *phPageAlloc);
-PVRSRV_ERROR OSFreePages(IMG_UINT32 ui32Flags, IMG_SIZE_T ui32Size, IMG_PVOID pvLinAddr, IMG_HANDLE hPageAlloc);
+PVRSRV_ERROR OSFreePages(IMG_UINT32 ui32Flags, IMG_SIZE_T uSize, IMG_PVOID pvLinAddr, IMG_HANDLE hPageAlloc);
 
 
 /*---------------------
@@ -434,14 +433,14 @@ else alias to level 1 wrapper, else the wrapper function will be used*/
 /*If level 1 wrapper is enabled declare the functions with extra parameters
 else alias to level 0 and declare the functions without the extra debugging parameters*/
 #if (defined(__linux__) || defined(__QNXNTO__)) && defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
-       PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T ui32Size, IMG_PVOID *ppvLinAddr, IMG_HANDLE *phBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line);
-       PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T ui32Size, IMG_PVOID pvLinAddr, IMG_HANDLE hBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line);
+       PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uSize, IMG_PVOID *ppvLinAddr, IMG_HANDLE *phBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line);
+       PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uSize, IMG_PVOID pvLinAddr, IMG_HANDLE hBlockAlloc, IMG_CHAR *pszFilename, IMG_UINT32 ui32Line);
        
        #define OSAllocMem_Debug_Linux_Memory_Allocations OSAllocMem_Impl
        #define OSFreeMem_Debug_Linux_Memory_Allocations OSFreeMem_Impl
 #else
-       PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T ui32Size, IMG_PVOID *ppvLinAddr, IMG_HANDLE *phBlockAlloc);
-       PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T ui32Size, IMG_PVOID pvLinAddr, IMG_HANDLE hBlockAlloc);
+       PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uSize, IMG_PVOID *ppvLinAddr, IMG_HANDLE *phBlockAlloc);
+       PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_SIZE_T uSize, IMG_PVOID pvLinAddr, IMG_HANDLE hBlockAlloc);
        
        #define OSAllocMem_Debug_Linux_Memory_Allocations(flags, size, addr, blockAlloc, file, line) \
                OSAllocMem_Impl(flags, size, addr, blockAlloc)
@@ -451,16 +450,16 @@ else alias to level 0 and declare the functions without the extra debugging para
 
 
 #if defined(__linux__) || defined(__QNXNTO__)
-IMG_CPU_PHYADDR OSMemHandleToCpuPAddr(IMG_VOID *hOSMemHandle, IMG_SIZE_T ui32ByteOffset);
+IMG_CPU_PHYADDR OSMemHandleToCpuPAddr(IMG_VOID *hOSMemHandle, IMG_UINTPTR_T uiByteOffset);
 #else
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(OSMemHandleToCpuPAddr)
 #endif
-static INLINE IMG_CPU_PHYADDR OSMemHandleToCpuPAddr(IMG_HANDLE hOSMemHandle, IMG_SIZE_T ui32ByteOffset)
+static INLINE IMG_CPU_PHYADDR OSMemHandleToCpuPAddr(IMG_HANDLE hOSMemHandle, IMG_UINTPTR_T uiByteOffset)
 {
        IMG_CPU_PHYADDR sCpuPAddr;
        PVR_UNREFERENCED_PARAMETER(hOSMemHandle);
-       PVR_UNREFERENCED_PARAMETER(ui32ByteOffset);
+       PVR_UNREFERENCED_PARAMETER(uiByteOffset);
        sCpuPAddr.uiAddr = 0;
        return sCpuPAddr;
 }
@@ -482,20 +481,9 @@ static INLINE IMG_BOOL OSMemHandleIsPhysContig(IMG_HANDLE hOSMemHandle)
 PVRSRV_ERROR OSInitEnvData(IMG_PVOID *ppvEnvSpecificData);
 PVRSRV_ERROR OSDeInitEnvData(IMG_PVOID pvEnvSpecificData);
 IMG_CHAR* OSStringCopy(IMG_CHAR *pszDest, const IMG_CHAR *pszSrc);
-IMG_INT32 OSSNPrintf(IMG_CHAR *pStr, IMG_SIZE_T ui32Size, const IMG_CHAR *pszFormat, ...) IMG_FORMAT_PRINTF(3, 4);
+IMG_INT32 OSSNPrintf(IMG_CHAR *pStr, IMG_SIZE_T uSize, const IMG_CHAR *pszFormat, ...) IMG_FORMAT_PRINTF(3, 4);
 #define OSStringLength(pszString) strlen(pszString)
 
-#if defined (SUPPORT_SID_INTERFACE)
-PVRSRV_ERROR OSEventObjectCreateKM(const IMG_CHAR *pszName,
-                                                                PVRSRV_EVENTOBJECT_KM *psEventObject);
-PVRSRV_ERROR OSEventObjectDestroyKM(PVRSRV_EVENTOBJECT_KM *psEventObject);
-PVRSRV_ERROR OSEventObjectSignalKM(IMG_HANDLE hOSEventKM);
-PVRSRV_ERROR OSEventObjectWaitKM(IMG_HANDLE hOSEventKM);
-PVRSRV_ERROR OSEventObjectOpenKM(PVRSRV_EVENTOBJECT_KM *psEventObject,
-                                                                                       IMG_HANDLE *phOSEvent);
-PVRSRV_ERROR OSEventObjectCloseKM(PVRSRV_EVENTOBJECT_KM *psEventObject,
-                                                                                       IMG_HANDLE hOSEventKM);
-#else
 PVRSRV_ERROR OSEventObjectCreateKM(const IMG_CHAR *pszName,
                                                                 PVRSRV_EVENTOBJECT *psEventObject);
 PVRSRV_ERROR OSEventObjectDestroyKM(PVRSRV_EVENTOBJECT *psEventObject);
@@ -505,17 +493,16 @@ PVRSRV_ERROR OSEventObjectOpenKM(PVRSRV_EVENTOBJECT *psEventObject,
                                                                                        IMG_HANDLE *phOSEvent);
 PVRSRV_ERROR OSEventObjectCloseKM(PVRSRV_EVENTOBJECT *psEventObject,
                                                                                        IMG_HANDLE hOSEventKM);
-#endif /* #if defined (SUPPORT_SID_INTERFACE) */
 
 
-PVRSRV_ERROR OSBaseAllocContigMemory(IMG_SIZE_T ui32Size, IMG_CPU_VIRTADDR *pLinAddr, IMG_CPU_PHYADDR *pPhysAddr);
-PVRSRV_ERROR OSBaseFreeContigMemory(IMG_SIZE_T ui32Size, IMG_CPU_VIRTADDR LinAddr, IMG_CPU_PHYADDR PhysAddr);
+PVRSRV_ERROR OSBaseAllocContigMemory(IMG_SIZE_T uSize, IMG_CPU_VIRTADDR *pLinAddr, IMG_CPU_PHYADDR *pPhysAddr);
+PVRSRV_ERROR OSBaseFreeContigMemory(IMG_SIZE_T uSize, IMG_CPU_VIRTADDR LinAddr, IMG_CPU_PHYADDR PhysAddr);
 
-IMG_PVOID MapUserFromKernel(IMG_PVOID pvLinAddrKM,IMG_SIZE_T ui32Size,IMG_HANDLE *phMemBlock);
+IMG_PVOID MapUserFromKernel(IMG_PVOID pvLinAddrKM,IMG_SIZE_T uSize,IMG_HANDLE *phMemBlock);
 IMG_PVOID OSMapHWRegsIntoUserSpace(IMG_HANDLE hDevCookie, IMG_SYS_PHYADDR sRegAddr, IMG_UINT32 ulSize, IMG_PVOID *ppvProcess);
 IMG_VOID  OSUnmapHWRegsFromUserSpace(IMG_HANDLE hDevCookie, IMG_PVOID pvUserAddr, IMG_PVOID pvProcess);
 
-IMG_VOID  UnmapUserFromKernel(IMG_PVOID pvLinAddrUM, IMG_SIZE_T ui32Size, IMG_HANDLE hMemBlock);
+IMG_VOID  UnmapUserFromKernel(IMG_PVOID pvLinAddrUM, IMG_SIZE_T uSize, IMG_HANDLE hMemBlock);
 
 PVRSRV_ERROR OSMapPhysToUserSpace(IMG_HANDLE hDevCookie,
                                                                  IMG_SYS_PHYADDR sCPUPhysAddr,
@@ -621,7 +608,7 @@ PVRSRV_ERROR OSRemoveTimer (IMG_HANDLE hTimer);
 PVRSRV_ERROR OSEnableTimer (IMG_HANDLE hTimer);
 PVRSRV_ERROR OSDisableTimer (IMG_HANDLE hTimer);
 
-PVRSRV_ERROR OSGetSysMemSize(IMG_SIZE_T *pui32Bytes);
+PVRSRV_ERROR OSGetSysMemSize(IMG_SIZE_T *puBytes);
 
 typedef enum _HOST_PCI_INIT_FLAGS_
 {
@@ -668,14 +655,14 @@ typedef enum _img_verify_test
        PVR_VERIFY_READ
 } IMG_VERIFY_TEST;
 
-IMG_BOOL OSAccessOK(IMG_VERIFY_TEST eVerification, IMG_VOID *pvUserPtr, IMG_SIZE_T ui32Bytes);
+IMG_BOOL OSAccessOK(IMG_VERIFY_TEST eVerification, IMG_VOID *pvUserPtr, IMG_SIZE_T uBytes);
 
-PVRSRV_ERROR OSCopyToUser(IMG_PVOID pvProcess, IMG_VOID *pvDest, IMG_VOID *pvSrc, IMG_SIZE_T ui32Bytes);
-PVRSRV_ERROR OSCopyFromUser(IMG_PVOID pvProcess, IMG_VOID *pvDest, IMG_VOID *pvSrc, IMG_SIZE_T ui32Bytes);
+PVRSRV_ERROR OSCopyToUser(IMG_PVOID pvProcess, IMG_VOID *pvDest, IMG_VOID *pvSrc, IMG_SIZE_T uBytes);
+PVRSRV_ERROR OSCopyFromUser(IMG_PVOID pvProcess, IMG_VOID *pvDest, IMG_VOID *pvSrc, IMG_SIZE_T uBytes);
 
 #if defined(__linux__) || defined(__QNXNTO__)
 PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID* pvCPUVAddr, 
-                                                                       IMG_SIZE_T ui32Bytes, 
+                                                                       IMG_SIZE_T uBytes, 
                                                                        IMG_SYS_PHYADDR *psSysPAddr,
                                                                        IMG_HANDLE *phOSWrapMem);
 PVRSRV_ERROR OSReleasePhysPageAddr(IMG_HANDLE hOSWrapMem);
@@ -684,12 +671,12 @@ PVRSRV_ERROR OSReleasePhysPageAddr(IMG_HANDLE hOSWrapMem);
 #pragma inline(OSAcquirePhysPageAddr)
 #endif
 static INLINE PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID* pvCPUVAddr, 
-                                                                                               IMG_SIZE_T ui32Bytes, 
+                                                                                               IMG_SIZE_T uBytes, 
                                                                                                IMG_SYS_PHYADDR *psSysPAddr,
                                                                                                IMG_HANDLE *phOSWrapMem)
 {
        PVR_UNREFERENCED_PARAMETER(pvCPUVAddr);
-       PVR_UNREFERENCED_PARAMETER(ui32Bytes);
+       PVR_UNREFERENCED_PARAMETER(uBytes);
        PVR_UNREFERENCED_PARAMETER(psSysPAddr);
        PVR_UNREFERENCED_PARAMETER(phOSWrapMem);
        return PVRSRV_OK;       
@@ -781,6 +768,12 @@ static INLINE IMG_VOID OSGetCurrentProcessNameKM(IMG_CHAR *pszName, IMG_UINT32 u
 
 #endif
 
+#if defined(__linux__) && defined(DEBUG)
+#define OSDumpStack dump_stack
+#else
+#define OSDumpStack()
+#endif
+
 #if defined (__cplusplus)
 }
 #endif
index e4325cc..a101d88 100644 (file)
@@ -77,6 +77,8 @@ extern IMG_UINT32 g_ui32EveryLineCounter;
 #define MAKEUNIQUETAG(hMemInfo)        (0)
 #endif
 
+IMG_BOOL _PDumpIsProcessActive(IMG_VOID);
+
 #ifdef PDUMP
 
 #define MAKEUNIQUETAG(hMemInfo)        (((BM_BUF *)(((PVRSRV_KERNEL_MEM_INFO *)(hMemInfo))->sMemBlk.hBuffer))->pMapping)
@@ -267,8 +269,8 @@ extern IMG_UINT32 g_ui32EveryLineCounter;
                                                                  IMG_HANDLE                            hOSMemHandle,
                                                                  IMG_UINT32                            ui32NumBytes,
                                                                  IMG_UINT32                            ui32PageSize,
-                                         IMG_BOOL                                      bShared,
-                                                                 IMG_HANDLE                            hUniqueTag);
+                                                                 IMG_HANDLE                            hUniqueTag,
+                                                                 IMG_UINT32                            ui32Flags);
        PVRSRV_ERROR PDumpMallocPageTable(PVRSRV_DEVICE_IDENTIFIER      *psDevId,
                                                                          IMG_HANDLE            hOSMemHandle,
                                                                          IMG_UINT32            ui32Offset,
@@ -282,7 +284,8 @@ extern IMG_UINT32 g_ui32EveryLineCounter;
                                                        IMG_UINT32                      ui32PageSize,
                                                        IMG_HANDLE              hUniqueTag,
                                                        IMG_BOOL                        bInterleaved,
-                                                       IMG_BOOL                        bSparse);
+                                                       IMG_BOOL                        bSparse,
+                                                       IMG_UINT32                      ui32Flags);
        PVRSRV_ERROR PDumpFreePageTable(PVRSRV_DEVICE_IDENTIFIER *psDevID,
                                                                        IMG_HANDLE          hOSMemHandle,
                                                                        IMG_CPU_VIRTADDR        pvLinAddr,
index 0f2e103..9fc1fd8 100644 (file)
@@ -58,7 +58,10 @@ extern "C" {
  * supported (e.g. Linux).
  */
 #define MAX_PDUMP_STRING_LENGTH (256)
-#if  defined(__QNXNTO__)
+
+
+#if defined(__QNXNTO__)
+
 #define PDUMP_GET_SCRIPT_STRING()      \
        IMG_CHAR pszScript[MAX_PDUMP_STRING_LENGTH];            \
        IMG_UINT32      ui32MaxLen = MAX_PDUMP_STRING_LENGTH-1; \
@@ -79,7 +82,12 @@ extern "C" {
        IMG_UINT32      ui32MaxLenFileName = MAX_PDUMP_STRING_LENGTH-1; \
        IMG_HANDLE      hScript = (IMG_HANDLE)pszScript;
 
-#else /* WIN32 or QNX */
+#define PDUMP_LOCK(args...)
+#define PDUMP_UNLOCK(args...)
+#define PDUMP_LOCK_MSG(args...)
+#define PDUMP_UNLOCK_MSG(args...)
+
+#else  /* __QNXNTO__ */
 
 
        /*
@@ -117,6 +125,48 @@ extern "C" {
        eError = PDumpOSGetFilenameString(&pszFileName, &ui32MaxLenFileName);\
        if(eError != PVRSRV_OK) return eError;
 
+#define PDUMP_LOCK()           \
+       PDumpOSLock(__LINE__);
+
+#define PDUMP_UNLOCK()         \
+       PDumpOSUnlock(__LINE__);
+
+#define PDUMP_LOCK_MSG()               \
+       PDumpOSLockMessageBuffer();
+
+#define PDUMP_UNLOCK_MSG()             \
+       PDumpOSUnlockMessageBuffer();
+
+       /*!
+        * @name        PDumpOSLock
+        * @brief       Lock the PDump streams
+        * @return      error none
+        */
+       IMG_VOID PDumpOSLock(IMG_UINT32 ui32Line);
+
+       /*!
+        * @name        PDumpOSUnlock
+        * @brief       Lock the PDump streams
+        * @return      error none
+        */
+       IMG_VOID PDumpOSUnlock(IMG_UINT32 ui32Line);
+
+       /*!
+        * @name        PDumpOSLockMessageBuffer
+        * @brief       Lock the PDump message buffer
+        * @return      error none
+        */
+       IMG_VOID PDumpOSLockMessageBuffer(IMG_VOID);
+
+       /*!
+        * @name        PDumpOSUnlockMessageBuffer
+        * @brief       Lock the PDump message buffer
+        * @return      error none
+        */
+       IMG_VOID PDumpOSUnlockMessageBuffer(IMG_VOID);
+
+#endif /* __QNXNTO__ */
+
        /*!
         * @name        PDumpOSGetScriptString
         * @brief       Get the "script" buffer
@@ -147,8 +197,6 @@ extern "C" {
         */
        PVRSRV_ERROR PDumpOSGetFilenameString(IMG_CHAR **ppszFile, IMG_UINT32 *pui32MaxLen);
 
-#endif /* WIN32 or QNX */
-
 
 /*
  * Define macro for processing variable args list in OS-independent
@@ -305,13 +353,13 @@ IMG_VOID PDumpOSCPUVAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType,
  * @param      hOSMemHandle    mem allocation handle (used if kernel virtual mem space is limited, e.g. linux)
  * @param      ui32Offset              offset within mem allocation block
  * @param      pui8LinAddr             CPU linear addr
- * @param      ui32DataPageMask        mask for data page (= data page size -1)
+ * @param      uiDataPageMask  mask for data page (= data page size -1)
  * @return     pui32PageOffset CPU page offset (same as device page offset if page sizes equal)
  */
 IMG_VOID PDumpOSCPUVAddrToPhysPages(IMG_HANDLE hOSMemHandle,
                IMG_UINT32 ui32Offset,
                IMG_PUINT8 pui8LinAddr,
-               IMG_UINT32 ui32DataPageMask,
+               IMG_UINTPTR_T uiDataPageMask,
                IMG_UINT32 *pui32PageOffset);
 
 /*!
index d603613..124f2f2 100644 (file)
@@ -56,21 +56,12 @@ typedef struct _PVRSRV_PER_PROCESS_DATA_
        IMG_UINT32              ui32PID;
        IMG_HANDLE              hBlockAlloc;
        PRESMAN_CONTEXT         hResManContext;
-#if defined (SUPPORT_SID_INTERFACE)
-       IMG_SID                 hPerProcData;
-#else
        IMG_HANDLE              hPerProcData;
-#endif
        PVRSRV_HANDLE_BASE      *psHandleBase;
-#if defined (SUPPORT_SID_INTERFACE)
-       /* Handles are being allocated in batches */
-       IMG_BOOL                bHandlesBatched;
-#else
 #if defined (PVR_SECURE_HANDLES)
        /* Handles are being allocated in batches */
        IMG_BOOL                bHandlesBatched;
 #endif  /* PVR_SECURE_HANDLES */
-#endif /* SUPPORT_SID_INTERFACE */
        IMG_UINT32              ui32RefCount;
 
        /* True if the process is the initialisation server. */
index 58f8093..49408ec 100644 (file)
@@ -51,9 +51,9 @@ extern "C" {
 /*!
  * Macro to Read Offset in given command queue
  */
-#define UPDATE_QUEUE_ROFF(psQueue, ui32Size)                                           \
-       (psQueue)->ui32ReadOffset = ((psQueue)->ui32ReadOffset + (ui32Size))    \
-       & ((psQueue)->ui32QueueSize - 1);
+#define UPDATE_QUEUE_ROFF(psQueue, uSize)                                              \
+       (psQueue)->uReadOffset = ((psQueue)->uReadOffset + (uSize))     \
+       & ((psQueue)->uQueueSize - 1);
 
 /*!
        generic cmd complete structure.
@@ -75,6 +75,11 @@ extern "C" {
        IMG_UINT32                      ui32AllocSize;          /*!< allocated size*/
        PFN_QUEUE_COMMAND_COMPLETE      pfnCommandComplete;     /*!< Command complete callback */
        IMG_HANDLE                                      hCallbackData;          /*!< Command complete callback data */
+
+#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
+       IMG_VOID                        *pvCleanupFence;        /*!< Sync fence to 'put' after timeline inc() */
+       IMG_VOID                        *pvTimeline;            /*!< Android sync timeline to inc() */
+#endif
  }COMMAND_COMPLETE_DATA, *PCOMMAND_COMPLETE_DATA;
 
 #if !defined(USE_CODE)
@@ -92,7 +97,7 @@ void ProcSeqShowQueue(struct seq_file *sfile,void* el);
 
 
 IMG_IMPORT
-PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T ui32QueueSize,
+PVRSRV_ERROR IMG_CALLCONV PVRSRVCreateCommandQueueKM(IMG_SIZE_T uQueueSize,
                                                                                                         PVRSRV_QUEUE_INFO **ppsQueueInfo);
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVDestroyCommandQueueKM(PVRSRV_QUEUE_INFO *psQueueInfo);
@@ -108,11 +113,12 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVInsertCommandKM(PVRSRV_QUEUE_INFO *psQueue,
                                                                                                PVRSRV_KERNEL_SYNC_INFO *apsSrcSync[],
                                                                                                IMG_SIZE_T                      ui32DataByteSize,
                                                                                                PFN_QUEUE_COMMAND_COMPLETE pfnCommandComplete,
-                                                                                               IMG_HANDLE                      hCallbackData);
+                                                                                               IMG_HANDLE                      hCallbackData,
+                                                                                               IMG_HANDLE                      *phFence);
 
 IMG_IMPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVGetQueueSpaceKM(PVRSRV_QUEUE_INFO *psQueue,
-                                                                                               IMG_SIZE_T ui32ParamSize,
+                                                                                               IMG_SIZE_T uParamSize,
                                                                                                IMG_VOID **ppvSpace);
 
 IMG_IMPORT
index 0e3479d..a2efd6c 100644 (file)
@@ -43,6 +43,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define __REFCOUNT_H__
 
 #include "pvr_bridge_km.h"
+#if defined(SUPPORT_ION)
+#include "ion_sync.h"
+#endif /* defined(SUPPORT_ION) */
 
 #if defined(PVRSRV_REFCOUNT_DEBUG)
 
@@ -111,6 +114,23 @@ void PVRSRVOffsetStructIncMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
 void PVRSRVOffsetStructDecMapped2(const IMG_CHAR *pszFile, IMG_INT iLine,
                                                                  PKV_OFFSET_STRUCT psOffsetStruct);
 
+#if defined(SUPPORT_ION)
+#define PVRSRVIonBufferSyncInfoIncRef(x...) \
+       PVRSRVIonBufferSyncInfoIncRef2(__FILE__, __LINE__, x)
+#define PVRSRVIonBufferSyncInfoDecRef(x...) \
+       PVRSRVIonBufferSyncInfoDecRef2(__FILE__, __LINE__, x)
+
+PVRSRV_ERROR PVRSRVIonBufferSyncInfoIncRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
+                                                                                       IMG_HANDLE hUnique,
+                                                                                       IMG_HANDLE hDevCookie,
+                                                                                       IMG_HANDLE hDevMemContext,
+                                                                                       PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo,
+                                                                                       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
+void PVRSRVIonBufferSyncInfoDecRef2(const IMG_CHAR *pszFile, IMG_INT iLine,
+                                                                       PVRSRV_ION_SYNC_INFO *psIonSyncInfo,
+                                                                       PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo);
+#endif /* defined (SUPPORT_ION) */
+
 #endif /* defined(__linux__) */
 
 #else /* defined(PVRSRV_REFCOUNT_DEBUG) */
@@ -196,6 +216,29 @@ static INLINE void PVRSRVOffsetStructDecMapped(PKV_OFFSET_STRUCT psOffsetStruct)
        psOffsetStruct->ui32Mapped--;
 }
 
+#if defined(SUPPORT_ION)
+static INLINE PVRSRV_ERROR PVRSRVIonBufferSyncInfoIncRef(IMG_HANDLE hUnique,
+                                                                                                                IMG_HANDLE hDevCookie,
+                                                                                                                IMG_HANDLE hDevMemContext,
+                                                                                                                PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo,
+                                                                                                                PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
+{
+       PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
+
+       return PVRSRVIonBufferSyncAcquire(hUnique,
+                                                                         hDevCookie,
+                                                                         hDevMemContext,
+                                                                         ppsIonSyncInfo);
+}
+
+static INLINE void PVRSRVIonBufferSyncInfoDecRef(PVRSRV_ION_SYNC_INFO *psIonSyncInfo,
+                                                                                  PVRSRV_KERNEL_MEM_INFO *psKernelMemInfo)
+{
+       PVR_UNREFERENCED_PARAMETER(psKernelMemInfo);
+       PVRSRVIonBufferSyncRelease(psIonSyncInfo);
+}
+#endif /* defined (SUPPORT_ION) */
+
 #endif /* defined(__linux__) */
 
 #endif /* defined(PVRSRV_REFCOUNT_DEBUG) */
index 5153a8b..6ac57df 100644 (file)
@@ -116,11 +116,7 @@ typedef struct _SYS_DATA_TAG_
        RA_ARENA                                        *apsLocalDevMemArena[SYS_MAX_LOCAL_DEVMEM_ARENAS]; /*!< RA Arenas for local device memory heap management */
 
     IMG_CHAR                    *pszVersionString;          /*!< Human readable string showing relevent system version info */
-#if defined (SUPPORT_SID_INTERFACE)
-       PVRSRV_EVENTOBJECT_KM           *psGlobalEventObject;           /*!< OS Global Event Object */
-#else
        PVRSRV_EVENTOBJECT                      *psGlobalEventObject;           /*!< OS Global Event Object */
-#endif
 
        PVRSRV_MISC_INFO_CPUCACHEOP_TYPE ePendingCacheOpType;   /*!< Deferred CPU cache op control */
 
similarity index 95%
rename from services4/system/omap4/sysconfig.c
rename to services4/system/omap/sysconfig.c
index a82f1b2..dd6aec6 100644 (file)
@@ -163,7 +163,7 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
         */
 
        /* Registers */
-       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP4430_SGX_REGS_SIZE;
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP_SGX_REGS_SIZE;
 
        eError = OSBaseAllocContigMemory(gsSGXDeviceMap.ui32RegsSize,
                                                                         &gsSGXRegsCPUVAddr,
@@ -215,17 +215,22 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
        PVR_TRACE(("SGX register base: 0x%lx", (unsigned long)gsSGXDeviceMap.sRegsCpuPBase.uiAddr));
 
+#if defined(SGX544) && defined(SGX_FEATURE_MP)
+       /* FIXME: Workaround due to HWMOD change. Otherwise this region is too small. */
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP_SGX_REGS_SIZE;
+#else
        gsSGXDeviceMap.ui32RegsSize = (unsigned int)(dev_res->end - dev_res->start);
+#endif
        PVR_TRACE(("SGX register size: %d",gsSGXDeviceMap.ui32RegsSize));
 
        gsSGXDeviceMap.ui32IRQ = dev_irq;
        PVR_TRACE(("SGX IRQ: %d", gsSGXDeviceMap.ui32IRQ));
 #else  /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
-       gsSGXDeviceMap.sRegsSysPBase.uiAddr = SYS_OMAP4430_SGX_REGS_SYS_PHYS_BASE;
+       gsSGXDeviceMap.sRegsSysPBase.uiAddr = SYS_OMAP_SGX_REGS_SYS_PHYS_BASE;
        gsSGXDeviceMap.sRegsCpuPBase = SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
-       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP4430_SGX_REGS_SIZE;
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP_SGX_REGS_SIZE;
 
-       gsSGXDeviceMap.ui32IRQ = SYS_OMAP4430_SGX_IRQ;
+       gsSGXDeviceMap.ui32IRQ = SYS_OMAP_SGX_IRQ;
 
 #endif /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
 #if defined(SGX_OCP_REGS_ENABLED)
@@ -274,46 +279,19 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 static IMG_CHAR *SysCreateVersionString(void)
 {
        static IMG_CHAR aszVersionString[100];
+       IMG_UINT32 ui32MaxStrLen;
        SYS_DATA        *psSysData;
        IMG_UINT32      ui32SGXRevision;
        IMG_INT32       i32Count;
-#if !defined(NO_HARDWARE)
-       IMG_VOID        *pvRegsLinAddr;
-
-       pvRegsLinAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
-                                                                  gsSGXDeviceMap.ui32RegsSize,
-                                                                  PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                                                  IMG_NULL);
-       if(!pvRegsLinAddr)
-       {
-               return IMG_NULL;
-       }
-
-       ui32SGXRevision = OSReadHWReg((IMG_PVOID)((IMG_PBYTE)pvRegsLinAddr),
-                                                                 EUR_CR_CORE_REVISION);
-#else
-       ui32SGXRevision = 0;
-#endif
 
        SysAcquireData(&psSysData);
 
-       i32Count = OSSNPrintf(aszVersionString, 100,
-                                                 "SGX revision = %u.%u.%u",
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAJOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAJOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MINOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MINOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAINTENANCE_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAINTENANCE_SHIFT)
-                                                );
-
-#if !defined(NO_HARDWARE)
-       OSUnMapPhysToLin(pvRegsLinAddr,
-                                        SYS_OMAP4430_SGX_REGS_SIZE,
-                                        PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                        IMG_NULL);
-#endif
+       ui32SGXRevision = SGX_CORE_REV;
+       ui32MaxStrLen = 99;
 
+       i32Count = OSSNPrintf(aszVersionString, ui32MaxStrLen + 1,
+                       "SGX revision = %u",
+                       (IMG_UINT)(ui32SGXRevision));
        if(i32Count == -1)
        {
                return IMG_NULL;
@@ -536,7 +514,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        TimerRegPhysBase = gsSysSpecificData.sTimerRegPhysBase;
 #else
-       TimerRegPhysBase.uiAddr = SYS_OMAP4430_GP11TIMER_REGS_SYS_PHYS_BASE;
+       TimerRegPhysBase.uiAddr = SYS_OMAP_GP11TIMER_REGS_SYS_PHYS_BASE;
 #endif
        gpsSysData->pvSOCTimerRegisterKM = IMG_NULL;
        gpsSysData->hSOCTimerRegisterOSMemHandle = 0;
@@ -685,7 +663,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 #endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
                /* Deinitialise SGX */
-               eError = PVRSRVDeinitialiseDevice (gui32SGXDeviceID);
+               eError = PVRSRVDeinitialiseDevice(gui32SGXDeviceID);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: failed to de-init the device"));
@@ -693,6 +671,12 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
                }
        }
 
+       /* Disable system clocks. Must happen after last access to hardware */
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
+       {
+               DisableSystemClocks(gpsSysData);
+       }
+
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT))
        {
                eError = SysDvfsDeinitialize(gpsSysSpecificData);
@@ -715,14 +699,6 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
                }
        }
 
-       /*
-               Disable system clocks - must happen after last access to hardware.
-        */
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
-       {
-               DisableSystemClocks(gpsSysData);
-       }
-
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_ENVDATA))
        {       
                eError = OSDeInitEnvData(gpsSysData->pvEnvSpecificData);
@@ -740,7 +716,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        {
 #if defined(NO_HARDWARE)
                /* Free hardware resources. */
-               OSBaseFreeContigMemory(SYS_OMAP4430_SGX_REGS_SIZE, gsSGXRegsCPUVAddr, gsSGXDeviceMap.sRegsCpuPBase);
+               OSBaseFreeContigMemory(SYS_OMAP_SGX_REGS_SIZE, gsSGXRegsCPUVAddr, gsSGXDeviceMap.sRegsCpuPBase);
 #else
 #if defined(SGX_OCP_REGS_ENABLED)
                OSUnMapPhysToLin(gsSGXRegsCPUVAddr,
similarity index 76%
rename from services4/system/omap4/sysconfig.h
rename to services4/system/omap/sysconfig.h
index 64f3187..b4ad4f4 100644 (file)
@@ -45,11 +45,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #define VS_PRODUCT_NAME        "OMAP4"
 
-#if defined(SGX540) && (SGX_CORE_REV == 120)
-#define SYS_SGX_CLOCK_SPEED            307200000
-#else
-#define SYS_SGX_CLOCK_SPEED            304742400
-#endif
 
 #define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   // 10ms (100hz)
 #define SYS_SGX_PDS_TIMER_FREQ                         (1000)  // 1ms (1000hz)
@@ -60,30 +55,30 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 
-#define SYS_OMAP4430_SGX_REGS_SYS_PHYS_BASE  0x56000000
-#define SYS_OMAP4430_SGX_REGS_SIZE           0xFFFF
+#define SYS_OMAP_SGX_REGS_SYS_PHYS_BASE  0x56000000
+#define SYS_OMAP_SGX_REGS_SIZE           0xFFFF
 
-#define SYS_OMAP4430_SGX_IRQ                            53 /* OMAP4 IRQ's are offset by 32 */
+#define SYS_OMAP_SGX_IRQ                                53 /* OMAP4 IRQ's are offset by 32 */
 
-#define SYS_OMAP4430_DSS_REGS_SYS_PHYS_BASE  0x58000000
-#define SYS_OMAP4430_DSS_REGS_SIZE           0x7000
+#define SYS_OMAP_DSS_REGS_SYS_PHYS_BASE  0x58000000
+#define SYS_OMAP_DSS_REGS_SIZE           0x7000
 
-#define SYS_OMAP4430_DSS_HDMI_INTERRUPT_STATUS_REG 0x6028
-#define SYS_OMAP4430_DSS_HDMI_INTERRUPT_ENABLE_REG 0x602c
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_STATUS_REG 0x6028
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_ENABLE_REG 0x602c
 
-#define SYS_OMAP4430_DSS_HDMI_INTERRUPT_VSYNC_ENABLE_MASK 0x10000
-#define SYS_OMAP4430_DSS_HDMI_INTERRUPT_VSYNC_STATUS_MASK 0x10000
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_ENABLE_MASK 0x10000
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_STATUS_MASK 0x10000
 
-#define SYS_OMAP4430_DSS_LCD_INTERRUPT_STATUS_REG 0x1018
-#define SYS_OMAP4430_DSS_LCD_INTERRUPT_ENABLE_REG 0x101c
+#define SYS_OMAP_DSS_LCD_INTERRUPT_STATUS_REG 0x1018
+#define SYS_OMAP_DSS_LCD_INTERRUPT_ENABLE_REG 0x101c
 
-#define SYS_OMAP4430_DSS_LCD_INTERRUPT_VSYNC_ENABLE_MASK 0x40002
-#define SYS_OMAP4430_DSS_LCD_INTERRUPT_VSYNC_STATUS_MASK 0x40002
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_ENABLE_MASK 0x40002
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_STATUS_MASK 0x40002
 
 
-#define SYS_OMAP4430_GP11TIMER_ENABLE_SYS_PHYS_BASE    0x48088038
-#define SYS_OMAP4430_GP11TIMER_REGS_SYS_PHYS_BASE      0x4808803C
-#define SYS_OMAP4430_GP11TIMER_TSICR_SYS_PHYS_BASE     0x48088054
+#define SYS_OMAP_GP11TIMER_ENABLE_SYS_PHYS_BASE        0x48088038
+#define SYS_OMAP_GP11TIMER_REGS_SYS_PHYS_BASE  0x4808803C
+#define SYS_OMAP_GP11TIMER_TSICR_SYS_PHYS_BASE 0x48088054
 
 /* Interrupt bits */
 #define DEVICE_SGX_INTERRUPT           (1<<0)
similarity index 95%
rename from services4/system/omap4/sysinfo.h
rename to services4/system/omap/sysinfo.h
index 70ae148..84febab 100644 (file)
@@ -43,6 +43,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #if !defined(__SYSINFO_H__)
 #define __SYSINFO_H__
 
+#if defined(SGX540) && (SGX_CORE_REV == 120)
+#define SYS_SGX_CLOCK_SPEED            307200000
+#else
+#define SYS_SGX_CLOCK_SPEED            304742400
+#endif
+
 /*!< System specific poll/timeout details */
 #if defined(PVR_LINUX_USING_WORKQUEUES)
 /*
similarity index 98%
rename from services4/system/omap4/syslocal.h
rename to services4/system/omap/syslocal.h
index 21e9675..89db8ee 100644 (file)
@@ -103,9 +103,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #if defined(__linux__)
 #if defined(SGX_OCP_REGS_ENABLED)
+/* FIXME: Temporary workaround for OMAP4470 and active power off in 4430 */
+#if !defined(SGX544) && defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
 #define SGX_OCP_NO_INT_BYPASS
 #endif
 #endif
+#endif
 
 #if defined (__cplusplus)
 extern "C" {
similarity index 93%
rename from services4/system/omap4/sysutils_linux.c
rename to services4/system/omap/sysutils_linux.c
index ebc4b05..5c5db21 100644 (file)
@@ -57,7 +57,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 
-#if defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
 #include <linux/opp.h>
 #endif
 
@@ -156,10 +156,10 @@ IMG_VOID SysGetSGXTimingInformation(SGX_TIMING_INFORMATION *psTimingInfo)
 #if !defined(NO_HARDWARE)
        PVR_ASSERT(atomic_read(&gpsSysSpecificData->sSGXClocksEnabled) != 0);
 #endif
-#if defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        psTimingInfo->ui32CoreClockSpeed =
                gpsSysSpecificData->pui32SGXFreqList[gpsSysSpecificData->ui32SGXFreqListIndex];
-#else /* defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#else /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
        psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
 #endif
        psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ;
@@ -196,7 +196,7 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
        PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-#if defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        {
                struct gpu_platform_data *pdata;
                IMG_UINT32 max_freq_index;
@@ -215,7 +215,9 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                {
                        PVR_ASSERT(pdata->device_scale != IMG_NULL);
                        res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
                                                                          &gpsPVRLDMDev->dev,
+#endif
                                                                          psSysSpecData->pui32SGXFreqList[max_freq_index]);
                        if (res == 0)
                        {
@@ -233,7 +235,7 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                        }
                }
        }
-#endif /* defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
        {
                /*
                 * pm_runtime_get_sync returns 1 after the module has
@@ -293,7 +295,7 @@ IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
                        PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
                }
        }
-#if defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        {
                struct gpu_platform_data *pdata;
                int res;
@@ -310,7 +312,9 @@ IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
                {
                        PVR_ASSERT(pdata->device_scale != IMG_NULL);
                        res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
                                                                          &gpsPVRLDMDev->dev,
+#endif
                                                                          psSysSpecData->pui32SGXFreqList[0]);
                        if (res == 0)
                        {
@@ -328,7 +332,7 @@ IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
                        }
                }
        }
-#endif /* defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
 #endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
        /* Indicate that the SGX clocks are disabled */
@@ -356,6 +360,14 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_ASSERT(psSysSpecData->psGPTimer == NULL);
 
+       /*
+        * This code has problems on module reload for OMAP5 running Linux
+        * 3.4.10, due to omap2_dm_timer_set_src (called by
+        * omap_dm_timer_request_specific), being unable to set the parent
+        * clock to OMAP_TIMER_SRC_32_KHZ.
+        * Not calling omap_dm_timer_set_source doesn't help.
+        */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) || !defined(MODULE)
        /*
         * This code could try requesting registers 9, 10, and 11,
         * stopping at the first succesful request.  We'll stick with
@@ -370,7 +382,6 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
        }
 
-       /* Set timer source to system clock */
        omap_dm_timer_set_source(psSysSpecData->psGPTimer, OMAP_TIMER_SRC_SYS_CLK);
        omap_dm_timer_enable(psSysSpecData->psGPTimer);
 
@@ -380,10 +391,13 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        omap_dm_timer_start(psSysSpecData->psGPTimer);
 
        /*
-        * The DM timer API doesn't have a mechansim for obtaining the
+        * The DM timer API doesn't have a mechanism for obtaining the
         * physical address of the counter register.
         */
-       psSysSpecData->sTimerRegPhysBase.uiAddr = SYS_OMAP4430_GP11TIMER_REGS_SYS_PHYS_BASE;
+       psSysSpecData->sTimerRegPhysBase.uiAddr = SYS_OMAP_GP11TIMER_REGS_SYS_PHYS_BASE;
+#else  /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
+       (void)psSysSpecData;
+#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
 
        return PVRSRV_OK;
 }
@@ -497,7 +511,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 #endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 
        /* Set the timer to non-posted mode */
-       sTimerRegPhysBase.uiAddr = SYS_OMAP4430_GP11TIMER_TSICR_SYS_PHYS_BASE;
+       sTimerRegPhysBase.uiAddr = SYS_OMAP_GP11TIMER_TSICR_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
                   PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -523,7 +537,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                    hTimerEnable);
 
        /* Enable the timer */
-       sTimerRegPhysBase.uiAddr = SYS_OMAP4430_GP11TIMER_ENABLE_SYS_PHYS_BASE;
+       sTimerRegPhysBase.uiAddr = SYS_OMAP_GP11TIMER_ENABLE_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
                   PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -695,9 +709,9 @@ PVRSRV_ERROR SysPMRuntimeUnregister(void)
 
 PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
 {
-#if !defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK)
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
-#else /* !defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
        IMG_UINT32 i, *freq_list;
        IMG_INT32 opp_count;
        unsigned long freq;
@@ -758,16 +772,16 @@ PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
 
        /* Start in unknown state - no frequency request to DVFS yet made */
        psSysSpecificData->ui32SGXFreqListIndex = opp_count;
-#endif /* !defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
 
        return PVRSRV_OK;
 }
 
 PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
 {
-#if !defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK)
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
-#else /* !defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
        /*
         * We assume this function is only called if SysDvfsInitialize() was
         * completed successfully before.
@@ -787,7 +801,9 @@ PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
 
                PVR_ASSERT(pdata->device_scale != IMG_NULL);
                res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
                                                                  &gpsPVRLDMDev->dev,
+#endif
                                                                  psSysSpecificData->pui32SGXFreqList[0]);
                if (res == -EBUSY)
                {
@@ -804,7 +820,7 @@ PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
        kfree(psSysSpecificData->pui32SGXFreqList);
        psSysSpecificData->pui32SGXFreqList = 0;
        psSysSpecificData->ui32SGXFreqListSize = 0;
-#endif /* !defined(SYS_OMAP4_HAS_DVFS_FRAMEWORK) */
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
 
        return PVRSRV_OK;
 }
index c8eea1e..0902042 100644 (file)
@@ -1,28 +1,43 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          SGX kernel/client driver interface structures and prototypes
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__OEMFUNCS_H__)
 #define __OEMFUNCS_H__
 extern "C" {
 #endif
 
+/* function in/out data structures: */
 typedef IMG_UINT32   (*PFN_SRV_BRIDGEDISPATCH)( IMG_UINT32  Ioctl,
                                                                                                IMG_BYTE   *pInBuf,
                                                                                                IMG_UINT32  InBufLen, 
                                                                                            IMG_BYTE   *pOutBuf,
                                                                                                IMG_UINT32  OutBufLen,
                                                                                                IMG_UINT32 *pdwBytesTransferred);
+/*
+       Function table for kernel 3rd party driver to kernel services
+*/
 typedef struct PVRSRV_DC_OEM_JTABLE_TAG
 {
        PFN_SRV_BRIDGEDISPATCH                  pfnOEMBridgeDispatch;
@@ -52,5 +71,10 @@ typedef struct PVRSRV_DC_OEM_JTABLE_TAG
 }
 #endif
 
-#endif 
+#endif /* __OEMFUNCS_H__ */
+
+/*****************************************************************************
+ End of file (oemfuncs.h)
+*****************************************************************************/
+
 
index 1513950..650e01a 100644 (file)
@@ -1,28 +1,44 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Configuration
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    System Configuration functions
+@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.
+*/ /**************************************************************************/
 
 #include "sysconfig.h"
 #include "services_headers.h"
 
 #include "ocpdefs.h"
 
+/* top level system data anchor point*/
 SYS_DATA* gpsSysData = (SYS_DATA*)IMG_NULL;
 SYS_DATA  gsSysData;
 
 static SYS_SPECIFIC_DATA gsSysSpecificData;
 SYS_SPECIFIC_DATA *gpsSysSpecificData;
 
-static IMG_UINT32      gui32SGXDeviceID;
-static SGX_DEVICE_MAP  gsSGXDeviceMap;
-static PVRSRV_DEVICE_NODE *gpsSGXDevNode;
+/* SGX structures */
+static IMG_UINT32                      gui32SGXDeviceID;
+static SGX_DEVICE_MAP          gsSGXDeviceMap;
+static PVRSRV_DEVICE_NODE      *gpsSGXDevNode;
 
-#define DEVICE_SGX_INTERRUPT (1 << 0)
 
 #if defined(NO_HARDWARE) || defined(SGX_OCP_REGS_ENABLED)
 static IMG_CPU_VIRTADDR gsSGXRegsCPUVAddr;
@@ -79,14 +96,14 @@ static PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
        return eError;
 }
 
-#else 
+#else /* defined(SGX_OCP_REGS_ENABLED) */
 
 static INLINE PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
 {
        return EnableSGXClocks(psSysData);
 }
 
-#endif 
+#endif /* defined(SGX_OCP_REGS_ENABLED) */
 
 static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
 {
@@ -95,7 +112,10 @@ static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
 #if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
        if(eError == PVRSRV_OK)
        {
-               
+               /*
+                * The SGX Clocks are enabled separately if active power
+                * management is enabled.
+                */
                eError = EnableSGXClocksWrap(psSysData);
                if (eError != PVRSRV_OK)
                {
@@ -107,6 +127,18 @@ static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
        return eError;
 }
 
+/*!
+******************************************************************************
+
+ @Function     SysLocateDevices
+
+ @Description  Specifies devices in the systems memory map
+
+ @Input                psSysData - sys data
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 {
 #if defined(NO_HARDWARE)
@@ -121,12 +153,16 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 
        PVR_UNREFERENCED_PARAMETER(psSysData);
 
-       
+       /* SGX Device: */
        gsSGXDeviceMap.ui32Flags = 0x0;
        
 #if defined(NO_HARDWARE)
-       
-       
+       /* 
+        * For no hardware, allocate some contiguous memory for the
+        * register block.
+        */
+
+       /* Registers */
        gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;
 
        eError = OSBaseAllocContigMemory(gsSGXDeviceMap.ui32RegsSize,
@@ -139,23 +175,27 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
        gsSGXDeviceMap.sRegsCpuPBase = sCpuPAddr;
        gsSGXDeviceMap.sRegsSysPBase = SysCpuPAddrToSysPAddr(gsSGXDeviceMap.sRegsCpuPBase);
 #if defined(__linux__)
-       
+       /* Indicate the registers are already mapped */
        gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
 #else
-       
+       /*
+        * FIXME: Could we just use the virtual address returned by
+        * OSBaseAllocContigMemory?
+        */
        gsSGXDeviceMap.pvRegsCpuVBase = IMG_NULL;
 #endif
 
        OSMemSet(gsSGXRegsCPUVAddr, 0, gsSGXDeviceMap.ui32RegsSize);
 
-       
-
-
+       /*
+               device interrupt IRQ
+               Note: no interrupts available on no hardware system
+       */
        gsSGXDeviceMap.ui32IRQ = 0;
 
-#else 
+#else /* defined(NO_HARDWARE) */
 #if defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO)
-       
+       /* get the resource and IRQ through platform resource API */
        dev_res = platform_get_resource(gpsPVRLDMDev, IORESOURCE_MEM, 0);
        if (dev_res == NULL)
        {
@@ -175,19 +215,24 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
        PVR_TRACE(("SGX register base: 0x%lx", (unsigned long)gsSGXDeviceMap.sRegsCpuPBase.uiAddr));
 
+#if defined(SGX544) && defined(SGX_FEATURE_MP)
+       /* FIXME: Workaround due to HWMOD change. Otherwise this region is too small. */
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;
+#else
        gsSGXDeviceMap.ui32RegsSize = (unsigned int)(dev_res->end - dev_res->start);
+#endif
        PVR_TRACE(("SGX register size: %d",gsSGXDeviceMap.ui32RegsSize));
 
        gsSGXDeviceMap.ui32IRQ = dev_irq;
        PVR_TRACE(("SGX IRQ: %d", gsSGXDeviceMap.ui32IRQ));
-#else  
+#else  /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
        gsSGXDeviceMap.sRegsSysPBase.uiAddr = SYS_OMAP3430_SGX_REGS_SYS_PHYS_BASE;
        gsSGXDeviceMap.sRegsCpuPBase = SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
        gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;
 
        gsSGXDeviceMap.ui32IRQ = SYS_OMAP3430_SGX_IRQ;
 
-#endif 
+#endif /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
 #if defined(SGX_OCP_REGS_ENABLED)
        gsSGXRegsCPUVAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
        gsSGXDeviceMap.ui32RegsSize,
@@ -200,70 +245,53 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                return PVRSRV_ERROR_BAD_MAPPING;
        }
 
-       
+       /* Indicate the registers are already mapped */
        gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
        gpvOCPRegsLinAddr = gsSGXRegsCPUVAddr;
 #endif
-#endif 
+#endif /* defined(NO_HARDWARE) */
 
 #if defined(PDUMP)
        {
-               
+               /* initialise memory region name for pdumping */
                static IMG_CHAR pszPDumpDevName[] = "SGXMEM";
                gsSGXDeviceMap.pszPDumpDevName = pszPDumpDevName;
        }
 #endif
 
-       
+       /* add other devices here: */
 
 
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysCreateVersionString
+
+ @Description Read the version string 
+
+ @Return   IMG_CHAR *  : Version string
+
+******************************************************************************/
 static IMG_CHAR *SysCreateVersionString(void)
 {
        static IMG_CHAR aszVersionString[100];
+       IMG_UINT32 ui32MaxStrLen;
        SYS_DATA        *psSysData;
        IMG_UINT32      ui32SGXRevision;
        IMG_INT32       i32Count;
-#if !defined(NO_HARDWARE)
-       IMG_VOID        *pvRegsLinAddr;
-
-       pvRegsLinAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
-                                                                  SYS_OMAP3430_SGX_REGS_SIZE,
-                                                                  PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                                                  IMG_NULL);
-       if(!pvRegsLinAddr)
-       {
-               return IMG_NULL;
-       }
-
-       ui32SGXRevision = OSReadHWReg((IMG_PVOID)((IMG_PBYTE)pvRegsLinAddr),
-                                                                 EUR_CR_CORE_REVISION);
-#else
-       ui32SGXRevision = 0;
-#endif
 
        SysAcquireData(&psSysData);
 
-       i32Count = OSSNPrintf(aszVersionString, 100,
-                                                 "SGX revision = %u.%u.%u",
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAJOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAJOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MINOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MINOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAINTENANCE_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAINTENANCE_SHIFT)
-                                                );
-
-#if !defined(NO_HARDWARE)
-       OSUnMapPhysToLin(pvRegsLinAddr,
-                                        SYS_OMAP3430_SGX_REGS_SIZE,
-                                        PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                        IMG_NULL);
-#endif
+       ui32SGXRevision = SGX_CORE_REV;
+       ui32MaxStrLen = 99;
 
+       i32Count = OSSNPrintf(aszVersionString, ui32MaxStrLen + 1,
+                       "SGX revision = %u",
+                       (IMG_UINT)(ui32SGXRevision));
        if(i32Count == -1)
        {
                return IMG_NULL;
@@ -273,6 +301,16 @@ static IMG_CHAR *SysCreateVersionString(void)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysInitialise
+ @Description Initialises kernel services at 'driver load' time
+ @Return   PVRSRV_ERROR  : 
+
+******************************************************************************/
 PVRSRV_ERROR SysInitialise(IMG_VOID)
 {
        IMG_UINT32                      i;
@@ -304,7 +342,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
 
        gpsSysData->ui32NumDevices = SYS_DEVICE_COUNT;
 
-       
+       /* init device ID's */
        for(i=0; i<SYS_DEVICE_COUNT; i++)
        {
                gpsSysData->sDeviceID[i].uiID = i;
@@ -324,7 +362,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        }
 
 #if !defined(SGX_DYNAMIC_TIMING_INFO)
-       
+       /* Set up timing information*/
        psTimingInfo = &gsSGXDeviceMap.sTimingInfo;
        psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
        psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ; 
@@ -332,19 +370,21 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        psTimingInfo->bEnableActivePM = IMG_TRUE;
 #else  
        psTimingInfo->bEnableActivePM = IMG_FALSE;
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS; 
        psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ; 
 #endif
 
-       
-
+       /*
+               Setup the Source Clock Divider value
+       */
        gpsSysSpecificData->ui32SrcClockDiv = 3;
 
-       
-
-
-
+       /*
+               Locate the devices within the system, specifying 
+               the physical addresses of each devices components 
+               (regs, mem, ports etc.)
+       */
        eError = SysLocateDevices(gpsSysData);
        if (eError != PVRSRV_OK)
        {
@@ -354,7 +394,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LOCATEDEV);
-#if 0
+
        eError = SysPMRuntimeRegister();
        if (eError != PVRSRV_OK)
        {
@@ -364,10 +404,21 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME);
-#endif
-       
 
+       eError = SysDvfsInitialize(gpsSysSpecificData);
+       if (eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to initialize DVFS"));
+               (IMG_VOID)SysDeinitialise(gpsSysData);
+               gpsSysData = IMG_NULL;
+               return eError;
+       }
+       SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT);
 
+       /*
+               Register devices with the system
+               This also sets up their memory maps/heaps
+       */
        eError = PVRSRVRegisterDevice(gpsSysData, SGXRegisterDevice,
                                                                  DEVICE_SGX_INTERRUPT, &gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
@@ -379,14 +430,14 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_REGDEV);
 
-       
-
-
-       
+       /*
+               Once all devices are registered, specify the backing store
+               and, if required, customise the memory heap config
+       */      
        psDeviceNode = gpsSysData->psDeviceNodeList;
        while(psDeviceNode)
        {
-               
+               /* perform any OEM SOC address space customisations here */
                switch(psDeviceNode->sDevId.eDeviceType)
                {
                        case PVRSRV_DEVICE_TYPE_SGX:
@@ -394,16 +445,17 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                DEVICE_MEMORY_INFO *psDevMemoryInfo;
                                DEVICE_MEMORY_HEAP_INFO *psDeviceMemoryHeap;
 
-                               
-
-
+                               /* 
+                                       specify the backing store to use for the devices MMU PT/PDs
+                                       - the PT/PDs are always UMA in this system
+                               */
                                psDeviceNode->psLocalDevMemArena = IMG_NULL;
 
-                               
+                               /* useful pointers */
                                psDevMemoryInfo = &psDeviceNode->sDevMemoryInfo;
                                psDeviceMemoryHeap = psDevMemoryInfo->psDeviceMemoryHeap;
 
-                               
+                               /* specify the backing store for all SGX heaps */
                                for(i=0; i<psDevMemoryInfo->ui32HeapCount; i++)
                                {
                                        psDeviceMemoryHeap[i].ui32Attribs |= PVRSRV_BACKINGSTORE_SYSMEM_NONCONTIG;
@@ -419,7 +471,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                return PVRSRV_ERROR_INIT_FAILURE;
                }
 
-               
+               /* advance to next device */
                psDeviceNode = psDeviceNode->psNext;
        }
 
@@ -441,7 +493,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                gpsSysData = IMG_NULL;
                return eError;
        }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        eError = PVRSRVInitialiseDevice(gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
@@ -454,9 +506,9 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_INITDEV);
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       
+       /* SGX defaults to D3 power state */
        DisableSGXClocks(gpsSysData);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
 #if !defined(PVR_NO_OMAP_TIMER)
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
@@ -471,16 +523,27 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                OSReservePhys(TimerRegPhysBase,
                                  4,
                                  PVRSRV_HAP_MULTI_PROCESS|PVRSRV_HAP_UNCACHED,
-                                 IMG_NULL,                                             
+                                 IMG_NULL,
                                  (IMG_VOID **)&gpsSysData->pvSOCTimerRegisterKM,
                                  &gpsSysData->hSOCTimerRegisterOSMemHandle);
        }
-#endif 
+#endif /* !defined(PVR_NO_OMAP_TIMER) */
+
 
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysFinalise
+ @Description Final part of initialisation at 'driver load' time
+ @Return   PVRSRV_ERROR  : 
+
+******************************************************************************/
 PVRSRV_ERROR SysFinalise(IMG_VOID)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -492,7 +555,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
                PVR_DPF((PVR_DBG_ERROR,"SysFinalise: Failed to Enable SGX clocks (%d)", eError));
                return eError;
        }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        eError = OSInstallMISR(gpsSysData);
        if (eError != PVRSRV_OK)
@@ -503,7 +566,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR);
 
 #if defined(SYS_USING_INTERRUPTS)
-       
+       /* install a Device ISR */
        eError = OSInstallDeviceLISR(gpsSysData, gsSGXDeviceMap.ui32IRQ, "SGX ISR", gpsSGXDevNode);
        if (eError != PVRSRV_OK)
        {
@@ -511,10 +574,12 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR);
-#endif 
-
+#if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+       SysEnableSGXInterrupts(gpsSysData);
+#endif
+#endif /* defined(SYS_USING_INTERRUPTS) */
 #if defined(__linux__)
-       
+       /* Create a human readable version string for this system */
        gpsSysData->pszVersionString = SysCreateVersionString();
        if (!gpsSysData->pszVersionString)
        {
@@ -527,9 +592,9 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
 #endif
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       
+       /* SGX defaults to D3 power state */
        DisableSGXClocks(gpsSysData);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        gpsSysSpecificData->bSGXInitComplete = IMG_TRUE;
 
@@ -537,10 +602,22 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDeinitialise
+
+ @Description  De-initialises kernel services at 'driver unload' time
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 {
        PVRSRV_ERROR eError;
 
+       PVR_UNREFERENCED_PARAMETER(psSysData);
+
        if(gpsSysData->pvSOCTimerRegisterKM)
        {
                OSUnReservePhys(gpsSysData->pvSOCTimerRegisterKM,
@@ -549,10 +626,11 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
                                                gpsSysData->hSOCTimerRegisterOSMemHandle);
        }
 
+
 #if defined(SYS_USING_INTERRUPTS)
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR))
        {
-               eError = OSUninstallDeviceLISR(psSysData);
+               eError = OSUninstallDeviceLISR(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: OSUninstallDeviceLISR failed"));
@@ -563,7 +641,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR))
        {
-               eError = OSUninstallMISR(psSysData);
+               eError = OSUninstallMISR(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: OSUninstallMISR failed"));
@@ -575,40 +653,50 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        {
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
                PVR_ASSERT(SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS));
-               
+               /* Reenable SGX clocks whilst SGX is being deinitialised. */
                eError = EnableSGXClocksWrap(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: EnableSGXClocks failed"));
                        return eError;
                }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
-               
-               eError = PVRSRVDeinitialiseDevice (gui32SGXDeviceID);
+               /* Deinitialise SGX */
+               eError = PVRSRVDeinitialiseDevice(gui32SGXDeviceID);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: failed to de-init the device"));
                        return eError;
                }
        }
-#if 0
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME))
+
+       /* Disable system clocks. Must happen after last access to hardware */
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
        {
-               eError = SysPMRuntimeUnregister();
+               DisableSystemClocks(gpsSysData);
+       }
+
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT))
+       {
+               eError = SysDvfsDeinitialize(gpsSysSpecificData);
                if (eError != PVRSRV_OK)
                {
-                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to unregister with OSPM!"));
+                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to de-init DVFS"));
                        gpsSysData = IMG_NULL;
                        return eError;
                }
        }
-#endif
-       
 
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME))
        {
-               DisableSystemClocks(gpsSysData);
+               eError = SysPMRuntimeUnregister();
+               if (eError != PVRSRV_OK)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to unregister with OSPM!"));
+                       gpsSysData = IMG_NULL;
+                       return eError;
+               }
        }
 
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_ENVDATA))
@@ -627,7 +715,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        if(gsSGXRegsCPUVAddr != IMG_NULL)
        {
 #if defined(NO_HARDWARE)
-               
+               /* Free hardware resources. */
                OSBaseFreeContigMemory(SYS_OMAP3430_SGX_REGS_SIZE, gsSGXRegsCPUVAddr, gsSGXDeviceMap.sRegsCpuPBase);
 #else
 #if defined(SGX_OCP_REGS_ENABLED)
@@ -638,11 +726,11 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 
                gpvOCPRegsLinAddr = IMG_NULL;
 #endif
-#endif 
+#endif /* defined(NO_HARDWARE) */
                gsSGXRegsCPUVAddr = IMG_NULL;
                gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
        }
-#endif 
+#endif /* defined(NO_HARDWARE) || defined(SGX_OCP_REGS_ENABLED) */
 
        
        gpsSysSpecificData->ui32SysSpecificData = 0;
@@ -654,6 +742,19 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function             SysGetDeviceMemoryMap
+
+ @Description  returns a device address map for the specified device
+
+ @Input                        eDeviceType - device type
+ @Input                        ppvDeviceMap - void ptr to receive device specific info.
+
+ @Return               PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE  eDeviceType,
                                                                   IMG_VOID                             **ppvDeviceMap)
 {
@@ -662,7 +763,7 @@ PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE       eDeviceType,
        {
                case PVRSRV_DEVICE_TYPE_SGX:
                {
-                       
+                       /* just return a pointer to the structure */
                        *ppvDeviceMap = (IMG_VOID*)&gsSGXDeviceMap;
 
                        break;
@@ -676,6 +777,20 @@ PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE      eDeviceType,
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysCpuPAddrToDevPAddr
+
+ @Description     Compute a device physical address from a cpu physical
+                  address. Relevant when
+
+ @Input           cpu_paddr - cpu physical address.
+ @Input           eDeviceType - device type required if DevPAddr
+                                address spaces vary across devices
+                                in the same system
+ @Return         device physical address.
+
+******************************************************************************/
 IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(PVRSRV_DEVICE_TYPE       eDeviceType,
                                                                          IMG_CPU_PHYADDR               CpuPAddr)
 {
@@ -683,98 +798,205 @@ IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType,
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == CpuP */
        DevPAddr.uiAddr = CpuPAddr.uiAddr;
        
        return DevPAddr;
 }
 
+/*!
+******************************************************************************
+ @Function        SysSysPAddrToCpuPAddr
+
+ @Description     Compute a cpu physical address from a system physical
+                  address.
+
+ @Input           sys_paddr - system physical address.
+ @Return          cpu physical address.
+
+******************************************************************************/
 IMG_CPU_PHYADDR SysSysPAddrToCpuPAddr (IMG_SYS_PHYADDR sys_paddr)
 {
        IMG_CPU_PHYADDR cpu_paddr;
 
-       
+       /* This would only be an inequality if the CPU's MMU did not point to
+          sys address 0, ie. multi CPU system */
        cpu_paddr.uiAddr = sys_paddr.uiAddr;
        return cpu_paddr;
 }
 
+/*!
+******************************************************************************
+ @Function        SysCpuPAddrToSysPAddr
+
+ @Description     Compute a system physical address from a cpu physical
+                   address.
+
+ @Input           cpu_paddr - cpu physical address.
+ @Return          device physical address.
+
+******************************************************************************/
 IMG_SYS_PHYADDR SysCpuPAddrToSysPAddr (IMG_CPU_PHYADDR cpu_paddr)
 {
        IMG_SYS_PHYADDR sys_paddr;
 
-       
+       /* This would only be an inequality if the CPU's MMU did not point to
+          sys address 0, ie. multi CPU system */
        sys_paddr.uiAddr = cpu_paddr.uiAddr;
        return sys_paddr;
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysSysPAddrToDevPAddr
+
+ @Description     Compute a device physical address from a system physical
+                   address.
+
+ @Input           SysPAddr - system physical address.
+ @Input           eDeviceType - device type required if DevPAddr 
+                               address spaces vary across devices 
+                               in the same system
+
+ @Return        Device physical address.
+
+******************************************************************************/
 IMG_DEV_PHYADDR SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType, IMG_SYS_PHYADDR SysPAddr)
 {
        IMG_DEV_PHYADDR DevPAddr;
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == CpuP */
        DevPAddr.uiAddr = SysPAddr.uiAddr;
 
        return DevPAddr;
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysDevPAddrToSysPAddr
+
+ @Description     Compute a device physical address from a system physical
+                   address.
+
+ @Input           DevPAddr - device physical address.
+ @Input           eDeviceType - device type required if DevPAddr 
+                 address spaces vary across devices 
+                 in the same system
+
+ @Return        System physical address.
+
+******************************************************************************/
 IMG_SYS_PHYADDR SysDevPAddrToSysPAddr(PVRSRV_DEVICE_TYPE eDeviceType, IMG_DEV_PHYADDR DevPAddr)
 {
        IMG_SYS_PHYADDR SysPAddr;
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == SysP */
        SysPAddr.uiAddr = DevPAddr.uiAddr;
 
        return SysPAddr;
 }
 
 
+/*****************************************************************************
+ @Function        SysRegisterExternalDevice
+
+ @Description     Called when a 3rd party device registers with services
+
+ @Input           psDeviceNode - the new device node.
+
+ @Return        IMG_VOID
+*****************************************************************************/
 IMG_VOID SysRegisterExternalDevice(PVRSRV_DEVICE_NODE *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psDeviceNode);
 }
 
 
+/*****************************************************************************
+ @Function        SysRemoveExternalDevice
+
+ @Description     Called when a 3rd party device unregisters from services
+
+ @Input           psDeviceNode - the device node being removed.
+
+ @Return        IMG_VOID
+*****************************************************************************/
 IMG_VOID SysRemoveExternalDevice(PVRSRV_DEVICE_NODE *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psDeviceNode);
 }
 
+/*!
+******************************************************************************
+ @Function        SysGetInterruptSource
 
+ @Description     Returns System specific information about the device(s) that
+                               generated the interrupt in the system
+
+ @Input           psSysData
+ @Input           psDeviceNode
+
+ @Return        System specific information indicating which device(s) 
+                               generated the interrupt
+
+******************************************************************************/
 IMG_UINT32 SysGetInterruptSource(SYS_DATA                      *psSysData,
                                                                 PVRSRV_DEVICE_NODE     *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psSysData);
 #if defined(NO_HARDWARE)
-       
+       /* no interrupts in no_hw system just return all bits */
        return 0xFFFFFFFF;
 #else
-       
+       /* Not a shared irq, so we know this is an interrupt for this device */
        return psDeviceNode->ui32SOCInterruptBit;
 #endif
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysClearInterrupts
+
+ @Description     Clears specified system interrupts
+
+ @Input           psSysData
+ @Input           ui32ClearBits
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysClearInterrupts(SYS_DATA* psSysData, IMG_UINT32 ui32ClearBits)
 {
        PVR_UNREFERENCED_PARAMETER(ui32ClearBits);
-#if defined(NO_HARDWARE)
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#else
+#if !defined(NO_HARDWARE)
 #if defined(SGX_OCP_NO_INT_BYPASS)
        OSWriteHWReg(gpvOCPRegsLinAddr, EUR_CR_OCP_IRQSTATUS_2, 0x1);
 #endif
-       
+       /* Flush posted writes */
        OSReadHWReg(((PVRSRV_SGXDEV_INFO *)gpsSGXDevNode->pvDevice)->pvRegsBaseKM, EUR_CR_EVENT_HOST_CLEAR);
-#endif 
+#endif /* defined(NO_HARDWARE) */
 }
 
 #if defined(SGX_OCP_NO_INT_BYPASS)
+/*!
+******************************************************************************
+ @Function        SysEnableSGXInterrupts
+
+ @Description     Enables SGX interrupts
+
+ @Input           psSysData
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysEnableSGXInterrupts(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *)psSysData->pvSysSpecificData;
@@ -786,6 +1008,17 @@ IMG_VOID SysEnableSGXInterrupts(SYS_DATA *psSysData)
        }
 }
 
+/*!
+******************************************************************************
+ @Function        SysDisableSGXInterrupts
+
+ @Description     Disables SGX interrupts
+
+ @Input           psSysData
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysDisableSGXInterrupts(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *)psSysData->pvSysSpecificData;
@@ -796,8 +1029,20 @@ IMG_VOID SysDisableSGXInterrupts(SYS_DATA *psSysData)
                SYS_SPECIFIC_DATA_CLEAR(psSysSpecData, SYS_SPECIFIC_DATA_IRQ_ENABLED);
        }
 }
-#endif 
+#endif /* defined(SGX_OCP_NO_INT_BYPASS) */
+
+/*!
+******************************************************************************
+
+ @Function     SysSystemPrePowerState
 
+ @Description  Perform system-level processing required before a power transition
+
+ @Input                eNewPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysSystemPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -842,6 +1087,18 @@ PVRSRV_ERROR SysSystemPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysSystemPostPowerState
+
+ @Description  Perform system-level processing required after a power transition
+
+ @Input                eNewPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -890,6 +1147,21 @@ PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDevicePrePowerState
+
+ @Description  Perform system level processing required before a device power
+                               transition
+
+ @Input                ui32DeviceIndex :
+ @Input                eNewPowerState :
+ @Input                eCurrentPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                         ui32DeviceIndex,
                                                                        PVRSRV_DEV_POWER_STATE  eNewPowerState,
                                                                        PVRSRV_DEV_POWER_STATE  eCurrentPowerState)
@@ -907,13 +1179,28 @@ PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                           ui32DeviceIndex,
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePrePowerState: SGX Entering state D3"));
                DisableSGXClocks(gpsSysData);
        }
-#else  
+#else  /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        PVR_UNREFERENCED_PARAMETER(eNewPowerState );
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDevicePostPowerState
+
+ @Description  Perform system level processing required after a device power
+                               transition
+
+ @Input                ui32DeviceIndex :
+ @Input                eNewPowerState :
+ @Input                eCurrentPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                                ui32DeviceIndex,
                                                                         PVRSRV_DEV_POWER_STATE eNewPowerState,
                                                                         PVRSRV_DEV_POWER_STATE eCurrentPowerState)
@@ -933,14 +1220,33 @@ PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                          ui32DeviceIndex,
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePostPowerState: SGX Leaving state D3"));
                eError = EnableSGXClocksWrap(gpsSysData);
        }
-#else  
+#else  /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        PVR_UNREFERENCED_PARAMETER(eCurrentPowerState);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        return eError;
 }
 
+#if defined(SYS_SUPPORTS_SGX_IDLE_CALLBACK)
+
+IMG_VOID SysSGXIdleTransition(IMG_BOOL bSGXIdle)
+{
+       PVR_DPF((PVR_DBG_MESSAGE, "SysSGXIdleTransition switch to %u", bSGXIdle));
+}
+
+#endif /* defined(SYS_SUPPORTS_SGX_IDLE_CALLBACK) */
+
+/*****************************************************************************
+ @Function        SysOEMFunction
+
+ @Description     marshalling function for custom OEM functions
+
+ @Input           ui32ID  - function ID
+ @Input           pvIn - in data
+ @Output          pvOut - out data
 
+ @Return        PVRSRV_ERROR
+*****************************************************************************/
 PVRSRV_ERROR SysOEMFunction (  IMG_UINT32      ui32ID,
                                                                IMG_VOID        *pvIn,
                                                                IMG_UINT32      ulInSize,
@@ -956,7 +1262,6 @@ PVRSRV_ERROR SysOEMFunction (      IMG_UINT32      ui32ID,
        if ((ui32ID == OEM_GET_EXT_FUNCS) &&
                (ulOutSize == sizeof(PVRSRV_DC_OEM_JTABLE)))
        {
-               
                PVRSRV_DC_OEM_JTABLE *psOEMJTable = (PVRSRV_DC_OEM_JTABLE*) pvOut;
                psOEMJTable->pfnOEMBridgeDispatch = &PVRSRV_BridgeDispatchKM;
                return PVRSRV_OK;
@@ -964,3 +1269,6 @@ PVRSRV_ERROR SysOEMFunction (      IMG_UINT32      ui32ID,
 
        return PVRSRV_ERROR_INVALID_PARAMS;
 }
+/******************************************************************************
+ End of file (sysconfig.c)
+******************************************************************************/
index 8dd1efe..234d707 100644 (file)
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Description Header
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides system-specific declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SOCCONFIG_H__)
 #define __SOCCONFIG_H__
 
+#define VS_PRODUCT_NAME        "OMAP3430"
 
-#define VS_PRODUCT_NAME        "OMAP3"
-
-#define SYS_SGX_CLOCK_SPEED            110666666
 
-#define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   
-#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  
+#define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   // 10ms (100hz)
+#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  // 1ms (1000hz)
 
+/* Allow the AP latency to be overridden in the build config */
 #if !defined(SYS_SGX_ACTIVE_POWER_LATENCY_MS)
 #define SYS_SGX_ACTIVE_POWER_LATENCY_MS                (2)
 #endif
 
 
 #define SYS_OMAP3430_SGX_REGS_SYS_PHYS_BASE  0x50000000
-
 #define SYS_OMAP3430_SGX_REGS_SIZE           0x4000
 
-#define SYS_OMAP3430_SGX_IRQ                            21
+#define SYS_OMAP3430_SGX_IRQ                            21 /* OMAP4 IRQ's are offset by 32 */
+
+#define SYS_OMAP_DSS_REGS_SYS_PHYS_BASE  0x58000000
+#define SYS_OMAP_DSS_REGS_SIZE           0x7000
 
-#define SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE  0x48088024
-#define SYS_OMAP3430_GP11TIMER_REGS_SYS_PHYS_BASE       0x48088028
-#define SYS_OMAP3430_GP11TIMER_TSICR_SYS_PHYS_BASE      0x48088040
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_STATUS_REG 0x6028
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_ENABLE_REG 0x602c
+
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_ENABLE_MASK 0x10000
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_STATUS_MASK 0x10000
+
+#define SYS_OMAP_DSS_LCD_INTERRUPT_STATUS_REG 0x1018
+#define SYS_OMAP_DSS_LCD_INTERRUPT_ENABLE_REG 0x101c
+
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_ENABLE_MASK 0x40002
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_STATUS_MASK 0x40002
+
+
+#define SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE      0x48088024
+#define SYS_OMAP3430_GP11TIMER_REGS_SYS_PHYS_BASE        0x48088028
+#define SYS_OMAP3430_GP11TIMER_TSICR_SYS_PHYS_BASE       0x48088040
+
+
+
+/* Interrupt bits */
+#define DEVICE_SGX_INTERRUPT           (1<<0)
+#define DEVICE_MSVDX_INTERRUPT         (1<<1)
+#define DEVICE_DISP_INTERRUPT          (1<<2)
+
+#if 0
+#if defined(__linux__)
+/*
+ * Recent OMAP4 kernels register SGX as platform device "omap_gpu".
+ * This device must be used with the Linux power management calls
+ * in sysutils_linux.c, in order for SGX to be powered on.
+ */
+#if defined(PVR_LDM_PLATFORM_PRE_REGISTERED_DEV)
+#define        SYS_SGX_DEV_NAME        PVR_LDM_PLATFORM_PRE_REGISTERED_DEV
+#else
+#define        SYS_SGX_DEV_NAME        "omap_gpu"
+#endif /* defined(PVR_LDM_PLATFORM_PRE_REGISTERED_DEV) */
+#endif /* defined(__linux__) */
+#endif
 
+/*****************************************************************************
+ * system specific data structures
+ *****************************************************************************/
  
-#endif 
+#endif /* __SYSCONFIG_H__ */
index b6d3f5a..7383b9c 100644 (file)
@@ -1,33 +1,62 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Description Header
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides system-specific declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SYSINFO_H__)
 #define __SYSINFO_H__
 
+#if defined(SGX540) && (SGX_CORE_REV == 120)
+#define SYS_SGX_CLOCK_SPEED            307200000
+#else
+#define SYS_SGX_CLOCK_SPEED            200000000
+#endif
+
+/*!< System specific poll/timeout details */
 #if defined(PVR_LINUX_USING_WORKQUEUES)
+/*
+ * The workqueue based 3rd party display driver may be blocked for up
+ * to 500ms waiting for a vsync when the screen goes blank, so we
+ * need to wait longer for the hardware if a flush of the swap chain is
+ * required.
+ */
 #define MAX_HW_TIME_US                         (1000000)
 #define WAIT_TRY_COUNT                         (20000)
 #else
@@ -36,6 +65,6 @@
 #endif
 
 
-#define SYS_DEVICE_COUNT 15 
+#define SYS_DEVICE_COUNT 15 /* SGX, DISPLAYCLASS (external), BUFFERCLASS (external) */
 
-#endif 
+#endif /* __SYSINFO_H__ */
index 0ae7ef5..090b38d 100644 (file)
@@ -1,28 +1,44 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          Local system definitions
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides local system declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SYSLOCAL_H__)
 #define __SYSLOCAL_H__
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
 #include <linux/semaphore.h>
 #include <linux/resource.h>
-#else 
+#else /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) */
 #include <asm/semaphore.h>
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
 #include <asm/arch/resource.h>
-#endif 
-#endif 
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)) */
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) */
 
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
 #if !defined(LDM_PLATFORM)
 #error "LDM_PLATFORM must be set"
 #endif
-/*#define      PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO*/
+//#define      PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO
 //#include <linux/platform_device.h>
 #endif
 
 #if ((defined(DEBUG) || defined(TIMING)) && \
     (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))) && \
     !defined(PVR_NO_OMAP_TIMER)
-#define        PVR_OMAP3_TIMING_PRCM
+/*
+ * We need to explicitly enable the GPTIMER11 clocks, or we'll get an
+ * abort when we try to access the timer registers.
+ */
+#define        PVR_OMAP4_TIMING_PRCM
 #endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
-/*#include <plat/gpu.h>*/
+//#include <plat/gpu.h>
 #if !defined(PVR_NO_OMAP_TIMER)
-/*#define      PVR_OMAP_USE_DM_TIMER_API*/
+//#define      PVR_OMAP_USE_DM_TIMER_API
 //#include <plat/dmtimer.h>
 #endif
 #endif
@@ -74,7 +94,7 @@
 #if !defined(PVR_NO_OMAP_TIMER)
 //#define PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA
 #endif
-#endif 
+#endif /* defined(__linux__) */
 
 #if !defined(NO_HARDWARE) && \
      defined(SYS_USING_INTERRUPTS) && \
 #endif
 
 #if defined(__linux__)
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) && defined(SGX_OCP_REGS_ENABLED)
-/*#define SGX_OCP_NO_INT_BYPASS*/
+#if defined(SGX_OCP_REGS_ENABLED)
+/* FIXME: Temporary workaround for OMAP4470 and active power off in 4430 */
+#if !defined(SGX544) && defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+//#define SGX_OCP_NO_INT_BYPASS
+#endif
 #endif
 #endif
 
 extern "C" {
 #endif
 
+/*****************************************************************************
+ * system specific data structures
+ *****************************************************************************/
  
+/*****************************************************************************
+ * system specific function prototypes
+ *****************************************************************************/
  
 IMG_VOID DisableSystemClocks(SYS_DATA *psSysData);
 PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData);
@@ -100,6 +129,10 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData);
 IMG_VOID DisableSGXClocks(SYS_DATA *psSysData);
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData);
 
+/*
+ * Various flags to indicate what has been initialised, and what
+ * has been temporarily deinitialised for power management purposes.
+ */
 #define SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS     0x00000001
 #define SYS_SPECIFIC_DATA_ENABLE_LISR          0x00000002
 #define SYS_SPECIFIC_DATA_ENABLE_MISR          0x00000004
@@ -114,9 +147,8 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData);
 #define        SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS  0x00000400
 #define SYS_SPECIFIC_DATA_ENABLE_OCPREGS       0x00000800
 #define SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME    0x00001000
-#if defined(SGX_OCP_REGS_ENABLED) && defined(SGX_OCP_NO_INT_BYPASS)
 #define SYS_SPECIFIC_DATA_IRQ_ENABLED          0x00002000
-#endif
+#define SYS_SPECIFIC_DATA_DVFS_INIT                    0x00004000
 
 #define        SYS_SPECIFIC_DATA_SET(psSysSpecData, flag) ((IMG_VOID)((psSysSpecData)->ui32SysSpecificData |= (flag)))
 
@@ -149,8 +181,8 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
        atomic_t        sNotifyLockCPU;
        IMG_BOOL        bCallVDD2PostFunc;
 #endif
-       struct clk      *psCORE_CK;
-        struct clk      *psSGX_FCK;
+        struct clk      *psCORE_CK;
+       struct clk      *psSGX_FCK;
         struct clk      *psSGX_ICK;
 
 #if defined(DEBUG) || defined(TIMING)
@@ -160,7 +192,10 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
 #if defined(PVR_OMAP_USE_DM_TIMER_API)
        struct omap_dm_timer *psGPTimer;
 #endif
-#endif 
+       IMG_UINT32 ui32SGXFreqListSize;
+       IMG_UINT32 *pui32SGXFreqList;
+       IMG_UINT32 ui32SGXFreqListIndex;
+#endif /* defined(__linux__) */
 } SYS_SPECIFIC_DATA;
 
 extern SYS_SPECIFIC_DATA *gpsSysSpecificData;
@@ -183,7 +218,10 @@ IMG_VOID UnwrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData);
 PVRSRV_ERROR SysPMRuntimeRegister(void);
 PVRSRV_ERROR SysPMRuntimeUnregister(void);
 
-#else 
+PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData);
+PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData);
+
+#else /* defined(__linux__) */
 
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(SysPMRuntimeRegister)
@@ -201,12 +239,28 @@ static INLINE PVRSRV_ERROR SysPMRuntimeUnregister(void)
        return PVRSRV_OK;
 }
 
-#endif 
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(SysDvfsInitialize)
+#endif
+static INLINE PVRSRV_ERROR SysDvfsInitialize(void)
+{
+       return PVRSRV_OK;
+}
+
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(SysDvfsDeinitialize)
+#endif
+static INLINE PVRSRV_ERROR SysDvfsDeinitialize(void)
+{
+       return PVRSRV_OK;
+}
+
+#endif /* defined(__linux__) */
 
 #if defined(__cplusplus)
 }
 #endif
 
-#endif 
+#endif /* __SYSLOCAL_H__ */
 
 
index 8736fcc..27b2df6 100644 (file)
@@ -1,30 +1,49 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          Shared (User/kernel) and System dependent utilities
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    Provides system-specific functions
+@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.
+*/ /**************************************************************************/
+
+/* Pull in the correct system dependent sysutils source */
 
 #if defined(__linux__)
 #include "sysutils_linux.c"
 #endif
 
+
index e6b0644..9f395e0 100644 (file)
@@ -1,34 +1,50 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
-
+/*************************************************************************/ /*!
+@Title          System dependent utilities
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    Provides system-specific functions
+@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.
+*/ /**************************************************************************/
 #include <linux/version.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/hardirq.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 
 #include "sgxdefs.h"
 #include "services_headers.h"
 #include "sgxinfokm.h"
 #include "syslocal.h"
 
-//#include <linux/platform_device.h>
-//#include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+#include <linux/opp.h>
+#endif
+
+#if defined(SUPPORT_DRI_DRM_PLUGIN)
+#include <drm/drmP.h>
+#include <drm/drm.h>
+
+#include <linux/omap_gpu.h>
+
+#include "pvr_drm.h"
+#endif
 
 #define        ONE_MHZ 1000000
 #define        HZ_TO_MHZ(m) ((m) / ONE_MHZ)
 extern struct platform_device *gpsPVRLDMDev;
 #endif
 
-
 static PVRSRV_ERROR PowerLockWrap(SYS_SPECIFIC_DATA *psSysSpecData, IMG_BOOL bTryLock)
 {
-        if (!in_interrupt())
-        {
-                if (bTryLock)
-                {
-                        int locked = mutex_trylock(&psSysSpecData->sPowerLock);
-                        if (locked == 0)
-                        {
-                                return PVRSRV_ERROR_RETRY;
-                        }
-                }
-                else
-                {
-                        mutex_lock(&psSysSpecData->sPowerLock);
-                }
-        }
+       if (!in_interrupt())
+       {
+               if (bTryLock)
+               {
+                       int locked = mutex_trylock(&psSysSpecData->sPowerLock);
+                       if (locked == 0)
+                       {
+                               return PVRSRV_ERROR_RETRY;
+                       }
+               }
+               else
+               {
+                       mutex_lock(&psSysSpecData->sPowerLock);
+               }
+       }
 
-        return PVRSRV_OK;
+       return PVRSRV_OK;
 }
 
 static IMG_VOID PowerLockUnwrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-        if (!in_interrupt())
-        {
-                mutex_unlock(&psSysSpecData->sPowerLock);
-        }
+       if (!in_interrupt())
+       {
+               mutex_unlock(&psSysSpecData->sPowerLock);
+       }
 }
 
 PVRSRV_ERROR SysPowerLockWrap(IMG_BOOL bTryLock)
 {
-        SYS_DATA        *psSysData;
+       SYS_DATA        *psSysData;
 
-        SysAcquireData(&psSysData);
+       SysAcquireData(&psSysData);
 
-        return PowerLockWrap(psSysData->pvSysSpecificData, bTryLock);
+       return PowerLockWrap(psSysData->pvSysSpecificData, bTryLock);
 }
 
 IMG_VOID SysPowerLockUnwrap(IMG_VOID)
 {
-        SYS_DATA        *psSysData;
+       SYS_DATA        *psSysData;
 
-        SysAcquireData(&psSysData);
+       SysAcquireData(&psSysData);
 
-        PowerLockUnwrap(psSysData->pvSysSpecificData);
+       PowerLockUnwrap(psSysData->pvSysSpecificData);
 }
 
-
-
-
+/*
+ * This function should be called to unwrap the Services power lock, prior
+ * to calling any function that might sleep.
+ * This function shouldn't be called prior to calling EnableSystemClocks
+ * or DisableSystemClocks, as those functions perform their own power lock
+ * unwrapping.
+ * If the function returns IMG_TRUE, UnwrapSystemPowerChange must be
+ * called to rewrap the power lock, prior to returning to Services.
+ */
 IMG_BOOL WrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        return IMG_TRUE;
@@ -114,76 +148,64 @@ IMG_VOID UnwrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
 }
 
-static inline IMG_UINT32 scale_by_rate(IMG_UINT32 val, IMG_UINT32 rate1, IMG_UINT32 rate2)
-{
-       if (rate1 >= rate2)
-       {
-               return val * (rate1 / rate2);
-       }
-
-       return val / (rate2 / rate1);
-}
-
-static inline IMG_UINT32 scale_prop_to_SGX_clock(IMG_UINT32 val, IMG_UINT32 rate)
-{
-       return scale_by_rate(val, rate, SYS_SGX_CLOCK_SPEED);
-}
-
-static inline IMG_UINT32 scale_inv_prop_to_SGX_clock(IMG_UINT32 val, IMG_UINT32 rate)
-{
-       return scale_by_rate(val, SYS_SGX_CLOCK_SPEED, rate);
-}
-
+/*
+ * Return SGX timining information to caller.
+ */
 IMG_VOID SysGetSGXTimingInformation(SGX_TIMING_INFORMATION *psTimingInfo)
 {
-       IMG_UINT32 rate;
-
-       rate = SYS_SGX_CLOCK_SPEED;
 #if !defined(NO_HARDWARE)
        PVR_ASSERT(atomic_read(&gpsSysSpecificData->sSGXClocksEnabled) != 0);
 #endif
-       psTimingInfo->ui32CoreClockSpeed = rate;
-       psTimingInfo->ui32HWRecoveryFreq = scale_prop_to_SGX_clock(SYS_SGX_HWRECOVERY_TIMEOUT_FREQ, rate);
-       psTimingInfo->ui32uKernelFreq = scale_prop_to_SGX_clock(SYS_SGX_PDS_TIMER_FREQ, rate);
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       psTimingInfo->ui32CoreClockSpeed =
+               gpsSysSpecificData->pui32SGXFreqList[gpsSysSpecificData->ui32SGXFreqListIndex];
+#else /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
+#endif
+       psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ;
+       psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ;
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
        psTimingInfo->bEnableActivePM = IMG_TRUE;
 #else
        psTimingInfo->bEnableActivePM = IMG_FALSE;
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS;
 }
 
+/*!
+******************************************************************************
+
+ @Function  EnableSGXClocks
+
+ @Description Enable SGX clocks
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-       IMG_INT res;
-       long lRate,lNewRate;
-       
+#if !defined(PM_RUNTIME_SUPPORT)
+        IMG_INT res;
+        long lRate,lNewRate;
+#endif
+       /* SGX clocks already enabled? */
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) != 0)
        {
                return PVRSRV_OK;
        }
 
-       PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
-       
-       res=clk_enable(psSysSpecData->psSGX_FCK);
-       if (res < 0)
-        {
-                PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX functional clock (%d)", res));
-                return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
-        }
-
-       res=clk_enable(psSysSpecData->psSGX_ICK);
+#if !defined(PM_RUNTIME_SUPPORT)
+        PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
+        res=clk_enable(psSysSpecData->psSGX_FCK);
         if (res < 0)
         {
-                PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX interface clock (%d)", res));
-
-                clk_disable(psSysSpecData->psSGX_FCK);
+                PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX functional clock (%d)", res));
                 return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
         }
 
-       lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
+        lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
         if (lNewRate <= 0)
         {
                 PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't round SGX functional clock rate"));
@@ -198,7 +220,7 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                 if (res < 0)
                 {
                         PVR_DPF((PVR_DBG_WARNING, "EnableSGXClocks: Couldn't set SGX functional clock rate (%d)", res));
-                       return PVRSRV_ERROR_UNABLE_TO_SET_CLOCK_RATE;
+                        return PVRSRV_ERROR_UNABLE_TO_SET_CLOCK_RATE;
                 }
         }
 
@@ -208,75 +230,194 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                 PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: SGX Functional Clock is %dMhz", HZ_TO_MHZ(rate)));
         }
 #endif
-
-
-
+#endif 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        {
-               
-//             int res = pm_runtime_get_sync(&gpsPVRLDMDev->dev);
-//             if (res < 0)
-//             {
-//                     PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: pm_runtime_get_sync failed (%d)", -res));
-//                     return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
-//             }
+               struct gpu_platform_data *pdata;
+               IMG_UINT32 max_freq_index;
+               int res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+               max_freq_index = psSysSpecData->ui32SGXFreqListSize - 2;
+
+               /*
+                * Request maximum frequency from DVFS layer if not already set. DVFS may
+                * report busy if early in initialization, but all other errors are
+                * considered serious. Upon any error we proceed assuming our safe frequency
+                * value to be in use as indicated by the "unknown" index.
+                */
+               if (psSysSpecData->ui32SGXFreqListIndex != max_freq_index)
+               {
+                       PVR_ASSERT(pdata->device_scale != IMG_NULL);
+                       res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                         &gpsPVRLDMDev->dev,
+#endif
+                                                                         psSysSpecData->pui32SGXFreqList[max_freq_index]);
+                       if (res == 0)
+                       {
+                               psSysSpecData->ui32SGXFreqListIndex = max_freq_index;
+                       }
+                       else if (res == -EBUSY)
+                       {
+                               PVR_DPF((PVR_DBG_WARNING, "EnableSGXClocks: Unable to scale SGX frequency (EBUSY)"));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+                       else if (res < 0)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Unable to scale SGX frequency (%d)", res));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+               }
        }
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       {
+               /*
+                * pm_runtime_get_sync returns 1 after the module has
+                * been reloaded.
+                */
+#if defined(PM_RUNTIME_SUPPORT)
+
+               int res = pm_runtime_get_sync(&gpsPVRLDMDev->dev);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: pm_runtime_get_sync failed (%d)", -res));
+                       return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
+               }
 #endif
-//     SysEnableSGXInterrupts(psSysData);
+       }
+#endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
-       
+       SysEnableSGXInterrupts(psSysData);
+
+       /* Indicate that the SGX clocks are enabled */
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 1);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function  DisableSGXClocks
+
+ @Description Disable SGX clocks.
+
+ @Return   none
+
+******************************************************************************/
 IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
 
+       /* SGX clocks already disabled? */
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) == 0)
        {
                return;
        }
-       
-       PVR_DPF((PVR_DBG_MESSAGE, "DisableSGXClocks: Disabling SGX Clocks"));
-       
-       clk_disable(psSysSpecData->psSGX_FCK);
-
-       clk_disable(psSysSpecData->psSGX_ICK);
 
-//     SysDisableSGXInterrupts(psSysData);
+       PVR_DPF((PVR_DBG_MESSAGE, "DisableSGXClocks: Disabling SGX Clocks"));
+#if !defined(PM_RUNTIME_SUPPORT)
+        clk_disable(psSysSpecData->psSGX_FCK);
+#endif
+       SysDisableSGXInterrupts(psSysData);
 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
        {
-//             int res = pm_runtime_put_sync(&gpsPVRLDMDev->dev);
-//             if (res < 0)
-//             {
-//                     PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
-//             }
+#if defined(PM_RUNTIME_SUPPORT)
+
+               int res = pm_runtime_put_sync(&gpsPVRLDMDev->dev);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
+               }
+#endif
        }
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       {
+               struct gpu_platform_data *pdata;
+               int res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+
+               /*
+                * Request minimum frequency (list index 0) from DVFS layer if not already
+                * set. DVFS may report busy if early in initialization, but all other errors
+                * are considered serious. Upon any error we proceed assuming our safe frequency
+                * value to be in use as indicated by the "unknown" index.
+                */
+               if (psSysSpecData->ui32SGXFreqListIndex != 0)
+               {
+                       PVR_ASSERT(pdata->device_scale != IMG_NULL);
+                       res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                         &gpsPVRLDMDev->dev,
 #endif
+                                                                         psSysSpecData->pui32SGXFreqList[0]);
+                       if (res == 0)
+                       {
+                               psSysSpecData->ui32SGXFreqListIndex = 0;
+                       }
+                       else if (res == -EBUSY)
+                       {
+                               PVR_DPF((PVR_DBG_WARNING, "DisableSGXClocks: Unable to scale SGX frequency (EBUSY)"));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+                       else if (res < 0)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: Unable to scale SGX frequency (%d)", res));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+               }
+       }
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+#endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
+       /* Indicate that the SGX clocks are disabled */
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
 }
 
 #if (defined(DEBUG) || defined(TIMING)) && !defined(PVR_NO_OMAP_TIMER)
 #if defined(PVR_OMAP_USE_DM_TIMER_API)
 #define        GPTIMER_TO_USE 11
+/*!
+******************************************************************************
+
+ @Function  AcquireGPTimer
+
+ @Description Acquire a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_ASSERT(psSysSpecData->psGPTimer == NULL);
 
-       
+       /*
+        * This code has problems on module reload for OMAP5 running Linux
+        * 3.4.10, due to omap2_dm_timer_set_src (called by
+        * omap_dm_timer_request_specific), being unable to set the parent
+        * clock to OMAP_TIMER_SRC_32_KHZ.
+        * Not calling omap_dm_timer_set_source doesn't help.
+        */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) || !defined(MODULE)
+       /*
+        * This code could try requesting registers 9, 10, and 11,
+        * stopping at the first succesful request.  We'll stick with
+        * 11 for now, as it avoids having to hard code yet more
+        * physical addresses into the code.
+        */
        psSysSpecData->psGPTimer = omap_dm_timer_request_specific(GPTIMER_TO_USE);
        if (psSysSpecData->psGPTimer == NULL)
        {
@@ -285,26 +426,41 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
        }
 
-       
        omap_dm_timer_set_source(psSysSpecData->psGPTimer, OMAP_TIMER_SRC_SYS_CLK);
        omap_dm_timer_enable(psSysSpecData->psGPTimer);
 
-       
+       /* Set autoreload, and start value of 0 */
        omap_dm_timer_set_load_start(psSysSpecData->psGPTimer, 1, 0);
 
        omap_dm_timer_start(psSysSpecData->psGPTimer);
 
-       
+       /*
+        * The DM timer API doesn't have a mechanism for obtaining the
+        * physical address of the counter register.
+        */
        psSysSpecData->sTimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_REGS_SYS_PHYS_BASE;
+#else  /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
+       (void)psSysSpecData;
+#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
 
        return PVRSRV_OK;
 }
 
+/*!
+******************************************************************************
+
+ @Function  ReleaseGPTimer
+
+ @Description Release a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        if (psSysSpecData->psGPTimer != NULL)
        {
-                       
+               /* Always returns 0 */  
                (void) omap_dm_timer_stop(psSysSpecData->psGPTimer);
 
                omap_dm_timer_disable(psSysSpecData->psGPTimer);
@@ -317,10 +473,20 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        }
 
 }
-#else  
+#else  /* PVR_OMAP_USE_DM_TIMER_API */
+/*!
+******************************************************************************
+
+ @Function  AcquireGPTimer
+
+ @Description Acquire a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        struct clk *psCLK;
        IMG_INT res;
        struct clk *sys_ck;
@@ -335,9 +501,8 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        PVR_ASSERT(psSysSpecData->sTimerRegPhysBase.uiAddr == 0);
 #endif
 
-
-#if defined(PVR_OMAP3_TIMING_PRCM)
-       
+#if defined(PVR_OMAP4_TIMING_PRCM)
+       /* assert our dependence on the GPTIMER11 module */
        psCLK = clk_get(NULL, "gpt11_fck");
        if (IS_ERR(psCLK))
        {
@@ -353,7 +518,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitError;
        }
        psSysSpecData->psGPT11_ICK = psCLK;
-
+       
        sys_ck = clk_get(NULL, "sys_ck");
        if (IS_ERR(sys_ck))
        {
@@ -371,6 +536,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitError;
                }
        }
+       
        rate = clk_get_rate(psSysSpecData->psGPT11_FCK);
        PVR_TRACE(("GPTIMER11 clock is %dMHz", HZ_TO_MHZ(rate)));
 
@@ -387,9 +553,9 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't enable GPTIMER11 interface clock (%d)", res));
                goto ExitDisableGPT11FCK;
        }
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 
-       
+       /* Set the timer to non-posted mode */
        sTimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_TSICR_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
@@ -406,7 +572,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        {
                PVR_TRACE(("Setting GPTIMER11 mode to posted (currently is non-posted)"));
 
-               
+               /* Set posted mode */
                *pui32TimerEnable |= 4;
        }
 
@@ -415,7 +581,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                    PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                    hTimerEnable);
 
-       
+       /* Enable the timer */
        sTimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
@@ -428,6 +594,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitDisableGPT11ICK;
        }
 
+       /* Enable and set autoreload on overflow */
        *pui32TimerEnable = 3;
 
        OSUnMapPhysToLin(pui32TimerEnable,
@@ -437,23 +604,32 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        psSysSpecData->sTimerRegPhysBase = sTimerRegPhysBase;
 #endif
-
        eError = PVRSRV_OK;
 
        goto Exit;
 
 ExitDisableGPT11ICK:
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        clk_disable(psSysSpecData->psGPT11_ICK);
 ExitDisableGPT11FCK:
        clk_disable(psSysSpecData->psGPT11_FCK);
 ExitError:
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
        eError = PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
 Exit:
        return eError;
 }
 
+/*!
+******************************************************************************
+
+ @Function  ReleaseGPTimer
+
+ @Description Release a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        IMG_HANDLE hTimerDisable;
@@ -465,7 +641,7 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return;
        }
 #endif
-       TimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE;  
+       /* Disable the timer */
        pui32TimerDisable = OSMapPhysToLin(TimerRegPhysBase,
                                4,
                                PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -484,35 +660,47 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                                PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                                hTimerDisable);
        }
-
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        psSysSpecData->sTimerRegPhysBase.uiAddr = 0;
 #endif
-
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        clk_disable(psSysSpecData->psGPT11_ICK);
 
        clk_disable(psSysSpecData->psGPT11_FCK);
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 }
-#endif 
-#else  
+#endif /* PVR_OMAP_USE_DM_TIMER_API */
+#else  /* (DEBUG || TIMING) && !PVR_NO_OMAP_TIMER */
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_UNREFERENCED_PARAMETER(psSysSpecData);
+
        return PVRSRV_OK;
 }
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_UNREFERENCED_PARAMETER(psSysSpecData);
 }
-#endif 
+#endif /* (DEBUG || TIMING) && !PVR_NO_OMAP_TIMER */
+
+/*!
+******************************************************************************
+
+ @Function  EnableSystemClocks
+
+ @Description Setup up the clocks for the graphics device to work.
 
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-       struct clk *psCLK;
+#if !defined(PM_RUNTIME_SUPPORT)
+        struct clk *psCLK;
        IMG_INT res;
+#endif
+
        PVR_TRACE(("EnableSystemClocks: Enabling System Clocks"));
 
        if (!psSysSpecData->bSysClocksOneTimeInit)
@@ -520,8 +708,8 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                mutex_init(&psSysSpecData->sPowerLock);
 
                atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
-
-                psCLK = clk_get(NULL, SGX_PARENT_CLOCK);
+               
+               psCLK = clk_get(NULL, SGX_PARENT_CLOCK);
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSsystemClocks: Couldn't get Core Clock"));
@@ -529,7 +717,10 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                 }
                 psSysSpecData->psCORE_CK = psCLK;
 
-               psCLK = clk_get(NULL, "sgx_fck");
+
+//             psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+#if !defined(PM_RUNTIME_SUPPORT)
+                psCLK = clk_get(NULL, "sgx_fck");
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSsystemClocks: Couldn't get SGX Functional Clock"));
@@ -537,7 +728,7 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                 }
                 psSysSpecData->psSGX_FCK = psCLK;
 
-                psCLK = clk_get(NULL, "sgx_ick");
+               psCLK = clk_get(NULL, "sgx_ick");
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't get SGX Interface Clock"));
@@ -553,27 +744,48 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                 }
 
 
-               psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+                psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+
+
+#endif
+
        }
 
        return AcquireGPTimer(psSysSpecData);
 }
 
+/*!
+******************************************************************************
+
+ @Function  DisableSystemClocks
+
+ @Description Disable the graphics clocks.
+
+ @Return  none
+
+******************************************************************************/
 IMG_VOID DisableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
+
        PVR_TRACE(("DisableSystemClocks: Disabling System Clocks"));
-       
+
+       /*
+        * Always disable the SGX clocks when the system clocks are disabled.
+        * This saves having to make an explicit call to DisableSGXClocks if
+        * active power management is enabled.
+        */
        DisableSGXClocks(psSysData);
 
        ReleaseGPTimer(psSysSpecData);
-
 }
 
 PVRSRV_ERROR SysPMRuntimeRegister(void)
 {
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-//     pm_runtime_enable(&gpsPVRLDMDev->dev);
+#if defined(PM_RUNTIME_SUPPORT)
+       pm_runtime_enable(&gpsPVRLDMDev->dev);
+#endif
 #endif
        return PVRSRV_OK;
 }
@@ -581,7 +793,166 @@ PVRSRV_ERROR SysPMRuntimeRegister(void)
 PVRSRV_ERROR SysPMRuntimeUnregister(void)
 {
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-//     pm_runtime_disable(&gpsPVRLDMDev->dev);
+#if defined(PM_RUNTIME_SUPPORT)
+       pm_runtime_disable(&gpsPVRLDMDev->dev);
+#endif
 #endif
        return PVRSRV_OK;
 }
+
+PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
+{
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       IMG_UINT32 i, *freq_list;
+       IMG_INT32 opp_count;
+       unsigned long freq;
+       struct opp *opp;
+
+       /*
+        * We query and store the list of SGX frequencies just this once under the
+        * assumption that they are unchanging, e.g. no disabling of high frequency
+        * option for thermal management. This is currently valid for 4430 and 4460.
+        */
+       rcu_read_lock();
+       opp_count = opp_get_opp_count(&gpsPVRLDMDev->dev);
+       if (opp_count < 1)
+       {
+               rcu_read_unlock();
+               PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not retrieve opp count"));
+               return PVRSRV_ERROR_NOT_SUPPORTED;
+       }
+
+       /*
+        * Allocate the frequency list with a slot for each available frequency plus
+        * one additional slot to hold a designated frequency value to assume when in
+        * an unknown frequency state.
+        */
+       freq_list = kmalloc((opp_count + 1) * sizeof(IMG_UINT32), GFP_ATOMIC);
+       if (!freq_list)
+       {
+               rcu_read_unlock();
+               PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not allocate frequency list"));
+               return PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+
+       /*
+        * Fill in frequency list from lowest to highest then finally the "unknown"
+        * frequency value. We use the highest available frequency as our assumed value
+        * when in an unknown state, because it is safer for APM and hardware recovery
+        * timers to be longer than intended rather than shorter.
+        */
+       freq = 0;
+       for (i = 0; i < opp_count; i++)
+       {
+               opp = opp_find_freq_ceil(&gpsPVRLDMDev->dev, &freq);
+               if (IS_ERR_OR_NULL(opp))
+               {
+                       rcu_read_unlock();
+                       PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not retrieve opp level %d", i));
+                       kfree(freq_list);
+                       return PVRSRV_ERROR_NOT_SUPPORTED;
+               }
+               freq_list[i] = (IMG_UINT32)freq;
+               freq++;
+       }
+       rcu_read_unlock();
+       freq_list[opp_count] = freq_list[opp_count - 1];
+
+       psSysSpecificData->ui32SGXFreqListSize = opp_count + 1;
+       psSysSpecificData->pui32SGXFreqList = freq_list;
+
+       /* Start in unknown state - no frequency request to DVFS yet made */
+       psSysSpecificData->ui32SGXFreqListIndex = opp_count;
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+
+       return PVRSRV_OK;
+}
+
+PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
+{
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       /*
+        * We assume this function is only called if SysDvfsInitialize() was
+        * completed successfully before.
+        *
+        * The DVFS interface does not allow us to actually unregister as a
+        * user of SGX, so we do the next best thing which is to lower our
+        * required frequency to the minimum if not already set. DVFS may
+        * report busy if early in initialization, but all other errors are
+        * considered serious.
+        */
+       if (psSysSpecificData->ui32SGXFreqListIndex != 0)
+       {
+               struct gpu_platform_data *pdata;
+               IMG_INT32 res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+
+               PVR_ASSERT(pdata->device_scale != IMG_NULL);
+               res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                 &gpsPVRLDMDev->dev,
+#endif
+                                                                 psSysSpecificData->pui32SGXFreqList[0]);
+               if (res == -EBUSY)
+               {
+                       PVR_DPF((PVR_DBG_WARNING, "SysDvfsDeinitialize: Unable to scale SGX frequency (EBUSY)"));
+               }
+               else if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "SysDvfsDeinitialize: Unable to scale SGX frequency (%d)", res));
+               }
+
+               psSysSpecificData->ui32SGXFreqListIndex = 0;
+       }
+
+       kfree(psSysSpecificData->pui32SGXFreqList);
+       psSysSpecificData->pui32SGXFreqList = 0;
+       psSysSpecificData->ui32SGXFreqListSize = 0;
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+
+       return PVRSRV_OK;
+}
+
+#if defined(SUPPORT_DRI_DRM_PLUGIN)
+static struct omap_gpu_plugin sOMAPGPUPlugin;
+
+#define        SYS_DRM_SET_PLUGIN_FIELD(d, s, f) (d)->f = (s)->f
+int
+SysDRMRegisterPlugin(PVRSRV_DRM_PLUGIN *psDRMPlugin)
+{
+       int iRes;
+
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, name);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, open);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, load);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, unload);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, release);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, mmap);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, ioctls);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, num_ioctls);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, ioctl_start);
+
+       iRes = omap_gpu_register_plugin(&sOMAPGPUPlugin);
+       if (iRes != 0)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: omap_gpu_register_plugin failed (%d)", __FUNCTION__, iRes));
+       }
+
+       return iRes;
+}
+
+void
+SysDRMUnregisterPlugin(PVRSRV_DRM_PLUGIN *psDRMPlugin)
+{
+       int iRes = omap_gpu_unregister_plugin(&sOMAPGPUPlugin);
+       if (iRes != 0)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: omap_gpu_unregister_plugin failed (%d)", __FUNCTION__, iRes));
+       }
+}
+#endif
index c8eea1e..0902042 100644 (file)
@@ -1,28 +1,43 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          SGX kernel/client driver interface structures and prototypes
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__OEMFUNCS_H__)
 #define __OEMFUNCS_H__
 extern "C" {
 #endif
 
+/* function in/out data structures: */
 typedef IMG_UINT32   (*PFN_SRV_BRIDGEDISPATCH)( IMG_UINT32  Ioctl,
                                                                                                IMG_BYTE   *pInBuf,
                                                                                                IMG_UINT32  InBufLen, 
                                                                                            IMG_BYTE   *pOutBuf,
                                                                                                IMG_UINT32  OutBufLen,
                                                                                                IMG_UINT32 *pdwBytesTransferred);
+/*
+       Function table for kernel 3rd party driver to kernel services
+*/
 typedef struct PVRSRV_DC_OEM_JTABLE_TAG
 {
        PFN_SRV_BRIDGEDISPATCH                  pfnOEMBridgeDispatch;
@@ -52,5 +71,10 @@ typedef struct PVRSRV_DC_OEM_JTABLE_TAG
 }
 #endif
 
-#endif 
+#endif /* __OEMFUNCS_H__ */
+
+/*****************************************************************************
+ End of file (oemfuncs.h)
+*****************************************************************************/
+
 
index db58824..1270ff3 100644 (file)
@@ -1,28 +1,44 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Configuration
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    System Configuration functions
+@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.
+*/ /**************************************************************************/
 
 #include "sysconfig.h"
 #include "services_headers.h"
 
 #include "ocpdefs.h"
 
+/* top level system data anchor point*/
 SYS_DATA* gpsSysData = (SYS_DATA*)IMG_NULL;
 SYS_DATA  gsSysData;
 
 static SYS_SPECIFIC_DATA gsSysSpecificData;
 SYS_SPECIFIC_DATA *gpsSysSpecificData;
 
-static IMG_UINT32      gui32SGXDeviceID;
-static SGX_DEVICE_MAP  gsSGXDeviceMap;
-static PVRSRV_DEVICE_NODE *gpsSGXDevNode;
+/* SGX structures */
+static IMG_UINT32                      gui32SGXDeviceID;
+static SGX_DEVICE_MAP          gsSGXDeviceMap;
+static PVRSRV_DEVICE_NODE      *gpsSGXDevNode;
 
-#define DEVICE_SGX_INTERRUPT (1 << 0)
 
 #if defined(NO_HARDWARE) || defined(SGX_OCP_REGS_ENABLED)
 static IMG_CPU_VIRTADDR gsSGXRegsCPUVAddr;
@@ -79,14 +96,14 @@ static PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
        return eError;
 }
 
-#else 
+#else /* defined(SGX_OCP_REGS_ENABLED) */
 
 static INLINE PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
 {
        return EnableSGXClocks(psSysData);
 }
 
-#endif 
+#endif /* defined(SGX_OCP_REGS_ENABLED) */
 
 static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
 {
@@ -95,7 +112,10 @@ static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
 #if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
        if(eError == PVRSRV_OK)
        {
-               
+               /*
+                * The SGX Clocks are enabled separately if active power
+                * management is enabled.
+                */
                eError = EnableSGXClocksWrap(psSysData);
                if (eError != PVRSRV_OK)
                {
@@ -107,6 +127,18 @@ static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
        return eError;
 }
 
+/*!
+******************************************************************************
+
+ @Function     SysLocateDevices
+
+ @Description  Specifies devices in the systems memory map
+
+ @Input                psSysData - sys data
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 {
 #if defined(NO_HARDWARE)
@@ -121,13 +153,17 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 
        PVR_UNREFERENCED_PARAMETER(psSysData);
 
-       
+       /* SGX Device: */
        gsSGXDeviceMap.ui32Flags = 0x0;
        
 #if defined(NO_HARDWARE)
-       
-       
-       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;
+       /* 
+        * For no hardware, allocate some contiguous memory for the
+        * register block.
+        */
+
+       /* Registers */
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3630_SGX_REGS_SIZE;
 
        eError = OSBaseAllocContigMemory(gsSGXDeviceMap.ui32RegsSize,
                                                                         &gsSGXRegsCPUVAddr,
@@ -139,23 +175,27 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
        gsSGXDeviceMap.sRegsCpuPBase = sCpuPAddr;
        gsSGXDeviceMap.sRegsSysPBase = SysCpuPAddrToSysPAddr(gsSGXDeviceMap.sRegsCpuPBase);
 #if defined(__linux__)
-       
+       /* Indicate the registers are already mapped */
        gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
 #else
-       
+       /*
+        * FIXME: Could we just use the virtual address returned by
+        * OSBaseAllocContigMemory?
+        */
        gsSGXDeviceMap.pvRegsCpuVBase = IMG_NULL;
 #endif
 
        OSMemSet(gsSGXRegsCPUVAddr, 0, gsSGXDeviceMap.ui32RegsSize);
 
-       
-
-
+       /*
+               device interrupt IRQ
+               Note: no interrupts available on no hardware system
+       */
        gsSGXDeviceMap.ui32IRQ = 0;
 
-#else 
+#else /* defined(NO_HARDWARE) */
 #if defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO)
-       
+       /* get the resource and IRQ through platform resource API */
        dev_res = platform_get_resource(gpsPVRLDMDev, IORESOURCE_MEM, 0);
        if (dev_res == NULL)
        {
@@ -175,19 +215,24 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
        PVR_TRACE(("SGX register base: 0x%lx", (unsigned long)gsSGXDeviceMap.sRegsCpuPBase.uiAddr));
 
+#if defined(SGX544) && defined(SGX_FEATURE_MP)
+       /* FIXME: Workaround due to HWMOD change. Otherwise this region is too small. */
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3630_SGX_REGS_SIZE;
+#else
        gsSGXDeviceMap.ui32RegsSize = (unsigned int)(dev_res->end - dev_res->start);
+#endif
        PVR_TRACE(("SGX register size: %d",gsSGXDeviceMap.ui32RegsSize));
 
        gsSGXDeviceMap.ui32IRQ = dev_irq;
        PVR_TRACE(("SGX IRQ: %d", gsSGXDeviceMap.ui32IRQ));
-#else  
-       gsSGXDeviceMap.sRegsSysPBase.uiAddr = SYS_OMAP3430_SGX_REGS_SYS_PHYS_BASE;
+#else  /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
+       gsSGXDeviceMap.sRegsSysPBase.uiAddr = SYS_OMAP3630_SGX_REGS_SYS_PHYS_BASE;
        gsSGXDeviceMap.sRegsCpuPBase = SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
-       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3430_SGX_REGS_SIZE;
+       gsSGXDeviceMap.ui32RegsSize = SYS_OMAP3630_SGX_REGS_SIZE;
 
-       gsSGXDeviceMap.ui32IRQ = SYS_OMAP3430_SGX_IRQ;
+       gsSGXDeviceMap.ui32IRQ = SYS_OMAP3630_SGX_IRQ;
 
-#endif 
+#endif /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
 #if defined(SGX_OCP_REGS_ENABLED)
        gsSGXRegsCPUVAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
        gsSGXDeviceMap.ui32RegsSize,
@@ -200,70 +245,53 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                return PVRSRV_ERROR_BAD_MAPPING;
        }
 
-       
+       /* Indicate the registers are already mapped */
        gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
        gpvOCPRegsLinAddr = gsSGXRegsCPUVAddr;
 #endif
-#endif 
+#endif /* defined(NO_HARDWARE) */
 
 #if defined(PDUMP)
        {
-               
+               /* initialise memory region name for pdumping */
                static IMG_CHAR pszPDumpDevName[] = "SGXMEM";
                gsSGXDeviceMap.pszPDumpDevName = pszPDumpDevName;
        }
 #endif
 
-       
+       /* add other devices here: */
 
 
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysCreateVersionString
+
+ @Description Read the version string 
+
+ @Return   IMG_CHAR *  : Version string
+
+******************************************************************************/
 static IMG_CHAR *SysCreateVersionString(void)
 {
        static IMG_CHAR aszVersionString[100];
+       IMG_UINT32 ui32MaxStrLen;
        SYS_DATA        *psSysData;
        IMG_UINT32      ui32SGXRevision;
        IMG_INT32       i32Count;
-#if !defined(NO_HARDWARE)
-       IMG_VOID        *pvRegsLinAddr;
-
-       pvRegsLinAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
-                                                                  SYS_OMAP3430_SGX_REGS_SIZE,
-                                                                  PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                                                  IMG_NULL);
-       if(!pvRegsLinAddr)
-       {
-               return IMG_NULL;
-       }
-
-       ui32SGXRevision = OSReadHWReg((IMG_PVOID)((IMG_PBYTE)pvRegsLinAddr),
-                                                                 EUR_CR_CORE_REVISION);
-#else
-       ui32SGXRevision = 0;
-#endif
 
        SysAcquireData(&psSysData);
 
-       i32Count = OSSNPrintf(aszVersionString, 100,
-                                                 "SGX revision = %u.%u.%u",
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAJOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAJOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MINOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MINOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAINTENANCE_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAINTENANCE_SHIFT)
-                                                );
-
-#if !defined(NO_HARDWARE)
-       OSUnMapPhysToLin(pvRegsLinAddr,
-                                        SYS_OMAP3430_SGX_REGS_SIZE,
-                                        PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                        IMG_NULL);
-#endif
+       ui32SGXRevision = SGX_CORE_REV;
+       ui32MaxStrLen = 99;
 
+       i32Count = OSSNPrintf(aszVersionString, ui32MaxStrLen + 1,
+                       "SGX revision = %u",
+                       (IMG_UINT)(ui32SGXRevision));
        if(i32Count == -1)
        {
                return IMG_NULL;
@@ -273,6 +301,16 @@ static IMG_CHAR *SysCreateVersionString(void)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysInitialise
+ @Description Initialises kernel services at 'driver load' time
+ @Return   PVRSRV_ERROR  : 
+
+******************************************************************************/
 PVRSRV_ERROR SysInitialise(IMG_VOID)
 {
        IMG_UINT32                      i;
@@ -304,7 +342,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
 
        gpsSysData->ui32NumDevices = SYS_DEVICE_COUNT;
 
-       
+       /* init device ID's */
        for(i=0; i<SYS_DEVICE_COUNT; i++)
        {
                gpsSysData->sDeviceID[i].uiID = i;
@@ -324,7 +362,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        }
 
 #if !defined(SGX_DYNAMIC_TIMING_INFO)
-       
+       /* Set up timing information*/
        psTimingInfo = &gsSGXDeviceMap.sTimingInfo;
        psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
        psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ; 
@@ -332,19 +370,21 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        psTimingInfo->bEnableActivePM = IMG_TRUE;
 #else  
        psTimingInfo->bEnableActivePM = IMG_FALSE;
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS; 
        psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ; 
 #endif
 
-       
-
+       /*
+               Setup the Source Clock Divider value
+       */
        gpsSysSpecificData->ui32SrcClockDiv = 3;
 
-       
-
-
-
+       /*
+               Locate the devices within the system, specifying 
+               the physical addresses of each devices components 
+               (regs, mem, ports etc.)
+       */
        eError = SysLocateDevices(gpsSysData);
        if (eError != PVRSRV_OK)
        {
@@ -354,7 +394,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LOCATEDEV);
-#if 0
+
        eError = SysPMRuntimeRegister();
        if (eError != PVRSRV_OK)
        {
@@ -364,10 +404,21 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME);
-#endif
-       
 
+       eError = SysDvfsInitialize(gpsSysSpecificData);
+       if (eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to initialize DVFS"));
+               (IMG_VOID)SysDeinitialise(gpsSysData);
+               gpsSysData = IMG_NULL;
+               return eError;
+       }
+       SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT);
 
+       /*
+               Register devices with the system
+               This also sets up their memory maps/heaps
+       */
        eError = PVRSRVRegisterDevice(gpsSysData, SGXRegisterDevice,
                                                                  DEVICE_SGX_INTERRUPT, &gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
@@ -379,14 +430,14 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_REGDEV);
 
-       
-
-
-       
+       /*
+               Once all devices are registered, specify the backing store
+               and, if required, customise the memory heap config
+       */      
        psDeviceNode = gpsSysData->psDeviceNodeList;
        while(psDeviceNode)
        {
-               
+               /* perform any OEM SOC address space customisations here */
                switch(psDeviceNode->sDevId.eDeviceType)
                {
                        case PVRSRV_DEVICE_TYPE_SGX:
@@ -394,16 +445,17 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                DEVICE_MEMORY_INFO *psDevMemoryInfo;
                                DEVICE_MEMORY_HEAP_INFO *psDeviceMemoryHeap;
 
-                               
-
-
+                               /* 
+                                       specify the backing store to use for the devices MMU PT/PDs
+                                       - the PT/PDs are always UMA in this system
+                               */
                                psDeviceNode->psLocalDevMemArena = IMG_NULL;
 
-                               
+                               /* useful pointers */
                                psDevMemoryInfo = &psDeviceNode->sDevMemoryInfo;
                                psDeviceMemoryHeap = psDevMemoryInfo->psDeviceMemoryHeap;
 
-                               
+                               /* specify the backing store for all SGX heaps */
                                for(i=0; i<psDevMemoryInfo->ui32HeapCount; i++)
                                {
                                        psDeviceMemoryHeap[i].ui32Attribs |= PVRSRV_BACKINGSTORE_SYSMEM_NONCONTIG;
@@ -419,7 +471,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                return PVRSRV_ERROR_INIT_FAILURE;
                }
 
-               
+               /* advance to next device */
                psDeviceNode = psDeviceNode->psNext;
        }
 
@@ -441,7 +493,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                gpsSysData = IMG_NULL;
                return eError;
        }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        eError = PVRSRVInitialiseDevice(gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
@@ -454,15 +506,15 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_INITDEV);
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       
+       /* SGX defaults to D3 power state */
        DisableSGXClocks(gpsSysData);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
 #if !defined(PVR_NO_OMAP_TIMER)
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        TimerRegPhysBase = gsSysSpecificData.sTimerRegPhysBase;
 #else
-       TimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_REGS_SYS_PHYS_BASE;
+       TimerRegPhysBase.uiAddr = SYS_OMAP3630_GP11TIMER_REGS_SYS_PHYS_BASE;
 #endif
        gpsSysData->pvSOCTimerRegisterKM = IMG_NULL;
        gpsSysData->hSOCTimerRegisterOSMemHandle = 0;
@@ -475,12 +527,23 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                  (IMG_VOID **)&gpsSysData->pvSOCTimerRegisterKM,
                                  &gpsSysData->hSOCTimerRegisterOSMemHandle);
        }
-#endif 
+#endif /* !defined(PVR_NO_OMAP_TIMER) */
+
 
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysFinalise
+ @Description Final part of initialisation at 'driver load' time
+ @Return   PVRSRV_ERROR  : 
+
+******************************************************************************/
 PVRSRV_ERROR SysFinalise(IMG_VOID)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -492,7 +555,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
                PVR_DPF((PVR_DBG_ERROR,"SysFinalise: Failed to Enable SGX clocks (%d)", eError));
                return eError;
        }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        eError = OSInstallMISR(gpsSysData);
        if (eError != PVRSRV_OK)
@@ -503,7 +566,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR);
 
 #if defined(SYS_USING_INTERRUPTS)
-       
+       /* install a Device ISR */
        eError = OSInstallDeviceLISR(gpsSysData, gsSGXDeviceMap.ui32IRQ, "SGX ISR", gpsSGXDevNode);
        if (eError != PVRSRV_OK)
        {
@@ -511,10 +574,12 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR);
-#endif 
-
+#if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+       SysEnableSGXInterrupts(gpsSysData);
+#endif
+#endif /* defined(SYS_USING_INTERRUPTS) */
 #if defined(__linux__)
-       
+       /* Create a human readable version string for this system */
        gpsSysData->pszVersionString = SysCreateVersionString();
        if (!gpsSysData->pszVersionString)
        {
@@ -527,9 +592,9 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
 #endif
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       
+       /* SGX defaults to D3 power state */
        DisableSGXClocks(gpsSysData);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        gpsSysSpecificData->bSGXInitComplete = IMG_TRUE;
 
@@ -537,10 +602,22 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDeinitialise
+
+ @Description  De-initialises kernel services at 'driver unload' time
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 {
        PVRSRV_ERROR eError;
 
+       PVR_UNREFERENCED_PARAMETER(psSysData);
+
        if(gpsSysData->pvSOCTimerRegisterKM)
        {
                OSUnReservePhys(gpsSysData->pvSOCTimerRegisterKM,
@@ -549,10 +626,11 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
                                                gpsSysData->hSOCTimerRegisterOSMemHandle);
        }
 
+
 #if defined(SYS_USING_INTERRUPTS)
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR))
        {
-               eError = OSUninstallDeviceLISR(psSysData);
+               eError = OSUninstallDeviceLISR(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: OSUninstallDeviceLISR failed"));
@@ -563,7 +641,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR))
        {
-               eError = OSUninstallMISR(psSysData);
+               eError = OSUninstallMISR(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: OSUninstallMISR failed"));
@@ -575,40 +653,50 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        {
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
                PVR_ASSERT(SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS));
-               
+               /* Reenable SGX clocks whilst SGX is being deinitialised. */
                eError = EnableSGXClocksWrap(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: EnableSGXClocks failed"));
                        return eError;
                }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
-               
-               eError = PVRSRVDeinitialiseDevice (gui32SGXDeviceID);
+               /* Deinitialise SGX */
+               eError = PVRSRVDeinitialiseDevice(gui32SGXDeviceID);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: failed to de-init the device"));
                        return eError;
                }
        }
-#if 0
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME))
+
+       /* Disable system clocks. Must happen after last access to hardware */
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
        {
-               eError = SysPMRuntimeUnregister();
+               DisableSystemClocks(gpsSysData);
+       }
+
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT))
+       {
+               eError = SysDvfsDeinitialize(gpsSysSpecificData);
                if (eError != PVRSRV_OK)
                {
-                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to unregister with OSPM!"));
+                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to de-init DVFS"));
                        gpsSysData = IMG_NULL;
                        return eError;
                }
        }
-#endif
-       
 
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME))
        {
-               DisableSystemClocks(gpsSysData);
+               eError = SysPMRuntimeUnregister();
+               if (eError != PVRSRV_OK)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to unregister with OSPM!"));
+                       gpsSysData = IMG_NULL;
+                       return eError;
+               }
        }
 
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_ENVDATA))
@@ -627,8 +715,8 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        if(gsSGXRegsCPUVAddr != IMG_NULL)
        {
 #if defined(NO_HARDWARE)
-               
-               OSBaseFreeContigMemory(SYS_OMAP3430_SGX_REGS_SIZE, gsSGXRegsCPUVAddr, gsSGXDeviceMap.sRegsCpuPBase);
+               /* Free hardware resources. */
+               OSBaseFreeContigMemory(SYS_OMAP3630_SGX_REGS_SIZE, gsSGXRegsCPUVAddr, gsSGXDeviceMap.sRegsCpuPBase);
 #else
 #if defined(SGX_OCP_REGS_ENABLED)
                OSUnMapPhysToLin(gsSGXRegsCPUVAddr,
@@ -638,11 +726,11 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 
                gpvOCPRegsLinAddr = IMG_NULL;
 #endif
-#endif 
+#endif /* defined(NO_HARDWARE) */
                gsSGXRegsCPUVAddr = IMG_NULL;
                gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
        }
-#endif 
+#endif /* defined(NO_HARDWARE) || defined(SGX_OCP_REGS_ENABLED) */
 
        
        gpsSysSpecificData->ui32SysSpecificData = 0;
@@ -654,6 +742,19 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function             SysGetDeviceMemoryMap
+
+ @Description  returns a device address map for the specified device
+
+ @Input                        eDeviceType - device type
+ @Input                        ppvDeviceMap - void ptr to receive device specific info.
+
+ @Return               PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE  eDeviceType,
                                                                   IMG_VOID                             **ppvDeviceMap)
 {
@@ -662,7 +763,7 @@ PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE       eDeviceType,
        {
                case PVRSRV_DEVICE_TYPE_SGX:
                {
-                       
+                       /* just return a pointer to the structure */
                        *ppvDeviceMap = (IMG_VOID*)&gsSGXDeviceMap;
 
                        break;
@@ -676,6 +777,20 @@ PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE      eDeviceType,
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysCpuPAddrToDevPAddr
+
+ @Description     Compute a device physical address from a cpu physical
+                  address. Relevant when
+
+ @Input           cpu_paddr - cpu physical address.
+ @Input           eDeviceType - device type required if DevPAddr
+                                address spaces vary across devices
+                                in the same system
+ @Return         device physical address.
+
+******************************************************************************/
 IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(PVRSRV_DEVICE_TYPE       eDeviceType,
                                                                          IMG_CPU_PHYADDR               CpuPAddr)
 {
@@ -683,98 +798,205 @@ IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType,
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == CpuP */
        DevPAddr.uiAddr = CpuPAddr.uiAddr;
        
        return DevPAddr;
 }
 
+/*!
+******************************************************************************
+ @Function        SysSysPAddrToCpuPAddr
+
+ @Description     Compute a cpu physical address from a system physical
+                  address.
+
+ @Input           sys_paddr - system physical address.
+ @Return          cpu physical address.
+
+******************************************************************************/
 IMG_CPU_PHYADDR SysSysPAddrToCpuPAddr (IMG_SYS_PHYADDR sys_paddr)
 {
        IMG_CPU_PHYADDR cpu_paddr;
 
-       
+       /* This would only be an inequality if the CPU's MMU did not point to
+          sys address 0, ie. multi CPU system */
        cpu_paddr.uiAddr = sys_paddr.uiAddr;
        return cpu_paddr;
 }
 
+/*!
+******************************************************************************
+ @Function        SysCpuPAddrToSysPAddr
+
+ @Description     Compute a system physical address from a cpu physical
+                   address.
+
+ @Input           cpu_paddr - cpu physical address.
+ @Return          device physical address.
+
+******************************************************************************/
 IMG_SYS_PHYADDR SysCpuPAddrToSysPAddr (IMG_CPU_PHYADDR cpu_paddr)
 {
        IMG_SYS_PHYADDR sys_paddr;
 
-       
+       /* This would only be an inequality if the CPU's MMU did not point to
+          sys address 0, ie. multi CPU system */
        sys_paddr.uiAddr = cpu_paddr.uiAddr;
        return sys_paddr;
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysSysPAddrToDevPAddr
+
+ @Description     Compute a device physical address from a system physical
+                   address.
+
+ @Input           SysPAddr - system physical address.
+ @Input           eDeviceType - device type required if DevPAddr 
+                               address spaces vary across devices 
+                               in the same system
+
+ @Return        Device physical address.
+
+******************************************************************************/
 IMG_DEV_PHYADDR SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType, IMG_SYS_PHYADDR SysPAddr)
 {
        IMG_DEV_PHYADDR DevPAddr;
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == CpuP */
        DevPAddr.uiAddr = SysPAddr.uiAddr;
 
        return DevPAddr;
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysDevPAddrToSysPAddr
+
+ @Description     Compute a device physical address from a system physical
+                   address.
+
+ @Input           DevPAddr - device physical address.
+ @Input           eDeviceType - device type required if DevPAddr 
+                 address spaces vary across devices 
+                 in the same system
+
+ @Return        System physical address.
+
+******************************************************************************/
 IMG_SYS_PHYADDR SysDevPAddrToSysPAddr(PVRSRV_DEVICE_TYPE eDeviceType, IMG_DEV_PHYADDR DevPAddr)
 {
        IMG_SYS_PHYADDR SysPAddr;
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == SysP */
        SysPAddr.uiAddr = DevPAddr.uiAddr;
 
        return SysPAddr;
 }
 
 
+/*****************************************************************************
+ @Function        SysRegisterExternalDevice
+
+ @Description     Called when a 3rd party device registers with services
+
+ @Input           psDeviceNode - the new device node.
+
+ @Return        IMG_VOID
+*****************************************************************************/
 IMG_VOID SysRegisterExternalDevice(PVRSRV_DEVICE_NODE *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psDeviceNode);
 }
 
 
+/*****************************************************************************
+ @Function        SysRemoveExternalDevice
+
+ @Description     Called when a 3rd party device unregisters from services
+
+ @Input           psDeviceNode - the device node being removed.
+
+ @Return        IMG_VOID
+*****************************************************************************/
 IMG_VOID SysRemoveExternalDevice(PVRSRV_DEVICE_NODE *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psDeviceNode);
 }
 
+/*!
+******************************************************************************
+ @Function        SysGetInterruptSource
 
+ @Description     Returns System specific information about the device(s) that
+                               generated the interrupt in the system
+
+ @Input           psSysData
+ @Input           psDeviceNode
+
+ @Return        System specific information indicating which device(s) 
+                               generated the interrupt
+
+******************************************************************************/
 IMG_UINT32 SysGetInterruptSource(SYS_DATA                      *psSysData,
                                                                 PVRSRV_DEVICE_NODE     *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psSysData);
 #if defined(NO_HARDWARE)
-       
+       /* no interrupts in no_hw system just return all bits */
        return 0xFFFFFFFF;
 #else
-       
+       /* Not a shared irq, so we know this is an interrupt for this device */
        return psDeviceNode->ui32SOCInterruptBit;
 #endif
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysClearInterrupts
+
+ @Description     Clears specified system interrupts
+
+ @Input           psSysData
+ @Input           ui32ClearBits
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysClearInterrupts(SYS_DATA* psSysData, IMG_UINT32 ui32ClearBits)
 {
        PVR_UNREFERENCED_PARAMETER(ui32ClearBits);
-#if defined(NO_HARDWARE)
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#else
+#if !defined(NO_HARDWARE)
 #if defined(SGX_OCP_NO_INT_BYPASS)
        OSWriteHWReg(gpvOCPRegsLinAddr, EUR_CR_OCP_IRQSTATUS_2, 0x1);
 #endif
-       
+       /* Flush posted writes */
        OSReadHWReg(((PVRSRV_SGXDEV_INFO *)gpsSGXDevNode->pvDevice)->pvRegsBaseKM, EUR_CR_EVENT_HOST_CLEAR);
-#endif 
+#endif /* defined(NO_HARDWARE) */
 }
 
 #if defined(SGX_OCP_NO_INT_BYPASS)
+/*!
+******************************************************************************
+ @Function        SysEnableSGXInterrupts
+
+ @Description     Enables SGX interrupts
+
+ @Input           psSysData
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysEnableSGXInterrupts(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *)psSysData->pvSysSpecificData;
@@ -786,6 +1008,17 @@ IMG_VOID SysEnableSGXInterrupts(SYS_DATA *psSysData)
        }
 }
 
+/*!
+******************************************************************************
+ @Function        SysDisableSGXInterrupts
+
+ @Description     Disables SGX interrupts
+
+ @Input           psSysData
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysDisableSGXInterrupts(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *)psSysData->pvSysSpecificData;
@@ -796,8 +1029,20 @@ IMG_VOID SysDisableSGXInterrupts(SYS_DATA *psSysData)
                SYS_SPECIFIC_DATA_CLEAR(psSysSpecData, SYS_SPECIFIC_DATA_IRQ_ENABLED);
        }
 }
-#endif 
+#endif /* defined(SGX_OCP_NO_INT_BYPASS) */
+
+/*!
+******************************************************************************
+
+ @Function     SysSystemPrePowerState
 
+ @Description  Perform system-level processing required before a power transition
+
+ @Input                eNewPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysSystemPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -842,6 +1087,18 @@ PVRSRV_ERROR SysSystemPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysSystemPostPowerState
+
+ @Description  Perform system-level processing required after a power transition
+
+ @Input                eNewPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -890,6 +1147,21 @@ PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDevicePrePowerState
+
+ @Description  Perform system level processing required before a device power
+                               transition
+
+ @Input                ui32DeviceIndex :
+ @Input                eNewPowerState :
+ @Input                eCurrentPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                         ui32DeviceIndex,
                                                                        PVRSRV_DEV_POWER_STATE  eNewPowerState,
                                                                        PVRSRV_DEV_POWER_STATE  eCurrentPowerState)
@@ -907,13 +1179,28 @@ PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                           ui32DeviceIndex,
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePrePowerState: SGX Entering state D3"));
                DisableSGXClocks(gpsSysData);
        }
-#else  
+#else  /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        PVR_UNREFERENCED_PARAMETER(eNewPowerState );
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDevicePostPowerState
+
+ @Description  Perform system level processing required after a device power
+                               transition
+
+ @Input                ui32DeviceIndex :
+ @Input                eNewPowerState :
+ @Input                eCurrentPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                                ui32DeviceIndex,
                                                                         PVRSRV_DEV_POWER_STATE eNewPowerState,
                                                                         PVRSRV_DEV_POWER_STATE eCurrentPowerState)
@@ -933,14 +1220,33 @@ PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                          ui32DeviceIndex,
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePostPowerState: SGX Leaving state D3"));
                eError = EnableSGXClocksWrap(gpsSysData);
        }
-#else  
+#else  /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        PVR_UNREFERENCED_PARAMETER(eCurrentPowerState);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        return eError;
 }
 
+#if defined(SYS_SUPPORTS_SGX_IDLE_CALLBACK)
+
+IMG_VOID SysSGXIdleTransition(IMG_BOOL bSGXIdle)
+{
+       PVR_DPF((PVR_DBG_MESSAGE, "SysSGXIdleTransition switch to %u", bSGXIdle));
+}
+
+#endif /* defined(SYS_SUPPORTS_SGX_IDLE_CALLBACK) */
+
+/*****************************************************************************
+ @Function        SysOEMFunction
+
+ @Description     marshalling function for custom OEM functions
+
+ @Input           ui32ID  - function ID
+ @Input           pvIn - in data
+ @Output          pvOut - out data
 
+ @Return        PVRSRV_ERROR
+*****************************************************************************/
 PVRSRV_ERROR SysOEMFunction (  IMG_UINT32      ui32ID,
                                                                IMG_VOID        *pvIn,
                                                                IMG_UINT32      ulInSize,
@@ -956,7 +1262,6 @@ PVRSRV_ERROR SysOEMFunction (      IMG_UINT32      ui32ID,
        if ((ui32ID == OEM_GET_EXT_FUNCS) &&
                (ulOutSize == sizeof(PVRSRV_DC_OEM_JTABLE)))
        {
-               
                PVRSRV_DC_OEM_JTABLE *psOEMJTable = (PVRSRV_DC_OEM_JTABLE*) pvOut;
                psOEMJTable->pfnOEMBridgeDispatch = &PVRSRV_BridgeDispatchKM;
                return PVRSRV_OK;
@@ -964,3 +1269,6 @@ PVRSRV_ERROR SysOEMFunction (      IMG_UINT32      ui32ID,
 
        return PVRSRV_ERROR_INVALID_PARAMS;
 }
+/******************************************************************************
+ End of file (sysconfig.c)
+******************************************************************************/
index e18bd3c..e956c83 100644 (file)
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Description Header
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides system-specific declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SOCCONFIG_H__)
 #define __SOCCONFIG_H__
 
-
 #define VS_PRODUCT_NAME        "OMAP3630"
 
-#define SYS_SGX_CLOCK_SPEED                    200000000       
 
-#define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   
-#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  
+#define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   // 10ms (100hz)
+#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  // 1ms (1000hz)
 
+/* Allow the AP latency to be overridden in the build config */
 #if !defined(SYS_SGX_ACTIVE_POWER_LATENCY_MS)
 #define SYS_SGX_ACTIVE_POWER_LATENCY_MS                (2)
 #endif
 
 
-#define SYS_OMAP3430_SGX_REGS_SYS_PHYS_BASE  0x50000000
+#define SYS_OMAP3630_SGX_REGS_SYS_PHYS_BASE  0x50000000
+#define SYS_OMAP3630_SGX_REGS_SIZE           0x10000
+
+#define SYS_OMAP3630_SGX_IRQ                            21 /* OMAP4 IRQ's are offset by 32 */
 
-#define SYS_OMAP3430_SGX_REGS_SIZE           0x10000
+#define SYS_OMAP_DSS_REGS_SYS_PHYS_BASE  0x58000000
+#define SYS_OMAP_DSS_REGS_SIZE           0x7000
 
-#define SYS_OMAP3430_SGX_IRQ                            21
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_STATUS_REG 0x6028
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_ENABLE_REG 0x602c
 
-#define SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE  0x48088024
-#define SYS_OMAP3430_GP11TIMER_REGS_SYS_PHYS_BASE       0x48088028
-#define SYS_OMAP3430_GP11TIMER_TSICR_SYS_PHYS_BASE      0x48088040
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_ENABLE_MASK 0x10000
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_STATUS_MASK 0x10000
+
+#define SYS_OMAP_DSS_LCD_INTERRUPT_STATUS_REG 0x1018
+#define SYS_OMAP_DSS_LCD_INTERRUPT_ENABLE_REG 0x101c
+
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_ENABLE_MASK 0x40002
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_STATUS_MASK 0x40002
+
+
+#define SYS_OMAP3630_GP11TIMER_ENABLE_SYS_PHYS_BASE      0x48088024
+#define SYS_OMAP3630_GP11TIMER_REGS_SYS_PHYS_BASE        0x48088028
+#define SYS_OMAP3630_GP11TIMER_TSICR_SYS_PHYS_BASE       0x48088040
+
+
+
+/* Interrupt bits */
+#define DEVICE_SGX_INTERRUPT           (1<<0)
+#define DEVICE_MSVDX_INTERRUPT         (1<<1)
+#define DEVICE_DISP_INTERRUPT          (1<<2)
+
+#if 0
+#if defined(__linux__)
+/*
+ * Recent OMAP4 kernels register SGX as platform device "omap_gpu".
+ * This device must be used with the Linux power management calls
+ * in sysutils_linux.c, in order for SGX to be powered on.
+ */
+#if defined(PVR_LDM_PLATFORM_PRE_REGISTERED_DEV)
+#define        SYS_SGX_DEV_NAME        PVR_LDM_PLATFORM_PRE_REGISTERED_DEV
+#else
+#define        SYS_SGX_DEV_NAME        "omap_gpu"
+#endif /* defined(PVR_LDM_PLATFORM_PRE_REGISTERED_DEV) */
+#endif /* defined(__linux__) */
+#endif
 
+/*****************************************************************************
+ * system specific data structures
+ *****************************************************************************/
  
-#endif 
+#endif /* __SYSCONFIG_H__ */
index e42b36b..7383b9c 100644 (file)
@@ -1,33 +1,62 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Description Header
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides system-specific declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SYSINFO_H__)
 #define __SYSINFO_H__
 
+#if defined(SGX540) && (SGX_CORE_REV == 120)
+#define SYS_SGX_CLOCK_SPEED            307200000
+#else
+#define SYS_SGX_CLOCK_SPEED            200000000
+#endif
+
+/*!< System specific poll/timeout details */
 #if defined(PVR_LINUX_USING_WORKQUEUES)
+/*
+ * The workqueue based 3rd party display driver may be blocked for up
+ * to 500ms waiting for a vsync when the screen goes blank, so we
+ * need to wait longer for the hardware if a flush of the swap chain is
+ * required.
+ */
 #define MAX_HW_TIME_US                         (1000000)
 #define WAIT_TRY_COUNT                         (20000)
 #else
@@ -36,6 +65,6 @@
 #endif
 
 
-#define SYS_DEVICE_COUNT 15
+#define SYS_DEVICE_COUNT 15 /* SGX, DISPLAYCLASS (external), BUFFERCLASS (external) */
 
-#endif 
+#endif /* __SYSINFO_H__ */
index 0ae7ef5..090b38d 100644 (file)
@@ -1,28 +1,44 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          Local system definitions
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides local system declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SYSLOCAL_H__)
 #define __SYSLOCAL_H__
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
 #include <linux/semaphore.h>
 #include <linux/resource.h>
-#else 
+#else /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) */
 #include <asm/semaphore.h>
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
 #include <asm/arch/resource.h>
-#endif 
-#endif 
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)) */
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) */
 
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
 #if !defined(LDM_PLATFORM)
 #error "LDM_PLATFORM must be set"
 #endif
-/*#define      PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO*/
+//#define      PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO
 //#include <linux/platform_device.h>
 #endif
 
 #if ((defined(DEBUG) || defined(TIMING)) && \
     (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))) && \
     !defined(PVR_NO_OMAP_TIMER)
-#define        PVR_OMAP3_TIMING_PRCM
+/*
+ * We need to explicitly enable the GPTIMER11 clocks, or we'll get an
+ * abort when we try to access the timer registers.
+ */
+#define        PVR_OMAP4_TIMING_PRCM
 #endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
-/*#include <plat/gpu.h>*/
+//#include <plat/gpu.h>
 #if !defined(PVR_NO_OMAP_TIMER)
-/*#define      PVR_OMAP_USE_DM_TIMER_API*/
+//#define      PVR_OMAP_USE_DM_TIMER_API
 //#include <plat/dmtimer.h>
 #endif
 #endif
@@ -74,7 +94,7 @@
 #if !defined(PVR_NO_OMAP_TIMER)
 //#define PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA
 #endif
-#endif 
+#endif /* defined(__linux__) */
 
 #if !defined(NO_HARDWARE) && \
      defined(SYS_USING_INTERRUPTS) && \
 #endif
 
 #if defined(__linux__)
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) && defined(SGX_OCP_REGS_ENABLED)
-/*#define SGX_OCP_NO_INT_BYPASS*/
+#if defined(SGX_OCP_REGS_ENABLED)
+/* FIXME: Temporary workaround for OMAP4470 and active power off in 4430 */
+#if !defined(SGX544) && defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+//#define SGX_OCP_NO_INT_BYPASS
+#endif
 #endif
 #endif
 
 extern "C" {
 #endif
 
+/*****************************************************************************
+ * system specific data structures
+ *****************************************************************************/
  
+/*****************************************************************************
+ * system specific function prototypes
+ *****************************************************************************/
  
 IMG_VOID DisableSystemClocks(SYS_DATA *psSysData);
 PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData);
@@ -100,6 +129,10 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData);
 IMG_VOID DisableSGXClocks(SYS_DATA *psSysData);
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData);
 
+/*
+ * Various flags to indicate what has been initialised, and what
+ * has been temporarily deinitialised for power management purposes.
+ */
 #define SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS     0x00000001
 #define SYS_SPECIFIC_DATA_ENABLE_LISR          0x00000002
 #define SYS_SPECIFIC_DATA_ENABLE_MISR          0x00000004
@@ -114,9 +147,8 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData);
 #define        SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS  0x00000400
 #define SYS_SPECIFIC_DATA_ENABLE_OCPREGS       0x00000800
 #define SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME    0x00001000
-#if defined(SGX_OCP_REGS_ENABLED) && defined(SGX_OCP_NO_INT_BYPASS)
 #define SYS_SPECIFIC_DATA_IRQ_ENABLED          0x00002000
-#endif
+#define SYS_SPECIFIC_DATA_DVFS_INIT                    0x00004000
 
 #define        SYS_SPECIFIC_DATA_SET(psSysSpecData, flag) ((IMG_VOID)((psSysSpecData)->ui32SysSpecificData |= (flag)))
 
@@ -149,8 +181,8 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
        atomic_t        sNotifyLockCPU;
        IMG_BOOL        bCallVDD2PostFunc;
 #endif
-       struct clk      *psCORE_CK;
-        struct clk      *psSGX_FCK;
+        struct clk      *psCORE_CK;
+       struct clk      *psSGX_FCK;
         struct clk      *psSGX_ICK;
 
 #if defined(DEBUG) || defined(TIMING)
@@ -160,7 +192,10 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
 #if defined(PVR_OMAP_USE_DM_TIMER_API)
        struct omap_dm_timer *psGPTimer;
 #endif
-#endif 
+       IMG_UINT32 ui32SGXFreqListSize;
+       IMG_UINT32 *pui32SGXFreqList;
+       IMG_UINT32 ui32SGXFreqListIndex;
+#endif /* defined(__linux__) */
 } SYS_SPECIFIC_DATA;
 
 extern SYS_SPECIFIC_DATA *gpsSysSpecificData;
@@ -183,7 +218,10 @@ IMG_VOID UnwrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData);
 PVRSRV_ERROR SysPMRuntimeRegister(void);
 PVRSRV_ERROR SysPMRuntimeUnregister(void);
 
-#else 
+PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData);
+PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData);
+
+#else /* defined(__linux__) */
 
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(SysPMRuntimeRegister)
@@ -201,12 +239,28 @@ static INLINE PVRSRV_ERROR SysPMRuntimeUnregister(void)
        return PVRSRV_OK;
 }
 
-#endif 
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(SysDvfsInitialize)
+#endif
+static INLINE PVRSRV_ERROR SysDvfsInitialize(void)
+{
+       return PVRSRV_OK;
+}
+
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(SysDvfsDeinitialize)
+#endif
+static INLINE PVRSRV_ERROR SysDvfsDeinitialize(void)
+{
+       return PVRSRV_OK;
+}
+
+#endif /* defined(__linux__) */
 
 #if defined(__cplusplus)
 }
 #endif
 
-#endif 
+#endif /* __SYSLOCAL_H__ */
 
 
index 8736fcc..27b2df6 100644 (file)
@@ -1,30 +1,49 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          Shared (User/kernel) and System dependent utilities
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    Provides system-specific functions
+@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.
+*/ /**************************************************************************/
+
+/* Pull in the correct system dependent sysutils source */
 
 #if defined(__linux__)
 #include "sysutils_linux.c"
 #endif
 
+
index e6b0644..6a5d862 100644 (file)
@@ -1,34 +1,50 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
-
+/*************************************************************************/ /*!
+@Title          System dependent utilities
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    Provides system-specific functions
+@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.
+*/ /**************************************************************************/
 #include <linux/version.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/hardirq.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 
 #include "sgxdefs.h"
 #include "services_headers.h"
 #include "sgxinfokm.h"
 #include "syslocal.h"
 
-//#include <linux/platform_device.h>
-//#include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+#include <linux/opp.h>
+#endif
+
+#if defined(SUPPORT_DRI_DRM_PLUGIN)
+#include <drm/drmP.h>
+#include <drm/drm.h>
+
+#include <linux/omap_gpu.h>
+
+#include "pvr_drm.h"
+#endif
 
 #define        ONE_MHZ 1000000
 #define        HZ_TO_MHZ(m) ((m) / ONE_MHZ)
 extern struct platform_device *gpsPVRLDMDev;
 #endif
 
-
 static PVRSRV_ERROR PowerLockWrap(SYS_SPECIFIC_DATA *psSysSpecData, IMG_BOOL bTryLock)
 {
-        if (!in_interrupt())
-        {
-                if (bTryLock)
-                {
-                        int locked = mutex_trylock(&psSysSpecData->sPowerLock);
-                        if (locked == 0)
-                        {
-                                return PVRSRV_ERROR_RETRY;
-                        }
-                }
-                else
-                {
-                        mutex_lock(&psSysSpecData->sPowerLock);
-                }
-        }
+       if (!in_interrupt())
+       {
+               if (bTryLock)
+               {
+                       int locked = mutex_trylock(&psSysSpecData->sPowerLock);
+                       if (locked == 0)
+                       {
+                               return PVRSRV_ERROR_RETRY;
+                       }
+               }
+               else
+               {
+                       mutex_lock(&psSysSpecData->sPowerLock);
+               }
+       }
 
-        return PVRSRV_OK;
+       return PVRSRV_OK;
 }
 
 static IMG_VOID PowerLockUnwrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-        if (!in_interrupt())
-        {
-                mutex_unlock(&psSysSpecData->sPowerLock);
-        }
+       if (!in_interrupt())
+       {
+               mutex_unlock(&psSysSpecData->sPowerLock);
+       }
 }
 
 PVRSRV_ERROR SysPowerLockWrap(IMG_BOOL bTryLock)
 {
-        SYS_DATA        *psSysData;
+       SYS_DATA        *psSysData;
 
-        SysAcquireData(&psSysData);
+       SysAcquireData(&psSysData);
 
-        return PowerLockWrap(psSysData->pvSysSpecificData, bTryLock);
+       return PowerLockWrap(psSysData->pvSysSpecificData, bTryLock);
 }
 
 IMG_VOID SysPowerLockUnwrap(IMG_VOID)
 {
-        SYS_DATA        *psSysData;
+       SYS_DATA        *psSysData;
 
-        SysAcquireData(&psSysData);
+       SysAcquireData(&psSysData);
 
-        PowerLockUnwrap(psSysData->pvSysSpecificData);
+       PowerLockUnwrap(psSysData->pvSysSpecificData);
 }
 
-
-
-
+/*
+ * This function should be called to unwrap the Services power lock, prior
+ * to calling any function that might sleep.
+ * This function shouldn't be called prior to calling EnableSystemClocks
+ * or DisableSystemClocks, as those functions perform their own power lock
+ * unwrapping.
+ * If the function returns IMG_TRUE, UnwrapSystemPowerChange must be
+ * called to rewrap the power lock, prior to returning to Services.
+ */
 IMG_BOOL WrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        return IMG_TRUE;
@@ -114,76 +148,64 @@ IMG_VOID UnwrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
 }
 
-static inline IMG_UINT32 scale_by_rate(IMG_UINT32 val, IMG_UINT32 rate1, IMG_UINT32 rate2)
-{
-       if (rate1 >= rate2)
-       {
-               return val * (rate1 / rate2);
-       }
-
-       return val / (rate2 / rate1);
-}
-
-static inline IMG_UINT32 scale_prop_to_SGX_clock(IMG_UINT32 val, IMG_UINT32 rate)
-{
-       return scale_by_rate(val, rate, SYS_SGX_CLOCK_SPEED);
-}
-
-static inline IMG_UINT32 scale_inv_prop_to_SGX_clock(IMG_UINT32 val, IMG_UINT32 rate)
-{
-       return scale_by_rate(val, SYS_SGX_CLOCK_SPEED, rate);
-}
-
+/*
+ * Return SGX timining information to caller.
+ */
 IMG_VOID SysGetSGXTimingInformation(SGX_TIMING_INFORMATION *psTimingInfo)
 {
-       IMG_UINT32 rate;
-
-       rate = SYS_SGX_CLOCK_SPEED;
 #if !defined(NO_HARDWARE)
        PVR_ASSERT(atomic_read(&gpsSysSpecificData->sSGXClocksEnabled) != 0);
 #endif
-       psTimingInfo->ui32CoreClockSpeed = rate;
-       psTimingInfo->ui32HWRecoveryFreq = scale_prop_to_SGX_clock(SYS_SGX_HWRECOVERY_TIMEOUT_FREQ, rate);
-       psTimingInfo->ui32uKernelFreq = scale_prop_to_SGX_clock(SYS_SGX_PDS_TIMER_FREQ, rate);
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       psTimingInfo->ui32CoreClockSpeed =
+               gpsSysSpecificData->pui32SGXFreqList[gpsSysSpecificData->ui32SGXFreqListIndex];
+#else /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
+#endif
+       psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ;
+       psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ;
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
        psTimingInfo->bEnableActivePM = IMG_TRUE;
 #else
        psTimingInfo->bEnableActivePM = IMG_FALSE;
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS;
 }
 
+/*!
+******************************************************************************
+
+ @Function  EnableSGXClocks
+
+ @Description Enable SGX clocks
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-       IMG_INT res;
-       long lRate,lNewRate;
-       
+#if !defined(PM_RUNTIME_SUPPORT)
+        IMG_INT res;
+        long lRate,lNewRate;
+#endif
+       /* SGX clocks already enabled? */
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) != 0)
        {
                return PVRSRV_OK;
        }
 
-       PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
-       
-       res=clk_enable(psSysSpecData->psSGX_FCK);
-       if (res < 0)
-        {
-                PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX functional clock (%d)", res));
-                return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
-        }
-
-       res=clk_enable(psSysSpecData->psSGX_ICK);
+#if !defined(PM_RUNTIME_SUPPORT)
+        PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
+        res=clk_enable(psSysSpecData->psSGX_FCK);
         if (res < 0)
         {
-                PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX interface clock (%d)", res));
-
-                clk_disable(psSysSpecData->psSGX_FCK);
+                PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX functional clock (%d)", res));
                 return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
         }
 
-       lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
+        lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
         if (lNewRate <= 0)
         {
                 PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't round SGX functional clock rate"));
@@ -198,7 +220,7 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                 if (res < 0)
                 {
                         PVR_DPF((PVR_DBG_WARNING, "EnableSGXClocks: Couldn't set SGX functional clock rate (%d)", res));
-                       return PVRSRV_ERROR_UNABLE_TO_SET_CLOCK_RATE;
+                        return PVRSRV_ERROR_UNABLE_TO_SET_CLOCK_RATE;
                 }
         }
 
@@ -208,75 +230,194 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                 PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: SGX Functional Clock is %dMhz", HZ_TO_MHZ(rate)));
         }
 #endif
-
-
-
+#endif 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        {
-               
-//             int res = pm_runtime_get_sync(&gpsPVRLDMDev->dev);
-//             if (res < 0)
-//             {
-//                     PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: pm_runtime_get_sync failed (%d)", -res));
-//                     return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
-//             }
+               struct gpu_platform_data *pdata;
+               IMG_UINT32 max_freq_index;
+               int res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+               max_freq_index = psSysSpecData->ui32SGXFreqListSize - 2;
+
+               /*
+                * Request maximum frequency from DVFS layer if not already set. DVFS may
+                * report busy if early in initialization, but all other errors are
+                * considered serious. Upon any error we proceed assuming our safe frequency
+                * value to be in use as indicated by the "unknown" index.
+                */
+               if (psSysSpecData->ui32SGXFreqListIndex != max_freq_index)
+               {
+                       PVR_ASSERT(pdata->device_scale != IMG_NULL);
+                       res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                         &gpsPVRLDMDev->dev,
+#endif
+                                                                         psSysSpecData->pui32SGXFreqList[max_freq_index]);
+                       if (res == 0)
+                       {
+                               psSysSpecData->ui32SGXFreqListIndex = max_freq_index;
+                       }
+                       else if (res == -EBUSY)
+                       {
+                               PVR_DPF((PVR_DBG_WARNING, "EnableSGXClocks: Unable to scale SGX frequency (EBUSY)"));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+                       else if (res < 0)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Unable to scale SGX frequency (%d)", res));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+               }
        }
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       {
+               /*
+                * pm_runtime_get_sync returns 1 after the module has
+                * been reloaded.
+                */
+#if defined(PM_RUNTIME_SUPPORT)
+
+               int res = pm_runtime_get_sync(&gpsPVRLDMDev->dev);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: pm_runtime_get_sync failed (%d)", -res));
+                       return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
+               }
 #endif
-//     SysEnableSGXInterrupts(psSysData);
+       }
+#endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
-       
+       SysEnableSGXInterrupts(psSysData);
+
+       /* Indicate that the SGX clocks are enabled */
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 1);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function  DisableSGXClocks
+
+ @Description Disable SGX clocks.
+
+ @Return   none
+
+******************************************************************************/
 IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
 
+       /* SGX clocks already disabled? */
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) == 0)
        {
                return;
        }
-       
-       PVR_DPF((PVR_DBG_MESSAGE, "DisableSGXClocks: Disabling SGX Clocks"));
-       
-       clk_disable(psSysSpecData->psSGX_FCK);
-
-       clk_disable(psSysSpecData->psSGX_ICK);
 
-//     SysDisableSGXInterrupts(psSysData);
+       PVR_DPF((PVR_DBG_MESSAGE, "DisableSGXClocks: Disabling SGX Clocks"));
+#if !defined(PM_RUNTIME_SUPPORT)
+        clk_disable(psSysSpecData->psSGX_FCK);
+#endif
+       SysDisableSGXInterrupts(psSysData);
 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
        {
-//             int res = pm_runtime_put_sync(&gpsPVRLDMDev->dev);
-//             if (res < 0)
-//             {
-//                     PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
-//             }
+#if defined(PM_RUNTIME_SUPPORT)
+
+               int res = pm_runtime_put_sync(&gpsPVRLDMDev->dev);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
+               }
+#endif
        }
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       {
+               struct gpu_platform_data *pdata;
+               int res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+
+               /*
+                * Request minimum frequency (list index 0) from DVFS layer if not already
+                * set. DVFS may report busy if early in initialization, but all other errors
+                * are considered serious. Upon any error we proceed assuming our safe frequency
+                * value to be in use as indicated by the "unknown" index.
+                */
+               if (psSysSpecData->ui32SGXFreqListIndex != 0)
+               {
+                       PVR_ASSERT(pdata->device_scale != IMG_NULL);
+                       res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                         &gpsPVRLDMDev->dev,
 #endif
+                                                                         psSysSpecData->pui32SGXFreqList[0]);
+                       if (res == 0)
+                       {
+                               psSysSpecData->ui32SGXFreqListIndex = 0;
+                       }
+                       else if (res == -EBUSY)
+                       {
+                               PVR_DPF((PVR_DBG_WARNING, "DisableSGXClocks: Unable to scale SGX frequency (EBUSY)"));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+                       else if (res < 0)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: Unable to scale SGX frequency (%d)", res));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+               }
+       }
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+#endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
+       /* Indicate that the SGX clocks are disabled */
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
 }
 
 #if (defined(DEBUG) || defined(TIMING)) && !defined(PVR_NO_OMAP_TIMER)
 #if defined(PVR_OMAP_USE_DM_TIMER_API)
 #define        GPTIMER_TO_USE 11
+/*!
+******************************************************************************
+
+ @Function  AcquireGPTimer
+
+ @Description Acquire a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_ASSERT(psSysSpecData->psGPTimer == NULL);
 
-       
+       /*
+        * This code has problems on module reload for OMAP5 running Linux
+        * 3.4.10, due to omap2_dm_timer_set_src (called by
+        * omap_dm_timer_request_specific), being unable to set the parent
+        * clock to OMAP_TIMER_SRC_32_KHZ.
+        * Not calling omap_dm_timer_set_source doesn't help.
+        */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) || !defined(MODULE)
+       /*
+        * This code could try requesting registers 9, 10, and 11,
+        * stopping at the first succesful request.  We'll stick with
+        * 11 for now, as it avoids having to hard code yet more
+        * physical addresses into the code.
+        */
        psSysSpecData->psGPTimer = omap_dm_timer_request_specific(GPTIMER_TO_USE);
        if (psSysSpecData->psGPTimer == NULL)
        {
@@ -285,26 +426,41 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
        }
 
-       
        omap_dm_timer_set_source(psSysSpecData->psGPTimer, OMAP_TIMER_SRC_SYS_CLK);
        omap_dm_timer_enable(psSysSpecData->psGPTimer);
 
-       
+       /* Set autoreload, and start value of 0 */
        omap_dm_timer_set_load_start(psSysSpecData->psGPTimer, 1, 0);
 
        omap_dm_timer_start(psSysSpecData->psGPTimer);
 
-       
-       psSysSpecData->sTimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_REGS_SYS_PHYS_BASE;
+       /*
+        * The DM timer API doesn't have a mechanism for obtaining the
+        * physical address of the counter register.
+        */
+       psSysSpecData->sTimerRegPhysBase.uiAddr = SYS_OMAP3630_GP11TIMER_REGS_SYS_PHYS_BASE;
+#else  /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
+       (void)psSysSpecData;
+#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
 
        return PVRSRV_OK;
 }
 
+/*!
+******************************************************************************
+
+ @Function  ReleaseGPTimer
+
+ @Description Release a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        if (psSysSpecData->psGPTimer != NULL)
        {
-                       
+               /* Always returns 0 */  
                (void) omap_dm_timer_stop(psSysSpecData->psGPTimer);
 
                omap_dm_timer_disable(psSysSpecData->psGPTimer);
@@ -317,10 +473,20 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        }
 
 }
-#else  
+#else  /* PVR_OMAP_USE_DM_TIMER_API */
+/*!
+******************************************************************************
+
+ @Function  AcquireGPTimer
+
+ @Description Acquire a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        struct clk *psCLK;
        IMG_INT res;
        struct clk *sys_ck;
@@ -335,9 +501,8 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        PVR_ASSERT(psSysSpecData->sTimerRegPhysBase.uiAddr == 0);
 #endif
 
-
-#if defined(PVR_OMAP3_TIMING_PRCM)
-       
+#if defined(PVR_OMAP4_TIMING_PRCM)
+       /* assert our dependence on the GPTIMER11 module */
        psCLK = clk_get(NULL, "gpt11_fck");
        if (IS_ERR(psCLK))
        {
@@ -353,7 +518,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitError;
        }
        psSysSpecData->psGPT11_ICK = psCLK;
-
+       
        sys_ck = clk_get(NULL, "sys_ck");
        if (IS_ERR(sys_ck))
        {
@@ -371,6 +536,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitError;
                }
        }
+       
        rate = clk_get_rate(psSysSpecData->psGPT11_FCK);
        PVR_TRACE(("GPTIMER11 clock is %dMHz", HZ_TO_MHZ(rate)));
 
@@ -387,10 +553,10 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't enable GPTIMER11 interface clock (%d)", res));
                goto ExitDisableGPT11FCK;
        }
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 
-       
-       sTimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_TSICR_SYS_PHYS_BASE;
+       /* Set the timer to non-posted mode */
+       sTimerRegPhysBase.uiAddr = SYS_OMAP3630_GP11TIMER_TSICR_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
                   PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -406,7 +572,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        {
                PVR_TRACE(("Setting GPTIMER11 mode to posted (currently is non-posted)"));
 
-               
+               /* Set posted mode */
                *pui32TimerEnable |= 4;
        }
 
@@ -415,8 +581,8 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                    PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                    hTimerEnable);
 
-       
-       sTimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE;
+       /* Enable the timer */
+       sTimerRegPhysBase.uiAddr = SYS_OMAP3630_GP11TIMER_ENABLE_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
                   PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -428,6 +594,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitDisableGPT11ICK;
        }
 
+       /* Enable and set autoreload on overflow */
        *pui32TimerEnable = 3;
 
        OSUnMapPhysToLin(pui32TimerEnable,
@@ -437,23 +604,32 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        psSysSpecData->sTimerRegPhysBase = sTimerRegPhysBase;
 #endif
-
        eError = PVRSRV_OK;
 
        goto Exit;
 
 ExitDisableGPT11ICK:
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        clk_disable(psSysSpecData->psGPT11_ICK);
 ExitDisableGPT11FCK:
        clk_disable(psSysSpecData->psGPT11_FCK);
 ExitError:
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
        eError = PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
 Exit:
        return eError;
 }
 
+/*!
+******************************************************************************
+
+ @Function  ReleaseGPTimer
+
+ @Description Release a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        IMG_HANDLE hTimerDisable;
@@ -465,7 +641,7 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return;
        }
 #endif
-       TimerRegPhysBase.uiAddr = SYS_OMAP3430_GP11TIMER_ENABLE_SYS_PHYS_BASE;  
+       /* Disable the timer */
        pui32TimerDisable = OSMapPhysToLin(TimerRegPhysBase,
                                4,
                                PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -484,35 +660,47 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                                PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                                hTimerDisable);
        }
-
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        psSysSpecData->sTimerRegPhysBase.uiAddr = 0;
 #endif
-
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        clk_disable(psSysSpecData->psGPT11_ICK);
 
        clk_disable(psSysSpecData->psGPT11_FCK);
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 }
-#endif 
-#else  
+#endif /* PVR_OMAP_USE_DM_TIMER_API */
+#else  /* (DEBUG || TIMING) && !PVR_NO_OMAP_TIMER */
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_UNREFERENCED_PARAMETER(psSysSpecData);
+
        return PVRSRV_OK;
 }
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_UNREFERENCED_PARAMETER(psSysSpecData);
 }
-#endif 
+#endif /* (DEBUG || TIMING) && !PVR_NO_OMAP_TIMER */
+
+/*!
+******************************************************************************
+
+ @Function  EnableSystemClocks
+
+ @Description Setup up the clocks for the graphics device to work.
 
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-       struct clk *psCLK;
+#if !defined(PM_RUNTIME_SUPPORT)
+        struct clk *psCLK;
        IMG_INT res;
+#endif
+
        PVR_TRACE(("EnableSystemClocks: Enabling System Clocks"));
 
        if (!psSysSpecData->bSysClocksOneTimeInit)
@@ -520,8 +708,8 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                mutex_init(&psSysSpecData->sPowerLock);
 
                atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
-
-                psCLK = clk_get(NULL, SGX_PARENT_CLOCK);
+               
+               psCLK = clk_get(NULL, SGX_PARENT_CLOCK);
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSsystemClocks: Couldn't get Core Clock"));
@@ -529,7 +717,10 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                 }
                 psSysSpecData->psCORE_CK = psCLK;
 
-               psCLK = clk_get(NULL, "sgx_fck");
+
+//             psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+#if !defined(PM_RUNTIME_SUPPORT)
+                psCLK = clk_get(NULL, "sgx_fck");
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSsystemClocks: Couldn't get SGX Functional Clock"));
@@ -537,7 +728,7 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                 }
                 psSysSpecData->psSGX_FCK = psCLK;
 
-                psCLK = clk_get(NULL, "sgx_ick");
+               psCLK = clk_get(NULL, "sgx_ick");
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't get SGX Interface Clock"));
@@ -553,27 +744,48 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
                 }
 
 
-               psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+                psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+
+
+#endif
+
        }
 
        return AcquireGPTimer(psSysSpecData);
 }
 
+/*!
+******************************************************************************
+
+ @Function  DisableSystemClocks
+
+ @Description Disable the graphics clocks.
+
+ @Return  none
+
+******************************************************************************/
 IMG_VOID DisableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
+
        PVR_TRACE(("DisableSystemClocks: Disabling System Clocks"));
-       
+
+       /*
+        * Always disable the SGX clocks when the system clocks are disabled.
+        * This saves having to make an explicit call to DisableSGXClocks if
+        * active power management is enabled.
+        */
        DisableSGXClocks(psSysData);
 
        ReleaseGPTimer(psSysSpecData);
-
 }
 
 PVRSRV_ERROR SysPMRuntimeRegister(void)
 {
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-//     pm_runtime_enable(&gpsPVRLDMDev->dev);
+#if defined(PM_RUNTIME_SUPPORT)
+       pm_runtime_enable(&gpsPVRLDMDev->dev);
+#endif
 #endif
        return PVRSRV_OK;
 }
@@ -581,7 +793,166 @@ PVRSRV_ERROR SysPMRuntimeRegister(void)
 PVRSRV_ERROR SysPMRuntimeUnregister(void)
 {
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-//     pm_runtime_disable(&gpsPVRLDMDev->dev);
+#if defined(PM_RUNTIME_SUPPORT)
+       pm_runtime_disable(&gpsPVRLDMDev->dev);
+#endif
 #endif
        return PVRSRV_OK;
 }
+
+PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
+{
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       IMG_UINT32 i, *freq_list;
+       IMG_INT32 opp_count;
+       unsigned long freq;
+       struct opp *opp;
+
+       /*
+        * We query and store the list of SGX frequencies just this once under the
+        * assumption that they are unchanging, e.g. no disabling of high frequency
+        * option for thermal management. This is currently valid for 4430 and 4460.
+        */
+       rcu_read_lock();
+       opp_count = opp_get_opp_count(&gpsPVRLDMDev->dev);
+       if (opp_count < 1)
+       {
+               rcu_read_unlock();
+               PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not retrieve opp count"));
+               return PVRSRV_ERROR_NOT_SUPPORTED;
+       }
+
+       /*
+        * Allocate the frequency list with a slot for each available frequency plus
+        * one additional slot to hold a designated frequency value to assume when in
+        * an unknown frequency state.
+        */
+       freq_list = kmalloc((opp_count + 1) * sizeof(IMG_UINT32), GFP_ATOMIC);
+       if (!freq_list)
+       {
+               rcu_read_unlock();
+               PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not allocate frequency list"));
+               return PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+
+       /*
+        * Fill in frequency list from lowest to highest then finally the "unknown"
+        * frequency value. We use the highest available frequency as our assumed value
+        * when in an unknown state, because it is safer for APM and hardware recovery
+        * timers to be longer than intended rather than shorter.
+        */
+       freq = 0;
+       for (i = 0; i < opp_count; i++)
+       {
+               opp = opp_find_freq_ceil(&gpsPVRLDMDev->dev, &freq);
+               if (IS_ERR_OR_NULL(opp))
+               {
+                       rcu_read_unlock();
+                       PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not retrieve opp level %d", i));
+                       kfree(freq_list);
+                       return PVRSRV_ERROR_NOT_SUPPORTED;
+               }
+               freq_list[i] = (IMG_UINT32)freq;
+               freq++;
+       }
+       rcu_read_unlock();
+       freq_list[opp_count] = freq_list[opp_count - 1];
+
+       psSysSpecificData->ui32SGXFreqListSize = opp_count + 1;
+       psSysSpecificData->pui32SGXFreqList = freq_list;
+
+       /* Start in unknown state - no frequency request to DVFS yet made */
+       psSysSpecificData->ui32SGXFreqListIndex = opp_count;
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+
+       return PVRSRV_OK;
+}
+
+PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
+{
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       /*
+        * We assume this function is only called if SysDvfsInitialize() was
+        * completed successfully before.
+        *
+        * The DVFS interface does not allow us to actually unregister as a
+        * user of SGX, so we do the next best thing which is to lower our
+        * required frequency to the minimum if not already set. DVFS may
+        * report busy if early in initialization, but all other errors are
+        * considered serious.
+        */
+       if (psSysSpecificData->ui32SGXFreqListIndex != 0)
+       {
+               struct gpu_platform_data *pdata;
+               IMG_INT32 res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+
+               PVR_ASSERT(pdata->device_scale != IMG_NULL);
+               res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                 &gpsPVRLDMDev->dev,
+#endif
+                                                                 psSysSpecificData->pui32SGXFreqList[0]);
+               if (res == -EBUSY)
+               {
+                       PVR_DPF((PVR_DBG_WARNING, "SysDvfsDeinitialize: Unable to scale SGX frequency (EBUSY)"));
+               }
+               else if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "SysDvfsDeinitialize: Unable to scale SGX frequency (%d)", res));
+               }
+
+               psSysSpecificData->ui32SGXFreqListIndex = 0;
+       }
+
+       kfree(psSysSpecificData->pui32SGXFreqList);
+       psSysSpecificData->pui32SGXFreqList = 0;
+       psSysSpecificData->ui32SGXFreqListSize = 0;
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+
+       return PVRSRV_OK;
+}
+
+#if defined(SUPPORT_DRI_DRM_PLUGIN)
+static struct omap_gpu_plugin sOMAPGPUPlugin;
+
+#define        SYS_DRM_SET_PLUGIN_FIELD(d, s, f) (d)->f = (s)->f
+int
+SysDRMRegisterPlugin(PVRSRV_DRM_PLUGIN *psDRMPlugin)
+{
+       int iRes;
+
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, name);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, open);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, load);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, unload);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, release);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, mmap);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, ioctls);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, num_ioctls);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, ioctl_start);
+
+       iRes = omap_gpu_register_plugin(&sOMAPGPUPlugin);
+       if (iRes != 0)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: omap_gpu_register_plugin failed (%d)", __FUNCTION__, iRes));
+       }
+
+       return iRes;
+}
+
+void
+SysDRMUnregisterPlugin(PVRSRV_DRM_PLUGIN *psDRMPlugin)
+{
+       int iRes = omap_gpu_unregister_plugin(&sOMAPGPUPlugin);
+       if (iRes != 0)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: omap_gpu_unregister_plugin failed (%d)", __FUNCTION__, iRes));
+       }
+}
+#endif
index c8eea1e..0902042 100644 (file)
@@ -1,28 +1,43 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          SGX kernel/client driver interface structures and prototypes
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__OEMFUNCS_H__)
 #define __OEMFUNCS_H__
 extern "C" {
 #endif
 
+/* function in/out data structures: */
 typedef IMG_UINT32   (*PFN_SRV_BRIDGEDISPATCH)( IMG_UINT32  Ioctl,
                                                                                                IMG_BYTE   *pInBuf,
                                                                                                IMG_UINT32  InBufLen, 
                                                                                            IMG_BYTE   *pOutBuf,
                                                                                                IMG_UINT32  OutBufLen,
                                                                                                IMG_UINT32 *pdwBytesTransferred);
+/*
+       Function table for kernel 3rd party driver to kernel services
+*/
 typedef struct PVRSRV_DC_OEM_JTABLE_TAG
 {
        PFN_SRV_BRIDGEDISPATCH                  pfnOEMBridgeDispatch;
@@ -52,5 +71,10 @@ typedef struct PVRSRV_DC_OEM_JTABLE_TAG
 }
 #endif
 
-#endif 
+#endif /* __OEMFUNCS_H__ */
+
+/*****************************************************************************
+ End of file (oemfuncs.h)
+*****************************************************************************/
+
 
index 0d23f62..be71344 100644 (file)
@@ -1,28 +1,44 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Configuration
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    System Configuration functions
+@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.
+*/ /**************************************************************************/
 
 #include "sysconfig.h"
 #include "services_headers.h"
 
 #include "ocpdefs.h"
 
+/* top level system data anchor point*/
 SYS_DATA* gpsSysData = (SYS_DATA*)IMG_NULL;
 SYS_DATA  gsSysData;
 
 static SYS_SPECIFIC_DATA gsSysSpecificData;
 SYS_SPECIFIC_DATA *gpsSysSpecificData;
 
-static IMG_UINT32      gui32SGXDeviceID;
-static SGX_DEVICE_MAP  gsSGXDeviceMap;
-static PVRSRV_DEVICE_NODE *gpsSGXDevNode;
+/* SGX structures */
+static IMG_UINT32                      gui32SGXDeviceID;
+static SGX_DEVICE_MAP          gsSGXDeviceMap;
+static PVRSRV_DEVICE_NODE      *gpsSGXDevNode;
 
-#define DEVICE_SGX_INTERRUPT (1 << 0)
 
 #if defined(NO_HARDWARE) || defined(SGX_OCP_REGS_ENABLED)
 static IMG_CPU_VIRTADDR gsSGXRegsCPUVAddr;
@@ -79,14 +96,14 @@ static PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
        return eError;
 }
 
-#else 
+#else /* defined(SGX_OCP_REGS_ENABLED) */
 
 static INLINE PVRSRV_ERROR EnableSGXClocksWrap(SYS_DATA *psSysData)
 {
        return EnableSGXClocks(psSysData);
 }
 
-#endif 
+#endif /* defined(SGX_OCP_REGS_ENABLED) */
 
 static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
 {
@@ -95,7 +112,10 @@ static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
 #if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
        if(eError == PVRSRV_OK)
        {
-               
+               /*
+                * The SGX Clocks are enabled separately if active power
+                * management is enabled.
+                */
                eError = EnableSGXClocksWrap(psSysData);
                if (eError != PVRSRV_OK)
                {
@@ -107,6 +127,18 @@ static INLINE PVRSRV_ERROR EnableSystemClocksWrap(SYS_DATA *psSysData)
        return eError;
 }
 
+/*!
+******************************************************************************
+
+ @Function     SysLocateDevices
+
+ @Description  Specifies devices in the systems memory map
+
+ @Input                psSysData - sys data
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 {
 #if defined(NO_HARDWARE)
@@ -121,12 +153,16 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
 
        PVR_UNREFERENCED_PARAMETER(psSysData);
 
-       
+       /* SGX Device: */
        gsSGXDeviceMap.ui32Flags = 0x0;
        
 #if defined(NO_HARDWARE)
-       
-       
+       /* 
+        * For no hardware, allocate some contiguous memory for the
+        * register block.
+        */
+
+       /* Registers */
        gsSGXDeviceMap.ui32RegsSize = SYS_TI335x_SGX_REGS_SIZE;
 
        eError = OSBaseAllocContigMemory(gsSGXDeviceMap.ui32RegsSize,
@@ -139,23 +175,27 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
        gsSGXDeviceMap.sRegsCpuPBase = sCpuPAddr;
        gsSGXDeviceMap.sRegsSysPBase = SysCpuPAddrToSysPAddr(gsSGXDeviceMap.sRegsCpuPBase);
 #if defined(__linux__)
-       
+       /* Indicate the registers are already mapped */
        gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
 #else
-       
+       /*
+        * FIXME: Could we just use the virtual address returned by
+        * OSBaseAllocContigMemory?
+        */
        gsSGXDeviceMap.pvRegsCpuVBase = IMG_NULL;
 #endif
 
        OSMemSet(gsSGXRegsCPUVAddr, 0, gsSGXDeviceMap.ui32RegsSize);
 
-       
-
-
+       /*
+               device interrupt IRQ
+               Note: no interrupts available on no hardware system
+       */
        gsSGXDeviceMap.ui32IRQ = 0;
 
-#else 
+#else /* defined(NO_HARDWARE) */
 #if defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO)
-       
+       /* get the resource and IRQ through platform resource API */
        dev_res = platform_get_resource(gpsPVRLDMDev, IORESOURCE_MEM, 0);
        if (dev_res == NULL)
        {
@@ -175,19 +215,24 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
        PVR_TRACE(("SGX register base: 0x%lx", (unsigned long)gsSGXDeviceMap.sRegsCpuPBase.uiAddr));
 
+#if defined(SGX544) && defined(SGX_FEATURE_MP)
+       /* FIXME: Workaround due to HWMOD change. Otherwise this region is too small. */
+       gsSGXDeviceMap.ui32RegsSize = SYS_TI335x_SGX_REGS_SIZE;
+#else
        gsSGXDeviceMap.ui32RegsSize = (unsigned int)(dev_res->end - dev_res->start);
+#endif
        PVR_TRACE(("SGX register size: %d",gsSGXDeviceMap.ui32RegsSize));
 
        gsSGXDeviceMap.ui32IRQ = dev_irq;
        PVR_TRACE(("SGX IRQ: %d", gsSGXDeviceMap.ui32IRQ));
-#else  
+#else  /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
        gsSGXDeviceMap.sRegsSysPBase.uiAddr = SYS_TI335x_SGX_REGS_SYS_PHYS_BASE;
        gsSGXDeviceMap.sRegsCpuPBase = SysSysPAddrToCpuPAddr(gsSGXDeviceMap.sRegsSysPBase);
        gsSGXDeviceMap.ui32RegsSize = SYS_TI335x_SGX_REGS_SIZE;
 
        gsSGXDeviceMap.ui32IRQ = SYS_TI335x_SGX_IRQ;
 
-#endif 
+#endif /* defined(PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO) */
 #if defined(SGX_OCP_REGS_ENABLED)
        gsSGXRegsCPUVAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
        gsSGXDeviceMap.ui32RegsSize,
@@ -200,70 +245,53 @@ static PVRSRV_ERROR SysLocateDevices(SYS_DATA *psSysData)
                return PVRSRV_ERROR_BAD_MAPPING;
        }
 
-       
+       /* Indicate the registers are already mapped */
        gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
        gpvOCPRegsLinAddr = gsSGXRegsCPUVAddr;
 #endif
-#endif 
+#endif /* defined(NO_HARDWARE) */
 
 #if defined(PDUMP)
        {
-               
+               /* initialise memory region name for pdumping */
                static IMG_CHAR pszPDumpDevName[] = "SGXMEM";
                gsSGXDeviceMap.pszPDumpDevName = pszPDumpDevName;
        }
 #endif
 
-       
+       /* add other devices here: */
 
 
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysCreateVersionString
+
+ @Description Read the version string 
+
+ @Return   IMG_CHAR *  : Version string
+
+******************************************************************************/
 static IMG_CHAR *SysCreateVersionString(void)
 {
        static IMG_CHAR aszVersionString[100];
+       IMG_UINT32 ui32MaxStrLen;
        SYS_DATA        *psSysData;
        IMG_UINT32      ui32SGXRevision;
        IMG_INT32       i32Count;
-#if !defined(NO_HARDWARE)
-       IMG_VOID        *pvRegsLinAddr;
-
-       pvRegsLinAddr = OSMapPhysToLin(gsSGXDeviceMap.sRegsCpuPBase,
-                                                                  SYS_TI335x_SGX_REGS_SIZE,
-                                                                  PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                                                  IMG_NULL);
-       if(!pvRegsLinAddr)
-       {
-               return IMG_NULL;
-       }
-
-       ui32SGXRevision = OSReadHWReg((IMG_PVOID)((IMG_PBYTE)pvRegsLinAddr),
-                                                                 EUR_CR_CORE_REVISION);
-#else
-       ui32SGXRevision = 0;
-#endif
 
        SysAcquireData(&psSysData);
 
-       i32Count = OSSNPrintf(aszVersionString, 100,
-                                                 "SGX revision = %u.%u.%u",
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAJOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAJOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MINOR_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MINOR_SHIFT),
-                                                 (IMG_UINT)((ui32SGXRevision & EUR_CR_CORE_REVISION_MAINTENANCE_MASK)
-                                                       >> EUR_CR_CORE_REVISION_MAINTENANCE_SHIFT)
-                                                );
-
-#if !defined(NO_HARDWARE)
-       OSUnMapPhysToLin(pvRegsLinAddr,
-                                        SYS_TI335x_SGX_REGS_SIZE,
-                                        PVRSRV_HAP_UNCACHED|PVRSRV_HAP_KERNEL_ONLY,
-                                        IMG_NULL);
-#endif
+       ui32SGXRevision = SGX_CORE_REV;
+       ui32MaxStrLen = 99;
 
+       i32Count = OSSNPrintf(aszVersionString, ui32MaxStrLen + 1,
+                       "SGX revision = %u",
+                       (IMG_UINT)(ui32SGXRevision));
        if(i32Count == -1)
        {
                return IMG_NULL;
@@ -273,6 +301,16 @@ static IMG_CHAR *SysCreateVersionString(void)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysInitialise
+ @Description Initialises kernel services at 'driver load' time
+ @Return   PVRSRV_ERROR  : 
+
+******************************************************************************/
 PVRSRV_ERROR SysInitialise(IMG_VOID)
 {
        IMG_UINT32                      i;
@@ -304,7 +342,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
 
        gpsSysData->ui32NumDevices = SYS_DEVICE_COUNT;
 
-       
+       /* init device ID's */
        for(i=0; i<SYS_DEVICE_COUNT; i++)
        {
                gpsSysData->sDeviceID[i].uiID = i;
@@ -324,7 +362,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        }
 
 #if !defined(SGX_DYNAMIC_TIMING_INFO)
-       
+       /* Set up timing information*/
        psTimingInfo = &gsSGXDeviceMap.sTimingInfo;
        psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
        psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ; 
@@ -332,19 +370,21 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        psTimingInfo->bEnableActivePM = IMG_TRUE;
 #else  
        psTimingInfo->bEnableActivePM = IMG_FALSE;
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS; 
        psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ; 
 #endif
 
-       
-
+       /*
+               Setup the Source Clock Divider value
+       */
        gpsSysSpecificData->ui32SrcClockDiv = 3;
 
-       
-
-
-
+       /*
+               Locate the devices within the system, specifying 
+               the physical addresses of each devices components 
+               (regs, mem, ports etc.)
+       */
        eError = SysLocateDevices(gpsSysData);
        if (eError != PVRSRV_OK)
        {
@@ -354,7 +394,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LOCATEDEV);
-#if 0
+
        eError = SysPMRuntimeRegister();
        if (eError != PVRSRV_OK)
        {
@@ -364,10 +404,21 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME);
-#endif
-       
 
+       eError = SysDvfsInitialize(gpsSysSpecificData);
+       if (eError != PVRSRV_OK)
+       {
+               PVR_DPF((PVR_DBG_ERROR,"SysInitialise: Failed to initialize DVFS"));
+               (IMG_VOID)SysDeinitialise(gpsSysData);
+               gpsSysData = IMG_NULL;
+               return eError;
+       }
+       SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT);
 
+       /*
+               Register devices with the system
+               This also sets up their memory maps/heaps
+       */
        eError = PVRSRVRegisterDevice(gpsSysData, SGXRegisterDevice,
                                                                  DEVICE_SGX_INTERRUPT, &gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
@@ -379,14 +430,14 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_REGDEV);
 
-       
-
-
-       
+       /*
+               Once all devices are registered, specify the backing store
+               and, if required, customise the memory heap config
+       */      
        psDeviceNode = gpsSysData->psDeviceNodeList;
        while(psDeviceNode)
        {
-               
+               /* perform any OEM SOC address space customisations here */
                switch(psDeviceNode->sDevId.eDeviceType)
                {
                        case PVRSRV_DEVICE_TYPE_SGX:
@@ -394,16 +445,17 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                DEVICE_MEMORY_INFO *psDevMemoryInfo;
                                DEVICE_MEMORY_HEAP_INFO *psDeviceMemoryHeap;
 
-                               
-
-
+                               /* 
+                                       specify the backing store to use for the devices MMU PT/PDs
+                                       - the PT/PDs are always UMA in this system
+                               */
                                psDeviceNode->psLocalDevMemArena = IMG_NULL;
 
-                               
+                               /* useful pointers */
                                psDevMemoryInfo = &psDeviceNode->sDevMemoryInfo;
                                psDeviceMemoryHeap = psDevMemoryInfo->psDeviceMemoryHeap;
 
-                               
+                               /* specify the backing store for all SGX heaps */
                                for(i=0; i<psDevMemoryInfo->ui32HeapCount; i++)
                                {
                                        psDeviceMemoryHeap[i].ui32Attribs |= PVRSRV_BACKINGSTORE_SYSMEM_NONCONTIG;
@@ -419,7 +471,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                return PVRSRV_ERROR_INIT_FAILURE;
                }
 
-               
+               /* advance to next device */
                psDeviceNode = psDeviceNode->psNext;
        }
 
@@ -441,7 +493,7 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                gpsSysData = IMG_NULL;
                return eError;
        }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        eError = PVRSRVInitialiseDevice(gui32SGXDeviceID);
        if (eError != PVRSRV_OK)
@@ -454,9 +506,9 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_INITDEV);
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       
+       /* SGX defaults to D3 power state */
        DisableSGXClocks(gpsSysData);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
 #if !defined(PVR_NO_OMAP_TIMER)
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
@@ -475,12 +527,23 @@ PVRSRV_ERROR SysInitialise(IMG_VOID)
                                  (IMG_VOID **)&gpsSysData->pvSOCTimerRegisterKM,
                                  &gpsSysData->hSOCTimerRegisterOSMemHandle);
        }
-#endif 
+#endif /* !defined(PVR_NO_OMAP_TIMER) */
+
 
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysFinalise
+ @Description Final part of initialisation at 'driver load' time
+ @Return   PVRSRV_ERROR  : 
+
+******************************************************************************/
 PVRSRV_ERROR SysFinalise(IMG_VOID)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -492,7 +555,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
                PVR_DPF((PVR_DBG_ERROR,"SysFinalise: Failed to Enable SGX clocks (%d)", eError));
                return eError;
        }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        eError = OSInstallMISR(gpsSysData);
        if (eError != PVRSRV_OK)
@@ -503,7 +566,7 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR);
 
 #if defined(SYS_USING_INTERRUPTS)
-       
+       /* install a Device ISR */
        eError = OSInstallDeviceLISR(gpsSysData, gsSGXDeviceMap.ui32IRQ, "SGX ISR", gpsSGXDevNode);
        if (eError != PVRSRV_OK)
        {
@@ -511,10 +574,12 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
                return eError;
        }
        SYS_SPECIFIC_DATA_SET(&gsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR);
-#endif 
-
+#if !defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+       SysEnableSGXInterrupts(gpsSysData);
+#endif
+#endif /* defined(SYS_USING_INTERRUPTS) */
 #if defined(__linux__)
-       
+       /* Create a human readable version string for this system */
        gpsSysData->pszVersionString = SysCreateVersionString();
        if (!gpsSysData->pszVersionString)
        {
@@ -527,9 +592,9 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
 #endif
 
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
-       
+       /* SGX defaults to D3 power state */
        DisableSGXClocks(gpsSysData);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        gpsSysSpecificData->bSGXInitComplete = IMG_TRUE;
 
@@ -537,10 +602,22 @@ PVRSRV_ERROR SysFinalise(IMG_VOID)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDeinitialise
+
+ @Description  De-initialises kernel services at 'driver unload' time
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 {
        PVRSRV_ERROR eError;
 
+       PVR_UNREFERENCED_PARAMETER(psSysData);
+
        if(gpsSysData->pvSOCTimerRegisterKM)
        {
                OSUnReservePhys(gpsSysData->pvSOCTimerRegisterKM,
@@ -549,10 +626,11 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
                                                gpsSysData->hSOCTimerRegisterOSMemHandle);
        }
 
+
 #if defined(SYS_USING_INTERRUPTS)
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_LISR))
        {
-               eError = OSUninstallDeviceLISR(psSysData);
+               eError = OSUninstallDeviceLISR(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: OSUninstallDeviceLISR failed"));
@@ -563,7 +641,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_MISR))
        {
-               eError = OSUninstallMISR(psSysData);
+               eError = OSUninstallMISR(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: OSUninstallMISR failed"));
@@ -575,40 +653,50 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        {
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
                PVR_ASSERT(SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS));
-               
+               /* Reenable SGX clocks whilst SGX is being deinitialised. */
                eError = EnableSGXClocksWrap(gpsSysData);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: EnableSGXClocks failed"));
                        return eError;
                }
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
-               
-               eError = PVRSRVDeinitialiseDevice (gui32SGXDeviceID);
+               /* Deinitialise SGX */
+               eError = PVRSRVDeinitialiseDevice(gui32SGXDeviceID);
                if (eError != PVRSRV_OK)
                {
                        PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: failed to de-init the device"));
                        return eError;
                }
        }
-#if 0
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME))
+
+       /* Disable system clocks. Must happen after last access to hardware */
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
        {
-               eError = SysPMRuntimeUnregister();
+               DisableSystemClocks(gpsSysData);
+       }
+
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_DVFS_INIT))
+       {
+               eError = SysDvfsDeinitialize(gpsSysSpecificData);
                if (eError != PVRSRV_OK)
                {
-                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to unregister with OSPM!"));
+                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to de-init DVFS"));
                        gpsSysData = IMG_NULL;
                        return eError;
                }
        }
-#endif
-       
 
-       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS))
+       if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME))
        {
-               DisableSystemClocks(gpsSysData);
+               eError = SysPMRuntimeUnregister();
+               if (eError != PVRSRV_OK)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,"SysDeinitialise: Failed to unregister with OSPM!"));
+                       gpsSysData = IMG_NULL;
+                       return eError;
+               }
        }
 
        if (SYS_SPECIFIC_DATA_TEST(gpsSysSpecificData, SYS_SPECIFIC_DATA_ENABLE_ENVDATA))
@@ -627,7 +715,7 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
        if(gsSGXRegsCPUVAddr != IMG_NULL)
        {
 #if defined(NO_HARDWARE)
-               
+               /* Free hardware resources. */
                OSBaseFreeContigMemory(SYS_TI335x_SGX_REGS_SIZE, gsSGXRegsCPUVAddr, gsSGXDeviceMap.sRegsCpuPBase);
 #else
 #if defined(SGX_OCP_REGS_ENABLED)
@@ -638,11 +726,11 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 
                gpvOCPRegsLinAddr = IMG_NULL;
 #endif
-#endif 
+#endif /* defined(NO_HARDWARE) */
                gsSGXRegsCPUVAddr = IMG_NULL;
                gsSGXDeviceMap.pvRegsCpuVBase = gsSGXRegsCPUVAddr;
        }
-#endif 
+#endif /* defined(NO_HARDWARE) || defined(SGX_OCP_REGS_ENABLED) */
 
        
        gpsSysSpecificData->ui32SysSpecificData = 0;
@@ -654,6 +742,19 @@ PVRSRV_ERROR SysDeinitialise (SYS_DATA *psSysData)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function             SysGetDeviceMemoryMap
+
+ @Description  returns a device address map for the specified device
+
+ @Input                        eDeviceType - device type
+ @Input                        ppvDeviceMap - void ptr to receive device specific info.
+
+ @Return               PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE  eDeviceType,
                                                                   IMG_VOID                             **ppvDeviceMap)
 {
@@ -662,7 +763,7 @@ PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE       eDeviceType,
        {
                case PVRSRV_DEVICE_TYPE_SGX:
                {
-                       
+                       /* just return a pointer to the structure */
                        *ppvDeviceMap = (IMG_VOID*)&gsSGXDeviceMap;
 
                        break;
@@ -676,6 +777,20 @@ PVRSRV_ERROR SysGetDeviceMemoryMap(PVRSRV_DEVICE_TYPE      eDeviceType,
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysCpuPAddrToDevPAddr
+
+ @Description     Compute a device physical address from a cpu physical
+                  address. Relevant when
+
+ @Input           cpu_paddr - cpu physical address.
+ @Input           eDeviceType - device type required if DevPAddr
+                                address spaces vary across devices
+                                in the same system
+ @Return         device physical address.
+
+******************************************************************************/
 IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(PVRSRV_DEVICE_TYPE       eDeviceType,
                                                                          IMG_CPU_PHYADDR               CpuPAddr)
 {
@@ -683,98 +798,205 @@ IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType,
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == CpuP */
        DevPAddr.uiAddr = CpuPAddr.uiAddr;
        
        return DevPAddr;
 }
 
+/*!
+******************************************************************************
+ @Function        SysSysPAddrToCpuPAddr
+
+ @Description     Compute a cpu physical address from a system physical
+                  address.
+
+ @Input           sys_paddr - system physical address.
+ @Return          cpu physical address.
+
+******************************************************************************/
 IMG_CPU_PHYADDR SysSysPAddrToCpuPAddr (IMG_SYS_PHYADDR sys_paddr)
 {
        IMG_CPU_PHYADDR cpu_paddr;
 
-       
+       /* This would only be an inequality if the CPU's MMU did not point to
+          sys address 0, ie. multi CPU system */
        cpu_paddr.uiAddr = sys_paddr.uiAddr;
        return cpu_paddr;
 }
 
+/*!
+******************************************************************************
+ @Function        SysCpuPAddrToSysPAddr
+
+ @Description     Compute a system physical address from a cpu physical
+                   address.
+
+ @Input           cpu_paddr - cpu physical address.
+ @Return          device physical address.
+
+******************************************************************************/
 IMG_SYS_PHYADDR SysCpuPAddrToSysPAddr (IMG_CPU_PHYADDR cpu_paddr)
 {
        IMG_SYS_PHYADDR sys_paddr;
 
-       
+       /* This would only be an inequality if the CPU's MMU did not point to
+          sys address 0, ie. multi CPU system */
        sys_paddr.uiAddr = cpu_paddr.uiAddr;
        return sys_paddr;
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysSysPAddrToDevPAddr
+
+ @Description     Compute a device physical address from a system physical
+                   address.
+
+ @Input           SysPAddr - system physical address.
+ @Input           eDeviceType - device type required if DevPAddr 
+                               address spaces vary across devices 
+                               in the same system
+
+ @Return        Device physical address.
+
+******************************************************************************/
 IMG_DEV_PHYADDR SysSysPAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType, IMG_SYS_PHYADDR SysPAddr)
 {
        IMG_DEV_PHYADDR DevPAddr;
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == CpuP */
        DevPAddr.uiAddr = SysPAddr.uiAddr;
 
        return DevPAddr;
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysDevPAddrToSysPAddr
+
+ @Description     Compute a device physical address from a system physical
+                   address.
+
+ @Input           DevPAddr - device physical address.
+ @Input           eDeviceType - device type required if DevPAddr 
+                 address spaces vary across devices 
+                 in the same system
+
+ @Return        System physical address.
+
+******************************************************************************/
 IMG_SYS_PHYADDR SysDevPAddrToSysPAddr(PVRSRV_DEVICE_TYPE eDeviceType, IMG_DEV_PHYADDR DevPAddr)
 {
        IMG_SYS_PHYADDR SysPAddr;
 
        PVR_UNREFERENCED_PARAMETER(eDeviceType);
 
-       
+       /* Note: for UMA system we assume DevP == SysP */
        SysPAddr.uiAddr = DevPAddr.uiAddr;
 
        return SysPAddr;
 }
 
 
+/*****************************************************************************
+ @Function        SysRegisterExternalDevice
+
+ @Description     Called when a 3rd party device registers with services
+
+ @Input           psDeviceNode - the new device node.
+
+ @Return        IMG_VOID
+*****************************************************************************/
 IMG_VOID SysRegisterExternalDevice(PVRSRV_DEVICE_NODE *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psDeviceNode);
 }
 
 
+/*****************************************************************************
+ @Function        SysRemoveExternalDevice
+
+ @Description     Called when a 3rd party device unregisters from services
+
+ @Input           psDeviceNode - the device node being removed.
+
+ @Return        IMG_VOID
+*****************************************************************************/
 IMG_VOID SysRemoveExternalDevice(PVRSRV_DEVICE_NODE *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psDeviceNode);
 }
 
+/*!
+******************************************************************************
+ @Function        SysGetInterruptSource
 
+ @Description     Returns System specific information about the device(s) that
+                               generated the interrupt in the system
+
+ @Input           psSysData
+ @Input           psDeviceNode
+
+ @Return        System specific information indicating which device(s) 
+                               generated the interrupt
+
+******************************************************************************/
 IMG_UINT32 SysGetInterruptSource(SYS_DATA                      *psSysData,
                                                                 PVRSRV_DEVICE_NODE     *psDeviceNode)
 {
        PVR_UNREFERENCED_PARAMETER(psSysData);
 #if defined(NO_HARDWARE)
-       
+       /* no interrupts in no_hw system just return all bits */
        return 0xFFFFFFFF;
 #else
-       
+       /* Not a shared irq, so we know this is an interrupt for this device */
        return psDeviceNode->ui32SOCInterruptBit;
 #endif
 }
 
 
+/*!
+******************************************************************************
+ @Function        SysClearInterrupts
+
+ @Description     Clears specified system interrupts
+
+ @Input           psSysData
+ @Input           ui32ClearBits
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysClearInterrupts(SYS_DATA* psSysData, IMG_UINT32 ui32ClearBits)
 {
        PVR_UNREFERENCED_PARAMETER(ui32ClearBits);
-#if defined(NO_HARDWARE)
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#else
+#if !defined(NO_HARDWARE)
 #if defined(SGX_OCP_NO_INT_BYPASS)
        OSWriteHWReg(gpvOCPRegsLinAddr, EUR_CR_OCP_IRQSTATUS_2, 0x1);
 #endif
-       
+       /* Flush posted writes */
        OSReadHWReg(((PVRSRV_SGXDEV_INFO *)gpsSGXDevNode->pvDevice)->pvRegsBaseKM, EUR_CR_EVENT_HOST_CLEAR);
-#endif 
+#endif /* defined(NO_HARDWARE) */
 }
 
 #if defined(SGX_OCP_NO_INT_BYPASS)
+/*!
+******************************************************************************
+ @Function        SysEnableSGXInterrupts
+
+ @Description     Enables SGX interrupts
+
+ @Input           psSysData
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysEnableSGXInterrupts(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *)psSysData->pvSysSpecificData;
@@ -786,6 +1008,17 @@ IMG_VOID SysEnableSGXInterrupts(SYS_DATA *psSysData)
        }
 }
 
+/*!
+******************************************************************************
+ @Function        SysDisableSGXInterrupts
+
+ @Description     Disables SGX interrupts
+
+ @Input           psSysData
+
+ @Return        IMG_VOID
+
+******************************************************************************/
 IMG_VOID SysDisableSGXInterrupts(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *)psSysData->pvSysSpecificData;
@@ -796,8 +1029,20 @@ IMG_VOID SysDisableSGXInterrupts(SYS_DATA *psSysData)
                SYS_SPECIFIC_DATA_CLEAR(psSysSpecData, SYS_SPECIFIC_DATA_IRQ_ENABLED);
        }
 }
-#endif 
+#endif /* defined(SGX_OCP_NO_INT_BYPASS) */
+
+/*!
+******************************************************************************
+
+ @Function     SysSystemPrePowerState
 
+ @Description  Perform system-level processing required before a power transition
+
+ @Input                eNewPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysSystemPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -842,6 +1087,18 @@ PVRSRV_ERROR SysSystemPrePowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysSystemPostPowerState
+
+ @Description  Perform system-level processing required after a power transition
+
+ @Input                eNewPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 {
        PVRSRV_ERROR eError = PVRSRV_OK;
@@ -890,6 +1147,21 @@ PVRSRV_ERROR SysSystemPostPowerState(PVRSRV_SYS_POWER_STATE eNewPowerState)
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDevicePrePowerState
+
+ @Description  Perform system level processing required before a device power
+                               transition
+
+ @Input                ui32DeviceIndex :
+ @Input                eNewPowerState :
+ @Input                eCurrentPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                         ui32DeviceIndex,
                                                                        PVRSRV_DEV_POWER_STATE  eNewPowerState,
                                                                        PVRSRV_DEV_POWER_STATE  eCurrentPowerState)
@@ -907,13 +1179,28 @@ PVRSRV_ERROR SysDevicePrePowerState(IMG_UINT32                           ui32DeviceIndex,
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePrePowerState: SGX Entering state D3"));
                DisableSGXClocks(gpsSysData);
        }
-#else  
+#else  /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        PVR_UNREFERENCED_PARAMETER(eNewPowerState );
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function     SysDevicePostPowerState
+
+ @Description  Perform system level processing required after a device power
+                               transition
+
+ @Input                ui32DeviceIndex :
+ @Input                eNewPowerState :
+ @Input                eCurrentPowerState :
+
+ @Return       PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                                ui32DeviceIndex,
                                                                         PVRSRV_DEV_POWER_STATE eNewPowerState,
                                                                         PVRSRV_DEV_POWER_STATE eCurrentPowerState)
@@ -933,14 +1220,33 @@ PVRSRV_ERROR SysDevicePostPowerState(IMG_UINT32                          ui32DeviceIndex,
                PVR_DPF((PVR_DBG_MESSAGE, "SysDevicePostPowerState: SGX Leaving state D3"));
                eError = EnableSGXClocksWrap(gpsSysData);
        }
-#else  
+#else  /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        PVR_UNREFERENCED_PARAMETER(eCurrentPowerState);
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
 
        return eError;
 }
 
+#if defined(SYS_SUPPORTS_SGX_IDLE_CALLBACK)
+
+IMG_VOID SysSGXIdleTransition(IMG_BOOL bSGXIdle)
+{
+       PVR_DPF((PVR_DBG_MESSAGE, "SysSGXIdleTransition switch to %u", bSGXIdle));
+}
+
+#endif /* defined(SYS_SUPPORTS_SGX_IDLE_CALLBACK) */
+
+/*****************************************************************************
+ @Function        SysOEMFunction
+
+ @Description     marshalling function for custom OEM functions
+
+ @Input           ui32ID  - function ID
+ @Input           pvIn - in data
+ @Output          pvOut - out data
 
+ @Return        PVRSRV_ERROR
+*****************************************************************************/
 PVRSRV_ERROR SysOEMFunction (  IMG_UINT32      ui32ID,
                                                                IMG_VOID        *pvIn,
                                                                IMG_UINT32      ulInSize,
@@ -956,7 +1262,6 @@ PVRSRV_ERROR SysOEMFunction (      IMG_UINT32      ui32ID,
        if ((ui32ID == OEM_GET_EXT_FUNCS) &&
                (ulOutSize == sizeof(PVRSRV_DC_OEM_JTABLE)))
        {
-               
                PVRSRV_DC_OEM_JTABLE *psOEMJTable = (PVRSRV_DC_OEM_JTABLE*) pvOut;
                psOEMJTable->pfnOEMBridgeDispatch = &PVRSRV_BridgeDispatchKM;
                return PVRSRV_OK;
@@ -964,3 +1269,6 @@ PVRSRV_ERROR SysOEMFunction (      IMG_UINT32      ui32ID,
 
        return PVRSRV_ERROR_INVALID_PARAMS;
 }
+/******************************************************************************
+ End of file (sysconfig.c)
+******************************************************************************/
index cfa3c09..7af00a6 100644 (file)
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Description Header
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides system-specific declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SOCCONFIG_H__)
 #define __SOCCONFIG_H__
 
-
 #define VS_PRODUCT_NAME        "TI335x"
 
-#define SYS_SGX_CLOCK_SPEED            200000000
 
-#define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   
-#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  
+#define SYS_SGX_HWRECOVERY_TIMEOUT_FREQ                (100)   // 10ms (100hz)
+#define SYS_SGX_PDS_TIMER_FREQ                         (1000)  // 1ms (1000hz)
 
+/* Allow the AP latency to be overridden in the build config */
 #if !defined(SYS_SGX_ACTIVE_POWER_LATENCY_MS)
 #define SYS_SGX_ACTIVE_POWER_LATENCY_MS                (2)
 #endif
 
 
 #define SYS_TI335x_SGX_REGS_SYS_PHYS_BASE  0x56000000
-
 #define SYS_TI335x_SGX_REGS_SIZE           0x1000000
 
-#define SYS_TI335x_SGX_IRQ                              37
+#define SYS_TI335x_SGX_IRQ                              37 /* OMAP4 IRQ's are offset by 32 */
+
+#define SYS_OMAP_DSS_REGS_SYS_PHYS_BASE  0x58000000
+#define SYS_OMAP_DSS_REGS_SIZE           0x7000
+
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_STATUS_REG 0x6028
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_ENABLE_REG 0x602c
+
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_ENABLE_MASK 0x10000
+#define SYS_OMAP_DSS_HDMI_INTERRUPT_VSYNC_STATUS_MASK 0x10000
+
+#define SYS_OMAP_DSS_LCD_INTERRUPT_STATUS_REG 0x1018
+#define SYS_OMAP_DSS_LCD_INTERRUPT_ENABLE_REG 0x101c
+
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_ENABLE_MASK 0x40002
+#define SYS_OMAP_DSS_LCD_INTERRUPT_VSYNC_STATUS_MASK 0x40002
+
 
 #define SYS_TI335x_GP7TIMER_ENABLE_SYS_PHYS_BASE      0x4804A038
 #define SYS_TI335x_GP7TIMER_REGS_SYS_PHYS_BASE        0x4804A03C
 #define SYS_TI335x_GP7TIMER_TSICR_SYS_PHYS_BASE       0x4804A054
 
+
+
+/* Interrupt bits */
+#define DEVICE_SGX_INTERRUPT           (1<<0)
+#define DEVICE_MSVDX_INTERRUPT         (1<<1)
+#define DEVICE_DISP_INTERRUPT          (1<<2)
+
+#if 0
+#if defined(__linux__)
+/*
+ * Recent OMAP4 kernels register SGX as platform device "omap_gpu".
+ * This device must be used with the Linux power management calls
+ * in sysutils_linux.c, in order for SGX to be powered on.
+ */
+#if defined(PVR_LDM_PLATFORM_PRE_REGISTERED_DEV)
+#define        SYS_SGX_DEV_NAME        PVR_LDM_PLATFORM_PRE_REGISTERED_DEV
+#else
+#define        SYS_SGX_DEV_NAME        "omap_gpu"
+#endif /* defined(PVR_LDM_PLATFORM_PRE_REGISTERED_DEV) */
+#endif /* defined(__linux__) */
+#endif
+
+/*****************************************************************************
+ * system specific data structures
+ *****************************************************************************/
  
-#endif 
+#endif /* __SYSCONFIG_H__ */
index b6d3f5a..7383b9c 100644 (file)
@@ -1,33 +1,62 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          System Description Header
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides system-specific declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SYSINFO_H__)
 #define __SYSINFO_H__
 
+#if defined(SGX540) && (SGX_CORE_REV == 120)
+#define SYS_SGX_CLOCK_SPEED            307200000
+#else
+#define SYS_SGX_CLOCK_SPEED            200000000
+#endif
+
+/*!< System specific poll/timeout details */
 #if defined(PVR_LINUX_USING_WORKQUEUES)
+/*
+ * The workqueue based 3rd party display driver may be blocked for up
+ * to 500ms waiting for a vsync when the screen goes blank, so we
+ * need to wait longer for the hardware if a flush of the swap chain is
+ * required.
+ */
 #define MAX_HW_TIME_US                         (1000000)
 #define WAIT_TRY_COUNT                         (20000)
 #else
@@ -36,6 +65,6 @@
 #endif
 
 
-#define SYS_DEVICE_COUNT 15 
+#define SYS_DEVICE_COUNT 15 /* SGX, DISPLAYCLASS (external), BUFFERCLASS (external) */
 
-#endif 
+#endif /* __SYSINFO_H__ */
index 0ae7ef5..090b38d 100644 (file)
@@ -1,28 +1,44 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          Local system definitions
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    This header provides local system declarations and macros
+@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.
+*/ /**************************************************************************/
 
 #if !defined(__SYSLOCAL_H__)
 #define __SYSLOCAL_H__
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26))
 #include <linux/semaphore.h>
 #include <linux/resource.h>
-#else 
+#else /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) */
 #include <asm/semaphore.h>
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
 #include <asm/arch/resource.h>
-#endif 
-#endif 
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)) */
+#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) */
 
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
 #if !defined(LDM_PLATFORM)
 #error "LDM_PLATFORM must be set"
 #endif
-/*#define      PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO*/
+//#define      PVR_LINUX_DYNAMIC_SGX_RESOURCE_INFO
 //#include <linux/platform_device.h>
 #endif
 
 #if ((defined(DEBUG) || defined(TIMING)) && \
     (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))) && \
     !defined(PVR_NO_OMAP_TIMER)
-#define        PVR_OMAP3_TIMING_PRCM
+/*
+ * We need to explicitly enable the GPTIMER11 clocks, or we'll get an
+ * abort when we try to access the timer registers.
+ */
+#define        PVR_OMAP4_TIMING_PRCM
 #endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
-/*#include <plat/gpu.h>*/
+//#include <plat/gpu.h>
 #if !defined(PVR_NO_OMAP_TIMER)
-/*#define      PVR_OMAP_USE_DM_TIMER_API*/
+//#define      PVR_OMAP_USE_DM_TIMER_API
 //#include <plat/dmtimer.h>
 #endif
 #endif
@@ -74,7 +94,7 @@
 #if !defined(PVR_NO_OMAP_TIMER)
 //#define PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA
 #endif
-#endif 
+#endif /* defined(__linux__) */
 
 #if !defined(NO_HARDWARE) && \
      defined(SYS_USING_INTERRUPTS) && \
 #endif
 
 #if defined(__linux__)
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) && defined(SGX_OCP_REGS_ENABLED)
-/*#define SGX_OCP_NO_INT_BYPASS*/
+#if defined(SGX_OCP_REGS_ENABLED)
+/* FIXME: Temporary workaround for OMAP4470 and active power off in 4430 */
+#if !defined(SGX544) && defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
+//#define SGX_OCP_NO_INT_BYPASS
+#endif
 #endif
 #endif
 
 extern "C" {
 #endif
 
+/*****************************************************************************
+ * system specific data structures
+ *****************************************************************************/
  
+/*****************************************************************************
+ * system specific function prototypes
+ *****************************************************************************/
  
 IMG_VOID DisableSystemClocks(SYS_DATA *psSysData);
 PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData);
@@ -100,6 +129,10 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData);
 IMG_VOID DisableSGXClocks(SYS_DATA *psSysData);
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData);
 
+/*
+ * Various flags to indicate what has been initialised, and what
+ * has been temporarily deinitialised for power management purposes.
+ */
 #define SYS_SPECIFIC_DATA_ENABLE_SYSCLOCKS     0x00000001
 #define SYS_SPECIFIC_DATA_ENABLE_LISR          0x00000002
 #define SYS_SPECIFIC_DATA_ENABLE_MISR          0x00000004
@@ -114,9 +147,8 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData);
 #define        SYS_SPECIFIC_DATA_PM_DISABLE_SYSCLOCKS  0x00000400
 #define SYS_SPECIFIC_DATA_ENABLE_OCPREGS       0x00000800
 #define SYS_SPECIFIC_DATA_ENABLE_PM_RUNTIME    0x00001000
-#if defined(SGX_OCP_REGS_ENABLED) && defined(SGX_OCP_NO_INT_BYPASS)
 #define SYS_SPECIFIC_DATA_IRQ_ENABLED          0x00002000
-#endif
+#define SYS_SPECIFIC_DATA_DVFS_INIT                    0x00004000
 
 #define        SYS_SPECIFIC_DATA_SET(psSysSpecData, flag) ((IMG_VOID)((psSysSpecData)->ui32SysSpecificData |= (flag)))
 
@@ -149,8 +181,8 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
        atomic_t        sNotifyLockCPU;
        IMG_BOOL        bCallVDD2PostFunc;
 #endif
-       struct clk      *psCORE_CK;
-        struct clk      *psSGX_FCK;
+        struct clk      *psCORE_CK;
+       struct clk      *psSGX_FCK;
         struct clk      *psSGX_ICK;
 
 #if defined(DEBUG) || defined(TIMING)
@@ -160,7 +192,10 @@ typedef struct _SYS_SPECIFIC_DATA_TAG_
 #if defined(PVR_OMAP_USE_DM_TIMER_API)
        struct omap_dm_timer *psGPTimer;
 #endif
-#endif 
+       IMG_UINT32 ui32SGXFreqListSize;
+       IMG_UINT32 *pui32SGXFreqList;
+       IMG_UINT32 ui32SGXFreqListIndex;
+#endif /* defined(__linux__) */
 } SYS_SPECIFIC_DATA;
 
 extern SYS_SPECIFIC_DATA *gpsSysSpecificData;
@@ -183,7 +218,10 @@ IMG_VOID UnwrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData);
 PVRSRV_ERROR SysPMRuntimeRegister(void);
 PVRSRV_ERROR SysPMRuntimeUnregister(void);
 
-#else 
+PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData);
+PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData);
+
+#else /* defined(__linux__) */
 
 #ifdef INLINE_IS_PRAGMA
 #pragma inline(SysPMRuntimeRegister)
@@ -201,12 +239,28 @@ static INLINE PVRSRV_ERROR SysPMRuntimeUnregister(void)
        return PVRSRV_OK;
 }
 
-#endif 
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(SysDvfsInitialize)
+#endif
+static INLINE PVRSRV_ERROR SysDvfsInitialize(void)
+{
+       return PVRSRV_OK;
+}
+
+#ifdef INLINE_IS_PRAGMA
+#pragma inline(SysDvfsDeinitialize)
+#endif
+static INLINE PVRSRV_ERROR SysDvfsDeinitialize(void)
+{
+       return PVRSRV_OK;
+}
+
+#endif /* defined(__linux__) */
 
 #if defined(__cplusplus)
 }
 #endif
 
-#endif 
+#endif /* __SYSLOCAL_H__ */
 
 
index 8736fcc..27b2df6 100644 (file)
@@ -1,30 +1,49 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
+/*************************************************************************/ /*!
+@Title          Shared (User/kernel) and System dependent utilities
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    Provides system-specific functions
+@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.
+*/ /**************************************************************************/
+
+/* Pull in the correct system dependent sysutils source */
 
 #if defined(__linux__)
 #include "sysutils_linux.c"
 #endif
 
+
index 58afcba..6b41588 100644 (file)
@@ -1,34 +1,50 @@
-/**********************************************************************
- *
- * Copyright (C) Imagination Technologies Ltd. All rights reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope it will be useful but, except 
- * as otherwise stated in writing, without any warranty; without even the 
- * implied warranty of merchantability or fitness for a particular purpose. 
- * See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- * 
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
- *
- ******************************************************************************/
-
+/*************************************************************************/ /*!
+@Title          System dependent utilities
+@Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
+@Description    Provides system-specific functions
+@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.
+*/ /**************************************************************************/
 #include <linux/version.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/hardirq.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 
 #include "sgxdefs.h"
 #include "services_headers.h"
 #include "sgxinfokm.h"
 #include "syslocal.h"
 
-//#include <linux/platform_device.h>
-//#include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+#include <linux/opp.h>
+#endif
+
+#if defined(SUPPORT_DRI_DRM_PLUGIN)
+#include <drm/drmP.h>
+#include <drm/drm.h>
+
+#include <linux/omap_gpu.h>
+
+#include "pvr_drm.h"
+#endif
 
 #define        ONE_MHZ 1000000
 #define        HZ_TO_MHZ(m) ((m) / ONE_MHZ)
 
-#if defined(SUPPORT_TI335x_SGXFCLK_96M)
+#if defined(SUPPORT_OMAP3430_SGXFCLK_96M)
 #define SGX_PARENT_CLOCK "cm_96m_fck"
 #else
 #define SGX_PARENT_CLOCK "core_ck"
 extern struct platform_device *gpsPVRLDMDev;
 #endif
 
-
 static PVRSRV_ERROR PowerLockWrap(SYS_SPECIFIC_DATA *psSysSpecData, IMG_BOOL bTryLock)
 {
-        if (!in_interrupt())
-        {
-                if (bTryLock)
-                {
-                        int locked = mutex_trylock(&psSysSpecData->sPowerLock);
-                        if (locked == 0)
-                        {
-                                return PVRSRV_ERROR_RETRY;
-                        }
-                }
-                else
-                {
-                        mutex_lock(&psSysSpecData->sPowerLock);
-                }
-        }
+       if (!in_interrupt())
+       {
+               if (bTryLock)
+               {
+                       int locked = mutex_trylock(&psSysSpecData->sPowerLock);
+                       if (locked == 0)
+                       {
+                               return PVRSRV_ERROR_RETRY;
+                       }
+               }
+               else
+               {
+                       mutex_lock(&psSysSpecData->sPowerLock);
+               }
+       }
 
-        return PVRSRV_OK;
+       return PVRSRV_OK;
 }
 
 static IMG_VOID PowerLockUnwrap(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-        if (!in_interrupt())
-        {
-                mutex_unlock(&psSysSpecData->sPowerLock);
-        }
+       if (!in_interrupt())
+       {
+               mutex_unlock(&psSysSpecData->sPowerLock);
+       }
 }
 
 PVRSRV_ERROR SysPowerLockWrap(IMG_BOOL bTryLock)
 {
-        SYS_DATA        *psSysData;
+       SYS_DATA        *psSysData;
 
-        SysAcquireData(&psSysData);
+       SysAcquireData(&psSysData);
 
-        return PowerLockWrap(psSysData->pvSysSpecificData, bTryLock);
+       return PowerLockWrap(psSysData->pvSysSpecificData, bTryLock);
 }
 
 IMG_VOID SysPowerLockUnwrap(IMG_VOID)
 {
-        SYS_DATA        *psSysData;
+       SYS_DATA        *psSysData;
 
-        SysAcquireData(&psSysData);
+       SysAcquireData(&psSysData);
 
-        PowerLockUnwrap(psSysData->pvSysSpecificData);
+       PowerLockUnwrap(psSysData->pvSysSpecificData);
 }
 
-
-
-
+/*
+ * This function should be called to unwrap the Services power lock, prior
+ * to calling any function that might sleep.
+ * This function shouldn't be called prior to calling EnableSystemClocks
+ * or DisableSystemClocks, as those functions perform their own power lock
+ * unwrapping.
+ * If the function returns IMG_TRUE, UnwrapSystemPowerChange must be
+ * called to rewrap the power lock, prior to returning to Services.
+ */
 IMG_BOOL WrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        return IMG_TRUE;
@@ -114,67 +148,66 @@ IMG_VOID UnwrapSystemPowerChange(SYS_SPECIFIC_DATA *psSysSpecData)
 {
 }
 
-static inline IMG_UINT32 scale_by_rate(IMG_UINT32 val, IMG_UINT32 rate1, IMG_UINT32 rate2)
-{
-       if (rate1 >= rate2)
-       {
-               return val * (rate1 / rate2);
-       }
-
-       return val / (rate2 / rate1);
-}
-
-static inline IMG_UINT32 scale_prop_to_SGX_clock(IMG_UINT32 val, IMG_UINT32 rate)
-{
-       return scale_by_rate(val, rate, SYS_SGX_CLOCK_SPEED);
-}
-
-static inline IMG_UINT32 scale_inv_prop_to_SGX_clock(IMG_UINT32 val, IMG_UINT32 rate)
-{
-       return scale_by_rate(val, SYS_SGX_CLOCK_SPEED, rate);
-}
-
+/*
+ * Return SGX timining information to caller.
+ */
 IMG_VOID SysGetSGXTimingInformation(SGX_TIMING_INFORMATION *psTimingInfo)
 {
-       IMG_UINT32 rate;
-
-       rate = SYS_SGX_CLOCK_SPEED;
 #if !defined(NO_HARDWARE)
        PVR_ASSERT(atomic_read(&gpsSysSpecificData->sSGXClocksEnabled) != 0);
 #endif
-       psTimingInfo->ui32CoreClockSpeed = rate;
-       psTimingInfo->ui32HWRecoveryFreq = scale_prop_to_SGX_clock(SYS_SGX_HWRECOVERY_TIMEOUT_FREQ, rate);
-       psTimingInfo->ui32uKernelFreq = scale_prop_to_SGX_clock(SYS_SGX_PDS_TIMER_FREQ, rate);
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       psTimingInfo->ui32CoreClockSpeed =
+               gpsSysSpecificData->pui32SGXFreqList[gpsSysSpecificData->ui32SGXFreqListIndex];
+#else /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       psTimingInfo->ui32CoreClockSpeed = SYS_SGX_CLOCK_SPEED;
+#endif
+       psTimingInfo->ui32HWRecoveryFreq = SYS_SGX_HWRECOVERY_TIMEOUT_FREQ;
+       psTimingInfo->ui32uKernelFreq = SYS_SGX_PDS_TIMER_FREQ;
 #if defined(SUPPORT_ACTIVE_POWER_MANAGEMENT)
        psTimingInfo->bEnableActivePM = IMG_TRUE;
 #else
        psTimingInfo->bEnableActivePM = IMG_FALSE;
-#endif 
+#endif /* SUPPORT_ACTIVE_POWER_MANAGEMENT */
        psTimingInfo->ui32ActivePowManLatencyms = SYS_SGX_ACTIVE_POWER_LATENCY_MS;
 }
 
+/*!
+******************************************************************************
+
+ @Function  EnableSGXClocks
+
+ @Description Enable SGX clocks
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-       IMG_INT res;
-       long lRate,lNewRate;
-       
+#if !defined(PM_RUNTIME_SUPPORT)
+        IMG_INT res;
+        long lRate,lNewRate;
+#endif
+
+       /* SGX clocks already enabled? */
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) != 0)
        {
                return PVRSRV_OK;
        }
 
        PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
-       
-       res=clk_enable(psSysSpecData->psSGX_FCK);
-       if (res < 0)
+#if !defined(PM_RUNTIME_SUPPORT)
+        PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: Enabling SGX Clocks"));
+        res=clk_enable(psSysSpecData->psSGX_FCK);
+        if (res < 0)
         {
                 PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't enable SGX functional clock (%d)", res));
                 return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
         }
-       
-       lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
+
+        lNewRate = clk_round_rate(psSysSpecData->psSGX_FCK, SYS_SGX_CLOCK_SPEED + ONE_MHZ);
         if (lNewRate <= 0)
         {
                 PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Couldn't round SGX functional clock rate"));
@@ -189,7 +222,7 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                 if (res < 0)
                 {
                         PVR_DPF((PVR_DBG_WARNING, "EnableSGXClocks: Couldn't set SGX functional clock rate (%d)", res));
-                       return PVRSRV_ERROR_UNABLE_TO_SET_CLOCK_RATE;
+                        return PVRSRV_ERROR_UNABLE_TO_SET_CLOCK_RATE;
                 }
         }
 
@@ -199,75 +232,194 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
                 PVR_DPF((PVR_DBG_MESSAGE, "EnableSGXClocks: SGX Functional Clock is %dMhz", HZ_TO_MHZ(rate)));
         }
 #endif
-
-
-
+#endif 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
        {
-               
-//             int res = pm_runtime_get_sync(&gpsPVRLDMDev->dev);
-//             if (res < 0)
-//             {
-//                     PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: pm_runtime_get_sync failed (%d)", -res));
-//                     return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
-//             }
+               struct gpu_platform_data *pdata;
+               IMG_UINT32 max_freq_index;
+               int res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+               max_freq_index = psSysSpecData->ui32SGXFreqListSize - 2;
+
+               /*
+                * Request maximum frequency from DVFS layer if not already set. DVFS may
+                * report busy if early in initialization, but all other errors are
+                * considered serious. Upon any error we proceed assuming our safe frequency
+                * value to be in use as indicated by the "unknown" index.
+                */
+               if (psSysSpecData->ui32SGXFreqListIndex != max_freq_index)
+               {
+                       PVR_ASSERT(pdata->device_scale != IMG_NULL);
+                       res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                         &gpsPVRLDMDev->dev,
+#endif
+                                                                         psSysSpecData->pui32SGXFreqList[max_freq_index]);
+                       if (res == 0)
+                       {
+                               psSysSpecData->ui32SGXFreqListIndex = max_freq_index;
+                       }
+                       else if (res == -EBUSY)
+                       {
+                               PVR_DPF((PVR_DBG_WARNING, "EnableSGXClocks: Unable to scale SGX frequency (EBUSY)"));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+                       else if (res < 0)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: Unable to scale SGX frequency (%d)", res));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+               }
        }
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       {
+               /*
+                * pm_runtime_get_sync returns 1 after the module has
+                * been reloaded.
+                */
+#if defined(PM_RUNTIME_SUPPORT)
+
+               int res = pm_runtime_get_sync(&gpsPVRLDMDev->dev);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "EnableSGXClocks: pm_runtime_get_sync failed (%d)", -res));
+                       return PVRSRV_ERROR_UNABLE_TO_ENABLE_CLOCK;
+               }
 #endif
-//     SysEnableSGXInterrupts(psSysData);
+       }
+#endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
-       
+       SysEnableSGXInterrupts(psSysData);
+
+       /* Indicate that the SGX clocks are enabled */
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 1);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
        return PVRSRV_OK;
 }
 
 
+/*!
+******************************************************************************
+
+ @Function  DisableSGXClocks
+
+ @Description Disable SGX clocks.
+
+ @Return   none
+
+******************************************************************************/
 IMG_VOID DisableSGXClocks(SYS_DATA *psSysData)
 {
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
 
+       /* SGX clocks already disabled? */
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) == 0)
        {
                return;
        }
-       
-       PVR_DPF((PVR_DBG_MESSAGE, "DisableSGXClocks: Disabling SGX Clocks"));
-       
-       clk_disable(psSysSpecData->psSGX_FCK);
-
-       clk_disable(psSysSpecData->psSGX_ICK);
 
-//     SysDisableSGXInterrupts(psSysData);
+       PVR_DPF((PVR_DBG_MESSAGE, "DisableSGXClocks: Disabling SGX Clocks"));
+#if !defined(PM_RUNTIME_SUPPORT)
+        clk_disable(psSysSpecData->psSGX_FCK);
+#endif
+       SysDisableSGXInterrupts(psSysData);
 
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
        {
-//             int res = pm_runtime_put_sync(&gpsPVRLDMDev->dev);
-//             if (res < 0)
-//             {
-//                     PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
-//             }
+#if defined(PM_RUNTIME_SUPPORT)
+
+               int res = pm_runtime_put_sync(&gpsPVRLDMDev->dev);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: pm_runtime_put_sync failed (%d)", -res));
+               }
+#endif
        }
+#if defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       {
+               struct gpu_platform_data *pdata;
+               int res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+
+               /*
+                * Request minimum frequency (list index 0) from DVFS layer if not already
+                * set. DVFS may report busy if early in initialization, but all other errors
+                * are considered serious. Upon any error we proceed assuming our safe frequency
+                * value to be in use as indicated by the "unknown" index.
+                */
+               if (psSysSpecData->ui32SGXFreqListIndex != 0)
+               {
+                       PVR_ASSERT(pdata->device_scale != IMG_NULL);
+                       res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                         &gpsPVRLDMDev->dev,
 #endif
+                                                                         psSysSpecData->pui32SGXFreqList[0]);
+                       if (res == 0)
+                       {
+                               psSysSpecData->ui32SGXFreqListIndex = 0;
+                       }
+                       else if (res == -EBUSY)
+                       {
+                               PVR_DPF((PVR_DBG_WARNING, "DisableSGXClocks: Unable to scale SGX frequency (EBUSY)"));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+                       else if (res < 0)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "DisableSGXClocks: Unable to scale SGX frequency (%d)", res));
+                               psSysSpecData->ui32SGXFreqListIndex = psSysSpecData->ui32SGXFreqListSize - 1;
+                       }
+               }
+       }
+#endif /* defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+#endif /* defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI) */
 
+       /* Indicate that the SGX clocks are disabled */
        atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
 
-#else  
+#else  /* !defined(NO_HARDWARE) */
        PVR_UNREFERENCED_PARAMETER(psSysData);
-#endif 
+#endif /* !defined(NO_HARDWARE) */
 }
 
 #if (defined(DEBUG) || defined(TIMING)) && !defined(PVR_NO_OMAP_TIMER)
 #if defined(PVR_OMAP_USE_DM_TIMER_API)
 #define        GPTIMER_TO_USE 11
+/*!
+******************************************************************************
+
+ @Function  AcquireGPTimer
+
+ @Description Acquire a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_ASSERT(psSysSpecData->psGPTimer == NULL);
 
-       
+       /*
+        * This code has problems on module reload for OMAP5 running Linux
+        * 3.4.10, due to omap2_dm_timer_set_src (called by
+        * omap_dm_timer_request_specific), being unable to set the parent
+        * clock to OMAP_TIMER_SRC_32_KHZ.
+        * Not calling omap_dm_timer_set_source doesn't help.
+        */
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) || !defined(MODULE)
+       /*
+        * This code could try requesting registers 9, 10, and 11,
+        * stopping at the first succesful request.  We'll stick with
+        * 11 for now, as it avoids having to hard code yet more
+        * physical addresses into the code.
+        */
        psSysSpecData->psGPTimer = omap_dm_timer_request_specific(GPTIMER_TO_USE);
        if (psSysSpecData->psGPTimer == NULL)
        {
@@ -276,42 +428,68 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
        }
 
-       
        omap_dm_timer_set_source(psSysSpecData->psGPTimer, OMAP_TIMER_SRC_SYS_CLK);
        omap_dm_timer_enable(psSysSpecData->psGPTimer);
 
-       
+       /* Set autoreload, and start value of 0 */
        omap_dm_timer_set_load_start(psSysSpecData->psGPTimer, 1, 0);
 
        omap_dm_timer_start(psSysSpecData->psGPTimer);
 
-       
+       /*
+        * The DM timer API doesn't have a mechanism for obtaining the
+        * physical address of the counter register.
+        */
        psSysSpecData->sTimerRegPhysBase.uiAddr = SYS_TI335x_GP7TIMER_REGS_SYS_PHYS_BASE;
+#else  /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
+       (void)psSysSpecData;
+#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0)) || !defined(MODULE) */
 
        return PVRSRV_OK;
 }
 
+/*!
+******************************************************************************
+
+ @Function  ReleaseGPTimer
+
+ @Description Release a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        if (psSysSpecData->psGPTimer != NULL)
        {
-                       
+               /* Always returns 0 */  
                (void) omap_dm_timer_stop(psSysSpecData->psGPTimer);
 
                omap_dm_timer_disable(psSysSpecData->psGPTimer);
 
                omap_dm_timer_free(psSysSpecData->psGPTimer);
-
+#if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
                psSysSpecData->sTimerRegPhysBase.uiAddr = 0;
+#endif
 
                psSysSpecData->psGPTimer = NULL;
        }
 
 }
-#else  
+#else  /* PVR_OMAP_USE_DM_TIMER_API */
+/*!
+******************************************************************************
+
+ @Function  AcquireGPTimer
+
+ @Description Acquire a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        struct clk *psCLK;
        IMG_INT res;
        struct clk *sys_ck;
@@ -326,9 +504,8 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        PVR_ASSERT(psSysSpecData->sTimerRegPhysBase.uiAddr == 0);
 #endif
 
-
-#if defined(PVR_OMAP3_TIMING_PRCM)
-       
+#if defined(PVR_OMAP4_TIMING_PRCM)
+       /* assert our dependence on the GPTIMER11 module */
        psCLK = clk_get(NULL, "gpt7_fck");
        if (IS_ERR(psCLK))
        {
@@ -344,7 +521,25 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitError;
        }
        psSysSpecData->psGPT11_ICK = psCLK;
+#if 0
+       sys_ck = clk_get(NULL, "sys_clkin_ck");
+       if (IS_ERR(sys_ck))
+       {
+               PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't get System clock"));
+               goto ExitError;
+       }
 
+       if(clk_get_parent(psSysSpecData->psGPT11_FCK) != sys_ck)
+       {
+               PVR_TRACE(("Setting GPTIMER11 parent to System Clock"));
+               res = clk_set_parent(psSysSpecData->psGPT11_FCK, sys_ck);
+               if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't set GPTIMER11 parent clock (%d)", res));
+               goto ExitError;
+               }
+       }
+#endif
        rate = clk_get_rate(psSysSpecData->psGPT11_FCK);
        PVR_TRACE(("GPTIMER11 clock is %dMHz", HZ_TO_MHZ(rate)));
 
@@ -361,9 +556,9 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                PVR_DPF((PVR_DBG_ERROR, "EnableSystemClocks: Couldn't enable GPTIMER11 interface clock (%d)", res));
                goto ExitDisableGPT11FCK;
        }
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 
-       
+       /* Set the timer to non-posted mode */
        sTimerRegPhysBase.uiAddr = SYS_TI335x_GP7TIMER_TSICR_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
@@ -380,7 +575,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
        {
                PVR_TRACE(("Setting GPTIMER11 mode to posted (currently is non-posted)"));
 
-               
+               /* Set posted mode */
                *pui32TimerEnable |= 4;
        }
 
@@ -389,7 +584,7 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                    PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                    hTimerEnable);
 
-       
+       /* Enable the timer */
        sTimerRegPhysBase.uiAddr = SYS_TI335x_GP7TIMER_ENABLE_SYS_PHYS_BASE;
        pui32TimerEnable = OSMapPhysToLin(sTimerRegPhysBase,
                   4,
@@ -402,32 +597,43 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                goto ExitDisableGPT11ICK;
        }
 
+       /* Enable and set autoreload on overflow */
        *pui32TimerEnable = 3;
 
        OSUnMapPhysToLin(pui32TimerEnable,
                    4,
                    PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                    hTimerEnable);
+
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        psSysSpecData->sTimerRegPhysBase = sTimerRegPhysBase;
 #endif
-
        eError = PVRSRV_OK;
 
        goto Exit;
 
 ExitDisableGPT11ICK:
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        clk_disable(psSysSpecData->psGPT11_ICK);
 ExitDisableGPT11FCK:
        clk_disable(psSysSpecData->psGPT11_FCK);
 ExitError:
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
        eError = PVRSRV_ERROR_CLOCK_REQUEST_FAILED;
 Exit:
        return eError;
 }
 
+/*!
+******************************************************************************
+
+ @Function  ReleaseGPTimer
+
+ @Description Release a GP timer
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        IMG_HANDLE hTimerDisable;
@@ -439,7 +645,7 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                return;
        }
 #endif
-       TimerRegPhysBase.uiAddr = SYS_TI335x_GP7TIMER_ENABLE_SYS_PHYS_BASE;     
+       /* Disable the timer */
        pui32TimerDisable = OSMapPhysToLin(TimerRegPhysBase,
                                4,
                                PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
@@ -458,34 +664,46 @@ static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
                                PVRSRV_HAP_KERNEL_ONLY|PVRSRV_HAP_UNCACHED,
                                hTimerDisable);
        }
-
 #if defined(PVR_OMAP_TIMER_BASE_IN_SYS_SPEC_DATA)
        psSysSpecData->sTimerRegPhysBase.uiAddr = 0;
 #endif
-
-#if defined(PVR_OMAP3_TIMING_PRCM)
+#if defined(PVR_OMAP4_TIMING_PRCM)
        clk_disable(psSysSpecData->psGPT11_ICK);
 
        clk_disable(psSysSpecData->psGPT11_FCK);
-#endif 
+#endif /* defined(PVR_OMAP4_TIMING_PRCM) */
 }
-#endif 
-#else  
+#endif /* PVR_OMAP_USE_DM_TIMER_API */
+#else  /* (DEBUG || TIMING) && !PVR_NO_OMAP_TIMER */
 static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_UNREFERENCED_PARAMETER(psSysSpecData);
+
        return PVRSRV_OK;
 }
 static void ReleaseGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 {
        PVR_UNREFERENCED_PARAMETER(psSysSpecData);
 }
-#endif 
+#endif /* (DEBUG || TIMING) && !PVR_NO_OMAP_TIMER */
 
+/*!
+******************************************************************************
+
+ @Function  EnableSystemClocks
+
+ @Description Setup up the clocks for the graphics device to work.
+
+ @Return   PVRSRV_ERROR
+
+******************************************************************************/
 PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
-       struct clk *psCLK;
+#if !defined(PM_RUNTIME_SUPPORT)
+        struct clk *psCLK;
+#endif
+
        PVR_TRACE(("EnableSystemClocks: Enabling System Clocks"));
 
        if (!psSysSpecData->bSysClocksOneTimeInit)
@@ -494,35 +712,54 @@ PVRSRV_ERROR EnableSystemClocks(SYS_DATA *psSysData)
 
                atomic_set(&psSysSpecData->sSGXClocksEnabled, 0);
 
-
-               psCLK = clk_get(NULL, "sgx_ck");
+               psSysSpecData->bSysClocksOneTimeInit = IMG_TRUE;
+#if !defined(PM_RUNTIME_SUPPORT)
+                psCLK = clk_get(NULL, "sgx_ck");
                 if (IS_ERR(psCLK))
                 {
                         PVR_DPF((PVR_DBG_ERROR, "EnableSsystemClocks: Couldn't get SGX Functional Clock"));
                         return PVRSRV_ERROR_UNABLE_TO_GET_CLOCK;
                 }
                 psSysSpecData->psSGX_FCK = psCLK;
+#endif
 
        }
 
        return AcquireGPTimer(psSysSpecData);
 }
 
+/*!
+******************************************************************************
+
+ @Function  DisableSystemClocks
+
+ @Description Disable the graphics clocks.
+
+ @Return  none
+
+******************************************************************************/
 IMG_VOID DisableSystemClocks(SYS_DATA *psSysData)
 {
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
+
        PVR_TRACE(("DisableSystemClocks: Disabling System Clocks"));
-       
+
+       /*
+        * Always disable the SGX clocks when the system clocks are disabled.
+        * This saves having to make an explicit call to DisableSGXClocks if
+        * active power management is enabled.
+        */
        DisableSGXClocks(psSysData);
 
        ReleaseGPTimer(psSysSpecData);
-
 }
 
 PVRSRV_ERROR SysPMRuntimeRegister(void)
 {
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-//     pm_runtime_enable(&gpsPVRLDMDev->dev);
+#if defined(PM_RUNTIME_SUPPORT)
+       pm_runtime_enable(&gpsPVRLDMDev->dev);
+#endif
 #endif
        return PVRSRV_OK;
 }
@@ -530,7 +767,166 @@ PVRSRV_ERROR SysPMRuntimeRegister(void)
 PVRSRV_ERROR SysPMRuntimeUnregister(void)
 {
 #if defined(LDM_PLATFORM) && !defined(PVR_DRI_DRM_NOT_PCI)
-//     pm_runtime_disable(&gpsPVRLDMDev->dev);
+#if defined(PM_RUNTIME_SUPPORT)
+       pm_runtime_disable(&gpsPVRLDMDev->dev);
 #endif
+#endif
+       return PVRSRV_OK;
+}
+
+PVRSRV_ERROR SysDvfsInitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
+{
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       IMG_UINT32 i, *freq_list;
+       IMG_INT32 opp_count;
+       unsigned long freq;
+       struct opp *opp;
+
+       /*
+        * We query and store the list of SGX frequencies just this once under the
+        * assumption that they are unchanging, e.g. no disabling of high frequency
+        * option for thermal management. This is currently valid for 4430 and 4460.
+        */
+       rcu_read_lock();
+       opp_count = opp_get_opp_count(&gpsPVRLDMDev->dev);
+       if (opp_count < 1)
+       {
+               rcu_read_unlock();
+               PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not retrieve opp count"));
+               return PVRSRV_ERROR_NOT_SUPPORTED;
+       }
+
+       /*
+        * Allocate the frequency list with a slot for each available frequency plus
+        * one additional slot to hold a designated frequency value to assume when in
+        * an unknown frequency state.
+        */
+       freq_list = kmalloc((opp_count + 1) * sizeof(IMG_UINT32), GFP_ATOMIC);
+       if (!freq_list)
+       {
+               rcu_read_unlock();
+               PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not allocate frequency list"));
+               return PVRSRV_ERROR_OUT_OF_MEMORY;
+       }
+
+       /*
+        * Fill in frequency list from lowest to highest then finally the "unknown"
+        * frequency value. We use the highest available frequency as our assumed value
+        * when in an unknown state, because it is safer for APM and hardware recovery
+        * timers to be longer than intended rather than shorter.
+        */
+       freq = 0;
+       for (i = 0; i < opp_count; i++)
+       {
+               opp = opp_find_freq_ceil(&gpsPVRLDMDev->dev, &freq);
+               if (IS_ERR_OR_NULL(opp))
+               {
+                       rcu_read_unlock();
+                       PVR_DPF((PVR_DBG_ERROR, "SysDvfsInitialize: Could not retrieve opp level %d", i));
+                       kfree(freq_list);
+                       return PVRSRV_ERROR_NOT_SUPPORTED;
+               }
+               freq_list[i] = (IMG_UINT32)freq;
+               freq++;
+       }
+       rcu_read_unlock();
+       freq_list[opp_count] = freq_list[opp_count - 1];
+
+       psSysSpecificData->ui32SGXFreqListSize = opp_count + 1;
+       psSysSpecificData->pui32SGXFreqList = freq_list;
+
+       /* Start in unknown state - no frequency request to DVFS yet made */
+       psSysSpecificData->ui32SGXFreqListIndex = opp_count;
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+
        return PVRSRV_OK;
 }
+
+PVRSRV_ERROR SysDvfsDeinitialize(SYS_SPECIFIC_DATA *psSysSpecificData)
+{
+#if !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK)
+       PVR_UNREFERENCED_PARAMETER(psSysSpecificData);
+#else /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+       /*
+        * We assume this function is only called if SysDvfsInitialize() was
+        * completed successfully before.
+        *
+        * The DVFS interface does not allow us to actually unregister as a
+        * user of SGX, so we do the next best thing which is to lower our
+        * required frequency to the minimum if not already set. DVFS may
+        * report busy if early in initialization, but all other errors are
+        * considered serious.
+        */
+       if (psSysSpecificData->ui32SGXFreqListIndex != 0)
+       {
+               struct gpu_platform_data *pdata;
+               IMG_INT32 res;
+
+               pdata = (struct gpu_platform_data *)gpsPVRLDMDev->dev.platform_data;
+
+               PVR_ASSERT(pdata->device_scale != IMG_NULL);
+               res = pdata->device_scale(&gpsPVRLDMDev->dev,
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(3,4,0))
+                                                                 &gpsPVRLDMDev->dev,
+#endif
+                                                                 psSysSpecificData->pui32SGXFreqList[0]);
+               if (res == -EBUSY)
+               {
+                       PVR_DPF((PVR_DBG_WARNING, "SysDvfsDeinitialize: Unable to scale SGX frequency (EBUSY)"));
+               }
+               else if (res < 0)
+               {
+                       PVR_DPF((PVR_DBG_ERROR, "SysDvfsDeinitialize: Unable to scale SGX frequency (%d)", res));
+               }
+
+               psSysSpecificData->ui32SGXFreqListIndex = 0;
+       }
+
+       kfree(psSysSpecificData->pui32SGXFreqList);
+       psSysSpecificData->pui32SGXFreqList = 0;
+       psSysSpecificData->ui32SGXFreqListSize = 0;
+#endif /* !defined(SYS_OMAP_HAS_DVFS_FRAMEWORK) */
+
+       return PVRSRV_OK;
+}
+
+#if defined(SUPPORT_DRI_DRM_PLUGIN)
+static struct omap_gpu_plugin sOMAPGPUPlugin;
+
+#define        SYS_DRM_SET_PLUGIN_FIELD(d, s, f) (d)->f = (s)->f
+int
+SysDRMRegisterPlugin(PVRSRV_DRM_PLUGIN *psDRMPlugin)
+{
+       int iRes;
+
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, name);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, open);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, load);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, unload);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, release);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, mmap);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, ioctls);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, num_ioctls);
+       SYS_DRM_SET_PLUGIN_FIELD(&sOMAPGPUPlugin, psDRMPlugin, ioctl_start);
+
+       iRes = omap_gpu_register_plugin(&sOMAPGPUPlugin);
+       if (iRes != 0)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: omap_gpu_register_plugin failed (%d)", __FUNCTION__, iRes));
+       }
+
+       return iRes;
+}
+
+void
+SysDRMUnregisterPlugin(PVRSRV_DRM_PLUGIN *psDRMPlugin)
+{
+       int iRes = omap_gpu_unregister_plugin(&sOMAPGPUPlugin);
+       if (iRes != 0)
+       {
+               PVR_DPF((PVR_DBG_ERROR, "%s: omap_gpu_unregister_plugin failed (%d)", __FUNCTION__, iRes));
+       }
+}
+#endif
index 7e461b3..717f04b 100644 (file)
@@ -30,7 +30,7 @@
 
 #define VS_PRODUCT_NAME        "TI81xx"
 
-//#define SYS_SGX_CLOCK_SPEED          200000000
+#define SYS_SGX_CLOCK_SPEED            200000000
 #define SYS_387x_SGX_CLOCK_SPEED       200000000
 
 /* Allowed SGX Clock Speeds on Netra 
index 5d59e40..e77e003 100644 (file)
@@ -174,7 +174,6 @@ PVRSRV_ERROR EnableSGXClocks(SYS_DATA *psSysData)
 #if !defined(NO_HARDWARE)
        SYS_SPECIFIC_DATA *psSysSpecData = (SYS_SPECIFIC_DATA *) psSysData->pvSysSpecificData;
        IMG_INT res;
-       long lRate,lNewRate;
        
        if (atomic_read(&psSysSpecData->sSGXClocksEnabled) != 0)
        {
@@ -351,7 +350,6 @@ static PVRSRV_ERROR AcquireGPTimer(SYS_SPECIFIC_DATA *psSysSpecData)
 #if defined(PVR_OMAP3_TIMING_PRCM)
        struct clk *psCLK;
        IMG_INT res;
-       struct clk *sys_ck;
        IMG_INT rate;
 #endif
        PVRSRV_ERROR eError;
index 0b8d445..848367a 100644 (file)
@@ -934,7 +934,7 @@ static IMG_UINT32 WriteExpandingBuffer(PDBG_STREAM psStream,IMG_UINT8 * pui8InBu
        */
        if ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_STREAMENABLE) == 0)
        {
-               PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: buffer %x is disabled", (IMG_UINTPTR_T) psStream));
+               PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: buffer %p is disabled", psStream));
                return(0);
        }
 
@@ -949,7 +949,7 @@ static IMG_UINT32 WriteExpandingBuffer(PDBG_STREAM psStream,IMG_UINT8 * pui8InBu
                */
                if (ui32Space < 32)
                {
-                       PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: buffer %x is full and isn't expandable", (IMG_UINTPTR_T) psStream));
+                       PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: buffer %p is full and isn't expandable", psStream));
                        return(0);
                }
        }
@@ -986,7 +986,7 @@ static IMG_UINT32 WriteExpandingBuffer(PDBG_STREAM psStream,IMG_UINT8 * pui8InBu
                                        else
                                        {
                                                /* out of memory */
-                                               PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: Unable to expand %x. Out of memory.", (IMG_UINTPTR_T) psStream));
+                                               PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: Unable to expand %p. Out of memory.", psStream));
                                                InvalidateAllStreams();
                                                return (0xFFFFFFFFUL);
                                        }
@@ -1815,13 +1815,13 @@ IMG_UINT32 IMG_CALLCONV DBGDrivWrite(PDBG_STREAM psMainStream,IMG_UINT8 * pui8In
        */
        if ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_STREAMENABLE) == 0)
        {
-               PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite: buffer %x is disabled", (IMG_UINTPTR_T) psStream));
+               PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite: buffer %p is disabled", psStream));
                return(0);
        }
 
        if (ui32Space < 8)
        {
-               PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite: buffer %x is full", (IMG_UINTPTR_T) psStream));
+               PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite: buffer %p is full", psStream));
                return(0);
        }
 
@@ -2002,7 +2002,7 @@ IMG_UINT32 IMG_CALLCONV DBGDrivRead(PDBG_STREAM psMainStream, IMG_BOOL bReadInit
        */
        if (!StreamValidForRead(psMainStream))
        {
-               PVR_DPF((PVR_DBG_ERROR, "DBGDrivRead: buffer %x is invalid", (IMG_UINTPTR_T) psMainStream));
+               PVR_DPF((PVR_DBG_ERROR, "DBGDrivRead: buffer %p is invalid", psMainStream));
                return(0);
        }
 
index d58c62d..e56d881 100644 (file)
@@ -51,7 +51,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define MAX_PROCESSES          2
 #define BLOCK_USED                     0x01
 #define BLOCK_LOCKED           0x02
-#define DBGDRIV_MONOBASE       0x000B0000
+#define DBGDRIV_MONOBASE       0x000B0000UL
 
 
 extern IMG_VOID *      g_pvAPIMutex;