2014-09-23 16:46:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/shm/shm_initialize.c
|
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-09-23 16:46:31 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-09-23 16:46:31 +02:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-09-23 16:46:31 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-09-24 00:04:39 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/addrenv.h>
|
|
|
|
#include <nuttx/sched.h>
|
2014-09-24 14:55:26 +02:00
|
|
|
#include <nuttx/mm/gran.h>
|
2014-09-24 00:04:39 +02:00
|
|
|
#include <nuttx/pgalloc.h>
|
2014-09-24 15:05:02 +02:00
|
|
|
#include <nuttx/mm/shm.h>
|
2014-09-24 00:04:39 +02:00
|
|
|
|
2014-09-23 16:46:31 +02:00
|
|
|
#include "shm/shm.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_MM_SHM
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* State of the all shared memory */
|
|
|
|
|
2022-03-11 20:58:25 +01:00
|
|
|
struct shm_info_s g_shminfo =
|
|
|
|
{
|
|
|
|
SEM_INITIALIZER(1)
|
|
|
|
};
|
2014-09-23 16:46:31 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-24 00:04:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: shm_group_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the group shared memory data structures when a new task
|
|
|
|
* group is initialized.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* group - A reference to the new group structure to be initialized.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int shm_group_initialize(FAR struct task_group_s *group)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(group && !group->tg_shm.gs_handle);
|
|
|
|
|
|
|
|
group->tg_shm.gs_handle =
|
|
|
|
gran_initialize((FAR void *)CONFIG_ARCH_SHM_VBASE,
|
|
|
|
ARCH_SHM_MAXPAGES << MM_PGSHIFT,
|
|
|
|
MM_PGSHIFT, MM_PGSHIFT);
|
|
|
|
|
|
|
|
if (!group->tg_shm.gs_handle)
|
|
|
|
{
|
2016-06-12 17:46:23 +02:00
|
|
|
shmerr("ERROR: gran_initialize() failed\n");
|
2014-09-24 00:04:39 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: shm_group_release
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release resources used by the group shared memory logic. This function
|
|
|
|
* is called at the time at the group is destroyed.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* group - A reference to the group structure to be un-initialized.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void shm_group_release(FAR struct task_group_s *group)
|
|
|
|
{
|
|
|
|
GRAN_HANDLE handle;
|
2015-05-27 21:32:39 +02:00
|
|
|
DEBUGASSERT(group);
|
2014-09-24 00:04:39 +02:00
|
|
|
|
|
|
|
handle = group->tg_shm.gs_handle;
|
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
gran_release(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 16:46:31 +02:00
|
|
|
#endif /* CONFIG_MM_SHM */
|