2014-08-24 02:43:21 +08:00
|
|
|
/****************************************************************************
|
2014-09-23 00:33:23 +08:00
|
|
|
* mm/mm_gran/mm_granreserve.c
|
2014-08-24 02:43:21 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08: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-08-24 02:43:21 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-08-24 02:43:21 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08: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-08-24 02:43:21 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2014-09-24 20:55:26 +08:00
|
|
|
#include <nuttx/mm/gran.h>
|
2014-08-24 02:43:21 +08:00
|
|
|
|
2014-09-23 00:33:23 +08:00
|
|
|
#include "mm_gran/mm_gran.h"
|
2014-08-24 02:43:21 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_GRAN
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-11-15 01:47:12 +08:00
|
|
|
* Public Functions
|
2014-08-24 02:43:21 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-11-15 01:47:12 +08:00
|
|
|
* Name: gran_reserve
|
2014-08-24 02:43:21 +08:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Reserve memory in the granule heap. This will reserve the granules
|
|
|
|
* that contain the start and end addresses plus all of the granules
|
|
|
|
* in between. This should be done early in the initialization sequence
|
|
|
|
* before any other allocations are made.
|
|
|
|
*
|
|
|
|
* Reserved memory can never be allocated (it can be freed however which
|
|
|
|
* essentially unreserves the memory).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2017-11-15 01:47:12 +08:00
|
|
|
* handle - The handle previously returned by gran_initialize
|
|
|
|
* start - The address of the beginning of the region to be reserved.
|
|
|
|
* size - The size of the region to be reserved
|
2014-08-24 02:43:21 +08:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-15 01:47:12 +08:00
|
|
|
void gran_reserve(GRAN_HANDLE handle, uintptr_t start, size_t size)
|
2014-08-24 02:43:21 +08:00
|
|
|
{
|
2017-11-15 01:47:12 +08:00
|
|
|
FAR struct gran_s *priv = (FAR struct gran_s *)handle;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv != NULL);
|
|
|
|
|
2014-08-24 02:43:21 +08:00
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
uintptr_t mask = (1 << priv->log2gran) - 1;
|
|
|
|
uintptr_t end = start + size - 1;
|
|
|
|
unsigned int ngranules;
|
|
|
|
|
|
|
|
/* Get the aligned (down) start address and the aligned (up) end
|
|
|
|
* address
|
|
|
|
*/
|
|
|
|
|
|
|
|
start &= ~mask;
|
|
|
|
end = (end + mask) & ~mask;
|
|
|
|
|
2014-08-24 06:35:52 +08:00
|
|
|
/* Calculate the new size in granules */
|
2014-08-24 02:43:21 +08:00
|
|
|
|
|
|
|
ngranules = ((end - start) >> priv->log2gran) + 1;
|
|
|
|
|
|
|
|
/* And reserve the granules */
|
|
|
|
|
|
|
|
gran_mark_allocated(priv, start, ngranules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_GRAN */
|