<commit_before>/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but 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.
 *
 */
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <mach/scm.h>
#include <mach/msm_qmi_interface.h>
#include "msm_memshare.h"
#include "heap_mem_ext_v01.h"
#define MEM_SHARE_SERVICE_SVC_ID 0x00000034
#define MEM_SHARE_SERVICE_INS_ID 1
#define MEM_SHARE_SERVICE_VERS 1

static struct qmi_handle *mem_share_svc_handle;
static void mem_share_svc_recv_msg(struct work_struct *work);
static DECLARE_DELAYED_WORK(work_recv_msg, mem_share_svc_recv_msg);
static struct workqueue_struct *mem_share_svc_workqueue;
static void *curr_conn;
struct mutex connection;
static struct mem_blocks memblock;
struct mutex mem_share;
struct mutex mem_free;
static uint32_t size;

static struct msg_desc mem_share_svc_alloc_req_desc = {
	.max_msg_len = MEM_ALLOC_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_ALLOC_REQ_MSG_V01,
	.ei_array = mem_alloc_req_msg_data_v01_ei,
};

static struct msg_desc mem_share_svc_alloc_resp_desc = {
	.max_msg_len = MEM_ALLOC_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_ALLOC_RESP_MSG_V01,
	.ei_array = mem_alloc_resp_msg_data_v01_ei,
};

static struct msg_desc mem_share_svc_free_req_desc = {
	.max_msg_len = MEM_FREE_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_FREE_REQ_MSG_V01,
	.ei_array = mem_free_req_msg_data_v01_ei,
};

static struct msg_desc mem_share_svc_free_resp_desc = {
	.max_msg_len = MEM_FREE_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_FREE_RESP_MSG_V01,
	.ei_array = mem_free_resp_msg_data_v01_ei,
};


static int handle_alloc_req(void *req_h, void *req)
{
	struct mem_alloc_req_msg_v01 *alloc_req;
	struct mem_alloc_resp_msg_v01 alloc_resp;
	int rc;

	alloc_req = (struct mem_alloc_req_msg_v01 *)req;
	pr_debug("%s: Received Alloc Request\n", __func__);
	pr_debug("%s: req->num_bytes = %d\n", __func__, alloc_req->num_bytes);
	alloc_resp.resp = QMI_RESULT_FAILURE_V01;
	mutex_lock(&mem_share);
	memset(&alloc_resp, 0, sizeof(struct mem_alloc_resp_msg_v01));
	rc = memshare_alloc(alloc_req->num_bytes,
				alloc_req->block_alignment,
				&memblock);
	if (rc) {
		mutex_unlock(&mem_share);
		return -ENOMEM;
	}

	alloc_resp.num_bytes_valid = 1;
	alloc_resp.num_bytes =  alloc_req->num_bytes;
	size = alloc_req->num_bytes;
	alloc_resp.handle_valid = 1;
	alloc_resp.handle = memblock.phy_addr;
	alloc_resp.resp = QMI_RESULT_SUCCESS_V01;
	mutex_unlock(&mem_share);
	pr_debug("alloc_resp.num_bytes :%d, alloc_resp.handle :%lx, alloc_resp.mem_req_result :%lx\n",
			  alloc_resp.num_bytes,
			  (unsigned long int)alloc_resp.handle,
			  (unsigned long int)alloc_resp.resp);
	rc = qmi_send_resp_from_cb(mem_share_svc_handle, curr_conn, req_h,
			&mem_share_svc_alloc_resp_desc, &alloc_resp,
			sizeof(alloc_resp));
	return rc;
}
static int handle_free_req(void *req_h, void *req)
{
	struct mem_free_req_msg_v01 *free_req;
	struct mem_free_resp_msg_v01 free_resp;
	int rc;

	free_req = (struct mem_free_req_msg_v01 *)req;
	pr_debug("%s: Received Free Request\n", __func__);
	mutex_lock(&mem_free);
	free_resp.resp = QMI_RESULT_FAILURE_V01;

	memset(&free_resp, 0, sizeof(struct mem_free_resp_msg_v01));
	pr_debug("In %s: pblk->virtual_addr :%lx, pblk->phy_addr %lx\n,size: %d",
			__func__,
			(unsigned long int)memblock.virtual_addr,
			(unsigned long int)free_req->handle, size);
	dma_free_coherent(NULL, size,
		memblock.virtual_addr, free_req->handle);
	mutex_unlock(&mem_free);
	free_resp.resp = QMI_RESULT_SUCCESS_V01;

	rc = qmi_send_resp_from_cb(mem_share_svc_handle, curr_conn, req_h,
			&mem_share_svc_free_resp_desc, &free_resp,<commit_msg>msm: memshare: Handle modem subsystem restart event<commit_after>/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but 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.
 *
 */
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <mach/scm.h>
#include <mach/msm_qmi_interface.h>
#include "msm_memshare.h"
#include "heap_mem_ext_v01.h"
#define MEM_SHARE_SERVICE_SVC_ID 0x00000034
#define MEM_SHARE_SERVICE_INS_ID 1
#define MEM_SHARE_SERVICE_VERS 1

static struct qmi_handle *mem_share_svc_handle;
static void mem_share_svc_recv_msg(struct work_struct *work);
static DECLARE_DELAYED_WORK(work_recv_msg, mem_share_svc_recv_msg);
static struct workqueue_struct *mem_share_svc_workqueue;
static void *curr_conn;
struct mutex connection;
static struct mem_blocks memblock;
struct mutex mem_share;
struct mutex mem_free;
static uint32_t size;

static struct msg_desc mem_share_svc_alloc_req_desc = {
	.max_msg_len = MEM_ALLOC_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_ALLOC_REQ_MSG_V01,
	.ei_array = mem_alloc_req_msg_data_v01_ei,
};

static struct msg_desc mem_share_svc_alloc_resp_desc = {
	.max_msg_len = MEM_ALLOC_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_ALLOC_RESP_MSG_V01,
	.ei_array = mem_alloc_resp_msg_data_v01_ei,
};

static struct msg_desc mem_share_svc_free_req_desc = {
	.max_msg_len = MEM_FREE_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_FREE_REQ_MSG_V01,
	.ei_array = mem_free_req_msg_data_v01_ei,
};

static struct msg_desc mem_share_svc_free_resp_desc = {
	.max_msg_len = MEM_FREE_REQ_MAX_MSG_LEN_V01,
	.msg_id = MEM_FREE_RESP_MSG_V01,
	.ei_array = mem_free_resp_msg_data_v01_ei,
};


static int handle_alloc_req(void *req_h, void *req)
{
	struct mem_alloc_req_msg_v01 *alloc_req;
	struct mem_alloc_resp_msg_v01 alloc_resp;
	int rc;

	alloc_req = (struct mem_alloc_req_msg_v01 *)req;
	pr_debug("%s: Received Alloc Request\n", __func__);
	pr_debug("%s: req->num_bytes = %d\n", __func__, alloc_req->num_bytes);
	alloc_resp.resp = QMI_RESULT_FAILURE_V01;
	mutex_lock(&mem_share);
	if (!size) {
		memset(&alloc_resp, 0, sizeof(struct mem_alloc_resp_msg_v01));
		rc = memshare_alloc(alloc_req->num_bytes,
					alloc_req->block_alignment,
					&memblock);
		if (rc) {
			mutex_unlock(&mem_share);
			return -ENOMEM;
		}
	}
	alloc_resp.num_bytes_valid = 1;
	alloc_resp.num_bytes =  alloc_req->num_bytes;
	size = alloc_req->num_bytes;
	alloc_resp.handle_valid = 1;
	alloc_resp.handle = memblock.phy_addr;
	alloc_resp.resp = QMI_RESULT_SUCCESS_V01;
	mutex_unlock(&mem_share);

	pr_debug("alloc_resp.num_bytes :%d, alloc_resp.handle :%lx, alloc_resp.mem_req_result :%lx\n",
			  alloc_resp.num_bytes,
			  (unsigned long int)alloc_resp.handle,
			  (unsigned long int)alloc_resp.resp);
	rc = qmi_send_resp_from_cb(mem_share_svc_handle, curr_conn, req_h,
			&mem_share_svc_alloc_resp_desc, &alloc_resp,
			sizeof(alloc_resp));
	return rc;
}
static int handle_free_req(void *req_h, void *req)
{
	struct mem_free_req_msg_v01 *free_req;
	struct mem_free_resp_msg_v01 free_resp;
	int rc;

	free_req = (struct mem_free_req_msg_v01 *)req;
	pr_debug("%s: Received Free Request\n", __func__);
	mutex_lock(&mem_free);
	free_resp.resp = QMI_RESULT_FAILURE_V01;

	memset(&free_resp, 0, sizeof(struct mem_free_resp_msg_v01));
	pr_debug("In %s: pblk->virtual_addr :%lx, pblk->phy_addr %lx\n,size: %d",
			__func__,
			(unsigned long int)memblock.virtual_addr,
			(unsigned long int)free_req->handle, size);
	dma_free_coherent(NULL, size,
		memblock.virtual_addr, free_req->handle);
	size = 0;
	mutex_unlock(&mem_free);
	free_resp.resp = QMI_RESULT_SUCCESS_V01;
	rc = qmi_send_resp_from_cb(mem_share_svc_handle, curr_conn, req_h,
			&mem_share_svc_free_resp_desc, &free_resp,
{'fraction_non_alphanumeric': 0.09486742884942836, 'fraction_numerical': 0.01836536122597908, 'mean_word_length': 6.131830008673027, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7045727', 'n_tokens_mistral': 3395, 'n_tokens_neox': 3214, 'n_words': 651}