From 51097579b18df865d833360e850e054ded56f730 Mon Sep 17 00:00:00 2001
From: Kevin Mihelich <kevin@archlinuxarm.org>
Date: Sun, 29 Oct 2017 19:51:12 +0000
Subject: [PATCH] core/linux-raspberrypi to 4.9.59-1

---
 ...move-the-driver-as-non-functional-on.patch | 1283 -----------------
 core/linux-raspberrypi/PKGBUILD               |   15 +-
 core/linux-raspberrypi/config                 |   44 +-
 3 files changed, 25 insertions(+), 1317 deletions(-)
 delete mode 100644 core/linux-raspberrypi/0001-Revert-vc-cma-Remove-the-driver-as-non-functional-on.patch

diff --git a/core/linux-raspberrypi/0001-Revert-vc-cma-Remove-the-driver-as-non-functional-on.patch b/core/linux-raspberrypi/0001-Revert-vc-cma-Remove-the-driver-as-non-functional-on.patch
deleted file mode 100644
index e02ce309f..000000000
--- a/core/linux-raspberrypi/0001-Revert-vc-cma-Remove-the-driver-as-non-functional-on.patch
+++ /dev/null
@@ -1,1283 +0,0 @@
-From 85549a2bfc21286330443a8fe6591f0ba1f090ac Mon Sep 17 00:00:00 2001
-From: Kevin Mihelich <kevin@archlinuxarm.org>
-Date: Sat, 21 Oct 2017 10:14:35 -0600
-Subject: [PATCH] Revert "vc-cma: Remove the driver as non-functional on Pi"
-
-This reverts commit b017e4f94b17ac322340159f63c546e8d115b104.
----
- arch/arm/configs/bcm2709_defconfig    |    1 +
- arch/arm/configs/bcmrpi_defconfig     |    1 +
- drivers/char/broadcom/Kconfig         |    7 +
- drivers/char/broadcom/Makefile        |    1 +
- drivers/char/broadcom/vc_cma/Makefile |    7 +
- drivers/char/broadcom/vc_cma/vc_cma.c | 1193 +++++++++++++++++++++++++++++++++
- 6 files changed, 1210 insertions(+)
- create mode 100644 drivers/char/broadcom/vc_cma/Makefile
- create mode 100644 drivers/char/broadcom/vc_cma/vc_cma.c
-
-diff --git a/arch/arm/configs/bcm2709_defconfig b/arch/arm/configs/bcm2709_defconfig
-index 889922c4..199550c7 100644
---- a/arch/arm/configs/bcm2709_defconfig
-+++ b/arch/arm/configs/bcm2709_defconfig
-@@ -595,6 +595,7 @@ CONFIG_GAMEPORT=m
- CONFIG_GAMEPORT_NS558=m
- CONFIG_GAMEPORT_L4=m
- CONFIG_BRCM_CHAR_DRIVERS=y
-+CONFIG_BCM_VC_CMA=y
- CONFIG_BCM_VCIO=y
- CONFIG_BCM_VC_SM=y
- # CONFIG_LEGACY_PTYS is not set
-diff --git a/arch/arm/configs/bcmrpi_defconfig b/arch/arm/configs/bcmrpi_defconfig
-index 6a098ee6..e36c0f92 100644
---- a/arch/arm/configs/bcmrpi_defconfig
-+++ b/arch/arm/configs/bcmrpi_defconfig
-@@ -591,6 +591,7 @@ CONFIG_GAMEPORT=m
- CONFIG_GAMEPORT_NS558=m
- CONFIG_GAMEPORT_L4=m
- CONFIG_BRCM_CHAR_DRIVERS=y
-+CONFIG_BCM_VC_CMA=y
- CONFIG_BCM_VCIO=y
- CONFIG_BCM_VC_SM=y
- # CONFIG_LEGACY_PTYS is not set
-diff --git a/drivers/char/broadcom/Kconfig b/drivers/char/broadcom/Kconfig
-index 77bf68a8..03216491 100644
---- a/drivers/char/broadcom/Kconfig
-+++ b/drivers/char/broadcom/Kconfig
-@@ -9,6 +9,13 @@ menuconfig BRCM_CHAR_DRIVERS
- 
- if BRCM_CHAR_DRIVERS
- 
-+config BCM_VC_CMA
-+	bool "Videocore CMA"
-+	depends on CMA && BCM2708_VCHIQ
-+	default n
-+        help
-+          Helper for videocore CMA access.
-+
- config BCM2708_VCMEM
- 	bool "Videocore Memory"
-         default y
-diff --git a/drivers/char/broadcom/Makefile b/drivers/char/broadcom/Makefile
-index 7d9cb3e0..14775c9b 100644
---- a/drivers/char/broadcom/Makefile
-+++ b/drivers/char/broadcom/Makefile
-@@ -1,3 +1,4 @@
-+obj-$(CONFIG_BCM_VC_CMA)	+= vc_cma/
- obj-$(CONFIG_BCM2708_VCMEM)	+= vc_mem.o
- obj-$(CONFIG_BCM_VCIO)		+= vcio.o
- obj-$(CONFIG_BCM_VC_SM)         += vc_sm/
-diff --git a/drivers/char/broadcom/vc_cma/Makefile b/drivers/char/broadcom/vc_cma/Makefile
-new file mode 100644
-index 00000000..d222313e
---- /dev/null
-+++ b/drivers/char/broadcom/vc_cma/Makefile
-@@ -0,0 +1,7 @@
-+ccflags-$(CONFIG_BCM_VC_CMA)  += -Wall -Wstrict-prototypes -Wno-trigraphs -Werror
-+ccflags-$(CONFIG_BCM_VC_CMA)  += -Iinclude/linux/broadcom -Idrivers/staging/vc04_services -Idrivers/staging/vc04_services/interface/vchi -Idrivers/staging/vc04_services/interface/vchiq_arm
-+ccflags-$(CONFIG_BCM_VC_CMA)  += -D__KERNEL__ -D__linux__
-+
-+obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
-+
-+vc-cma-objs := vc_cma.o
-diff --git a/drivers/char/broadcom/vc_cma/vc_cma.c b/drivers/char/broadcom/vc_cma/vc_cma.c
-new file mode 100644
-index 00000000..85f6e9da
---- /dev/null
-+++ b/drivers/char/broadcom/vc_cma/vc_cma.c
-@@ -0,0 +1,1193 @@
-+/**
-+ * Copyright (c) 2010-2012 Broadcom. All rights reserved.
-+ *
-+ * Redistribution and use in source and binary forms, with or without
-+ * modification, are permitted provided that the following conditions
-+ * are met:
-+ * 1. Redistributions of source code must retain the above copyright
-+ *    notice, this list of conditions, and the following disclaimer,
-+ *    without modification.
-+ * 2. Redistributions in binary form must reproduce the above copyright
-+ *    notice, this list of conditions and the following disclaimer in the
-+ *    documentation and/or other materials provided with the distribution.
-+ * 3. The names of the above-listed copyright holders may not be used
-+ *    to endorse or promote products derived from this software without
-+ *    specific prior written permission.
-+ *
-+ * ALTERNATIVELY, this software may be distributed under the terms of the
-+ * GNU General Public License ("GPL") version 2, as published by the Free
-+ * Software Foundation.
-+ *
-+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-+ */
-+
-+#include <linux/kernel.h>
-+#include <linux/module.h>
-+#include <linux/kthread.h>
-+#include <linux/fs.h>
-+#include <linux/device.h>
-+#include <linux/cdev.h>
-+#include <linux/mm.h>
-+#include <linux/proc_fs.h>
-+#include <linux/seq_file.h>
-+#include <linux/dma-mapping.h>
-+#include <linux/dma-contiguous.h>
-+#include <linux/platform_device.h>
-+#include <linux/uaccess.h>
-+#include <asm/cacheflush.h>
-+
-+#include "vc_cma.h"
-+
-+#include "vchiq_util.h"
-+#include "vchiq_connected.h"
-+//#include "debug_sym.h"
-+//#include "vc_mem.h"
-+
-+#define DRIVER_NAME  "vc-cma"
-+
-+#define LOG_DBG(fmt, ...) \
-+	if (vc_cma_debug) \
-+		printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
-+#define LOG_INFO(fmt, ...) \
-+	printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
-+#define LOG_ERR(fmt, ...) \
-+	printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
-+
-+#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
-+#define VC_CMA_VERSION 2
-+
-+#define VC_CMA_CHUNK_ORDER 6	/* 256K */
-+#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
-+#define VC_CMA_MAX_PARAMS_PER_MSG \
-+	((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
-+#define VC_CMA_RESERVE_COUNT_MAX 16
-+
-+#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
-+
-+#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
-+
-+#define loud_error(...) \
-+	LOG_ERR("===== " __VA_ARGS__)
-+
-+enum {
-+	VC_CMA_MSG_QUIT,
-+	VC_CMA_MSG_OPEN,
-+	VC_CMA_MSG_TICK,
-+	VC_CMA_MSG_ALLOC,	/* chunk count */
-+	VC_CMA_MSG_FREE,	/* chunk, chunk, ... */
-+	VC_CMA_MSG_ALLOCATED,	/* chunk, chunk, ... */
-+	VC_CMA_MSG_REQUEST_ALLOC,	/* chunk count */
-+	VC_CMA_MSG_REQUEST_FREE,	/* chunk count */
-+	VC_CMA_MSG_RESERVE,	/* bytes lo, bytes hi */
-+	VC_CMA_MSG_UPDATE_RESERVE,
-+	VC_CMA_MSG_MAX
-+};
-+
-+struct cma_msg {
-+	unsigned short type;
-+	unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
-+};
-+
-+struct vc_cma_reserve_user {
-+	unsigned int pid;
-+	unsigned int reserve;
-+};
-+
-+/* Device (/dev) related variables */
-+static dev_t vc_cma_devnum;
-+static struct class *vc_cma_class;
-+static struct cdev vc_cma_cdev;
-+static int vc_cma_inited;
-+static int vc_cma_debug;
-+
-+/* Proc entry */
-+static struct proc_dir_entry *vc_cma_proc_entry;
-+
-+phys_addr_t vc_cma_base;
-+struct page *vc_cma_base_page;
-+unsigned int vc_cma_size;
-+EXPORT_SYMBOL(vc_cma_size);
-+unsigned int vc_cma_initial;
-+unsigned int vc_cma_chunks;
-+unsigned int vc_cma_chunks_used;
-+unsigned int vc_cma_chunks_reserved;
-+
-+
-+void *vc_cma_dma_alloc;
-+unsigned int vc_cma_dma_size;
-+
-+static int in_loud_error;
-+
-+unsigned int vc_cma_reserve_total;
-+unsigned int vc_cma_reserve_count;
-+struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
-+static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
-+static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
-+
-+static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
-+static struct platform_device vc_cma_device = {
-+	.name = "vc-cma",
-+	.id = 0,
-+	.dev = {
-+		.dma_mask = &vc_cma_dma_mask,
-+		.coherent_dma_mask = DMA_BIT_MASK(32),
-+		},
-+};
-+
-+static VCHIQ_INSTANCE_T cma_instance;
-+static VCHIQ_SERVICE_HANDLE_T cma_service;
-+static VCHIU_QUEUE_T cma_msg_queue;
-+static struct task_struct *cma_worker;
-+
-+static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
-+static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
-+static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
-+					   VCHIQ_HEADER_T * header,
-+					   VCHIQ_SERVICE_HANDLE_T service,
-+					   void *bulk_userdata);
-+static void send_vc_msg(unsigned short type,
-+			unsigned short param1, unsigned short param2);
-+static bool send_worker_msg(VCHIQ_HEADER_T * msg);
-+
-+static int early_vc_cma_mem(char *p)
-+{
-+	unsigned int new_size;
-+	printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
-+	vc_cma_size = memparse(p, &p);
-+	vc_cma_initial = vc_cma_size;
-+	if (*p == '/')
-+		vc_cma_size = memparse(p + 1, &p);
-+	if (*p == '@')
-+		vc_cma_base = memparse(p + 1, &p);
-+
-+	new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
-+	    & ~(VC_CMA_CHUNK_SIZE - 1);
-+	if (new_size > vc_cma_size)
-+		vc_cma_size = 0;
-+	vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
-+	    & ~(VC_CMA_CHUNK_SIZE - 1);
-+	if (vc_cma_initial > vc_cma_size)
-+		vc_cma_initial = vc_cma_size;
-+	vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
-+	    & ~(VC_CMA_CHUNK_SIZE - 1);
-+
-+	printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
-+	       vc_cma_size, (unsigned int)vc_cma_base);
-+
-+	return 0;
-+}
-+
-+early_param("vc-cma-mem", early_vc_cma_mem);
-+
-+void __init vc_cma_early_init(void)
-+{
-+	LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
-+	if (vc_cma_size) {
-+		int rc = platform_device_register(&vc_cma_device);
-+		LOG_DBG("platform_device_register -> %d", rc);
-+	}
-+}
-+
-+void __init vc_cma_reserve(void)
-+{
-+	/* if vc_cma_size is set, then declare vc CMA area of the same
-+	 * size from the end of memory
-+	 */
-+	if (vc_cma_size) {
-+		if (dma_declare_contiguous(&vc_cma_device.dev, vc_cma_size,
-+					   vc_cma_base, 0) == 0) {
-+			if (!dev_get_cma_area(NULL)) {
-+				/* There is no default CMA area - make this
-+				   the default */
-+				struct cma *vc_cma_area = dev_get_cma_area(
-+					&vc_cma_device.dev);
-+				dma_contiguous_set_default(vc_cma_area);
-+				LOG_INFO("vc_cma_reserve - using vc_cma as "
-+					 "the default contiguous DMA area");
-+			}
-+		} else {
-+			LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
-+				vc_cma_size, (unsigned int)vc_cma_base);
-+			vc_cma_size = 0;
-+		}
-+	}
-+	vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
-+}
-+
-+/****************************************************************************
-+*
-+*   vc_cma_open
-+*
-+***************************************************************************/
-+
-+static int vc_cma_open(struct inode *inode, struct file *file)
-+{
-+	(void)inode;
-+	(void)file;
-+
-+	return 0;
-+}
-+
-+/****************************************************************************
-+*
-+*   vc_cma_release
-+*
-+***************************************************************************/
-+
-+static int vc_cma_release(struct inode *inode, struct file *file)
-+{
-+	(void)inode;
-+	(void)file;
-+
-+	vc_cma_set_reserve(0, current->tgid);
-+
-+	return 0;
-+}
-+
-+/****************************************************************************
-+*
-+*   vc_cma_ioctl
-+*
-+***************************************************************************/
-+
-+static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
-+{
-+	int rc = 0;
-+
-+	(void)cmd;
-+	(void)arg;
-+
-+	switch (cmd) {
-+	case VC_CMA_IOC_RESERVE:
-+		rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
-+		if (rc >= 0)
-+			rc = 0;
-+		break;
-+	default:
-+		LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
-+		return -ENOTTY;
-+	}
-+
-+	return rc;
-+}
-+
-+/****************************************************************************
-+*
-+*   File Operations for the driver.
-+*
-+***************************************************************************/
-+
-+static const struct file_operations vc_cma_fops = {
-+	.owner = THIS_MODULE,
-+	.open = vc_cma_open,
-+	.release = vc_cma_release,
-+	.unlocked_ioctl = vc_cma_ioctl,
-+};
-+
-+/****************************************************************************
-+*
-+*   vc_cma_proc_open
-+*
-+***************************************************************************/
-+
-+static int vc_cma_show_info(struct seq_file *m, void *v)
-+{
-+	int i;
-+
-+	seq_printf(m, "Videocore CMA:\n");
-+	seq_printf(m, "   Base       : %08x\n", (unsigned int)vc_cma_base);
-+	seq_printf(m, "   Length     : %08x\n", vc_cma_size);
-+	seq_printf(m, "   Initial    : %08x\n", vc_cma_initial);
-+	seq_printf(m, "   Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
-+	seq_printf(m, "   Chunks     : %4d (%d bytes)\n",
-+		   (int)vc_cma_chunks,
-+		   (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
-+	seq_printf(m, "   Used       : %4d (%d bytes)\n",
-+		   (int)vc_cma_chunks_used,
-+		   (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
-+	seq_printf(m, "   Reserved   : %4d (%d bytes)\n",
-+		   (unsigned int)vc_cma_chunks_reserved,
-+		   (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
-+
-+	for (i = 0; i < vc_cma_reserve_count; i++) {
-+		struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
-+		seq_printf(m, "     PID %5d: %d bytes\n", user->pid,
-+			   user->reserve);
-+	}
-+	seq_printf(m, "   dma_alloc  : %p (%d pages)\n",
-+		   vc_cma_dma_alloc ? page_address(vc_cma_dma_alloc) : 0,
-+		   vc_cma_dma_size);
-+
-+	seq_printf(m, "\n");
-+
-+	return 0;
-+}
-+
-+static int vc_cma_proc_open(struct inode *inode, struct file *file)
-+{
-+	return single_open(file, vc_cma_show_info, NULL);
-+}
-+
-+/****************************************************************************
-+*
-+*   vc_cma_proc_write
-+*
-+***************************************************************************/
-+
-+static int vc_cma_proc_write(struct file *file,
-+			     const char __user *buffer,
-+			     size_t size, loff_t *ppos)
-+{
-+	int rc = -EFAULT;
-+	char input_str[20];
-+
-+	memset(input_str, 0, sizeof(input_str));
-+
-+	if (size > sizeof(input_str)) {
-+		LOG_ERR("%s: input string length too long", __func__);
-+		goto out;
-+	}
-+
-+	if (copy_from_user(input_str, buffer, size - 1)) {
-+		LOG_ERR("%s: failed to get input string", __func__);
-+		goto out;
-+	}
-+#define ALLOC_STR "alloc"
-+#define FREE_STR "free"
-+#define DEBUG_STR "debug"
-+#define RESERVE_STR "reserve"
-+#define DMA_ALLOC_STR "dma_alloc"
-+#define DMA_FREE_STR "dma_free"
-+	if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
-+		int alloc_size;
-+		char *p = input_str + strlen(ALLOC_STR);
-+
-+		while (*p == ' ')
-+			p++;
-+		alloc_size = memparse(p, NULL);
-+		LOG_INFO("/proc/vc-cma: alloc %d", alloc_size);
-+		if (alloc_size)
-+			send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
-+				    alloc_size / VC_CMA_CHUNK_SIZE, 0);
-+		else
-+			LOG_ERR("invalid size '%s'", p);
-+		rc = size;
-+	} else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
-+		int alloc_size;
-+		char *p = input_str + strlen(FREE_STR);
-+
-+		while (*p == ' ')
-+			p++;
-+		alloc_size = memparse(p, NULL);
-+		LOG_INFO("/proc/vc-cma: free %d", alloc_size);
-+		if (alloc_size)
-+			send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
-+				    alloc_size / VC_CMA_CHUNK_SIZE, 0);
-+		else
-+			LOG_ERR("invalid size '%s'", p);
-+		rc = size;
-+	} else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
-+		char *p = input_str + strlen(DEBUG_STR);
-+		while (*p == ' ')
-+			p++;
-+		if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
-+			vc_cma_debug = 1;
-+		else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
-+			vc_cma_debug = 0;
-+		LOG_INFO("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
-+		rc = size;
-+	} else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
-+		int alloc_size;
-+		int reserved;
-+		char *p = input_str + strlen(RESERVE_STR);
-+		while (*p == ' ')
-+			p++;
-+		alloc_size = memparse(p, NULL);
-+
-+		reserved = vc_cma_set_reserve(alloc_size, current->tgid);
-+		rc = (reserved >= 0) ? size : reserved;
-+	} else if (strncmp(input_str, DMA_ALLOC_STR, strlen(DMA_ALLOC_STR)) == 0) {
-+		int alloc_size;
-+		char *p = input_str + strlen(DMA_ALLOC_STR);
-+		while (*p == ' ')
-+			p++;
-+		alloc_size = memparse(p, NULL);
-+
-+		if (vc_cma_dma_alloc) {
-+		    dma_release_from_contiguous(NULL, vc_cma_dma_alloc,
-+						vc_cma_dma_size);
-+		    vc_cma_dma_alloc = NULL;
-+		    vc_cma_dma_size = 0;
-+		}
-+		vc_cma_dma_alloc = dma_alloc_from_contiguous(NULL, alloc_size, 0);
-+		vc_cma_dma_size = (vc_cma_dma_alloc ? alloc_size : 0);
-+		if (vc_cma_dma_alloc)
-+			LOG_INFO("dma_alloc(%d pages) -> %p", alloc_size, page_address(vc_cma_dma_alloc));
-+		else
-+			LOG_ERR("dma_alloc(%d pages) failed", alloc_size);
-+		rc = size;
-+	} else if (strncmp(input_str, DMA_FREE_STR, strlen(DMA_FREE_STR)) == 0) {
-+		if (vc_cma_dma_alloc) {
-+		    dma_release_from_contiguous(NULL, vc_cma_dma_alloc,
-+						vc_cma_dma_size);
-+		    vc_cma_dma_alloc = NULL;
-+		    vc_cma_dma_size = 0;
-+		}
-+		rc = size;
-+	}
-+
-+out:
-+	return rc;
-+}
-+
-+/****************************************************************************
-+*
-+*   File Operations for /proc interface.
-+*
-+***************************************************************************/
-+
-+static const struct file_operations vc_cma_proc_fops = {
-+	.open = vc_cma_proc_open,
-+	.read = seq_read,
-+	.write = vc_cma_proc_write,
-+	.llseek = seq_lseek,
-+	.release = single_release
-+};
-+
-+static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
-+{
-+	struct vc_cma_reserve_user *user = NULL;
-+	int delta = 0;
-+	int i;
-+
-+	if (down_interruptible(&vc_cma_reserve_mutex))
-+		return -ERESTARTSYS;
-+
-+	for (i = 0; i < vc_cma_reserve_count; i++) {
-+		if (pid == vc_cma_reserve_users[i].pid) {
-+			user = &vc_cma_reserve_users[i];
-+			delta = reserve - user->reserve;
-+			if (reserve)
-+				user->reserve = reserve;
-+			else {
-+				/* Remove this entry by copying downwards */
-+				while ((i + 1) < vc_cma_reserve_count) {
-+					user[0].pid = user[1].pid;
-+					user[0].reserve = user[1].reserve;
-+					user++;
-+					i++;
-+				}
-+				vc_cma_reserve_count--;
-+				user = NULL;
-+			}
-+			break;
-+		}
-+	}
-+
-+	if (reserve && !user) {
-+		if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
-+			LOG_ERR("vc-cma: Too many reservations - "
-+				"increase CMA_RESERVE_COUNT_MAX");
-+			up(&vc_cma_reserve_mutex);
-+			return -EBUSY;
-+		}
-+		user = &vc_cma_reserve_users[vc_cma_reserve_count];
-+		user->pid = pid;
-+		user->reserve = reserve;
-+		delta = reserve;
-+		vc_cma_reserve_count++;
-+	}
-+
-+	vc_cma_reserve_total += delta;
-+
-+	send_vc_msg(VC_CMA_MSG_RESERVE,
-+		    vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
-+
-+	send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
-+
-+	LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
-+		reserve, pid, vc_cma_reserve_total);
-+
-+	up(&vc_cma_reserve_mutex);
-+
-+	return vc_cma_reserve_total;
-+}
-+
-+static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
-+					   VCHIQ_HEADER_T * header,
-+					   VCHIQ_SERVICE_HANDLE_T service,
-+					   void *bulk_userdata)
-+{
-+	switch (reason) {
-+	case VCHIQ_MESSAGE_AVAILABLE:
-+		if (!send_worker_msg(header))
-+			return VCHIQ_RETRY;
-+		break;
-+	case VCHIQ_SERVICE_CLOSED:
-+		LOG_DBG("CMA service closed");
-+		break;
-+	default:
-+		LOG_ERR("Unexpected CMA callback reason %d", reason);
-+		break;
-+	}
-+	return VCHIQ_SUCCESS;
-+}
-+
-+static void send_vc_msg(unsigned short type,
-+			unsigned short param1, unsigned short param2)
-+{
-+	unsigned short msg[] = { type, param1, param2 };
-+	VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
-+	VCHIQ_STATUS_T ret;
-+	vchiq_use_service(cma_service);
-+	ret = vchiq_queue_message(cma_service, &elem, 1);
-+	vchiq_release_service(cma_service);
-+	if (ret != VCHIQ_SUCCESS)
-+		LOG_ERR("vchiq_queue_message returned %x", ret);
-+}
-+
-+static bool send_worker_msg(VCHIQ_HEADER_T * msg)
-+{
-+	if (down_interruptible(&vc_cma_worker_queue_push_mutex))
-+		return false;
-+	vchiu_queue_push(&cma_msg_queue, msg);
-+	up(&vc_cma_worker_queue_push_mutex);
-+	return true;
-+}
-+
-+static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
-+{
-+	int i;
-+	for (i = 0; i < num_chunks; i++) {
-+		struct page *chunk;
-+		unsigned int chunk_num;
-+		uint8_t *chunk_addr;
-+		size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
-+
-+		chunk = dma_alloc_from_contiguous(&vc_cma_device.dev,
-+						  PAGES_PER_CHUNK,
-+						  VC_CMA_CHUNK_ORDER);
-+		if (!chunk)
-+			break;
-+
-+		chunk_addr = page_address(chunk);
-+		dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
-+		outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
-+			chunk_size);
-+
-+		chunk_num =
-+		    (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
-+		BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
-+			VC_CMA_CHUNK_SIZE) != 0);
-+		if (chunk_num >= vc_cma_chunks) {
-+			phys_addr_t _pa = vc_cma_base + vc_cma_size - 1;
-+			LOG_ERR("%s: ===============================",
-+				__func__);
-+			LOG_ERR("%s: chunk phys %x, vc_cma %pa-%pa - "
-+				"bad SPARSEMEM configuration?",
-+				__func__, (unsigned int)page_to_phys(chunk),
-+				&vc_cma_base, &_pa);
-+			LOG_ERR("%s: dev->cma_area = %p", __func__,
-+				(void*)0/*vc_cma_device.dev.cma_area*/);
-+			LOG_ERR("%s: ===============================",
-+				__func__);
-+			break;
-+		}
-+		reply->params[i] = chunk_num;
-+		vc_cma_chunks_used++;
-+	}
-+
-+	if (i < num_chunks) {
-+		LOG_ERR("%s: dma_alloc_from_contiguous failed "
-+			"for %x bytes (alloc %d of %d, %d free)",
-+			__func__, VC_CMA_CHUNK_SIZE, i,
-+			num_chunks, vc_cma_chunks - vc_cma_chunks_used);
-+		num_chunks = i;
-+	}
-+
-+	LOG_DBG("CMA allocated %d chunks -> %d used",
-+		num_chunks, vc_cma_chunks_used);
-+	reply->type = VC_CMA_MSG_ALLOCATED;
-+
-+	{
-+		VCHIQ_ELEMENT_T elem = {
-+			reply,
-+			offsetof(struct cma_msg, params[0]) +
-+			    num_chunks * sizeof(reply->params[0])
-+		};
-+		VCHIQ_STATUS_T ret;
-+		vchiq_use_service(cma_service);
-+		ret = vchiq_queue_message(cma_service, &elem, 1);
-+		vchiq_release_service(cma_service);
-+		if (ret != VCHIQ_SUCCESS)
-+			LOG_ERR("vchiq_queue_message return " "%x", ret);
-+	}
-+
-+	return num_chunks;
-+}
-+
-+static int cma_worker_proc(void *param)
-+{
-+	static struct cma_msg reply;
-+	(void)param;
-+
-+	while (1) {
-+		VCHIQ_HEADER_T *msg;
-+		static struct cma_msg msg_copy;
-+		struct cma_msg *cma_msg = &msg_copy;
-+		int type, msg_size;
-+
-+		msg = vchiu_queue_pop(&cma_msg_queue);
-+		if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
-+			msg_size = msg->size;
-+			memcpy(&msg_copy, msg->data, msg_size);
-+			type = cma_msg->type;
-+			vchiq_release_message(cma_service, msg);
-+		} else {
-+			msg_size = 0;
-+			type = (int)msg;
-+			if (type == VC_CMA_MSG_QUIT)
-+				break;
-+			else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
-+				msg = NULL;
-+				cma_msg = NULL;
-+			} else {
-+				BUG();
-+				continue;
-+			}
-+		}
-+
-+		switch (type) {
-+		case VC_CMA_MSG_ALLOC:{
-+				int num_chunks, free_chunks;
-+				num_chunks = cma_msg->params[0];
-+				free_chunks =
-+				    vc_cma_chunks - vc_cma_chunks_used;
-+				LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
-+				if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
-+					LOG_ERR
-+					    ("CMA_MSG_ALLOC - chunk count (%d) "
-+					     "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
-+					     num_chunks,
-+					     VC_CMA_MAX_PARAMS_PER_MSG);
-+					num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
-+				}
-+
-+				if (num_chunks > free_chunks) {
-+					LOG_ERR
-+					    ("CMA_MSG_ALLOC - chunk count (%d) "
-+					     "exceeds free chunks (%d)",
-+					     num_chunks, free_chunks);
-+					num_chunks = free_chunks;
-+				}
-+
-+				vc_cma_alloc_chunks(num_chunks, &reply);
-+			}
-+			break;
-+
-+		case VC_CMA_MSG_FREE:{
-+				int chunk_count =
-+				    (msg_size -
-+				     offsetof(struct cma_msg,
-+					      params)) /
-+				    sizeof(cma_msg->params[0]);
-+				int i;
-+				BUG_ON(chunk_count <= 0);
-+
-+				LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
-+					chunk_count, cma_msg->params[0]);
-+				for (i = 0; i < chunk_count; i++) {
-+					int chunk_num = cma_msg->params[i];
-+					struct page *page = vc_cma_base_page +
-+					    chunk_num * PAGES_PER_CHUNK;
-+					if (chunk_num >= vc_cma_chunks) {
-+						LOG_ERR
-+						    ("CMA_MSG_FREE - chunk %d of %d"
-+						     " (value %x) exceeds maximum "
-+						     "(%x)", i, chunk_count,
-+						     chunk_num,
-+						     vc_cma_chunks - 1);
-+						break;
-+					}
-+
-+					if (!dma_release_from_contiguous
-+					    (&vc_cma_device.dev, page,
-+					     PAGES_PER_CHUNK)) {
-+						phys_addr_t _pa = page_to_phys(page);
-+						LOG_ERR
-+						    ("CMA_MSG_FREE - failed to "
-+						     "release chunk %d (phys %pa, "
-+						     "page %x)", chunk_num,
-+						     &_pa,
-+						     (unsigned int)page);
-+					}
-+					vc_cma_chunks_used--;
-+				}
-+				LOG_DBG("CMA released %d chunks -> %d used",
-+					i, vc_cma_chunks_used);
-+			}
-+			break;
-+
-+		case VC_CMA_MSG_UPDATE_RESERVE:{
-+				int chunks_needed =
-+				    ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
-+				      1)
-+				     / VC_CMA_CHUNK_SIZE) -
-+				    vc_cma_chunks_reserved;
-+
-+				LOG_DBG
-+				    ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
-+				     chunks_needed);
-+
-+				/* Cap the reservations to what is available */
-+				if (chunks_needed > 0) {
-+					if (chunks_needed >
-+					    (vc_cma_chunks -
-+					     vc_cma_chunks_used))
-+						chunks_needed =
-+						    (vc_cma_chunks -
-+						     vc_cma_chunks_used);
-+
-+					chunks_needed =
-+					    vc_cma_alloc_chunks(chunks_needed,
-+								&reply);
-+				}
-+
-+				LOG_DBG
-+				    ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
-+				     chunks_needed);
-+				vc_cma_chunks_reserved += chunks_needed;
-+			}
-+			break;
-+
-+		default:
-+			LOG_ERR("unexpected msg type %d", type);
-+			break;
-+		}
-+	}
-+
-+	LOG_DBG("quitting...");
-+	return 0;
-+}
-+
-+/****************************************************************************
-+*
-+*   vc_cma_connected_init
-+*
-+*   This function is called once the videocore has been connected.
-+*
-+***************************************************************************/
-+
-+static void vc_cma_connected_init(void)
-+{
-+	VCHIQ_SERVICE_PARAMS_T service_params;
-+
-+	LOG_DBG("vc_cma_connected_init");
-+
-+	if (!vchiu_queue_init(&cma_msg_queue, 16)) {
-+		LOG_ERR("could not create CMA msg queue");
-+		goto fail_queue;
-+	}
-+
-+	if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
-+		goto fail_vchiq_init;
-+
-+	vchiq_connect(cma_instance);
-+
-+	service_params.fourcc = VC_CMA_FOURCC;
-+	service_params.callback = cma_service_callback;
-+	service_params.userdata = NULL;
-+	service_params.version = VC_CMA_VERSION;
-+	service_params.version_min = VC_CMA_VERSION;
-+
-+	if (vchiq_open_service(cma_instance, &service_params,
-+			       &cma_service) != VCHIQ_SUCCESS) {
-+		LOG_ERR("failed to open service - already in use?");
-+		goto fail_vchiq_open;
-+	}
-+
-+	vchiq_release_service(cma_service);
-+
-+	cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
-+	if (!cma_worker) {
-+		LOG_ERR("could not create CMA worker thread");
-+		goto fail_worker;
-+	}
-+	set_user_nice(cma_worker, -20);
-+	wake_up_process(cma_worker);
-+
-+	return;
-+
-+fail_worker:
-+	vchiq_close_service(cma_service);
-+fail_vchiq_open:
-+	vchiq_shutdown(cma_instance);
-+fail_vchiq_init:
-+	vchiu_queue_delete(&cma_msg_queue);
-+fail_queue:
-+	return;
-+}
-+
-+void
-+loud_error_header(void)
-+{
-+	if (in_loud_error)
-+		return;
-+
-+	LOG_ERR("============================================================"
-+		"================");
-+	LOG_ERR("============================================================"
-+		"================");
-+	LOG_ERR("=====");
-+
-+	in_loud_error = 1;
-+}
-+
-+void
-+loud_error_footer(void)
-+{
-+	if (!in_loud_error)
-+		return;
-+
-+	LOG_ERR("=====");
-+	LOG_ERR("============================================================"
-+		"================");
-+	LOG_ERR("============================================================"
-+		"================");
-+
-+	in_loud_error = 0;
-+}
-+
-+#if 1
-+static int check_cma_config(void) { return 1; }
-+#else
-+static int
-+read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
-+	const char *symbol,
-+	void *buf, size_t bufsize)
-+{
-+	VC_MEM_ADDR_T vcMemAddr;
-+	size_t vcMemSize;
-+	uint8_t *mapAddr;
-+	off_t  vcMapAddr;
-+
-+	if (!LookupVideoCoreSymbol(handle, symbol,
-+		&vcMemAddr,
-+		&vcMemSize)) {
-+		loud_error_header();
-+		loud_error(
-+			"failed to find VC symbol \"%s\".",
-+			symbol);
-+		loud_error_footer();
-+		return 0;
-+	}
-+
-+	if (vcMemSize != bufsize) {
-+		loud_error_header();
-+		loud_error(
-+			"VC symbol \"%s\" is the wrong size.",
-+			symbol);
-+		loud_error_footer();
-+		return 0;
-+	}
-+
-+	vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
-+	vcMapAddr += mm_vc_mem_phys_addr;
-+	mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
-+	if (mapAddr == 0) {
-+		loud_error_header();
-+		loud_error(
-+			"failed to ioremap \"%s\" @ 0x%x "
-+			"(phys: 0x%x, size: %u).",
-+			symbol,
-+			(unsigned int)vcMapAddr,
-+			(unsigned int)vcMemAddr,
-+			(unsigned int)vcMemSize);
-+		loud_error_footer();
-+		return 0;
-+	}
-+
-+	memcpy(buf, mapAddr, bufsize);
-+	iounmap(mapAddr);
-+
-+	return 1;
-+}
-+
-+
-+static int
-+check_cma_config(void)
-+{
-+	VC_MEM_ACCESS_HANDLE_T mem_hndl;
-+	VC_MEM_ADDR_T mempool_start;
-+	VC_MEM_ADDR_T mempool_end;
-+	VC_MEM_ADDR_T mempool_offline_start;
-+	VC_MEM_ADDR_T mempool_offline_end;
-+	VC_MEM_ADDR_T cam_alloc_base;
-+	VC_MEM_ADDR_T cam_alloc_size;
-+	VC_MEM_ADDR_T cam_alloc_end;
-+	int success = 0;
-+
-+	if (OpenVideoCoreMemory(&mem_hndl) != 0)
-+		goto out;
-+
-+	/* Read the relevant VideoCore variables */
-+	if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
-+		&mempool_start,
-+		sizeof(mempool_start)))
-+		goto close;
-+
-+	if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
-+		&mempool_end,
-+		sizeof(mempool_end)))
-+		goto close;
-+
-+	if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
-+		&mempool_offline_start,
-+		sizeof(mempool_offline_start)))
-+		goto close;
-+
-+	if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
-+		&mempool_offline_end,
-+		sizeof(mempool_offline_end)))
-+		goto close;
-+
-+	if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
-+		&cam_alloc_base,
-+		sizeof(cam_alloc_base)))
-+		goto close;
-+
-+	if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
-+		&cam_alloc_size,
-+		sizeof(cam_alloc_size)))
-+		goto close;
-+
-+	cam_alloc_end = cam_alloc_base + cam_alloc_size;
-+
-+	success = 1;
-+
-+	/* Now the sanity checks */
-+	if (!mempool_offline_start)
-+		mempool_offline_start = mempool_start;
-+	if (!mempool_offline_end)
-+		mempool_offline_end = mempool_end;
-+
-+	if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
-+		loud_error_header();
-+		loud_error(
-+			"__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
-+			"vc_cma_base(%x)",
-+			mempool_offline_start,
-+			VCADDR_TO_PHYSADDR(mempool_offline_start),
-+			vc_cma_base);
-+		success = 0;
-+	}
-+
-+	if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
-+		(vc_cma_base + vc_cma_size)) {
-+		loud_error_header();
-+		loud_error(
-+			"__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
-+			"vc_cma_base(%x) + vc_cma_size(%x) = %x",
-+			mempool_offline_start,
-+			VCADDR_TO_PHYSADDR(mempool_offline_end),
-+			vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
-+		success = 0;
-+	}
-+
-+	if (mempool_end < mempool_start) {
-+		loud_error_header();
-+		loud_error(
-+			"__MEMPOOL_END(%x) must not be before "
-+			"__MEMPOOL_START(%x)",
-+			mempool_end,
-+			mempool_start);
-+		success = 0;
-+	}
-+
-+	if (mempool_offline_end < mempool_offline_start) {
-+		loud_error_header();
-+		loud_error(
-+			"__MEMPOOL_OFFLINE_END(%x) must not be before "
-+			"__MEMPOOL_OFFLINE_START(%x)",
-+			mempool_offline_end,
-+			mempool_offline_start);
-+		success = 0;
-+	}
-+
-+	if (mempool_offline_start < mempool_start) {
-+		loud_error_header();
-+		loud_error(
-+			"__MEMPOOL_OFFLINE_START(%x) must not be before "
-+			"__MEMPOOL_START(%x)",
-+			mempool_offline_start,
-+			mempool_start);
-+		success = 0;
-+	}
-+
-+	if (mempool_offline_end > mempool_end) {
-+		loud_error_header();
-+		loud_error(
-+			"__MEMPOOL_OFFLINE_END(%x) must not be after "
-+			"__MEMPOOL_END(%x)",
-+			mempool_offline_end,
-+			mempool_end);
-+		success = 0;
-+	}
-+
-+	if ((cam_alloc_base < mempool_end) &&
-+		(cam_alloc_end > mempool_start)) {
-+		loud_error_header();
-+		loud_error(
-+			"cam_alloc pool(%x-%x) overlaps "
-+			"mempool(%x-%x)",
-+			cam_alloc_base, cam_alloc_end,
-+			mempool_start, mempool_end);
-+		success = 0;
-+	}
-+
-+	loud_error_footer();
-+
-+close:
-+	CloseVideoCoreMemory(mem_hndl);
-+
-+out:
-+	return success;
-+}
-+#endif
-+
-+static int vc_cma_init(void)
-+{
-+	int rc = -EFAULT;
-+	struct device *dev;
-+
-+	if (!check_cma_config())
-+		goto out_release;
-+
-+	LOG_INFO("vc-cma: Videocore CMA driver");
-+	LOG_INFO("vc-cma: vc_cma_base      = %pa", &vc_cma_base);
-+	LOG_INFO("vc-cma: vc_cma_size      = 0x%08x (%u MiB)",
-+		 vc_cma_size, vc_cma_size / (1024 * 1024));
-+	LOG_INFO("vc-cma: vc_cma_initial   = 0x%08x (%u MiB)",
-+		 vc_cma_initial, vc_cma_initial / (1024 * 1024));
-+
-+	vc_cma_base_page = phys_to_page(vc_cma_base);
-+
-+	if (vc_cma_chunks) {
-+		int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
-+
-+		for (vc_cma_chunks_used = 0;
-+		     vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
-+			struct page *chunk;
-+			chunk = dma_alloc_from_contiguous(&vc_cma_device.dev,
-+							  PAGES_PER_CHUNK,
-+							  VC_CMA_CHUNK_ORDER);
-+			if (!chunk)
-+				break;
-+			BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
-+				VC_CMA_CHUNK_SIZE) != 0);
-+		}
-+		if (vc_cma_chunks_used != chunks_needed) {
-+			LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
-+				"bytes, allocation %d of %d)",
-+				__func__, VC_CMA_CHUNK_SIZE,
-+				vc_cma_chunks_used, chunks_needed);
-+			goto out_release;
-+		}
-+
-+		vchiq_add_connected_callback(vc_cma_connected_init);
-+	}
-+
-+	rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
-+	if (rc < 0) {
-+		LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
-+		goto out_release;
-+	}
-+
-+	cdev_init(&vc_cma_cdev, &vc_cma_fops);
-+	rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
-+	if (rc != 0) {
-+		LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
-+		goto out_unregister;
-+	}
-+
-+	vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
-+	if (IS_ERR(vc_cma_class)) {
-+		rc = PTR_ERR(vc_cma_class);
-+		LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
-+		goto out_cdev_del;
-+	}
-+
-+	dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
-+			    DRIVER_NAME);
-+	if (IS_ERR(dev)) {
-+		rc = PTR_ERR(dev);
-+		LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
-+		goto out_class_destroy;
-+	}
-+
-+	vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
-+	if (vc_cma_proc_entry == NULL) {
-+		rc = -EFAULT;
-+		LOG_ERR("%s: proc_create failed", __func__);
-+		goto out_device_destroy;
-+	}
-+
-+	vc_cma_inited = 1;
-+	return 0;
-+
-+out_device_destroy:
-+	device_destroy(vc_cma_class, vc_cma_devnum);
-+
-+out_class_destroy:
-+	class_destroy(vc_cma_class);
-+	vc_cma_class = NULL;
-+
-+out_cdev_del:
-+	cdev_del(&vc_cma_cdev);
-+
-+out_unregister:
-+	unregister_chrdev_region(vc_cma_devnum, 1);
-+
-+out_release:
-+	/* It is tempting to try to clean up by calling
-+	   dma_release_from_contiguous for all allocated chunks, but it isn't
-+	   a very safe thing to do. If vc_cma_initial is non-zero it is because
-+	   VideoCore is already using that memory, so giving it back to Linux
-+	   is likely to be fatal.
-+	 */
-+	return -1;
-+}
-+
-+/****************************************************************************
-+*
-+*   vc_cma_exit
-+*
-+***************************************************************************/
-+
-+static void __exit vc_cma_exit(void)
-+{
-+	LOG_DBG("%s: called", __func__);
-+
-+	if (vc_cma_inited) {
-+		remove_proc_entry(DRIVER_NAME, NULL);
-+		device_destroy(vc_cma_class, vc_cma_devnum);
-+		class_destroy(vc_cma_class);
-+		cdev_del(&vc_cma_cdev);
-+		unregister_chrdev_region(vc_cma_devnum, 1);
-+	}
-+}
-+
-+module_init(vc_cma_init);
-+module_exit(vc_cma_exit);
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Broadcom Corporation");
--- 
-2.14.1
-
diff --git a/core/linux-raspberrypi/PKGBUILD b/core/linux-raspberrypi/PKGBUILD
index faef30e25..b93bd727d 100644
--- a/core/linux-raspberrypi/PKGBUILD
+++ b/core/linux-raspberrypi/PKGBUILD
@@ -5,11 +5,11 @@
 buildarch=20
 
 pkgbase=linux-raspberrypi
-_commit=8f34d03766cb1e4d29b3fd00cbc8e0e70e63e18a
+_commit=6820d0cbec64cfee481b961833feffec8880111e
 _srcname=linux-${_commit}
 _kernelname=${pkgbase#linux}
 _desc="Raspberry Pi"
-pkgver=4.9.58
+pkgver=4.9.59
 pkgrel=1
 arch=('armv6h' 'armv7h')
 url="http://www.kernel.org/"
@@ -18,19 +18,17 @@ makedepends=('xmlto' 'docbook-xsl' 'kmod' 'inetutils' 'bc' 'git')
 options=('!strip')
 source=("https://github.com/raspberrypi/linux/archive/${_commit}.tar.gz"
         'https://archlinuxarm.org/builder/src/brcmfmac43430-sdio.bin' 'https://archlinuxarm.org/builder/src/brcmfmac43430-sdio.txt'
-        0001-Revert-vc-cma-Remove-the-driver-as-non-functional-on.patch
         'config.txt'
         'cmdline.txt'
         'config'
         'linux.preset'
         '99-linux.hook')
-md5sums=('3ebbeb11a27f1276b7e66ed96bf39fc6'
+md5sums=('48175bfca539a247858b089b2b2f87bc'
          '4a410ab9a1eefe82e158d36df02b3589'
          '8c3cb6d8f0609b43f09d083b4006ec5a'
-         '9246abe34ecf6235c5452d5af71eb403'
          '7c6b37a1353caccf6d3786bb4161c218'
          '60bc3624123c183305677097bcd56212'
-         '83327f60faf355b8cf59a8b463f795a8'
+         'ccf446c3a5ddd0f6aa201686ba74d54f'
          '552c43bf6c0225bc213b31ee942b7000'
          '982f9184dfcfbe52110795cf73674334')
 
@@ -45,7 +43,6 @@ prepare() {
   # don't run depmod on 'make install'. We'll do this ourselves in packaging
   sed -i '2iexit 0' scripts/depmod.sh
 
-  git apply ../0001-Revert-vc-cma-Remove-the-driver-as-non-functional-on.patch
   mkdir firmware/brcm
   cp ../brcmfmac43430-sdio.{bin,txt} firmware/brcm
 }
@@ -101,9 +98,9 @@ _package() {
   make INSTALL_MOD_PATH="${pkgdir}" modules_install
   make INSTALL_DTBS_PATH="${pkgdir}/boot" dtbs_install
 
-  [[ $CARCH == "armv6h" ]] && perl scripts/mkknlimg --dtok arch/$KARCH/boot/zImage "${pkgdir}/boot/kernel.img" \
+  [[ $CARCH == "armv6h" ]] && cp arch/$KARCH/boot/zImage "${pkgdir}/boot/kernel.img" \
                            && rm -f "${pkgdir}"/boot/bcm{2836,2709,2710}*.dtb
-  [[ $CARCH == "armv7h" ]] && perl scripts/mkknlimg --dtok arch/$KARCH/boot/zImage "${pkgdir}/boot/kernel7.img" \
+  [[ $CARCH == "armv7h" ]] && cp arch/$KARCH/boot/zImage "${pkgdir}/boot/kernel7.img" \
                            && rm -f "${pkgdir}"/boot/bcm{2835,2708}*.dtb
   cp arch/$KARCH/boot/dts/overlays/README "${pkgdir}/boot/overlays"
 
diff --git a/core/linux-raspberrypi/config b/core/linux-raspberrypi/config
index 2e392c43d..4ae4928c0 100644
--- a/core/linux-raspberrypi/config
+++ b/core/linux-raspberrypi/config
@@ -1,6 +1,6 @@
 #
 # Automatically generated file; DO NOT EDIT.
-# Linux/arm 4.9.57-2 Kernel Configuration
+# Linux/arm 4.9.59-1 Kernel Configuration
 #
 CONFIG_ARM=y
 CONFIG_ARM_HAS_SG_CHAIN=y
@@ -492,7 +492,7 @@ CONFIG_DEBUG_ALIGN_RODATA=y
 CONFIG_MULTI_IRQ_HANDLER=y
 CONFIG_ARM_ERRATA_411920=y
 # CONFIG_ARM_ERRATA_430973 is not set
-# CONFIG_ARM_ERRATA_643719 is not set
+CONFIG_ARM_ERRATA_643719=y
 # CONFIG_ARM_ERRATA_720789 is not set
 # CONFIG_ARM_ERRATA_754322 is not set
 # CONFIG_ARM_ERRATA_754327 is not set
@@ -532,7 +532,7 @@ CONFIG_VMSPLIT_2G=y
 # CONFIG_VMSPLIT_1G is not set
 CONFIG_PAGE_OFFSET=0x80000000
 CONFIG_NR_CPUS=4
-CONFIG_HOTPLUG_CPU=y
+# CONFIG_HOTPLUG_CPU is not set
 # CONFIG_ARM_PSCI is not set
 CONFIG_ARCH_NR_GPIO=0
 # CONFIG_PREEMPT_NONE is not set
@@ -1602,10 +1602,7 @@ CONFIG_CMA_ALIGNMENT=8
 #
 # Bus devices
 #
-CONFIG_ARM_CCI=y
-CONFIG_ARM_CCI_PMU=y
-CONFIG_ARM_CCI400_COMMON=y
-CONFIG_ARM_CCI400_PMU=y
+# CONFIG_ARM_CCI400_PMU is not set
 # CONFIG_ARM_CCI5xx_PMU is not set
 # CONFIG_ARM_CCN is not set
 # CONFIG_BRCMSTB_GISB_ARB is not set
@@ -1862,7 +1859,7 @@ CONFIG_SCSI_ISCSI_ATTRS=y
 # CONFIG_SCSI_SRP_ATTRS is not set
 CONFIG_SCSI_LOWLEVEL=y
 CONFIG_ISCSI_TCP=m
-# CONFIG_ISCSI_BOOT_SYSFS is not set
+CONFIG_ISCSI_BOOT_SYSFS=m
 # CONFIG_SCSI_UFSHCD is not set
 # CONFIG_SCSI_DEBUG is not set
 # CONFIG_SCSI_DH is not set
@@ -2173,7 +2170,7 @@ CONFIG_B43_SSB=y
 CONFIG_B43_BUSES_BCMA_AND_SSB=y
 # CONFIG_B43_BUSES_BCMA is not set
 # CONFIG_B43_BUSES_SSB is not set
-CONFIG_B43_SDIO=y
+# CONFIG_B43_SDIO is not set
 CONFIG_B43_BCMA_PIO=y
 CONFIG_B43_PIO=y
 CONFIG_B43_PHY_G=y
@@ -2451,6 +2448,7 @@ CONFIG_TOUCHSCREEN_EDT_FT5X06=m
 CONFIG_TOUCHSCREEN_RPI_FT5406=m
 CONFIG_TOUCHSCREEN_TOUCHRIGHT=m
 CONFIG_TOUCHSCREEN_TOUCHWIN=m
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
 CONFIG_TOUCHSCREEN_PIXCIR=m
 CONFIG_TOUCHSCREEN_WDT87XX_I2C=m
 CONFIG_TOUCHSCREEN_WM97XX=m
@@ -2495,7 +2493,6 @@ CONFIG_TOUCHSCREEN_ZFORCE=m
 # CONFIG_TOUCHSCREEN_COLIBRI_VF50 is not set
 CONFIG_TOUCHSCREEN_ROHM_BU21023=m
 CONFIG_INPUT_MISC=y
-# CONFIG_INPUT_88PM80X_ONKEY is not set
 CONFIG_INPUT_AD714X=m
 CONFIG_INPUT_AD714X_I2C=m
 CONFIG_INPUT_AD714X_SPI=m
@@ -2553,7 +2550,6 @@ CONFIG_GAMEPORT_L4=m
 # Character devices
 #
 CONFIG_BRCM_CHAR_DRIVERS=y
-CONFIG_BCM_VC_CMA=y
 CONFIG_BCM2708_VCMEM=y
 CONFIG_BCM_VCIO=y
 CONFIG_BCM_VC_SM=y
@@ -2673,7 +2669,7 @@ CONFIG_I2C_BCM2835=m
 # CONFIG_I2C_DESIGNWARE_PLATFORM is not set
 # CONFIG_I2C_EMEV2 is not set
 CONFIG_I2C_GPIO=m
-CONFIG_I2C_NOMADIK=y
+# CONFIG_I2C_NOMADIK is not set
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_PXA_PCI is not set
@@ -2720,7 +2716,7 @@ CONFIG_SPI_GPIO=m
 # CONFIG_SPI_PXA2XX_PCI is not set
 # CONFIG_SPI_ROCKCHIP is not set
 # CONFIG_SPI_SC18IS602 is not set
-CONFIG_SPI_XCOMM=m
+# CONFIG_SPI_XCOMM is not set
 # CONFIG_SPI_XILINX is not set
 # CONFIG_SPI_ZYNQMP_GQSPI is not set
 
@@ -2814,6 +2810,7 @@ CONFIG_GPIO_BCM_VIRT=y
 CONFIG_GPIO_ARIZONA=m
 # CONFIG_HTC_EGPIO is not set
 CONFIG_GPIO_STMPE=y
+# CONFIG_GPIO_UCB1400 is not set
 
 #
 # SPI GPIO expanders
@@ -2855,6 +2852,7 @@ CONFIG_W1_SLAVE_DS2423=m
 CONFIG_W1_SLAVE_DS2431=m
 CONFIG_W1_SLAVE_DS2433=m
 # CONFIG_W1_SLAVE_DS2433_CRC is not set
+CONFIG_W1_SLAVE_DS2438=m
 CONFIG_W1_SLAVE_DS2760=m
 CONFIG_W1_SLAVE_DS2780=m
 CONFIG_W1_SLAVE_DS2781=m
@@ -3082,7 +3080,7 @@ CONFIG_SSB_POSSIBLE=y
 CONFIG_SSB=m
 CONFIG_SSB_BLOCKIO=y
 CONFIG_SSB_SDIOHOST_POSSIBLE=y
-CONFIG_SSB_SDIOHOST=y
+# CONFIG_SSB_SDIOHOST is not set
 # CONFIG_SSB_SILENT is not set
 # CONFIG_SSB_DEBUG is not set
 # CONFIG_SSB_DRIVER_GPIO is not set
@@ -3130,8 +3128,8 @@ CONFIG_MFD_RPISENSE_CORE=m
 # CONFIG_HTC_I2CPLD is not set
 # CONFIG_INTEL_SOC_PMIC is not set
 # CONFIG_MFD_KEMPLD is not set
-CONFIG_MFD_88PM800=m
-CONFIG_MFD_88PM805=m
+# CONFIG_MFD_88PM800 is not set
+# CONFIG_MFD_88PM805 is not set
 # CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_MAX14577 is not set
 # CONFIG_MFD_MAX77620 is not set
@@ -3148,7 +3146,7 @@ CONFIG_MFD_88PM805=m
 # CONFIG_MFD_VIPERBOARD is not set
 # CONFIG_MFD_RETU is not set
 # CONFIG_MFD_PCF50633 is not set
-# CONFIG_UCB1400_CORE is not set
+CONFIG_UCB1400_CORE=m
 # CONFIG_MFD_PM8921_CORE is not set
 # CONFIG_MFD_RT5033 is not set
 # CONFIG_MFD_RTSX_USB is not set
@@ -3213,7 +3211,6 @@ CONFIG_REGULATOR=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=m
 # CONFIG_REGULATOR_VIRTUAL_CONSUMER is not set
 # CONFIG_REGULATOR_USERSPACE_CONSUMER is not set
-# CONFIG_REGULATOR_88PM800 is not set
 # CONFIG_REGULATOR_ACT8865 is not set
 # CONFIG_REGULATOR_AD5398 is not set
 # CONFIG_REGULATOR_ANATOP is not set
@@ -3481,7 +3478,7 @@ CONFIG_V4L_MEM2MEM_DRIVERS=y
 #
 # Supported MMC/SDIO adapters
 #
-CONFIG_SMS_SDIO_DRV=m
+# CONFIG_SMS_SDIO_DRV is not set
 CONFIG_RADIO_ADAPTERS=y
 CONFIG_RADIO_TEA575X=m
 CONFIG_RADIO_SI470X=y
@@ -3515,7 +3512,6 @@ CONFIG_CYPRESS_FIRMWARE=m
 CONFIG_DVB_B2C2_FLEXCOP=m
 CONFIG_SMS_SIANO_MDTV=m
 CONFIG_SMS_SIANO_RC=y
-# CONFIG_SMS_SIANO_DEBUGFS is not set
 
 #
 # Media ancillary drivers (tuners, sensors, i2c, spi, frontends)
@@ -3787,7 +3783,7 @@ CONFIG_DRM_PANEL_SIMPLE=m
 # CONFIG_DRM_PANEL_SAMSUNG_LD9040 is not set
 # CONFIG_DRM_PANEL_LG_LG4573 is not set
 # CONFIG_DRM_PANEL_PANASONIC_VVX10F034N00 is not set
-# CONFIG_DRM_PANEL_RASPBERRYPI_TOUCHSCREEN is not set
+CONFIG_DRM_PANEL_RASPBERRYPI_TOUCHSCREEN=m
 # CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0 is not set
 # CONFIG_DRM_PANEL_SHARP_LQ101R1SX01 is not set
 # CONFIG_DRM_PANEL_SHARP_LS043T1LE01 is not set
@@ -4535,7 +4531,7 @@ CONFIG_MMC_SDHCI_PLTFM=y
 # CONFIG_MMC_SDHCI_OF_AT91 is not set
 # CONFIG_MMC_SDHCI_F_SDH30 is not set
 # CONFIG_MMC_SDHCI_IPROC is not set
-# CONFIG_MMC_SPI is not set
+CONFIG_MMC_SPI=m
 # CONFIG_MMC_DW is not set
 # CONFIG_MMC_VUB300 is not set
 # CONFIG_MMC_USHC is not set
@@ -4624,7 +4620,6 @@ CONFIG_RTC_INTF_DEV=y
 #
 # I2C RTC drivers
 #
-# CONFIG_RTC_DRV_88PM80X is not set
 # CONFIG_RTC_DRV_ABB5ZES3 is not set
 CONFIG_RTC_DRV_ABX80X=m
 CONFIG_RTC_DRV_DS1307=m
@@ -4746,7 +4741,7 @@ CONFIG_DMA_BCM2708=y
 # CONFIG_AUXDISPLAY is not set
 CONFIG_UIO=m
 CONFIG_UIO_PDRV_GENIRQ=m
-CONFIG_UIO_DMEM_GENIRQ=m
+# CONFIG_UIO_DMEM_GENIRQ is not set
 # CONFIG_UIO_PRUSS is not set
 # CONFIG_VIRT_DRIVERS is not set
 
@@ -5796,7 +5791,6 @@ CONFIG_RCU_CPU_STALL_TIMEOUT=21
 # CONFIG_RCU_EQS_DEBUG is not set
 # CONFIG_DEBUG_WQ_FORCE_RR_CPU is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
-# CONFIG_CPU_HOTPLUG_STATE_CONTROL is not set
 # CONFIG_NOTIFIER_ERROR_INJECTION is not set
 # CONFIG_FAULT_INJECTION is not set
 CONFIG_LATENCYTOP=y