mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
msm: ocmem: Add zone initialization checks
Since OCMEM zones can vary based on the target add an initialization flag for each zone. Also restrict each client to only operate on active zones. Change-Id: Iccac64fea277f833034ddfe71cce084060cfa16d Signed-off-by: Naveen Ramaraj <nramaraj@codeaurora.org>
This commit is contained in:
parent
6e75a748ce
commit
133c77a33f
4 changed files with 69 additions and 1 deletions
|
@ -36,6 +36,7 @@ struct ocmem_zone_ops {
|
|||
};
|
||||
|
||||
struct ocmem_zone {
|
||||
bool active;
|
||||
int owner;
|
||||
int active_regions;
|
||||
int max_regions;
|
||||
|
@ -178,6 +179,7 @@ static inline int ocmem_write(unsigned long val, void *at)
|
|||
}
|
||||
|
||||
struct ocmem_zone *get_zone(unsigned);
|
||||
int zone_active(int);
|
||||
unsigned long offset_to_phys(unsigned long);
|
||||
unsigned long phys_to_offset(unsigned long);
|
||||
unsigned long allocate_head(struct ocmem_zone *, unsigned long);
|
||||
|
|
|
@ -103,7 +103,7 @@ int check_id(int id)
|
|||
const char *get_name(int id)
|
||||
{
|
||||
if (!check_id(id))
|
||||
return NULL;
|
||||
return "Unknown";
|
||||
return client_names[id];
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,15 @@ inline unsigned long offset_to_phys(unsigned long offset)
|
|||
return offset + ocmem_pdata->base;
|
||||
}
|
||||
|
||||
inline int zone_active(int id)
|
||||
{
|
||||
struct ocmem_zone *z = get_zone(id);
|
||||
if (z)
|
||||
return z->active == true ? 1 : 0;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ocmem_plat_data *parse_static_config(struct platform_device *pdev)
|
||||
{
|
||||
struct ocmem_plat_data *pdata = NULL;
|
||||
|
@ -444,6 +453,7 @@ static int ocmem_zone_init(struct platform_device *pdev)
|
|||
for (i = 0; i < pdata->nr_parts; i++) {
|
||||
struct ocmem_partition *part = &pdata->parts[i];
|
||||
zone = get_zone(part->id);
|
||||
zone->active = false;
|
||||
|
||||
dev_dbg(dev, "Partition %d, start %lx, size %lx for %s\n",
|
||||
i, part->p_start, part->p_size,
|
||||
|
@ -501,6 +511,7 @@ static int ocmem_zone_init(struct platform_device *pdev)
|
|||
z_ops->allocate = allocate_head;
|
||||
z_ops->free = free_head;
|
||||
}
|
||||
zone->active = true;
|
||||
active_zones++;
|
||||
|
||||
if (active_zones == 1)
|
||||
|
|
|
@ -110,6 +110,12 @@ struct ocmem_buf *ocmem_allocate(int client_id, unsigned long size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < OCMEM_MIN_ALLOC) {
|
||||
pr_err("ocmem: requested size %lx must be at least %x\n",
|
||||
size, OCMEM_MIN_ALLOC);
|
||||
|
@ -136,6 +142,12 @@ struct ocmem_buf *ocmem_allocate_nowait(int client_id, unsigned long size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < OCMEM_MIN_ALLOC) {
|
||||
pr_err("ocmem: requested size %lx must be at least %x\n",
|
||||
size, OCMEM_MIN_ALLOC);
|
||||
|
@ -162,6 +174,12 @@ struct ocmem_buf *ocmem_allocate_range(int client_id, unsigned long min,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Asynchronous API requires notifier registration */
|
||||
if (!check_notifier(client_id)) {
|
||||
pr_err("ocmem: No notifier registered for client %d\n",
|
||||
|
@ -202,6 +220,12 @@ struct ocmem_buf *ocmem_allocate_nb(int client_id, unsigned long size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < OCMEM_MIN_ALLOC) {
|
||||
pr_err("ocmem: requested size %lx must be at least %x\n",
|
||||
size, OCMEM_MIN_ALLOC);
|
||||
|
@ -226,6 +250,12 @@ int ocmem_free(int client_id, struct ocmem_buf *buffer)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!buffer) {
|
||||
pr_err("ocmem: Invalid buffer\n");
|
||||
return -EINVAL;
|
||||
|
@ -240,6 +270,13 @@ int ocmem_shrink(int client_id, struct ocmem_buf *buffer, unsigned long len)
|
|||
return -EINVAL;
|
||||
if (len >= buffer->len)
|
||||
return -EINVAL;
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return __ocmem_shrink(client_id, buffer, len);
|
||||
}
|
||||
|
||||
|
@ -282,6 +319,12 @@ int ocmem_map(int client_id, struct ocmem_buf *buffer,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Asynchronous API requires notifier registration */
|
||||
if (!check_notifier(client_id)) {
|
||||
pr_err("ocmem: No notifier registered for client %d\n",
|
||||
|
@ -320,6 +363,12 @@ int ocmem_unmap(int client_id, struct ocmem_buf *buffer,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Asynchronous API requires notifier registration */
|
||||
if (!check_notifier(client_id)) {
|
||||
pr_err("ocmem: No notifier registered for client %d\n",
|
||||
|
|
|
@ -82,6 +82,12 @@ struct ocmem_notifier *ocmem_notifier_register(int client_id,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!zone_active(client_id)) {
|
||||
pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n",
|
||||
get_name(client_id), client_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!nb) {
|
||||
pr_err("ocmem: Invalid Notifier Block\n");
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in a new issue