source: rtems/cpukit/rtems/src/regioncreate.c @ a29d2e7

4.104.114.84.95
Last change on this file since a29d2e7 was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  Region Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/score/object.h>
23#include <rtems/rtems/options.h>
24#include <rtems/rtems/region.h>
25#include <rtems/score/states.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/apimutex.h>
28
29/*PAGE
30 *
31 *  rtems_region_create
32 *
33 *  This directive creates a region of physical contiguous memory area
34 *  from which variable sized segments can be allocated.
35 *
36 *  Input parameters:
37 *    name             - user defined region name
38 *    starting_address - physical start address of region
39 *    length           - physical length in bytes
40 *    page_size        - page size in bytes
41 *    attribute_set    - region attributes
42 *    id               - address of region id to set
43 *
44 *  Output parameters:
45 *    id               - region id
46 *    RTEMS_SUCCESSFUL - if successful
47 *    error code       - if unsuccessful
48 */
49
50rtems_status_code rtems_region_create(
51  rtems_name          name,
52  void               *starting_address,
53  uint32_t            length,
54  uint32_t            page_size,
55  rtems_attribute     attribute_set,
56  Objects_Id         *id
57)
58{
59  Region_Control *the_region;
60
61  if ( !rtems_is_name_valid( name ) )
62    return RTEMS_INVALID_NAME;
63
64  if ( !starting_address )
65    return RTEMS_INVALID_ADDRESS;
66
67  if ( !id )
68    return RTEMS_INVALID_ADDRESS;
69
70  if ( !_Addresses_Is_aligned( starting_address ) )
71    return RTEMS_INVALID_ADDRESS;
72
73  _RTEMS_Lock_allocator();                      /* to prevent deletion */
74
75  the_region = _Region_Allocate();
76
77  if ( !the_region ) {
78    _RTEMS_Unlock_allocator();
79    return RTEMS_TOO_MANY;
80  }
81
82  the_region->maximum_segment_size =
83    _Heap_Initialize(&the_region->Memory, starting_address, length, page_size);
84
85  if ( !the_region->maximum_segment_size ) {
86    _Region_Free( the_region );
87    _RTEMS_Unlock_allocator();
88    return RTEMS_INVALID_SIZE;
89  }
90
91  the_region->starting_address      = starting_address;
92  the_region->length                = length;
93  the_region->page_size             = page_size;
94  the_region->attribute_set         = attribute_set;
95  the_region->number_of_used_blocks = 0;
96
97  _Thread_queue_Initialize(
98    &the_region->Wait_queue,
99    _Attributes_Is_priority( attribute_set ) ?
100       THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
101    STATES_WAITING_FOR_SEGMENT,
102    RTEMS_TIMEOUT
103  );
104
105  _Objects_Open(
106    &_Region_Information,
107    &the_region->Object,
108    (Objects_Name) name
109  );
110
111  *id = the_region->Object.id;
112  _RTEMS_Unlock_allocator();
113  return RTEMS_SUCCESSFUL;
114}
Note: See TracBrowser for help on using the repository browser.