summaryrefslogtreecommitdiff
path: root/drivers/soc/qcom/msm_bus/msm_bus_id.c
blob: 3238161c2aad295c58937e5a89f69d293482e974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* 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/kernel.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/msm-bus.h>
#include <linux/msm-bus-board.h>
#include "msm_bus_core.h"
#include "msm_bus_noc.h"
#include "msm_bus_bimc.h"

static uint32_t master_iids[MSM_BUS_MASTER_LAST];
static uint32_t slave_iids[MSM_BUS_SLAVE_LAST - SLAVE_ID_KEY];

static void msm_bus_assign_iids(struct msm_bus_fabric_registration
	*fabreg, int fabid)
{
	int i;
	for (i = 0; i < fabreg->len; i++) {
		if (!fabreg->info[i].gateway) {
			fabreg->info[i].priv_id = fabid + fabreg->info[i].id;
			if (fabreg->info[i].id < SLAVE_ID_KEY) {
				if (fabreg->info[i].id >= MSM_BUS_MASTER_LAST) {
					WARN(1, "id %d exceeds array size!\n",
						fabreg->info[i].id);
					continue;
				}

				master_iids[fabreg->info[i].id] =
					fabreg->info[i].priv_id;
			} else {
				if ((fabreg->info[i].id - SLAVE_ID_KEY) >=
					(MSM_BUS_SLAVE_LAST - SLAVE_ID_KEY)) {
					WARN(1, "id %d exceeds array size!\n",
						fabreg->info[i].id);
					continue;
				}

				slave_iids[fabreg->info[i].id - (SLAVE_ID_KEY)]
					= fabreg->info[i].priv_id;
			}
		} else {
			fabreg->info[i].priv_id = fabreg->info[i].id;
		}
	}
}

static int msm_bus_get_iid(int id)
{
	if ((id < SLAVE_ID_KEY && id >= MSM_BUS_MASTER_LAST) ||
		id >= MSM_BUS_SLAVE_LAST) {
		MSM_BUS_ERR("Cannot get iid. Invalid id %d passed\n", id);
		return -EINVAL;
	}

	return CHECK_ID(((id < SLAVE_ID_KEY) ? master_iids[id] :
		slave_iids[id - SLAVE_ID_KEY]), id);
}

static struct msm_bus_board_algorithm msm_bus_id_algo = {
	.get_iid = msm_bus_get_iid,
	.assign_iids = msm_bus_assign_iids,
};

int msm_bus_board_rpm_get_il_ids(uint16_t *id)
{
	return -ENXIO;
}

void msm_bus_board_init(struct msm_bus_fabric_registration *pdata)
{
	pdata->board_algo = &msm_bus_id_algo;
}

void msm_bus_board_set_nfab(struct msm_bus_fabric_registration *pdata,
	int nfab)
{
	if (nfab <= 0)
		return;

	msm_bus_id_algo.board_nfab = nfab;
}