~vibhavp/ubuntu/raring/dahdi-tools/merge-from-debian

« back to all changes in this revision

Viewing changes to xpp/oct612x/apilib/llman/octapi_llman.c

  • Committer: Vibhav Pant
  • Date: 2012-12-26 17:23:16 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: vibhavp@gmail.com-20121226172316-o2jojsfcnr0aqrme
* Merge from Debian unstable. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - debian/control: Added gawk as dependency for dkms build (LP: #493304)
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2
 
 
3
File:  octapi_llman.c
 
4
 
 
5
    Copyright (c) 2001-2007 Octasic Inc.
 
6
    
 
7
Description: 
 
8
 
 
9
        Library used to manage allocation tables and linked lists.  The library is
 
10
        made such that only a block of contiguous memory is needed for the
 
11
        management of the linked list/allocation table.
 
12
 
 
13
This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API  is 
 
14
free software; you can redistribute it and/or modify it under the terms of 
 
15
the GNU General Public License as published by the Free Software Foundation; 
 
16
either version 2 of the License, or (at your option) any later version.
 
17
 
 
18
The OCT6100 GPL API is distributed in the hope that it will be useful, but 
 
19
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 
20
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 
21
for more details. 
 
22
 
 
23
You should have received a copy of the GNU General Public License 
 
24
along with the OCT6100 GPL API; if not, write to the Free Software 
 
25
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
26
 
 
27
$Octasic_Release: OCT612xAPI-01.00-PR49 $
 
28
 
 
29
$Octasic_Revision: 22 $
 
30
 
 
31
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
32
#include "octapi_llman_private.h"
 
33
#include "apilib/octapi_llman.h"
 
34
#include "apilib/octapi_largmath.h"
 
35
 
 
36
 
 
37
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
38
|       API UTILITIES
 
39
|
 
40
|       Function:               OctapiLlmAllocGetSize.
 
41
|
 
42
|       Description:    This function determines the amount of memory needed to
 
43
|                                       manage the allocation of a fixed amount of resources.
 
44
|                                       The memory is measured in bytes.
 
45
|
 
46
|  -----------------------------------------------------------------------  
 
47
|  |   Variable        |     Type     |          Description                
 
48
|  -----------------------------------------------------------------------  
 
49
|       number_of_items         UINT32                  The number of resources to be allocated.
 
50
|       *l_size UINT32          UINT32                  The amount of memory needed, returned.
 
51
|
 
52
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
53
#if !SKIP_OctapiLlmAllocGetSize
 
54
UINT32 OctapiLlmAllocGetSize(UINT32 number_of_items,UINT32 * l_size)
 
55
{
 
56
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
57
 
 
58
        *l_size = (sizeof(LLM_ALLOC)) + (number_of_items * sizeof(UINT32));
 
59
 
 
60
        return(GENERIC_OK);
 
61
}
 
62
#endif
 
63
 
 
64
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
65
|       API UTILITIES
 
66
|
 
67
|       Function:               OctapiLlmAllocInit.
 
68
|
 
69
|       Description:    This function intializes the LLM_ALLOC structure.
 
70
|
 
71
|  -----------------------------------------------------------------------  
 
72
|  |   Variable        |     Type     |          Description                
 
73
|  -----------------------------------------------------------------------  
 
74
|       **l                                     void                    The memory used by the LLM_ALLOC structure.
 
75
|       number_of_items         UINT32                  The number of resources to be allocated.
 
76
|
 
77
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
78
#if !SKIP_OctapiLlmAllocInit
 
79
UINT32 OctapiLlmAllocInit(void ** l,UINT32 number_of_items)
 
80
{
 
81
        LLM_ALLOC* ls;
 
82
        UINT32 i;
 
83
 
 
84
        /* Check the number of items required.*/
 
85
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
86
 
 
87
        /* If no memory has been allocated yet:*/
 
88
        if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
 
89
 
 
90
        /* Build the structure before starting.*/
 
91
        ls = (LLM_ALLOC *)(*l);
 
92
        ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
 
93
 
 
94
        ls->number_of_items = number_of_items;
 
95
 
 
96
        /* Linked list links all structures in ascending order.*/
 
97
        for(i=0;i<number_of_items;i++)
 
98
        {
 
99
                ls->linked_list[i] = i+1;
 
100
        }
 
101
 
 
102
        ls->linked_list[number_of_items - 1] = 0xFFFFFFFF; /* Invalid link.*/
 
103
 
 
104
        /* Next avail is 0.*/
 
105
        ls->next_avail_num = 0;
 
106
 
 
107
        /* Number of allocated items is null.*/
 
108
        ls->allocated_items = 0;
 
109
 
 
110
        return(GENERIC_OK);
 
111
}
 
112
#endif
 
113
 
 
114
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
115
|       API UTILITIES
 
116
|
 
117
|       Function:               OctapiLlmAllocInfo.
 
118
|
 
119
|       Description:    This function returns the number of free and allocated
 
120
|                                       block in the LLMAN list.
 
121
|
 
122
|  -----------------------------------------------------------------------  
 
123
|  |   Variable        |     Type     |          Description                
 
124
|  -----------------------------------------------------------------------  
 
125
|       *l                                      void                    The memory used by the LLM_ALLOC structure.
 
126
|       *allocated_items        UINT32                  Number of allocated items.
 
127
|       *available_items        UINT32                  Number of available items.
 
128
|
 
129
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
130
#if !SKIP_OctapiLlmAllocInfo
 
131
UINT32 OctapiLlmAllocInfo(void * l,UINT32 * allocated_items,UINT32 * available_items)
 
132
{
 
133
        LLM_ALLOC* ls;
 
134
 
 
135
        /* Build the structure before starting.*/
 
136
        ls = (LLM_ALLOC *)l;
 
137
        ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
 
138
 
 
139
        *allocated_items = ls->allocated_items;
 
140
        *available_items = ls->number_of_items - ls->allocated_items;
 
141
        return(GENERIC_OK);
 
142
}
 
143
#endif
 
144
 
 
145
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
146
|       API UTILITIES
 
147
|
 
148
|       Function:               OctapiLlmAllocInfo.
 
149
|
 
150
|       Description:    This function allocates the resource indicated by blocknum.
 
151
|                                       If the resource can be allocated then GENERIC_OK is returned.  
 
152
|                                       Else an error.
 
153
|
 
154
|  -----------------------------------------------------------------------  
 
155
|  |   Variable        |     Type     |          Description                
 
156
|  -----------------------------------------------------------------------  
 
157
|       *l                                      void                    The memory used by the LLM_ALLOC structure.
 
158
|       *block_num                      UINT32                  The resource to be allocated.
 
159
|
 
160
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
161
#if !SKIP_OctapiLlmAllocAlloc
 
162
UINT32 OctapiLlmAllocAlloc(void * l,UINT32 * blocknum)
 
163
{
 
164
        LLM_ALLOC* ls;
 
165
        UINT32 allocated_block;
 
166
        UINT32* node;
 
167
 
 
168
        /* Build the structure before starting.*/
 
169
        ls = (LLM_ALLOC *)l;
 
170
        ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
 
171
 
 
172
        /* Get next available block number.*/
 
173
        allocated_block = ls->next_avail_num;
 
174
 
 
175
        /* Check if block is invalid.*/
 
176
        if (allocated_block == 0xFFFFFFFF)
 
177
        {
 
178
                /* Make blocknum NULL.*/
 
179
                *blocknum = 0xFFFFFFFF;
 
180
 
 
181
                return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
 
182
        }
 
183
 
 
184
        node = &ls->linked_list[allocated_block];
 
185
 
 
186
        /* Copy next block number.*/
 
187
        ls->next_avail_num = *node;
 
188
 
 
189
        /* Tag as used the current block number.*/
 
190
        *node = 0xFFFFFFFE;
 
191
 
 
192
        /* Return proper block number.*/
 
193
        *blocknum = allocated_block;
 
194
 
 
195
        /* Update block usage number.*/
 
196
        ls->allocated_items++;
 
197
 
 
198
        return(GENERIC_OK);
 
199
}
 
200
#endif
 
201
 
 
202
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
203
|       API UTILITIES
 
204
|
 
205
|       Function:               OctapiLlmAllocDealloc.
 
206
|
 
207
|       Description:    This function deallocates the resource indicated by blocknum.
 
208
|                                       If the resource is not already allocated an error is returned.
 
209
|                                       Else GENERIC_OK is returned.
 
210
|
 
211
|  -----------------------------------------------------------------------  
 
212
|  |   Variable        |     Type     |          Description                
 
213
|  -----------------------------------------------------------------------  
 
214
|       *l                                      void                    The memory used by the LLM_ALLOC structure.
 
215
|       block_num                       UINT32                  The resource to be deallocated.
 
216
|
 
217
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
218
#if !SKIP_OctapiLlmAllocDealloc
 
219
UINT32 OctapiLlmAllocDealloc(void * l,UINT32 blocknum)
 
220
{
 
221
        LLM_ALLOC* ls;
 
222
        UINT32* node;
 
223
 
 
224
        /* Build the structure before starting.*/
 
225
        ls = (LLM_ALLOC *)l;
 
226
        ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
 
227
        
 
228
        /* Check for null item pointer.*/
 
229
        if (blocknum == 0xFFFFFFFF) return(GENERIC_OK);
 
230
 
 
231
        /* Check if blocknum is within specified item range.*/
 
232
        if (blocknum >= ls->number_of_items) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
233
 
 
234
        node = &ls->linked_list[blocknum];
 
235
 
 
236
        /* Check if block is really used as of now.*/
 
237
        if (*node != 0xFFFFFFFE) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
 
238
 
 
239
        /* Add link to list.*/
 
240
        *node = ls->next_avail_num;
 
241
 
 
242
        /* Point to returned block.*/
 
243
        ls->next_avail_num = blocknum;
 
244
 
 
245
        /* Update block usage number.*/
 
246
        ls->allocated_items--;
 
247
 
 
248
        return(GENERIC_OK);
 
249
}
 
250
#endif
 
251
 
 
252
 
 
253
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
254
|       API UTILITIES
 
255
|
 
256
|       Function:               OctApiTllmAllocGetSize.
 
257
|
 
258
|       Description:    This function determines the amount of memory needed to
 
259
|                                       manage the allocation of a fixed amount of resources.
 
260
|                                       The memory is measured in bytes. 
 
261
|
 
262
|                                       This version is a time manage version of llman.
 
263
|
 
264
|  -----------------------------------------------------------------------  
 
265
|  |   Variable        |     Type     |          Description                
 
266
|  -----------------------------------------------------------------------  
 
267
|       number_of_items         UINT32                  The number of resources to be allocated.
 
268
|       *l_size UINT32          UINT32                  The amount of memory needed, returned.
 
269
|
 
270
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
271
#if !SKIP_OctApiTllmAllocGetSize
 
272
UINT32 OctApiTllmAllocGetSize(UINT32 number_of_items,UINT32 * l_size)
 
273
{
 
274
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
275
 
 
276
        *l_size = (sizeof(TLLM_ALLOC)) + (number_of_items * sizeof(TLLM_ALLOC_NODE));
 
277
 
 
278
        return(GENERIC_OK);
 
279
}
 
280
#endif
 
281
 
 
282
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
283
|       API UTILITIES
 
284
|
 
285
|       Function:               OctApiTllmAllocInit.
 
286
|
 
287
|       Description:    This function intializes the TLLM_ALLOC structure.
 
288
|
 
289
|  -----------------------------------------------------------------------  
 
290
|  |   Variable        |     Type     |          Description                
 
291
|  -----------------------------------------------------------------------  
 
292
|       **l                                     void                    The memory used by the LLM_ALLOC structure.
 
293
|       number_of_items         UINT32                  The number of resources to be allocated.
 
294
|
 
295
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
296
#if !SKIP_OctApiTllmAllocInit
 
297
UINT32 OctApiTllmAllocInit(void ** l,UINT32 number_of_items)
 
298
{
 
299
        TLLM_ALLOC* ls;
 
300
        UINT32 i;
 
301
 
 
302
        /* Check the number of items required.*/
 
303
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
304
 
 
305
        /* If no memory has been allocated yet.*/
 
306
        if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
 
307
 
 
308
        /* Build the structure before starting.*/
 
309
        ls = (TLLM_ALLOC *)(*l);
 
310
        ls->linked_list = (TLLM_ALLOC_NODE *)((BYTE *)ls + sizeof(TLLM_ALLOC));
 
311
 
 
312
        ls->number_of_items = number_of_items;
 
313
 
 
314
        /* Linked list links all structures in ascending order.*/
 
315
        for(i=0;i<number_of_items;i++)
 
316
        {
 
317
                ls->linked_list[i].value = i+1;
 
318
        }
 
319
 
 
320
        ls->linked_list[number_of_items - 1].value = 0xFFFFFFFF; /* Invalid link.*/
 
321
 
 
322
        /* Next avail is 0.*/
 
323
        ls->next_avail_num = 0;
 
324
 
 
325
        /* Number of allocated items is null.*/
 
326
        ls->allocated_items = 0;
 
327
 
 
328
        /* Set the number of timeout entry.*/
 
329
        ls->number_of_timeout = 0;
 
330
 
 
331
        /* Next timeout is 0.*/
 
332
        ls->next_timeout_num = 0xFFFFFFFF;
 
333
        ls->last_timeout_num = 0xFFFFFFFF;
 
334
 
 
335
        /* Set the known time to 0.*/
 
336
        ls->last_known_time[ 0 ] = 0;
 
337
        ls->last_known_time[ 1 ] = 0;
 
338
 
 
339
        return(GENERIC_OK);
 
340
}
 
341
#endif
 
342
 
 
343
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
344
|       API UTILITIES
 
345
|
 
346
|       Function:               OctApiTllmAllocInfo.
 
347
|
 
348
|       Description:    This function returns the number of free and allocated
 
349
|                                       block in the TLLMAN list.
 
350
|
 
351
|  -----------------------------------------------------------------------  
 
352
|  |   Variable        |     Type     |          Description                
 
353
|  -----------------------------------------------------------------------  
 
354
|       *l                                      void                    The memory used by the LLM_ALLOC structure.
 
355
|       *allocated_items        UINT32                  Number of allocated items.
 
356
|       *available_items        UINT32                  Number of available items.
 
357
|
 
358
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
359
#if !SKIP_OctApiTllmAllocInfo
 
360
UINT32 OctApiTllmAllocInfo(void * l,UINT32 * allocated_items,UINT32 * available_items)
 
361
{
 
362
        TLLM_ALLOC* ls;
 
363
 
 
364
        /* Build the structure before starting.*/
 
365
        ls = (TLLM_ALLOC *)l;
 
366
        *allocated_items = ls->allocated_items;
 
367
        *available_items = ls->number_of_items - ls->allocated_items;
 
368
 
 
369
        return(GENERIC_OK);
 
370
}
 
371
#endif
 
372
 
 
373
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
374
|       API UTILITIES
 
375
|
 
376
|       Function:               OctApiTllmAllocAlloc.
 
377
|
 
378
|       Description:    This function allocates the resource indicated by blocknum.
 
379
|                                       If the resource can be allocated then GENERIC_OK is returned.  
 
380
|                                       Else an error.
 
381
|
 
382
|  -----------------------------------------------------------------------  
 
383
|  |   Variable        |     Type     |          Description                
 
384
|  -----------------------------------------------------------------------  
 
385
|       *l                                      void                    The memory used by the LLM_ALLOC structure.
 
386
|       *block_num                      UINT32                  The resource to be allocated.
 
387
|       *current_time           UINT32
 
388
|
 
389
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
390
#if !SKIP_OctApiTllmAllocAlloc
 
391
UINT32 OctApiTllmAllocAlloc(void * l,UINT32 * blocknum, UINT32 *current_time)
 
392
{
 
393
        TLLM_ALLOC* ls;
 
394
        UINT32 allocated_block;
 
395
        TLLM_ALLOC_NODE* node;
 
396
 
 
397
        /* Build the structure before starting.*/
 
398
        ls = (TLLM_ALLOC *)l;
 
399
        ls->linked_list = (TLLM_ALLOC_NODE *)((BYTE *)ls + sizeof(TLLM_ALLOC));
 
400
        
 
401
        if ( ls->allocated_items == ls->number_of_items  && 
 
402
                 ls->next_timeout_num != 0xFFFFFFFF )
 
403
        {
 
404
                UINT32 l_ulResult;
 
405
                l_ulResult = OctApiTllmCheckTimeoutList( ls, current_time );
 
406
                if ( l_ulResult != GENERIC_OK )
 
407
                        return l_ulResult;
 
408
        }
 
409
        
 
410
        /* Get next available block number.*/
 
411
        allocated_block = ls->next_avail_num;
 
412
 
 
413
        /* Check if block is invalid.*/
 
414
        if (allocated_block == 0xFFFFFFFF)
 
415
        {
 
416
                /* Make blocknum NULL.*/
 
417
                *blocknum = 0xFFFFFFFF;
 
418
 
 
419
                return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
 
420
        }
 
421
 
 
422
        node = &ls->linked_list[allocated_block];
 
423
 
 
424
        /* Copy next block number.*/
 
425
        ls->next_avail_num = node->value;
 
426
 
 
427
        /* Tag as used the current block number.*/
 
428
        node->value = 0xFFFFFFFE;
 
429
 
 
430
        /* Return proper block number.*/
 
431
        *blocknum = allocated_block;
 
432
 
 
433
        /* Update block usage number.*/
 
434
        ls->allocated_items++;
 
435
 
 
436
        return(GENERIC_OK);
 
437
}
 
438
#endif
 
439
 
 
440
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
441
|       API UTILITIES
 
442
|
 
443
|       Function:               OctApiTllmAllocDealloc.
 
444
|
 
445
|       Description:    This function deallocates the resource indicated by blocknum.
 
446
|                                       If the resource is not already allocated an error is returned.
 
447
|                                       Else GENERIC_OK is returned.
 
448
|
 
449
|  -----------------------------------------------------------------------  
 
450
|  |   Variable        |     Type     |          Description                
 
451
|  -----------------------------------------------------------------------  
 
452
|       *l                                      void                    The memory used by the LLM_ALLOC structure.
 
453
|       block_num                       UINT32                  The resource to be deallocated.
 
454
|
 
455
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
456
#if !SKIP_OctApiTllmAllocDealloc
 
457
UINT32 OctApiTllmAllocDealloc(void * l,UINT32 blocknum, UINT32 timeout_value, UINT32 current_time[2])
 
458
{
 
459
        TLLM_ALLOC* ls;
 
460
        TLLM_ALLOC_NODE* node;
 
461
        UINT32  l_ulResult;
 
462
 
 
463
        /* Build the structure before starting.*/
 
464
        ls = (TLLM_ALLOC *)l;
 
465
        ls->linked_list = (TLLM_ALLOC_NODE *)((BYTE *)ls + sizeof(TLLM_ALLOC));
 
466
        
 
467
        /* Check for null item pointer.*/
 
468
        if (blocknum == 0xFFFFFFFF) return(GENERIC_OK);
 
469
 
 
470
        /* Check if blocknum is within specified item range.*/
 
471
        if (blocknum >= ls->number_of_items) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
472
 
 
473
        if ( ls->next_timeout_num != 0xFFFFFFFF )
 
474
        {
 
475
                l_ulResult = OctApiTllmCheckTimeoutList( ls, current_time );
 
476
                if ( l_ulResult != GENERIC_OK )
 
477
                        return l_ulResult;
 
478
        }
 
479
 
 
480
        node = &ls->linked_list[blocknum];
 
481
 
 
482
        /* Check if block is really used as of now.*/
 
483
        if (node->value != 0xFFFFFFFE) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
 
484
 
 
485
        /* Add link to timeout list.*/
 
486
        if ( ls->last_timeout_num != 0xFFFFFFFF )
 
487
        {
 
488
                TLLM_ALLOC_NODE* last_node;
 
489
 
 
490
                /* insert the node at the end of the list.*/
 
491
                node->value = 0xFFFFFFFF;
 
492
                last_node = &ls->linked_list[ ls->last_timeout_num ];
 
493
                last_node->value = blocknum;
 
494
        }
 
495
        else
 
496
        {
 
497
                /* The node is alone in the list.*/
 
498
                node->value = 0xFFFFFFFF;
 
499
                ls->next_timeout_num = blocknum;
 
500
        }
 
501
 
 
502
        ls->last_timeout_num = blocknum;
 
503
        ls->number_of_timeout++;
 
504
 
 
505
        /* Set the timeout time of the node.*/
 
506
        l_ulResult = OctApiLmAdd( current_time, 1, &timeout_value, 0, node->timeout, 1 );
 
507
        if (l_ulResult != GENERIC_OK) 
 
508
                return(l_ulResult);
 
509
 
 
510
        return(GENERIC_OK);
 
511
}
 
512
#endif
 
513
 
 
514
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
515
|       API UTILITIES
 
516
|
 
517
|       Function:               OctApiTllmCheckTimeoutList.
 
518
|
 
519
|       Description:    This function will verify if the timeout time 
 
520
|                                       of all the node present in the timeout list are bigger
 
521
|                                       then the current time.  If so the node will be returned
 
522
|                                       ot the free node list.
 
523
|
 
524
|  -----------------------------------------------------------------------  
 
525
|  |   Variable        |     Type     |          Description                
 
526
|  -----------------------------------------------------------------------  
 
527
|       *ls                                             TLLM_ALLOC              The memory used by the TLLM_ALLOC structure.
 
528
|       current_time                    UINT32[2]               The current time in msec.
 
529
|
 
530
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
531
#if !SKIP_OctApiTllmCheckTimeoutList
 
532
UINT32 OctApiTllmCheckTimeoutList(TLLM_ALLOC *ls, UINT32 current_time[2])
 
533
{
 
534
        UINT32  result;
 
535
        UINT32  fConditionFlag = TRUE;
 
536
 
 
537
        /* Free-up any pending memory before trying the allocation:*/
 
538
        if ((ls->last_known_time[0] != current_time[0] ||
 
539
                ls->last_known_time[1] != current_time[1]) && 
 
540
                (current_time[1] != 0 || current_time[0] != 0)) /* Time has changed.*/
 
541
        {
 
542
                TLLM_ALLOC_NODE *pcurrent_node;
 
543
                UINT32  current_num;
 
544
                USHORT  neg;
 
545
 
 
546
                /* Remember time for next time!*/
 
547
                ls->last_known_time[0] = current_time[0];
 
548
                ls->last_known_time[1] = current_time[1];
 
549
 
 
550
        
 
551
                while ( fConditionFlag == TRUE )
 
552
                {
 
553
                        /* Get a node from the timeout list.*/
 
554
                        pcurrent_node = &ls->linked_list[ ls->next_timeout_num ];
 
555
                        current_num = ls->next_timeout_num;
 
556
        
 
557
                        /* Check if first node has timeout.*/
 
558
                        result = OctApiLmCompare(current_time,1,pcurrent_node->timeout ,1,&neg);
 
559
                        if (result != GENERIC_OK) return(result);
 
560
                        
 
561
                        /* if the timeout tiem was exceeded, set the block as free.*/
 
562
                        if ( neg == FALSE )
 
563
                        {
 
564
                                /* set the next node pointer.*/
 
565
                                ls->next_timeout_num = pcurrent_node->value;
 
566
                                ls->number_of_timeout--;
 
567
 
 
568
                                /* reset the last pointer of the timeout list.*/
 
569
                                if ( ls->number_of_timeout == 0 )
 
570
                                        ls->last_timeout_num = 0xFFFFFFFF;
 
571
 
 
572
                                /* return the node the free list.*/
 
573
                                pcurrent_node->value = ls->next_avail_num;
 
574
                                ls->next_avail_num = current_num;
 
575
                                ls->allocated_items--;
 
576
                        }
 
577
                        else    /* node not in timeout */
 
578
                        {
 
579
                                fConditionFlag = FALSE;
 
580
                                break;
 
581
                        }
 
582
 
 
583
                        if ( ls->next_timeout_num == 0xFFFFFFFF )
 
584
                        {
 
585
                                fConditionFlag = FALSE;
 
586
                                break;  /* end of timeout list.*/
 
587
                        }
 
588
                }
 
589
        }
 
590
 
 
591
        return(GENERIC_OK);
 
592
}
 
593
#endif
 
594
/**************************************** llm_alloc section **********************************************/
 
595
 
 
596
 
 
597
 
 
598
 
 
599
 
 
600
 
 
601
 
 
602
/**************************************** llm_list section **********************************************/
 
603
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
604
|       API UTILITIES
 
605
|
 
606
|       Function:               OctApiLlmListGetSize
 
607
|
 
608
|       Description:    This function determines the amount of memory needed by
 
609
|                                       the LLM_LIST structure to manage the allocation of
 
610
|                                       number_of_items number of resources.  The memory is
 
611
|                                       measured in bytes.
 
612
|
 
613
|  -----------------------------------------------------------------------  
 
614
|  |   Variable        |     Type     |          Description                
 
615
|  -----------------------------------------------------------------------  
 
616
|       number_of_items         UINT32                  The number of resources to be allocated
 
617
|                                                                               amongst all linked-lists.
 
618
|       number_of_lists         UINT32                  The maximum number of linked-lists that
 
619
|                                                                               can be allocated.
 
620
|       *l_size UINT32          UINT32                  The amount of memory needed, returned.
 
621
|
 
622
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
623
#if !SKIP_OctApiLlmListGetSize
 
624
UINT32 OctApiLlmListGetSize(UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size,UINT32 * l_size)
 
625
{
 
626
        UINT32 head_alloc_size;
 
627
        UINT32 result;
 
628
        UINT32 user_info_size_roundup;
 
629
 
 
630
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
631
        if (number_of_lists == 0) return(GENERIC_BAD_PARAM);
 
632
        if (user_info_size == 0) return(GENERIC_BAD_PARAM);
 
633
 
 
634
        user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
 
635
 
 
636
        result = OctapiLlmAllocGetSize(number_of_lists,&head_alloc_size);
 
637
        if(result != GENERIC_OK) return(result);
 
638
 
 
639
        *l_size = sizeof(LLM_LIST) + (number_of_lists * sizeof(LLM_LIST_HEAD)) + head_alloc_size + (number_of_items * (sizeof(LLM_LIST_ITEM) + user_info_size_roundup - 4));
 
640
 
 
641
        return(GENERIC_OK);
 
642
}
 
643
#endif
 
644
 
 
645
#if !SKIP_OctApiLlmListGetItemPointer
 
646
LLM_LIST_ITEM * OctApiLlmListGetItemPointer(LLM_LIST * ls, UINT32 item_number)
 
647
{
 
648
        return (LLM_LIST_ITEM *) (((BYTE *)ls->li) + (ls->item_size * item_number)) ;
 
649
}
 
650
#endif
 
651
 
 
652
 
 
653
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
654
|       API UTILITIES
 
655
|
 
656
|       Function:               OctApiLlmListInit.
 
657
|
 
658
|       Description:    This function intializes the LLM_TALLOC structure.
 
659
|
 
660
|  -----------------------------------------------------------------------  
 
661
|  |   Variable        |     Type     |          Description                
 
662
|  -----------------------------------------------------------------------  
 
663
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
664
|       number_of_items         UINT32                  The number of resources to be allocated
 
665
|                                                                               amongst all linked-lists.
 
666
|       number_of_lists         UINT32                  The maximum number of linked-lists that
 
667
|                                                                               can be allocated.
 
668
|
 
669
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
670
#if !SKIP_OctApiLlmListInit
 
671
UINT32 OctApiLlmListInit(void ** l,UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size)
 
672
{
 
673
        LLM_LIST* ls;
 
674
        LLM_LIST_ITEM* item;
 
675
        UINT32 i;
 
676
        UINT32 head_alloc_size;
 
677
        UINT32 result;
 
678
        UINT32 user_info_size_roundup;
 
679
        UINT32 total_lists;
 
680
        BYTE* lsbyte;
 
681
 
 
682
 
 
683
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
684
        if (number_of_lists == 0) return(GENERIC_BAD_PARAM);
 
685
        if (user_info_size == 0) return(GENERIC_BAD_PARAM);
 
686
 
 
687
        user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
 
688
 
 
689
        /* Get the size of the Alloc structure used to manage head of list structures.*/
 
690
        result = OctapiLlmAllocGetSize(number_of_lists,&head_alloc_size);
 
691
        if(result != GENERIC_OK) return(result);
 
692
 
 
693
        if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
 
694
 
 
695
        /* Built the structure based on the base address:*/
 
696
        ls = (LLM_LIST *)(*l);
 
697
        lsbyte = (BYTE *)ls;
 
698
        total_lists = ls->total_lists;
 
699
 
 
700
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
701
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
702
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
703
 
 
704
        /* Initialize parameters in the structure.*/
 
705
        ls->head_alloc_size = head_alloc_size;
 
706
        ls->user_info_bytes = user_info_size;
 
707
        ls->user_info_size = user_info_size_roundup;
 
708
        ls->total_items = number_of_items;
 
709
        ls->assigned_items = 0;
 
710
        ls->total_lists = number_of_lists;
 
711
        ls->assigned_lists = 0;
 
712
        ls->next_empty_item = 0;
 
713
        ls->item_size = sizeof(LLM_LIST_ITEM) + user_info_size_roundup - 4;
 
714
 
 
715
        /* Complete the build!*/
 
716
        ls = (LLM_LIST *)(*l);
 
717
        lsbyte = (BYTE *)ls;
 
718
        total_lists = ls->total_lists;
 
719
 
 
720
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
721
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
722
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
723
 
 
724
        /* Initialize the head of queue Alloc structure.*/
 
725
        result = OctapiLlmAllocInit(&(ls->list_head_alloc),number_of_lists);
 
726
        if(result != GENERIC_OK) return(result);
 
727
 
 
728
        /* Initialize the linked list of the items:*/
 
729
        for(i=0; i<number_of_items; i++)
 
730
        {
 
731
                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * i);
 
732
 
 
733
                if (i == (number_of_items - 1))
 
734
                        item->forward_link = 0xFFFFFFFF;
 
735
                else
 
736
                        item->forward_link = i + 1;
 
737
        }
 
738
 
 
739
        return(GENERIC_OK);
 
740
}
 
741
#endif
 
742
 
 
743
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
744
|       API UTILITIES
 
745
|
 
746
|       Function:               OctApiLlmListInfo.
 
747
|
 
748
|       Description:    This function returns the status of the LLM_LIST structure.
 
749
|
 
750
|  -----------------------------------------------------------------------  
 
751
|  |   Variable        |     Type     |          Description                
 
752
|  -----------------------------------------------------------------------  
 
753
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
754
|       *allocated_lists        UINT32                  The number of linked_lists allocated.
 
755
|       *free_lists                     UINT32                  The number of linked_lists still free.
 
756
|       *allocated_items        UINT32                  The number of items allocated to lists.
 
757
|       *free_items                     UINT32                  The number of items still free.
 
758
|
 
759
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
760
#if !SKIP_OctApiLlmListInfo
 
761
UINT32 OctApiLlmListInfo(void * l,UINT32 * allocated_lists,UINT32 * allocated_items,
 
762
                                                                        UINT32 * free_lists,UINT32 * free_items)
 
763
{
 
764
        LLM_LIST* ls;
 
765
        BYTE* lsbyte;
 
766
        UINT32 total_lists;
 
767
 
 
768
        /* Built the structure based on the base address:*/
 
769
        ls = (LLM_LIST *)l;
 
770
        lsbyte = (BYTE *)ls;
 
771
        total_lists = ls->total_lists;
 
772
 
 
773
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
774
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
775
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
776
 
 
777
        *allocated_items = ls->assigned_items;
 
778
        *free_items = ls->total_items - ls->assigned_items;
 
779
 
 
780
        *allocated_lists = ls->assigned_lists;
 
781
        *free_lists = ls->total_lists - ls->assigned_lists;
 
782
 
 
783
        return(GENERIC_OK);
 
784
}
 
785
#endif
 
786
 
 
787
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
788
|       API UTILITIES
 
789
|
 
790
|       Function:               OctApiLlmListCreate.
 
791
|
 
792
|       Description:    This function creates a linked list.  The target which is
 
793
|                                       allocated the newly created list can request additions
 
794
|                                       or removals from the list later on.  To target identifies
 
795
|                                       its list with the returned list handle.
 
796
|
 
797
|  -----------------------------------------------------------------------  
 
798
|  |   Variable        |     Type     |          Description                
 
799
|  -----------------------------------------------------------------------  
 
800
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
801
|       *list_handle            UINT32                  The handle to the new list, returned.
 
802
|
 
803
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
804
#if !SKIP_OctApiLlmListCreate
 
805
UINT32 OctApiLlmListCreate(void * l,UINT32 * list_handle)
 
806
{
 
807
        LLM_LIST* ls;
 
808
        LLM_LIST_HEAD* lh;
 
809
        UINT32 blocknum;
 
810
        UINT32 total_lists;
 
811
        UINT32 result;
 
812
        BYTE* lsbyte;
 
813
 
 
814
        /* Built the structure based on the base address:*/
 
815
        ls = (LLM_LIST *)l;
 
816
        lsbyte = (BYTE *)ls;
 
817
        total_lists = ls->total_lists;
 
818
 
 
819
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
820
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
821
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
822
 
 
823
        /* Get a list using the list head alloc structure.*/
 
824
        result = OctapiLlmAllocAlloc(ls->list_head_alloc, &blocknum);
 
825
        if (result != GENERIC_OK) return(result);
 
826
 
 
827
        /* The handle is the block number.*/
 
828
        *list_handle = blocknum;
 
829
 
 
830
        /* Initialize the list head structure.*/
 
831
        lh = &ls->lh[blocknum];
 
832
        lh->list_length = 0;
 
833
        lh->head_pointer = 0xFFFFFFFF;
 
834
        lh->tail_pointer = 0xFFFFFFFF;
 
835
        lh->cache_item_number = 0xFFFFFFFF;
 
836
        lh->cache_item_pointer = 0xFFFFFFFF;
 
837
 
 
838
        ls->assigned_lists++;
 
839
 
 
840
        return(GENERIC_OK);
 
841
}
 
842
#endif
 
843
 
 
844
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
845
|       API UTILITIES
 
846
|
 
847
|       Function:               OctApiLlmListDelete.
 
848
|
 
849
|       Description:    This function deletes the linked list indicated by the
 
850
|                                       handle list_handle.  Any items which are still allocated
 
851
|                                       to the list are first deallocated.
 
852
|
 
853
|  -----------------------------------------------------------------------  
 
854
|  |   Variable        |     Type     |          Description                
 
855
|  -----------------------------------------------------------------------  
 
856
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
857
|       *list_handle            UINT32                  The handle to the list.
 
858
|
 
859
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
860
#if !SKIP_OctApiLlmListDelete
 
861
UINT32 OctApiLlmListDelete(void * l,UINT32 list_handle)
 
862
{
 
863
        LLM_LIST* ls;
 
864
        LLM_LIST_HEAD* lh;
 
865
        UINT32 total_lists;
 
866
        UINT32 result;
 
867
        BYTE* lsbyte;
 
868
 
 
869
        /* Built the structure based on the base address:*/
 
870
        ls = (LLM_LIST *)l;
 
871
        lsbyte = (BYTE *)ls;
 
872
        total_lists = ls->total_lists;
 
873
 
 
874
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
875
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
876
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
877
 
 
878
        
 
879
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
880
        if (ls->lh[list_handle].list_length == 0xFFFFFFFF) return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
881
 
 
882
        /* Release internal list header handle...*/
 
883
        result = OctapiLlmAllocDealloc(ls->list_head_alloc,list_handle);
 
884
        if (result != GENERIC_OK) return(result);
 
885
 
 
886
        lh = &ls->lh[list_handle];
 
887
 
 
888
        /* Deallocate all items in the list!*/
 
889
        if (lh->list_length != 0)
 
890
        {
 
891
                LLM_LIST_ITEM * item;
 
892
 
 
893
                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->tail_pointer);
 
894
 
 
895
                /* Release the items using only the links.*/
 
896
                item->forward_link = ls->next_empty_item;
 
897
                ls->next_empty_item = lh->head_pointer;
 
898
 
 
899
                /* Remove items from item counter.*/
 
900
                ls->assigned_items -= lh->list_length;
 
901
        }
 
902
 
 
903
        lh->list_length = 0xFFFFFFFF;
 
904
        lh->head_pointer = 0xFFFFFFFF;
 
905
        lh->tail_pointer = 0xFFFFFFFF;
 
906
        lh->cache_item_number = 0xFFFFFFFF;
 
907
        lh->cache_item_pointer = 0xFFFFFFFF;
 
908
 
 
909
        ls->assigned_lists--;
 
910
 
 
911
        return(GENERIC_OK);
 
912
}
 
913
#endif
 
914
 
 
915
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
916
|       API UTILITIES
 
917
|
 
918
|       Function:               OctApiLlmListLength.
 
919
|
 
920
|       Description:    This function returns the number of items allocated to the
 
921
|                                       list indicated by the handle list_handle.
 
922
|
 
923
|  -----------------------------------------------------------------------  
 
924
|  |   Variable        |     Type     |          Description                
 
925
|  -----------------------------------------------------------------------  
 
926
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
927
|       list_handle                     UINT32                  The handle to the list.
 
928
|       *number_of_items        UINT32                  The number of items in the list, returned.
 
929
|
 
930
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
931
#if !SKIP_OctApiLlmListLength
 
932
UINT32 OctApiLlmListLength(void * l,UINT32 list_handle, UINT32 * number_of_items_in_list)
 
933
{
 
934
        LLM_LIST* ls;
 
935
        LLM_LIST_HEAD* lh;
 
936
        UINT32 total_lists;
 
937
        BYTE* lsbyte;
 
938
 
 
939
        /* Built the structure based on the base address:*/
 
940
        ls = (LLM_LIST *)l;
 
941
        lsbyte = (BYTE *)ls;
 
942
        total_lists = ls->total_lists;
 
943
 
 
944
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
945
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
946
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
947
 
 
948
        lh = &ls->lh[list_handle];
 
949
        
 
950
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
951
        if (lh->list_length == 0xFFFFFFFF) return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
952
 
 
953
        *number_of_items_in_list = lh->list_length;
 
954
 
 
955
        return(GENERIC_OK);
 
956
}
 
957
#endif
 
958
 
 
959
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
960
|       API UTILITIES
 
961
|
 
962
|       Function:               OctApiLlmListItemData
 
963
|
 
964
|       Description:    This function returns a pointer to the user data associated
 
965
|                                       with an item.
 
966
|
 
967
|  -----------------------------------------------------------------------  
 
968
|  |   Variable        |     Type     |          Description                
 
969
|  -----------------------------------------------------------------------  
 
970
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
971
|       list_handle                     UINT32                  The handle to the list.
 
972
|       item_number                     UINT32                  The number of the list node in question.
 
973
|       **item_data_pnt         void                    The pointer to the user data, returned.
 
974
|
 
975
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
976
#if !SKIP_OctApiLlmListItemData
 
977
UINT32 OctApiLlmListItemData(void * l,UINT32 list_handle,UINT32 item_number,void ** item_data_pnt)
 
978
{
 
979
        LLM_LIST* ls;
 
980
        LLM_LIST_HEAD* lh;
 
981
        LLM_LIST_ITEM* item;
 
982
        UINT32  cur_list_pnt;
 
983
        UINT32  cur_list_num;
 
984
        UINT32  total_lists;
 
985
        UINT32  list_length;
 
986
        BYTE*   lsbyte;
 
987
        UINT32  fConditionFlag = TRUE;
 
988
 
 
989
        /* Built the structure based on the base address:*/
 
990
        ls = (LLM_LIST *)l;
 
991
        lsbyte = (BYTE *)ls;
 
992
        total_lists = ls->total_lists;
 
993
 
 
994
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
995
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
996
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
997
 
 
998
        lh = &ls->lh[list_handle];
 
999
        list_length = lh->list_length;
 
1000
        
 
1001
        *item_data_pnt = NULL;
 
1002
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
1003
        if (list_length == 0xFFFFFFFF) return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1004
        if (list_length <= item_number) return(OCTAPI_LLM_ELEMENT_NOT_FOUND);
 
1005
 
 
1006
        /* Determine where the search will start.*/
 
1007
        if (list_length == (item_number + 1))   /* Last item in list:*/
 
1008
        {
 
1009
                cur_list_pnt = lh->tail_pointer;
 
1010
                cur_list_num = item_number;
 
1011
        }
 
1012
        else if (lh->cache_item_number <= item_number)  /* Start at cache:*/
 
1013
        {
 
1014
                cur_list_pnt = lh->cache_item_pointer;
 
1015
                cur_list_num = lh->cache_item_number;
 
1016
        }
 
1017
        else  /* Start at beginning:*/
 
1018
        {
 
1019
                cur_list_pnt = lh->head_pointer;
 
1020
                cur_list_num = 0;
 
1021
        }
 
1022
 
 
1023
        /* Start search from cur_list_pnt and cur_list_num.*/
 
1024
        while ( fConditionFlag == TRUE )
 
1025
        {
 
1026
                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
1027
 
 
1028
                if (cur_list_num == item_number) /* Item number found.*/
 
1029
                {
 
1030
                        /* Write new cache entry.*/
 
1031
                        lh->cache_item_pointer = cur_list_pnt;
 
1032
                        lh->cache_item_number = cur_list_num;
 
1033
 
 
1034
                        /* Get item info.*/
 
1035
                        *item_data_pnt = (void *)item->user_info;
 
1036
 
 
1037
                        return(GENERIC_OK);
 
1038
                }
 
1039
                else if(item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
 
1040
                {
 
1041
                        return(OCTAPI_LLM_INTERNAL_ERROR0);
 
1042
                }
 
1043
                else /* Item was not found, but continue searching.*/
 
1044
                {
 
1045
                        cur_list_pnt = item->forward_link;
 
1046
                }
 
1047
 
 
1048
                cur_list_num++;
 
1049
        }
 
1050
 
 
1051
        return(GENERIC_OK);
 
1052
}
 
1053
#endif
 
1054
 
 
1055
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1056
|       API UTILITIES
 
1057
|
 
1058
|       Function:               OctApiLlmListInsertItem.
 
1059
|
 
1060
|       Description:    This function allocates a node to the linked list specified
 
1061
|                                       by the handle list_handle.  The position of the new item
 
1062
|                                       can be specified. A position of 0xFFFFFFFF means append to the 
 
1063
|                                       list( use the OCTAPI_LLM_LIST_APPEND define for clarity); 
 
1064
|                   a position of 0 mean insert at the begining of the list.
 
1065
|
 
1066
|  -----------------------------------------------------------------------  
 
1067
|  |   Variable        |     Type     |          Description                
 
1068
|  -----------------------------------------------------------------------  
 
1069
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
1070
|       *list_handle            UINT32                  The handle to the list.
 
1071
|       **item_data                     void                    Address of the user data space for this item.
 
1072
|
 
1073
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1074
#if !SKIP_OctApiLlmListInsertItem
 
1075
UINT32 OctApiLlmListInsertItem(void * l,UINT32 list_handle,UINT32 item_number,void ** item_data_pnt)
 
1076
{
 
1077
        LLM_LIST* ls;
 
1078
        LLM_LIST_HEAD* lh;
 
1079
        LLM_LIST_ITEM* free_item;
 
1080
        UINT32 free_item_pnt;
 
1081
        UINT32 total_lists;
 
1082
        BYTE* lsbyte;
 
1083
        UINT32  fConditionFlag = TRUE;
 
1084
 
 
1085
        /* Built the structure based on the base address:*/
 
1086
        ls = (LLM_LIST *)l;
 
1087
        lsbyte = (BYTE *)ls;
 
1088
        total_lists = ls->total_lists;
 
1089
 
 
1090
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1091
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1092
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1093
 
 
1094
        lh = &ls->lh[list_handle];
 
1095
        
 
1096
        *item_data_pnt = NULL;
 
1097
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
1098
        if (lh->list_length == 0xFFFFFFFF) return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1099
        if (lh->list_length < item_number && item_number != 0xFFFFFFFF) 
 
1100
                return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
1101
        if (ls->next_empty_item == 0xFFFFFFFF) return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
 
1102
 
 
1103
        /* Get a free item from the free item list!*/
 
1104
        free_item_pnt = ls->next_empty_item;
 
1105
        free_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * free_item_pnt);
 
1106
        ls->next_empty_item = free_item->forward_link;
 
1107
 
 
1108
        if (item_number == 0xFFFFFFFF)
 
1109
                item_number = lh->list_length;
 
1110
 
 
1111
        if (lh->list_length == 0)       /* First item and only item:*/
 
1112
        {
 
1113
                free_item->forward_link = 0xFFFFFFFF;
 
1114
                lh->tail_pointer = free_item_pnt;
 
1115
                lh->head_pointer = free_item_pnt;
 
1116
        }
 
1117
        else if (item_number == 0)      /* First item and but list not empty:*/
 
1118
        {
 
1119
                free_item->forward_link = lh->head_pointer;
 
1120
                lh->head_pointer = free_item_pnt;
 
1121
        }
 
1122
        else if (item_number == lh->list_length)        /* Append:*/
 
1123
        {
 
1124
                LLM_LIST_ITEM * last_item;
 
1125
                last_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->tail_pointer);
 
1126
 
 
1127
                last_item->forward_link = free_item_pnt;
 
1128
                free_item->forward_link = 0xFFFFFFFF;
 
1129
                lh->tail_pointer = free_item_pnt;
 
1130
        }
 
1131
        else    /* Insert:*/
 
1132
        {
 
1133
                LLM_LIST_ITEM * last_item = NULL;
 
1134
                LLM_LIST_ITEM * item;
 
1135
                UINT32 last_list_pnt;
 
1136
                UINT32 cur_list_pnt;
 
1137
                UINT32 cur_list_num;
 
1138
 
 
1139
                if (lh->cache_item_number < item_number)        /* Start at cache:*/
 
1140
                {
 
1141
                        cur_list_pnt = lh->cache_item_pointer;
 
1142
                        cur_list_num = lh->cache_item_number;
 
1143
                }
 
1144
                else /* Start at beginning:*/
 
1145
                {
 
1146
                        cur_list_pnt = lh->head_pointer;
 
1147
                        cur_list_num = 0;
 
1148
                }
 
1149
 
 
1150
                last_list_pnt = 0xFFFFFFFF;
 
1151
 
 
1152
                /* Start search from cur_list_pnt and cur_list_num.*/
 
1153
                while ( fConditionFlag == TRUE )
 
1154
                {
 
1155
                        item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
1156
 
 
1157
                        if (cur_list_num == item_number) /* Item number found.*/
 
1158
                        {
 
1159
                                if (last_list_pnt == 0xFFFFFFFF) return(OCTAPI_LLM_INTERNAL_ERROR1);
 
1160
 
 
1161
                                free_item->forward_link = cur_list_pnt;
 
1162
                                last_item->forward_link = free_item_pnt;
 
1163
                                
 
1164
                                fConditionFlag = FALSE;
 
1165
                                break;
 
1166
                        }
 
1167
                        else if (item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
 
1168
                        {
 
1169
                                return(OCTAPI_LLM_INTERNAL_ERROR0);
 
1170
                        }
 
1171
                        else /* Item was not found, but continue searching.*/
 
1172
                        {
 
1173
                                last_item = item;
 
1174
                                last_list_pnt = cur_list_pnt;
 
1175
                                cur_list_pnt = item->forward_link;
 
1176
                        }
 
1177
 
 
1178
                        cur_list_num++;
 
1179
                }
 
1180
        }
 
1181
 
 
1182
        /* Increase the list length.*/
 
1183
        lh->list_length++;
 
1184
        ls->assigned_items++;
 
1185
        *item_data_pnt = (void *)free_item->user_info;
 
1186
 
 
1187
        /* Write new cache entry.*/
 
1188
        lh->cache_item_pointer = free_item_pnt;
 
1189
        lh->cache_item_number = item_number;
 
1190
 
 
1191
        return(GENERIC_OK);
 
1192
}
 
1193
#endif
 
1194
 
 
1195
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1196
|       API UTILITIES
 
1197
|
 
1198
|       Function:               OctApiLlmListCreateFull.
 
1199
|
 
1200
|       Description:    This function allocates the desired number of nodes to
 
1201
|                                       the linked list specified by the handle list_handle.
 
1202
|                                       The position of the new item can be specified. A
 
1203
|                                       position of 0xFFFFFFFF means append to the list (use the
 
1204
|                                       OCTAPI_LLM_LIST_APPEND define for clarity); a position
 
1205
|                                       of 0 means insert at the begining of the list.
 
1206
|
 
1207
|  -----------------------------------------------------------------------  
 
1208
|  |   Variable        |     Type     |          Description                
 
1209
|  -----------------------------------------------------------------------  
 
1210
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
1211
|       *list_handle            UINT32                  The handle to the list.
 
1212
|       **item_data                     void                    Address of the user data space for this item.
 
1213
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1214
#if !SKIP_OctApiLlmListCreateFull
 
1215
UINT32 OctApiLlmListCreateFull(void* l, UINT32 list_length, UINT32* plist_handle)
 
1216
{
 
1217
        LLM_LIST* ls;
 
1218
        LLM_LIST_HEAD* lh;
 
1219
        LLM_LIST_ITEM* free_item;
 
1220
        LLM_LIST_ITEM* last_item = NULL;
 
1221
        UINT32 free_item_pnt = 0xFFFFFFFF;
 
1222
        UINT32 total_lists;
 
1223
        UINT32 list_handle;
 
1224
        UINT32 list_length_m1;
 
1225
        UINT32 next_empty_item;
 
1226
        UINT32 result;
 
1227
        UINT32 i;
 
1228
        BYTE* lsbyte;
 
1229
 
 
1230
 
 
1231
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1232
        /* Build the structure based on the base address:*/
 
1233
        ls = (LLM_LIST *)l;
 
1234
        lsbyte = (BYTE *)ls;
 
1235
        total_lists = ls->total_lists;
 
1236
 
 
1237
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1238
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1239
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1240
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1241
 
 
1242
 
 
1243
 
 
1244
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1245
        /* Make sure another list can be created.*/
 
1246
        if (ls->assigned_lists == ls->total_lists)
 
1247
                return(OCTAPI_LLM_ELEMENT_ALREADY_ASSIGNED);
 
1248
 
 
1249
        /* Make sure there are enough free nodes to fill the new list.*/
 
1250
        if (list_length > (ls->total_items - ls->assigned_items))
 
1251
                return(OCTAPI_LLM_ELEMENT_ALREADY_ASSIGNED);
 
1252
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1253
 
 
1254
 
 
1255
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1256
        /* Create list (i.e. get a list using the list head alloc structure.*/
 
1257
        result = OctapiLlmAllocAlloc(ls->list_head_alloc, &list_handle);
 
1258
        if (result != GENERIC_OK) return(result);
 
1259
 
 
1260
        /* Initialize the list head structure.*/
 
1261
        lh = &ls->lh[list_handle];
 
1262
        lh->list_length = 0;
 
1263
        lh->head_pointer = 0xFFFFFFFF;
 
1264
        lh->tail_pointer = 0xFFFFFFFF;
 
1265
        lh->cache_item_number = 0xFFFFFFFF;
 
1266
        lh->cache_item_pointer = 0xFFFFFFFF;
 
1267
 
 
1268
        ls->assigned_lists++;
 
1269
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1270
 
 
1271
 
 
1272
 
 
1273
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1274
        /* Add the number of requested nodes to the list.*/
 
1275
        lh = &ls->lh[list_handle];
 
1276
        list_length_m1 = list_length - 1;
 
1277
        next_empty_item = ls->next_empty_item;
 
1278
 
 
1279
        for (i=0; i<list_length; i++)
 
1280
        {
 
1281
                /* Get a free item from the free item list!*/
 
1282
                free_item_pnt = next_empty_item;
 
1283
                free_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * free_item_pnt);
 
1284
                next_empty_item = free_item->forward_link;
 
1285
 
 
1286
                /* Branch according to whether the node is the first in list, last, or in
 
1287
                        the middle.*/
 
1288
                if (i == 0)     
 
1289
                {
 
1290
                        /* First item.*/
 
1291
                        free_item->forward_link = 0xFFFFFFFF;
 
1292
                        lh->head_pointer = free_item_pnt;
 
1293
                        lh->tail_pointer = free_item_pnt;
 
1294
                }
 
1295
                else if (i == list_length_m1)   
 
1296
                {
 
1297
                        /* Last item.*/
 
1298
                        last_item->forward_link = free_item_pnt;
 
1299
                        free_item->forward_link = 0xFFFFFFFF;
 
1300
                        lh->tail_pointer = free_item_pnt;
 
1301
                }
 
1302
                else
 
1303
                {
 
1304
                        /* Node somewhere in the middle.*/
 
1305
                        last_item->forward_link = free_item_pnt;
 
1306
                }
 
1307
 
 
1308
                /* Store pointer to free item as pointer to last item (for next iteration).*/
 
1309
                last_item = free_item;
 
1310
        }
 
1311
 
 
1312
        /* Store new value of next_empty_item.*/
 
1313
        ls->next_empty_item = next_empty_item;
 
1314
 
 
1315
        /* Write new cache entry.*/
 
1316
        lh->cache_item_pointer = free_item_pnt;
 
1317
        lh->cache_item_number = list_length_m1;
 
1318
 
 
1319
        /* Set the list length.*/
 
1320
        lh->list_length = list_length;
 
1321
        ls->assigned_items += list_length;
 
1322
 
 
1323
        /* Return pointer to new list.*/
 
1324
        *plist_handle = list_handle;
 
1325
 
 
1326
        return(GENERIC_OK);
 
1327
}
 
1328
#endif
 
1329
 
 
1330
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1331
|       API UTILITIES
 
1332
|
 
1333
|       Function:               OctApiLlmListAppendItems.
 
1334
|
 
1335
|       Description:    This function allocates the desired number of nodes to
 
1336
|                                       the linked list specified by the handle list_handle.
 
1337
|                                       The position of the new item can be specified. A
 
1338
|                                       position of 0xFFFFFFFF means append to the list (use the
 
1339
|                                       OCTAPI_LLM_LIST_APPEND define for clarity); a position
 
1340
|                                       of 0 means insert at the begining of the list.
 
1341
|
 
1342
|  -----------------------------------------------------------------------  
 
1343
|  |   Variable        |     Type     |          Description                
 
1344
|  -----------------------------------------------------------------------  
 
1345
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
1346
|       *list_handle            UINT32                  The handle to the list.
 
1347
|       **item_data                     void                    Address of the user data space for this item.
 
1348
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1349
#if !SKIP_OctApiLlmListAppendItems
 
1350
UINT32 OctApiLlmListAppendItems(void* l, UINT32 list_handle, UINT32 num_items)
 
1351
{
 
1352
        LLM_LIST* ls;
 
1353
        LLM_LIST_HEAD* lh;
 
1354
        LLM_LIST_ITEM* item_list;
 
1355
        LLM_LIST_ITEM* curr_item = NULL;
 
1356
        LLM_LIST_ITEM* free_item;
 
1357
        UINT32 curr_item_pnt = 0xFFFFFFFF;
 
1358
        UINT32 total_lists;
 
1359
        UINT32 next_empty_item;
 
1360
        UINT32 item_size;
 
1361
        UINT32 i;
 
1362
        BYTE* lsbyte;
 
1363
 
 
1364
 
 
1365
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1366
        /* Build the structure based on the base address:*/
 
1367
        ls = (LLM_LIST *)l;
 
1368
        lsbyte = (BYTE *)ls;
 
1369
        total_lists = ls->total_lists;
 
1370
 
 
1371
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1372
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1373
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1374
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1375
 
 
1376
 
 
1377
 
 
1378
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1379
        /* Make sure list handle is valid.*/
 
1380
        if (list_handle >= ls->total_lists)
 
1381
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1382
 
 
1383
        /* Make sure there is at least one item.*/
 
1384
        if (num_items == 0)
 
1385
                return(OCTAPI_LLM_INVALID_PARAMETER);
 
1386
 
 
1387
        /* Make sure there are enough free nodes.*/
 
1388
        if (num_items > (ls->total_items - ls->assigned_items))
 
1389
                return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
 
1390
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1391
 
 
1392
 
 
1393
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1394
        /* Get pointer to list structure.*/
 
1395
        lh = &ls->lh[list_handle];
 
1396
        if (lh->list_length == 0xFFFFFFFF)
 
1397
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1398
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1399
 
 
1400
 
 
1401
 
 
1402
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1403
        /* Add the number of requested nodes to the list.*/
 
1404
        item_list = ls->li;
 
1405
        item_size = ls->item_size;
 
1406
        next_empty_item = ls->next_empty_item;
 
1407
 
 
1408
        for (i=0; i<num_items; i++)
 
1409
        {
 
1410
                if (i == 0)
 
1411
                {
 
1412
                        if (lh->head_pointer == 0xFFFFFFFF)
 
1413
                        {
 
1414
                                /* Current and next items are one and the same!*/
 
1415
                                curr_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
 
1416
 
 
1417
                                /* Set new head and tail pointers.*/
 
1418
                                lh->head_pointer = next_empty_item;
 
1419
                                lh->tail_pointer = next_empty_item;
 
1420
 
 
1421
                                /* Update current item pnt.*/
 
1422
                                curr_item_pnt = next_empty_item;
 
1423
 
 
1424
                                /* Update next item.*/
 
1425
                                next_empty_item = curr_item->forward_link;
 
1426
 
 
1427
                                /* Set first item to be only item in list.*/
 
1428
                                curr_item->forward_link = 0xFFFFFFFF;
 
1429
                        }
 
1430
                        else
 
1431
                        {
 
1432
                                /* Get a free item from the free item list!*/
 
1433
                                curr_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * lh->tail_pointer);
 
1434
                                free_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
 
1435
 
 
1436
                                /* Have current item point to next empty item.*/
 
1437
                                curr_item->forward_link = next_empty_item;
 
1438
 
 
1439
                                /* Update current item pnt.*/
 
1440
                                curr_item_pnt = next_empty_item;
 
1441
 
 
1442
                                /* Update next_empty_item.*/
 
1443
                                next_empty_item = free_item->forward_link;
 
1444
 
 
1445
                                /* Update pointers to current item and free item.*/
 
1446
                                curr_item = free_item;
 
1447
                        }
 
1448
                }
 
1449
                else
 
1450
                {
 
1451
                        /* Update pointers to current item and free item.*/
 
1452
                        free_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
 
1453
 
 
1454
                        /* Have current item point to next empty item.*/
 
1455
                        curr_item->forward_link = next_empty_item;
 
1456
 
 
1457
                        /* Update current item pnt.*/
 
1458
                        curr_item_pnt = next_empty_item;
 
1459
 
 
1460
                        /* Update next_empty_item.*/
 
1461
                        next_empty_item = free_item->forward_link;
 
1462
 
 
1463
                        /* Update pointers to current item and free item.*/
 
1464
                        curr_item = free_item;
 
1465
                }
 
1466
        }
 
1467
 
 
1468
        /* Terminate list.*/
 
1469
        if ( curr_item != NULL )
 
1470
                curr_item->forward_link = 0xFFFFFFFF;
 
1471
 
 
1472
        /* Update llman structure variables.*/
 
1473
        ls->next_empty_item = next_empty_item;
 
1474
        ls->assigned_items += num_items;
 
1475
 
 
1476
        /* Update list variables.*/
 
1477
        lh->list_length += num_items;
 
1478
        lh->cache_item_pointer = curr_item_pnt;
 
1479
        lh->cache_item_number = lh->list_length - 1;
 
1480
        lh->tail_pointer = curr_item_pnt;
 
1481
 
 
1482
        return(GENERIC_OK);
 
1483
}
 
1484
#endif
 
1485
 
 
1486
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1487
|       API UTILITIES
 
1488
|
 
1489
|       Function:               OctApiLlmListAppendAndSetItems.
 
1490
|
 
1491
|       Description:
 
1492
|
 
1493
|  -----------------------------------------------------------------------  
 
1494
|  |   Variable        |     Type     |          Description                
 
1495
|  -----------------------------------------------------------------------  
 
1496
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1497
#if !SKIP_OctApiLlmListAppendAndSetItems
 
1498
UINT32 OctApiLlmListAppendAndSetItems(void* l, UINT32 list_handle, UINT32 num_items, void* data_list)
 
1499
{
 
1500
        LLM_LIST* ls;
 
1501
        LLM_LIST_HEAD* lh;
 
1502
        LLM_LIST_ITEM* item_list;
 
1503
        LLM_LIST_ITEM* curr_item = NULL;
 
1504
        LLM_LIST_ITEM* free_item;
 
1505
        UINT32 curr_item_pnt = 0xFFFFFFFF;
 
1506
        UINT32 total_lists;
 
1507
        UINT32 next_empty_item;
 
1508
        UINT32 user_info_bytes;
 
1509
        UINT32 item_size;
 
1510
        UINT32 i;
 
1511
        BYTE* lsbyte;
 
1512
        void* data_item;
 
1513
 
 
1514
 
 
1515
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1516
        /* Build the structure based on the base address:*/
 
1517
        ls = (LLM_LIST *)l;
 
1518
        lsbyte = (BYTE *)ls;
 
1519
        total_lists = ls->total_lists;
 
1520
 
 
1521
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1522
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1523
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1524
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1525
 
 
1526
 
 
1527
 
 
1528
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1529
        /* Make sure list handle is valid.*/
 
1530
        if (list_handle >= ls->total_lists)
 
1531
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1532
 
 
1533
        /* Make sure there is at least one item.*/
 
1534
        if (num_items == 0)
 
1535
                return(OCTAPI_LLM_INVALID_PARAMETER);
 
1536
 
 
1537
        /* Make sure there are enough free nodes.*/
 
1538
        if (num_items > (ls->total_items - ls->assigned_items))
 
1539
                return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
 
1540
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1541
 
 
1542
 
 
1543
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1544
        /* Get pointer to list structure.*/
 
1545
        lh = &ls->lh[list_handle];
 
1546
        if (lh->list_length == 0xFFFFFFFF)
 
1547
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1548
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1549
 
 
1550
 
 
1551
 
 
1552
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1553
        /* Add the number of requested nodes to the list.*/
 
1554
        item_list = ls->li;
 
1555
        user_info_bytes = ls->user_info_bytes;
 
1556
        item_size = ls->item_size;
 
1557
        next_empty_item = ls->next_empty_item;
 
1558
        data_item = data_list;
 
1559
 
 
1560
        for (i=0; i<num_items; i++)
 
1561
        {
 
1562
                if (i == 0)
 
1563
                {
 
1564
                        if (lh->head_pointer == 0xFFFFFFFF)
 
1565
                        {
 
1566
                                /* Current and next items are one and the same!*/
 
1567
                                curr_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
 
1568
 
 
1569
                                /* Set new head and tail pointers.*/
 
1570
                                lh->head_pointer = next_empty_item;
 
1571
                                lh->tail_pointer = next_empty_item;
 
1572
 
 
1573
                                /* Update current item pnt.*/
 
1574
                                curr_item_pnt = next_empty_item;
 
1575
 
 
1576
                                /* Update next item.*/
 
1577
                                next_empty_item = curr_item->forward_link;
 
1578
 
 
1579
                                /* Set first item to be only item in list.*/
 
1580
                                curr_item->forward_link = 0xFFFFFFFF;
 
1581
                        }
 
1582
                        else
 
1583
                        {
 
1584
                                /* Get a free item from the free item list!*/
 
1585
                                curr_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * lh->tail_pointer);
 
1586
                                free_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
 
1587
 
 
1588
                                /* Have current item point to next empty item.*/
 
1589
                                curr_item->forward_link = next_empty_item;
 
1590
 
 
1591
                                /* Update current item pnt.*/
 
1592
                                curr_item_pnt = next_empty_item;
 
1593
 
 
1594
                                /* Update next_empty_item.*/
 
1595
                                next_empty_item = free_item->forward_link;
 
1596
 
 
1597
                                /* Update pointers to current item and free item.*/
 
1598
                                curr_item = free_item;
 
1599
                        }
 
1600
                }
 
1601
                else
 
1602
                {
 
1603
                        /* Update pointers to current item and free item.*/
 
1604
                        free_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
 
1605
 
 
1606
                        /* Have current item point to next empty item.*/
 
1607
                        curr_item->forward_link = next_empty_item;
 
1608
 
 
1609
                        /* Update current item pnt.*/
 
1610
                        curr_item_pnt = next_empty_item;
 
1611
 
 
1612
                        /* Update next_empty_item.*/
 
1613
                        next_empty_item = free_item->forward_link;
 
1614
 
 
1615
                        /* Update pointers to current item and free item.*/
 
1616
                        curr_item = free_item;
 
1617
                }
 
1618
 
 
1619
                /* Copy data to new item.*/
 
1620
                OctApiLlmMemCpy(curr_item->user_info, data_item, user_info_bytes);
 
1621
 
 
1622
                /* Update data_item pointer for next iteration (item).*/
 
1623
                data_item = (void *)((BYTE *)data_item + user_info_bytes);
 
1624
        }
 
1625
 
 
1626
 
 
1627
        /* Terminate list.*/
 
1628
        if ( curr_item != NULL )
 
1629
                curr_item->forward_link = 0xFFFFFFFF;
 
1630
 
 
1631
        /* Update llman structure variables.*/
 
1632
        ls->next_empty_item = next_empty_item;
 
1633
        ls->assigned_items += num_items;
 
1634
 
 
1635
        /* Update list variables.*/
 
1636
        lh->list_length += num_items;
 
1637
        lh->cache_item_pointer = curr_item_pnt;
 
1638
        lh->cache_item_number = lh->list_length - 1;
 
1639
        lh->tail_pointer = curr_item_pnt;
 
1640
 
 
1641
        return(GENERIC_OK);
 
1642
}
 
1643
#endif
 
1644
 
 
1645
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1646
|       API UTILITIES
 
1647
|
 
1648
|       Function:               OctApiLlmListSetItems.
 
1649
|
 
1650
|       Description:    This function takes a start entry (0 to length - 1),
 
1651
|                                       a pointer to a list of data (each item of list is the
 
1652
|                                       size of one data unit, specified at init), and the
 
1653
|                                       length of the data list.  From this, the data will be
 
1654
|                                       copied from the data list to the linked list, from
 
1655
|                                       entry start_entry to (start_entry + data_length - 1).
 
1656
|
 
1657
|  -----------------------------------------------------------------------  
 
1658
|  |   Variable        |     Type     |          Description                
 
1659
|  -----------------------------------------------------------------------  
 
1660
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1661
#if !SKIP_OctApiLlmListSetItems
 
1662
UINT32 OctApiLlmListSetItems(void* l, UINT32 list_handle, UINT32 start_item, UINT32 data_length, void* pdata_list)
 
1663
{
 
1664
        LLM_LIST* ls;
 
1665
        LLM_LIST_HEAD* lh;
 
1666
        LLM_LIST_ITEM* item = NULL;
 
1667
        UINT32 total_lists;
 
1668
        UINT32 item_pnt = 0xFFFFFFFF;
 
1669
        UINT32 i, j;
 
1670
        BYTE* lsbyte;
 
1671
        void* pdata_item = NULL;
 
1672
 
 
1673
 
 
1674
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1675
        /* Build the structure based on the base address:*/
 
1676
        ls = (LLM_LIST *)l;
 
1677
        lsbyte = (BYTE *)ls;
 
1678
        total_lists = ls->total_lists;
 
1679
 
 
1680
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1681
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1682
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1683
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1684
 
 
1685
 
 
1686
 
 
1687
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1688
        /* Make sure list handle is valid.*/
 
1689
        if (list_handle >= ls->total_lists)
 
1690
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1691
        lh = &ls->lh[list_handle];
 
1692
        if (lh->list_length == 0xFFFFFFFF)
 
1693
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1694
 
 
1695
        /* Make sure the start_entry is within limits.*/
 
1696
        if (start_item >= lh->list_length)
 
1697
                return(OCTAPI_LLM_INVALID_PARAMETER);
 
1698
 
 
1699
        /* Make sure the end_entry is within limits.*/
 
1700
        lh = &ls->lh[list_handle];
 
1701
        if ((start_item + data_length) > lh->list_length)
 
1702
                return(OCTAPI_LLM_INVALID_PARAMETER);
 
1703
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1704
 
 
1705
 
 
1706
 
 
1707
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1708
        /* Set the data of each node.*/
 
1709
        for (i=0; i<data_length; i++)
 
1710
        {
 
1711
                /* Obtain pointer to current item.*/
 
1712
                if (i == 0)     
 
1713
                {
 
1714
                        /* Check if location of start item is already cached.  If not, must search
 
1715
                                for it manually.*/
 
1716
                        if (start_item == (lh->cache_item_number + 1))
 
1717
                        {
 
1718
                                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->cache_item_pointer);
 
1719
                                item_pnt = item->forward_link;
 
1720
                                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
 
1721
                        }
 
1722
                        else
 
1723
                        {
 
1724
                                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->head_pointer);
 
1725
                                item_pnt = lh->head_pointer;
 
1726
                                for (j=0; j<start_item; j++)
 
1727
                                {
 
1728
                                        item_pnt = item->forward_link;
 
1729
                                        item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
 
1730
                                }
 
1731
                        }
 
1732
 
 
1733
                        pdata_item = (void *)((BYTE *)pdata_list + (i * ls->user_info_bytes));
 
1734
                }
 
1735
                else
 
1736
                {
 
1737
                        item_pnt = item->forward_link;
 
1738
                        item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
 
1739
 
 
1740
                        pdata_item = (void *)((BYTE *)pdata_item + ls->user_info_bytes);
 
1741
                }
 
1742
 
 
1743
                /* Set the value of the item's user data.*/
 
1744
                OctApiLlmMemCpy(item->user_info, pdata_item, ls->user_info_bytes);
 
1745
        }
 
1746
 
 
1747
        /* Write new cache entry.*/
 
1748
        lh->cache_item_pointer = item_pnt;
 
1749
        lh->cache_item_number = start_item + data_length - 1;
 
1750
 
 
1751
        return(GENERIC_OK);
 
1752
}
 
1753
#endif
 
1754
 
 
1755
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1756
|       API UTILITIES
 
1757
|
 
1758
|       Function:               OctApiLlmListCopyData.
 
1759
|
 
1760
|       Description:    This function takes a start entry (0 to length - 1),
 
1761
|                                       a pointer to a list of data (each item of list is the
 
1762
|                                       size of one data unit, specified at init), and the
 
1763
|                                       length of the data list.  From this, the data will be
 
1764
|                                       copied from the linked list to the data list, from
 
1765
|                                       entry start_entry of the linked list to
 
1766
|                                       (start_entry + data_length - 1).
 
1767
|
 
1768
|  -----------------------------------------------------------------------  
 
1769
|  |   Variable        |     Type     |          Description                
 
1770
|  -----------------------------------------------------------------------  
 
1771
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1772
#if !SKIP_OctApiLlmListCopyData
 
1773
UINT32 OctApiLlmListCopyData(void* l, UINT32 list_handle, UINT32 start_item, UINT32 data_length, void* pdata_list)
 
1774
{
 
1775
        LLM_LIST* ls;
 
1776
        LLM_LIST_HEAD* lh;
 
1777
        LLM_LIST_ITEM* item = NULL;
 
1778
        UINT32 item_pnt = 0xFFFFFFFF;
 
1779
        UINT32 total_lists;
 
1780
        UINT32 i, j;
 
1781
        BYTE* lsbyte;
 
1782
        void* pdata_item = NULL;
 
1783
 
 
1784
 
 
1785
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1786
        /* Build the structure based on the base address:*/
 
1787
        ls = (LLM_LIST *)l;
 
1788
        lsbyte = (BYTE *)ls;
 
1789
        total_lists = ls->total_lists;
 
1790
 
 
1791
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1792
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1793
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1794
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1795
 
 
1796
 
 
1797
 
 
1798
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1799
        /* Make sure list handle is valid.*/
 
1800
        if (list_handle >= ls->total_lists)
 
1801
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1802
        lh = &ls->lh[list_handle];
 
1803
        if (lh->list_length == 0xFFFFFFFF)
 
1804
                return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1805
 
 
1806
        /* Make sure the start_entry is within limits.*/
 
1807
        if (start_item >= lh->list_length)
 
1808
                return(OCTAPI_LLM_INVALID_PARAMETER);
 
1809
 
 
1810
        /* Make sure the end_entry is within limits.*/
 
1811
        lh = &ls->lh[list_handle];
 
1812
        if ((start_item + data_length) > lh->list_length)
 
1813
                return(OCTAPI_LLM_INVALID_PARAMETER);
 
1814
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1815
 
 
1816
 
 
1817
 
 
1818
        /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
 
1819
        /* Set the data of each node.*/
 
1820
        for (i=0; i<data_length; i++)
 
1821
        {
 
1822
                /* Obtain pointer to current item.*/
 
1823
                if (i == 0)     
 
1824
                {
 
1825
                        /* Check if location of start item is already cached.  If not, must search
 
1826
                                for it manually.*/
 
1827
                        if (start_item == (lh->cache_item_number + 1))
 
1828
                        {
 
1829
                                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->cache_item_pointer);
 
1830
                                item_pnt = item->forward_link;
 
1831
                                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
 
1832
                        }
 
1833
                        else
 
1834
                        {
 
1835
                                item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->head_pointer);
 
1836
                                for (j=0; j<start_item; j++)
 
1837
                                {
 
1838
                                        item_pnt = item->forward_link;
 
1839
                                        item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
 
1840
                                }
 
1841
                        }
 
1842
 
 
1843
                        pdata_item = (void *)((BYTE *)pdata_list + (i * ls->user_info_bytes));
 
1844
                }
 
1845
                else
 
1846
                {
 
1847
                        item_pnt = item->forward_link;
 
1848
                        item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
 
1849
 
 
1850
                        pdata_item = (void *)((BYTE *)pdata_item + ls->user_info_bytes);
 
1851
                }
 
1852
 
 
1853
                /* Set the value of the item's user data.*/
 
1854
                OctApiLlmMemCpy(pdata_item, item->user_info, ls->user_info_bytes);
 
1855
        }
 
1856
 
 
1857
        /* Write new cache entry.*/
 
1858
        lh->cache_item_pointer = item_pnt;
 
1859
        lh->cache_item_number = start_item + data_length - 1;
 
1860
 
 
1861
        return(GENERIC_OK);
 
1862
}
 
1863
#endif
 
1864
 
 
1865
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
1866
|       API UTILITIES
 
1867
|
 
1868
|       Function:               OctApiLlmListRemoveItem.
 
1869
|
 
1870
|       Description:    This function deallocates a node of the linked list specified
 
1871
|                                       by the handle list_handle.  
 
1872
|
 
1873
|  -----------------------------------------------------------------------  
 
1874
|  |   Variable        |     Type     |          Description                
 
1875
|  -----------------------------------------------------------------------  
 
1876
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
1877
|       list_handle                     UINT32                  The handle to the list.
 
1878
|       item_number                     UINT32                  The number of the item to be removed.
 
1879
|
 
1880
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
1881
#if !SKIP_OctApiLlmListRemoveItem
 
1882
UINT32 OctApiLlmListRemoveItem(void * l,UINT32 list_handle,UINT32 item_number)
 
1883
{
 
1884
        LLM_LIST* ls;
 
1885
        LLM_LIST_ITEM* freed_item = NULL;
 
1886
        LLM_LIST_HEAD* lh;
 
1887
        UINT32 freed_item_pnt = 0xFFFFFFFF;
 
1888
        UINT32 total_lists;
 
1889
        BYTE* lsbyte;
 
1890
        UINT32  fConditionFlag = TRUE;
 
1891
 
 
1892
        /* Built the structure based on the base address:*/
 
1893
        ls = (LLM_LIST *)l;
 
1894
        lsbyte = (BYTE *)ls;
 
1895
        total_lists = ls->total_lists;
 
1896
 
 
1897
        ls->lh = (LLM_LIST_HEAD *)(lsbyte + sizeof(LLM_LIST));
 
1898
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)));
 
1899
        ls->li = (LLM_LIST_ITEM *)(lsbyte + sizeof(LLM_LIST) + (total_lists * sizeof(LLM_LIST_HEAD)) + ls->head_alloc_size);
 
1900
 
 
1901
        lh = &ls->lh[list_handle];
 
1902
        
 
1903
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
1904
        if (lh->list_length == 0xFFFFFFFF) return(OCTAPI_LLM_INVALID_LIST_HANDLE);
 
1905
        if (lh->list_length <= item_number)     return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
 
1906
 
 
1907
        if (item_number == 0 && lh->list_length == 1)/* First item and only item:*/
 
1908
        {
 
1909
                freed_item_pnt = lh->head_pointer;
 
1910
                freed_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * freed_item_pnt);
 
1911
 
 
1912
                lh->head_pointer = 0xFFFFFFFF;
 
1913
                lh->tail_pointer = 0xFFFFFFFF;
 
1914
 
 
1915
                lh->cache_item_number = 0xFFFFFFFF;
 
1916
                lh->cache_item_pointer = 0xFFFFFFFF;
 
1917
        }
 
1918
        else if (item_number == 0)      /* First item and but list not empty:*/
 
1919
        {
 
1920
                freed_item_pnt = ls->lh[list_handle].head_pointer;
 
1921
                freed_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * freed_item_pnt);
 
1922
 
 
1923
                lh->head_pointer = freed_item->forward_link;
 
1924
 
 
1925
                lh->cache_item_number = 0;
 
1926
                lh->cache_item_pointer = freed_item->forward_link;
 
1927
        }
 
1928
        else    /* Discard non-first item! (Caution: this could be the last item!)*/
 
1929
        {
 
1930
                LLM_LIST_ITEM * last_item = NULL;
 
1931
                LLM_LIST_ITEM * item;
 
1932
                UINT32 last_list_pnt;
 
1933
                UINT32 cur_list_pnt;
 
1934
                UINT32 cur_list_num;
 
1935
 
 
1936
                if (lh->cache_item_number < item_number)        /* Start at cache:*/
 
1937
                {
 
1938
                        cur_list_pnt = lh->cache_item_pointer;
 
1939
                        cur_list_num = lh->cache_item_number;
 
1940
                }
 
1941
                else /* Start at beginning:*/
 
1942
                {
 
1943
                        cur_list_pnt = lh->head_pointer;
 
1944
                        cur_list_num = 0;
 
1945
                }
 
1946
 
 
1947
                last_list_pnt = 0xFFFFFFFF;
 
1948
 
 
1949
                /* Start search from cur_list_pnt and cur_list_num.*/
 
1950
                while( fConditionFlag == TRUE )
 
1951
                {
 
1952
                        item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
1953
 
 
1954
                        if (cur_list_num == item_number) /* Item number found.*/
 
1955
                        {
 
1956
                                if (last_list_pnt == 0xFFFFFFFF) return(OCTAPI_LLM_INTERNAL_ERROR1);
 
1957
 
 
1958
                                if ((item_number + 1) == lh->list_length)
 
1959
                                {
 
1960
                                        lh->tail_pointer = last_list_pnt;
 
1961
                                        last_item->forward_link = 0xFFFFFFFF;
 
1962
                                }
 
1963
                                else
 
1964
                                {
 
1965
                                        last_item->forward_link = item->forward_link;
 
1966
                                }
 
1967
                                freed_item_pnt = cur_list_pnt;
 
1968
                                freed_item = item;
 
1969
 
 
1970
                                /* Reset cache entry.*/
 
1971
                                lh->cache_item_pointer = last_list_pnt;
 
1972
                                lh->cache_item_number = cur_list_num - 1;
 
1973
 
 
1974
                                fConditionFlag = FALSE;
 
1975
                                break;
 
1976
                        }
 
1977
                        else if (item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
 
1978
                        {
 
1979
                                return(OCTAPI_LLM_INTERNAL_ERROR0);
 
1980
                        }
 
1981
                        else /* Item was not found, but continue searching.*/
 
1982
                        {
 
1983
                                last_item = item;
 
1984
                                last_list_pnt = cur_list_pnt;
 
1985
                                cur_list_pnt = item->forward_link;
 
1986
                        }
 
1987
 
 
1988
                        cur_list_num++;
 
1989
                }
 
1990
        }
 
1991
 
 
1992
        /* Decrease the list length.*/
 
1993
        lh->list_length--;
 
1994
        ls->assigned_items--;
 
1995
 
 
1996
        /* Return free block to free block list:*/
 
1997
        freed_item->forward_link = ls->next_empty_item;
 
1998
        ls->next_empty_item = freed_item_pnt;
 
1999
 
 
2000
        return(GENERIC_OK);
 
2001
}
 
2002
#endif
 
2003
 
 
2004
/**************************************** llm2 function section *****************************************/
 
2005
 
 
2006
 
 
2007
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2008
|       API UTILITIES
 
2009
|
 
2010
|       Function:               OctApiLlm2ListGetSize
 
2011
|
 
2012
|       Description:    This function determines the amount of memory needed by
 
2013
|                                       the LLM2_LIST structure to manage the allocation of
 
2014
|                                       number_of_items number of resources.  The memory is
 
2015
|                                       measured in bytes.
 
2016
|
 
2017
|  -----------------------------------------------------------------------  
 
2018
|  |   Variable        |     Type     |          Description                
 
2019
|  -----------------------------------------------------------------------  
 
2020
|       number_of_items         UINT32                  The number of resources to be allocated
 
2021
|                                                                               amongst all linked-lists.
 
2022
|       number_of_lists         UINT32                  The maximum number of linked-lists that
 
2023
|                                                                               can be allocated.
 
2024
|       *l_size UINT32          UINT32                  The amount of memory needed, returned.
 
2025
|
 
2026
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2027
#if !SKIP_OctApiLlm2ListGetSize
 
2028
UINT32 OctApiLlm2ListGetSize(UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size,UINT32 * l_size)
 
2029
{
 
2030
        UINT32 head_alloc_size;
 
2031
        UINT32 result;
 
2032
        UINT32 user_info_size_roundup;
 
2033
 
 
2034
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
2035
        if (number_of_lists == 0) return(GENERIC_BAD_PARAM);
 
2036
        if (user_info_size == 0) return(GENERIC_BAD_PARAM);
 
2037
 
 
2038
        user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
 
2039
 
 
2040
        result = OctapiLlmAllocGetSize(number_of_lists,&head_alloc_size);
 
2041
        if(result != GENERIC_OK) return(result);
 
2042
 
 
2043
        *l_size = sizeof(LLM2_LIST) + (number_of_lists * sizeof(LLM2_LIST_HEAD)) + head_alloc_size + (number_of_items * (sizeof(LLM2_LIST_ITEM) + user_info_size_roundup - 4));
 
2044
 
 
2045
        return(GENERIC_OK);
 
2046
}
 
2047
#endif
 
2048
 
 
2049
#if !SKIP_OctApiLlm2ListGetItemPointer
 
2050
LLM2_LIST_ITEM * OctApiLlm2ListGetItemPointer(LLM2_LIST * ls, UINT32 item_number)
 
2051
{
 
2052
        return (LLM2_LIST_ITEM *) (((BYTE *)ls->li) + (ls->item_size * item_number)) ;
 
2053
}
 
2054
#endif
 
2055
 
 
2056
 
 
2057
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2058
|       API UTILITIES
 
2059
|
 
2060
|       Function:               OctApiLlm2ListInit.
 
2061
|
 
2062
|       Description:    This function intializes the LLM2_TALLOC structure.
 
2063
|
 
2064
|  -----------------------------------------------------------------------  
 
2065
|  |   Variable        |     Type     |          Description                
 
2066
|  -----------------------------------------------------------------------  
 
2067
|       *l                                      void                    The memory used by the LLM2_LIST structure.
 
2068
|       number_of_items         UINT32                  The number of resources to be allocated
 
2069
|                                                                               amongst all linked-lists.
 
2070
|       number_of_lists         UINT32                  The maximum number of linked-lists that
 
2071
|                                                                               can be allocated.
 
2072
|
 
2073
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2074
#if !SKIP_OctApiLlm2ListInit
 
2075
UINT32 OctApiLlm2ListInit(void ** l,UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size)
 
2076
{
 
2077
        LLM2_LIST* ls;
 
2078
        LLM2_LIST_ITEM* item;
 
2079
        UINT32 i;
 
2080
        UINT32 head_alloc_size;
 
2081
        UINT32 result;
 
2082
        UINT32 user_info_size_roundup;
 
2083
        UINT32 total_lists;
 
2084
        BYTE* lsbyte;
 
2085
 
 
2086
 
 
2087
        if (number_of_items == 0) return(GENERIC_BAD_PARAM);
 
2088
        if (number_of_lists == 0) return(GENERIC_BAD_PARAM);
 
2089
        if (user_info_size == 0) return(GENERIC_BAD_PARAM);
 
2090
 
 
2091
        user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
 
2092
 
 
2093
        /* Get the size of the Alloc structure used to manage head of list structures.*/
 
2094
        result = OctapiLlmAllocGetSize(number_of_lists,&head_alloc_size);
 
2095
        if(result != GENERIC_OK) return(result);
 
2096
 
 
2097
        if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
 
2098
 
 
2099
        /* Built the structure based on the base address:*/
 
2100
        ls = (LLM2_LIST *)(*l);
 
2101
        lsbyte = (BYTE *)ls;
 
2102
        total_lists = ls->total_lists;
 
2103
 
 
2104
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2105
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2106
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2107
 
 
2108
        /* Initialize parameters in the structure.*/
 
2109
        ls->head_alloc_size = head_alloc_size;
 
2110
        ls->user_info_bytes = user_info_size;
 
2111
        ls->user_info_size = user_info_size_roundup;
 
2112
        ls->total_items = number_of_items;
 
2113
        ls->assigned_items = 0;
 
2114
        ls->total_lists = number_of_lists;
 
2115
        ls->assigned_lists = 0;
 
2116
        ls->next_empty_item = 0;
 
2117
        ls->item_size = sizeof(LLM2_LIST_ITEM) + user_info_size_roundup - 4;
 
2118
 
 
2119
        /* Complete the build!*/
 
2120
        ls = (LLM2_LIST *)(*l);
 
2121
        lsbyte = (BYTE *)ls;
 
2122
        total_lists = ls->total_lists;
 
2123
 
 
2124
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2125
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2126
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2127
 
 
2128
        /* Initialize the head of queue Alloc structure.*/
 
2129
        result = OctapiLlmAllocInit(&(ls->list_head_alloc),number_of_lists);
 
2130
        if(result != GENERIC_OK) return(result);
 
2131
 
 
2132
        /* Initialize the linked list of the items:*/
 
2133
        for(i=0; i<number_of_items; i++)
 
2134
        {
 
2135
                item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * i);
 
2136
 
 
2137
                if (i == (number_of_items - 1))
 
2138
                        item->forward_link = 0xFFFFFFFF;
 
2139
                else
 
2140
                        item->forward_link = i + 1;
 
2141
        }
 
2142
 
 
2143
        return(GENERIC_OK);
 
2144
}
 
2145
#endif
 
2146
 
 
2147
 
 
2148
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2149
|       API UTILITIES
 
2150
|
 
2151
|       Function:               OctApiLlm2ListCreate.
 
2152
|
 
2153
|       Description:    This function creates a linked list.  The target which is
 
2154
|                                       allocated the newly created list can request additions
 
2155
|                                       or removals from the list later on.  To target identifies
 
2156
|                                       its list with the returned list handle.
 
2157
|
 
2158
|  -----------------------------------------------------------------------  
 
2159
|  |   Variable        |     Type     |          Description                
 
2160
|  -----------------------------------------------------------------------  
 
2161
|       *l                                      void                    The memory used by the LLM_LIST structure.
 
2162
|       *list_handle            UINT32                  The handle to the new list, returned.
 
2163
|
 
2164
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2165
#if !SKIP_OctApiLlm2ListCreate
 
2166
UINT32 OctApiLlm2ListCreate(void * l,UINT32 * list_handle)
 
2167
{
 
2168
        LLM2_LIST* ls;
 
2169
        LLM2_LIST_HEAD* lh;
 
2170
        UINT32 blocknum;
 
2171
        UINT32 total_lists;
 
2172
        UINT32 result;
 
2173
        BYTE* lsbyte;
 
2174
 
 
2175
        /* Built the structure based on the base address:*/
 
2176
        ls = (LLM2_LIST *)l;
 
2177
        lsbyte = (BYTE *)ls;
 
2178
        total_lists = ls->total_lists;
 
2179
 
 
2180
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2181
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2182
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2183
 
 
2184
        /* Get a list using the list head alloc structure.*/
 
2185
        result = OctapiLlmAllocAlloc(ls->list_head_alloc, &blocknum);
 
2186
        if (result != GENERIC_OK) return(result);
 
2187
 
 
2188
        /* The handle is the block number.*/
 
2189
        *list_handle = blocknum;
 
2190
 
 
2191
        /* Initialize the list head structure.*/
 
2192
        lh = &ls->lh[blocknum];
 
2193
        lh->list_length = 0;
 
2194
        lh->head_pointer = 0xFFFFFFFF;
 
2195
        lh->tail_pointer = 0xFFFFFFFF;
 
2196
 
 
2197
        ls->assigned_lists++;
 
2198
 
 
2199
        return(GENERIC_OK);
 
2200
}
 
2201
#endif
 
2202
 
 
2203
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2204
|       API UTILITIES
 
2205
|
 
2206
|       Function:               OctApiLlmListDelete.
 
2207
|
 
2208
|       Description:    This function deletes the linked list indicated by the
 
2209
|                                       handle list_handle.  Any items which are still allocated
 
2210
|                                       to the list are first deallocated.
 
2211
|
 
2212
|  -----------------------------------------------------------------------  
 
2213
|  |   Variable        |     Type     |          Description                
 
2214
|  -----------------------------------------------------------------------  
 
2215
|       *l                                      void                    The memory used by the LLM2_LIST structure.
 
2216
|       *list_handle            UINT32                  The handle to the list.
 
2217
|
 
2218
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2219
#if !SKIP_OctApiLlm2ListDelete
 
2220
UINT32 OctApiLlm2ListDelete(void * l,UINT32 list_handle)
 
2221
{
 
2222
        LLM2_LIST* ls;
 
2223
        LLM2_LIST_HEAD* lh;
 
2224
        UINT32 total_lists;
 
2225
        UINT32 result;
 
2226
        BYTE* lsbyte;
 
2227
 
 
2228
        /* Built the structure based on the base address:*/
 
2229
        ls = (LLM2_LIST *)l;
 
2230
        lsbyte = (BYTE *)ls;
 
2231
        total_lists = ls->total_lists;
 
2232
 
 
2233
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2234
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2235
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2236
 
 
2237
        
 
2238
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM2_BLOCKNUM_OUT_OF_RANGE);
 
2239
        if (ls->lh[list_handle].list_length == 0xFFFFFFFF) return(OCTAPI_LLM2_INVALID_LIST_HANDLE);
 
2240
 
 
2241
        /* Release internal list header handle...*/
 
2242
        result = OctapiLlmAllocDealloc(ls->list_head_alloc,list_handle);
 
2243
        if (result != GENERIC_OK) return(result);
 
2244
 
 
2245
        lh = &ls->lh[list_handle];
 
2246
 
 
2247
        /* Deallocate all items in the list!*/
 
2248
        if (lh->list_length != 0)
 
2249
        {
 
2250
                LLM2_LIST_ITEM * item;
 
2251
 
 
2252
                item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->tail_pointer);
 
2253
 
 
2254
                /* Release the items using only the links.*/
 
2255
                item->forward_link = ls->next_empty_item;
 
2256
                ls->next_empty_item = lh->head_pointer;
 
2257
 
 
2258
                /* Remove items from item counter.*/
 
2259
                ls->assigned_items -= lh->list_length;
 
2260
        }
 
2261
 
 
2262
        lh->list_length = 0xFFFFFFFF;
 
2263
        lh->head_pointer = 0xFFFFFFFF;
 
2264
        lh->tail_pointer = 0xFFFFFFFF;
 
2265
 
 
2266
        ls->assigned_lists--;
 
2267
 
 
2268
        return(GENERIC_OK);
 
2269
}
 
2270
#endif
 
2271
 
 
2272
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2273
|       API UTILITIES
 
2274
|
 
2275
|       Function:               OctApiLlmListLength.
 
2276
|
 
2277
|       Description:    This function returns the number of items allocated to the
 
2278
|                                       list indicated by the handle list_handle.
 
2279
|
 
2280
|  -----------------------------------------------------------------------  
 
2281
|  |   Variable        |     Type     |          Description                
 
2282
|  -----------------------------------------------------------------------  
 
2283
|       *l                                      void                    The memory used by the LLM2_LIST structure.
 
2284
|       list_handle                     UINT32                  The handle to the list.
 
2285
|       *number_of_items        UINT32                  The number of items in the list, returned.
 
2286
|
 
2287
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2288
#if !SKIP_OctApiLlm2ListLength
 
2289
UINT32 OctApiLlm2ListLength(void * l,UINT32 list_handle, UINT32 * number_of_items_in_list)
 
2290
{
 
2291
        LLM2_LIST* ls;
 
2292
        LLM2_LIST_HEAD* lh;
 
2293
        UINT32 total_lists;
 
2294
        BYTE* lsbyte;
 
2295
 
 
2296
        /* Built the structure based on the base address:*/
 
2297
        ls = (LLM2_LIST *)l;
 
2298
        lsbyte = (BYTE *)ls;
 
2299
        total_lists = ls->total_lists;
 
2300
 
 
2301
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2302
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2303
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2304
 
 
2305
        lh = &ls->lh[list_handle];
 
2306
        
 
2307
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM2_BLOCKNUM_OUT_OF_RANGE);
 
2308
        if (lh->list_length == 0xFFFFFFFF) return(OCTAPI_LLM2_INVALID_LIST_HANDLE);
 
2309
 
 
2310
        *number_of_items_in_list = lh->list_length;
 
2311
 
 
2312
        return(GENERIC_OK);
 
2313
}
 
2314
#endif
 
2315
 
 
2316
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2317
|       API UTILITIES
 
2318
|
 
2319
|       Function:               OctApiLlm2ListItemData
 
2320
|
 
2321
|       Description:    This function returns a pointer to the user data associated
 
2322
|                                       with an item.
 
2323
|
 
2324
|  -----------------------------------------------------------------------  
 
2325
|  |   Variable        |     Type     |          Description                
 
2326
|  -----------------------------------------------------------------------  
 
2327
|       *l                                      void                    The memory used by the LLM2_LIST structure.
 
2328
|       list_handle                     UINT32                  The handle to the list.
 
2329
|       item_number                     UINT32                  The number of the list node in question.
 
2330
|       **item_data_pnt         void                    The pointer to the user data, returned.
 
2331
|
 
2332
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2333
#if !SKIP_OctApiLlm2ListItemData
 
2334
UINT32 OctApiLlm2ListItemData(void * l,UINT32 list_handle,UINT32 item_key,void ** item_data_pnt, PUINT32 item_number_pnt)
 
2335
{
 
2336
        LLM2_LIST* ls;
 
2337
        LLM2_LIST_HEAD* lh;
 
2338
        LLM2_LIST_ITEM* item;
 
2339
        UINT32 cur_list_pnt;
 
2340
        UINT32 cur_list_key = 0xFFFFFFFF;
 
2341
        UINT32 total_lists;
 
2342
        UINT32 list_length;
 
2343
        BYTE* lsbyte;
 
2344
        UINT32  fConditionFlag = TRUE;
 
2345
 
 
2346
        /* Built the structure based on the base address:*/
 
2347
        ls = (LLM2_LIST *)l;
 
2348
        lsbyte = (BYTE *)ls;
 
2349
        total_lists = ls->total_lists;
 
2350
 
 
2351
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2352
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2353
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2354
 
 
2355
        lh = &ls->lh[list_handle];
 
2356
        list_length = lh->list_length;
 
2357
        
 
2358
        *item_data_pnt = NULL;
 
2359
        *item_number_pnt = 0;
 
2360
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM2_BLOCKNUM_OUT_OF_RANGE);
 
2361
        if (list_length == 0xFFFFFFFF) return(OCTAPI_LLM2_INVALID_LIST_HANDLE);
 
2362
 
 
2363
        /* Determine where the search will start.*/
 
2364
        /* Start at beginning:*/
 
2365
        cur_list_pnt = lh->head_pointer;
 
2366
        item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
2367
        cur_list_key = item->key;
 
2368
        
 
2369
        /* Start search from cur_list_pnt and cur_list_num.*/
 
2370
        while ( fConditionFlag == TRUE )
 
2371
        {
 
2372
                if (cur_list_key == item_key) /* Item key found.*/
 
2373
                {
 
2374
                        /* Get item info.*/
 
2375
                        *item_data_pnt = (void *)item->user_info;
 
2376
 
 
2377
                        return(GENERIC_OK);
 
2378
                }
 
2379
                else if(item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
 
2380
                {
 
2381
                        return(OCTAPI_LLM2_INTERNAL_ERROR0);
 
2382
                }
 
2383
                else /* Item was not found, but continue searching.*/
 
2384
                {
 
2385
                        cur_list_pnt = item->forward_link;
 
2386
                }
 
2387
 
 
2388
                item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
2389
                cur_list_key = item->key;
 
2390
                (*item_number_pnt)++;
 
2391
        }
 
2392
 
 
2393
        return(GENERIC_OK);
 
2394
}
 
2395
#endif
 
2396
 
 
2397
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2398
|       API UTILITIES
 
2399
|
 
2400
|       Function:               OctApiLlm2ListInsertItem.
 
2401
|
 
2402
|       Description:    This function allocates a node to the linked list specified
 
2403
|                                       by the handle list_handle.  The position of the new item
 
2404
|                                       will be defined based on the key value.  All entry are inserted
 
2405
|                                       in the list in incremental Key value.
 
2406
|
 
2407
|  -----------------------------------------------------------------------  
 
2408
|  |   Variable        |     Type     |          Description                
 
2409
|  -----------------------------------------------------------------------  
 
2410
|       *l                                      void                    The memory used by the LLM2_LIST structure.
 
2411
|       *list_handle            UINT32                  The handle to the list.
 
2412
|       **item_data                     void                    Address of the user data space for this item.
 
2413
|       **prev_item_data        void                    Address of the user data space for the previous item.
 
2414
|
 
2415
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2416
#if !SKIP_OctApiLlm2ListInsertItem
 
2417
UINT32 OctApiLlm2ListInsertItem(void * l,UINT32 list_handle,UINT32 item_key,void ** item_data_pnt, void ** prev_item_data_pnt, void ** prev_prev_item_data_pnt, PUINT32 insert_status_pnt )
 
2418
{
 
2419
        LLM2_LIST* ls;
 
2420
        LLM2_LIST_HEAD* lh;
 
2421
        LLM2_LIST_ITEM* free_item;
 
2422
        UINT32 free_item_pnt;
 
2423
        UINT32 total_lists;
 
2424
        BYTE* lsbyte;
 
2425
        UINT32  ulPassCount = 0;
 
2426
        UINT32  fConditionFlag = TRUE;
 
2427
 
 
2428
        /* Set the status of the insertion.*/
 
2429
        *insert_status_pnt = OCTAPI_LLM2_INSERT_ERROR;
 
2430
 
 
2431
        /* Built the structure based on the base address:*/
 
2432
        ls = (LLM2_LIST *)l;
 
2433
        lsbyte = (BYTE *)ls;
 
2434
        total_lists = ls->total_lists;
 
2435
 
 
2436
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2437
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2438
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2439
 
 
2440
        lh = &ls->lh[list_handle];
 
2441
        
 
2442
        *item_data_pnt = NULL;
 
2443
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM2_BLOCKNUM_OUT_OF_RANGE);
 
2444
        if (lh->list_length == 0xFFFFFFFF) return(OCTAPI_LLM2_INVALID_LIST_HANDLE);
 
2445
        if (ls->next_empty_item == 0xFFFFFFFF) return(OCTAPI_LLM2_NO_STRUCTURES_LEFT);
 
2446
 
 
2447
        /* Get a free item from the free item list!*/
 
2448
        free_item_pnt = ls->next_empty_item;
 
2449
        free_item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * free_item_pnt);
 
2450
        free_item->key = item_key;
 
2451
        ls->next_empty_item = free_item->forward_link;
 
2452
 
 
2453
        if (lh->list_length == 0)       /* First item and only item:*/
 
2454
        {
 
2455
                free_item->forward_link = 0xFFFFFFFF;
 
2456
                lh->tail_pointer = free_item_pnt;
 
2457
                lh->head_pointer = free_item_pnt;
 
2458
                *insert_status_pnt = OCTAPI_LLM2_INSERT_FIRST_NODE;
 
2459
 
 
2460
                /* There is no previous node information to return.*/
 
2461
                *prev_item_data_pnt = NULL;
 
2462
                *prev_prev_item_data_pnt = NULL;
 
2463
        }
 
2464
        else    /* Insert:*/
 
2465
        {
 
2466
                LLM2_LIST_ITEM * last_last_item = NULL;
 
2467
                LLM2_LIST_ITEM * last_item = NULL;
 
2468
                LLM2_LIST_ITEM * item;
 
2469
                UINT32 last_list_pnt;
 
2470
                UINT32 cur_list_pnt;
 
2471
                UINT32 cur_list_key = 0xFFFFFFFF;
 
2472
 
 
2473
                /* Start at beginning:*/
 
2474
                cur_list_pnt = lh->head_pointer;
 
2475
                item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
2476
                cur_list_key = item->key;
 
2477
                
 
2478
                last_list_pnt = 0xFFFFFFFF;
 
2479
 
 
2480
                /* Start search from cur_list_pnt and cur_list_num.*/
 
2481
                while ( fConditionFlag == TRUE )
 
2482
                {
 
2483
                        /* Increment the pass count to determine if the addition will happen next to last.*/
 
2484
                        ulPassCount++;
 
2485
        
 
2486
                        if (cur_list_key >= item_key) /* Item new node between the last and the curent. */
 
2487
                        {
 
2488
                                if (last_list_pnt == 0xFFFFFFFF) /* Must insert at the head of the list.*/
 
2489
                                {
 
2490
                                        free_item->forward_link = cur_list_pnt;
 
2491
                                        lh->head_pointer = free_item_pnt;
 
2492
                                }
 
2493
                                else                                                                    /* Standard insertion.*/
 
2494
                                {
 
2495
                                        free_item->forward_link = cur_list_pnt;
 
2496
                                        last_item->forward_link = free_item_pnt;
 
2497
                                }
 
2498
                        
 
2499
                                /* Check if the entry was made before the last one.*/
 
2500
                                if ( ulPassCount == lh->list_length )
 
2501
                                        *insert_status_pnt = OCTAPI_LLM2_INSERT_BEFORE_LAST_NODE;
 
2502
                                else
 
2503
                                        *insert_status_pnt = OCTAPI_LLM2_INSERT_LIST_NODE;
 
2504
 
 
2505
                                fConditionFlag = FALSE;
 
2506
                                break;
 
2507
                        }
 
2508
                        else if (item->forward_link == 0xFFFFFFFF) /* End of list found, must insert at the end.*/
 
2509
                        {
 
2510
                                free_item->forward_link = 0xFFFFFFFF;
 
2511
                                item->forward_link = free_item_pnt;
 
2512
                                lh->tail_pointer = free_item_pnt;
 
2513
 
 
2514
                                *insert_status_pnt = OCTAPI_LLM2_INSERT_LAST_NODE;
 
2515
 
 
2516
                                fConditionFlag = FALSE;
 
2517
                                break;
 
2518
                        }
 
2519
                        else /* Item was not found, but continue searching.*/
 
2520
                        {
 
2521
                                last_last_item = last_item;
 
2522
                                last_item = item;
 
2523
                                last_list_pnt = cur_list_pnt;
 
2524
                                cur_list_pnt = item->forward_link;
 
2525
                        }
 
2526
 
 
2527
                        item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
2528
                        cur_list_key = item->key;
 
2529
 
 
2530
                }
 
2531
 
 
2532
                /* Return the previous node if possible.*/
 
2533
                if ( *insert_status_pnt == OCTAPI_LLM2_INSERT_LIST_NODE ||
 
2534
                     *insert_status_pnt == OCTAPI_LLM2_INSERT_BEFORE_LAST_NODE )
 
2535
                {
 
2536
                        if ( last_item != NULL )
 
2537
                                *prev_item_data_pnt = (void *)last_item->user_info;
 
2538
 
 
2539
                        if ( last_last_item != NULL )
 
2540
                                *prev_prev_item_data_pnt = (void *)last_last_item->user_info;
 
2541
                        else
 
2542
                                *prev_prev_item_data_pnt = NULL;
 
2543
                }
 
2544
                else
 
2545
                {
 
2546
                        *prev_item_data_pnt = (void *)item->user_info;
 
2547
 
 
2548
                        if ( ( last_last_item != NULL ) && ( last_item != NULL ) )
 
2549
                                *prev_prev_item_data_pnt = (void *)last_item->user_info;
 
2550
                        else
 
2551
                                *prev_prev_item_data_pnt = NULL;
 
2552
                }
 
2553
        }
 
2554
 
 
2555
        /* Increase the list length.*/
 
2556
        lh->list_length++;
 
2557
        ls->assigned_items++;
 
2558
        *item_data_pnt = (void *)free_item->user_info;
 
2559
 
 
2560
        return(GENERIC_OK);
 
2561
}
 
2562
#endif
 
2563
 
 
2564
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2565
|       API UTILITIES
 
2566
|
 
2567
|       Function:               OctApiLlm2ListRemoveItem.
 
2568
|
 
2569
|       Description:    This function deallocates a node of the linked list specified
 
2570
|                                       by the handle list_handle.  
 
2571
|
 
2572
|  -----------------------------------------------------------------------  
 
2573
|  |   Variable        |     Type     |          Description                
 
2574
|  -----------------------------------------------------------------------  
 
2575
|       *l                                      void                    The memory used by the LLM2_LIST structure.
 
2576
|       list_handle                     UINT32                  The handle to the list.
 
2577
|       item_key                        UINT32                  The key of the item to be removed.
 
2578
|
 
2579
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2580
#if !SKIP_OctApiLlm2ListRemoveItem
 
2581
UINT32 OctApiLlm2ListRemoveItem(void * l,UINT32 list_handle,UINT32 item_key, PUINT32 prev_item_key_pnt, PUINT32 prev_prev_item_key_pnt, PUINT32 remove_status_pnt )
 
2582
{
 
2583
        LLM2_LIST* ls;
 
2584
        LLM2_LIST_ITEM* freed_item = NULL;
 
2585
        LLM2_LIST_HEAD* lh;
 
2586
        UINT32 freed_item_pnt = 0xFFFFFFFF;
 
2587
        UINT32 total_lists;
 
2588
        BYTE* lsbyte;
 
2589
        UINT32  fConditionFlag = TRUE;
 
2590
        UINT32  ulPassCount = 0;
 
2591
 
 
2592
        /* Built the structure based on the base address:*/
 
2593
        ls = (LLM2_LIST *)l;
 
2594
        lsbyte = (BYTE *)ls;
 
2595
        total_lists = ls->total_lists;
 
2596
 
 
2597
        /* Set the status of the removal to error as a default value.*/
 
2598
        *remove_status_pnt = OCTAPI_LLM2_REMOVE_ERROR;
 
2599
        
 
2600
        ls->lh = (LLM2_LIST_HEAD *)(lsbyte + sizeof(LLM2_LIST));
 
2601
        ls->list_head_alloc = (void *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)));
 
2602
        ls->li = (LLM2_LIST_ITEM *)(lsbyte + sizeof(LLM2_LIST) + (total_lists * sizeof(LLM2_LIST_HEAD)) + ls->head_alloc_size);
 
2603
 
 
2604
        lh = &ls->lh[list_handle];
 
2605
        
 
2606
        if (list_handle >= ls->total_lists) return(OCTAPI_LLM2_BLOCKNUM_OUT_OF_RANGE);
 
2607
        if (lh->list_length == 0xFFFFFFFF) return(OCTAPI_LLM2_INVALID_LIST_HANDLE);
 
2608
 
 
2609
        if (lh->list_length == 1)/* First item and only item if he matches.*/
 
2610
        {
 
2611
                freed_item_pnt = lh->head_pointer;
 
2612
                freed_item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * freed_item_pnt);
 
2613
 
 
2614
                if ( freed_item->key == item_key )
 
2615
                {
 
2616
                        lh->head_pointer = 0xFFFFFFFF;
 
2617
                        lh->tail_pointer = 0xFFFFFFFF;
 
2618
                }
 
2619
                else
 
2620
                        return(OCTAPI_LLM2_INTERNAL_ERROR1);
 
2621
                
 
2622
                /* Indicate that there was no node prior to the one removed.*/
 
2623
                *prev_item_key_pnt = 0xFFFFFFFF;
 
2624
                *prev_prev_item_key_pnt = 0xFFFFFFFF;
 
2625
                *remove_status_pnt = OCTAPI_LLM2_REMOVE_FIRST_NODE;
 
2626
        }
 
2627
        else    /* Discard non-first item! (Caution: this could be the last item!)*/
 
2628
        {
 
2629
                LLM2_LIST_ITEM * last_last_item = NULL;
 
2630
                LLM2_LIST_ITEM * last_item = NULL;
 
2631
                LLM2_LIST_ITEM * item;
 
2632
                UINT32 last_list_pnt;
 
2633
                UINT32 cur_list_pnt;
 
2634
                UINT32 cur_list_key;
 
2635
 
 
2636
                /* Start at beginning:*/
 
2637
                cur_list_pnt = lh->head_pointer;
 
2638
                item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
2639
                cur_list_key = item->key;
 
2640
                
 
2641
                last_list_pnt = 0xFFFFFFFF;
 
2642
 
 
2643
                /* Start search from cur_list_pnt and cur_list_num.*/
 
2644
                while( fConditionFlag == TRUE )
 
2645
                {
 
2646
                        ulPassCount++;
 
2647
                        if (cur_list_key == item_key) /* Item number found.*/
 
2648
                        {
 
2649
                                if (last_list_pnt == 0xFFFFFFFF)        /* First item in the list.*/
 
2650
                                {
 
2651
                                        lh->head_pointer = item->forward_link;
 
2652
                                        *remove_status_pnt = OCTAPI_LLM2_REMOVE_FIRST_NODE;
 
2653
                                }
 
2654
                                else if ( item->forward_link == 0xFFFFFFFF)     /* Last item of the list.*/
 
2655
                                {
 
2656
                                        last_item->forward_link = 0xFFFFFFFF;
 
2657
                                        lh->tail_pointer = last_list_pnt;
 
2658
                                        *remove_status_pnt = OCTAPI_LLM2_REMOVE_LAST_NODE;
 
2659
                                }
 
2660
                                else
 
2661
                                {
 
2662
                                        last_item->forward_link = item->forward_link;
 
2663
 
 
2664
                                        if ( ulPassCount == ( lh->list_length - 1 ) )
 
2665
                                                *remove_status_pnt = OCTAPI_LLM2_REMOVE_BEFORE_LAST_NODE;
 
2666
                                        else
 
2667
                                                *remove_status_pnt = OCTAPI_LLM2_REMOVE_LIST_NODE;
 
2668
                                }
 
2669
                                        
 
2670
                                freed_item_pnt = cur_list_pnt;
 
2671
                                freed_item = item;
 
2672
 
 
2673
                                fConditionFlag = FALSE;
 
2674
                                break;
 
2675
                        }
 
2676
                        else if (item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
 
2677
                        {
 
2678
                                return(OCTAPI_LLM2_INTERNAL_ERROR0);
 
2679
                        }
 
2680
                        else /* Item was not found, but continue searching.*/
 
2681
                        {
 
2682
                                last_last_item = last_item;
 
2683
                                last_item = item;
 
2684
                                last_list_pnt = cur_list_pnt;
 
2685
                                cur_list_pnt = item->forward_link;
 
2686
                        }
 
2687
 
 
2688
                        item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
 
2689
                        cur_list_key = item->key;
 
2690
                }
 
2691
 
 
2692
                /* Return the key of the node before the node removed if possible.*/
 
2693
                if ( last_list_pnt == 0xFFFFFFFF )
 
2694
                        *prev_item_key_pnt = 0xFFFFFFFF;
 
2695
                else if ( last_item != NULL )
 
2696
                        *prev_item_key_pnt = last_item->key;
 
2697
 
 
2698
                /* Return the key of the node before before the node removed if possible.*/
 
2699
                if ( last_last_item == NULL )
 
2700
                        *prev_prev_item_key_pnt = 0xFFFFFFFF;
 
2701
                else
 
2702
                        *prev_prev_item_key_pnt = last_last_item->key;
 
2703
 
 
2704
        }
 
2705
 
 
2706
        /* Decrease the list length.*/
 
2707
        lh->list_length--;
 
2708
        ls->assigned_items--;
 
2709
 
 
2710
        /* Return free block to free block list:*/
 
2711
        freed_item->forward_link = ls->next_empty_item;
 
2712
        ls->next_empty_item = freed_item_pnt;
 
2713
 
 
2714
        return(GENERIC_OK);
 
2715
}
 
2716
#endif
 
2717
 
 
2718
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
 
2719
|       API UTILITIES
 
2720
|
 
2721
|       Function:               OctApiLlmMemCpy.
 
2722
|
 
2723
|       Description:    This function copies data from a source to a destination.
 
2724
|
 
2725
|  -----------------------------------------------------------------------  
 
2726
|  |   Variable        |     Type     |          Description                
 
2727
|  -----------------------------------------------------------------------  
 
2728
|       *f_pvDestination        VOID                    The destination where to copy the data.
 
2729
|       *f_pvSource                     VOID                    The source where to copy the data from.
 
2730
|       f_ulSize                        UINT32                  The number of bytes to copy.
 
2731
|
 
2732
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
 
2733
#if !SKIP_OctApiLlmMemCpy
 
2734
VOID * OctApiLlmMemCpy( VOID *f_pvDestination, const VOID * f_pvSource, UINT32 f_ulSize )
 
2735
{
 
2736
    CHAR * pbyDst;
 
2737
    const CHAR * pbySrc;
 
2738
    UINT32 * f_pulAlignedDst;
 
2739
    const UINT32 * f_pulAlignedSrc;
 
2740
    
 
2741
    pbyDst = (CHAR *)f_pvDestination;
 
2742
    pbySrc = (const CHAR *)f_pvSource;
 
2743
 
 
2744
    /* 
 
2745
     * If the size is small, or either SRC or DST is unaligned,
 
2746
     * then punt into the byte copy loop.  This should be rare.
 
2747
     */
 
2748
    if ( ( f_ulSize < sizeof(UINT32) ) 
 
2749
                || ( ( (unsigned long)( pbySrc ) & ( sizeof(UINT32) - 1 ) ) | ( (unsigned long)( pbyDst ) & ( sizeof(UINT32) - 1 ) ) ) )
 
2750
    {
 
2751
        while ( f_ulSize-- )
 
2752
            *pbyDst++ = *pbySrc++;
 
2753
        return f_pvDestination;
 
2754
    }
 
2755
    
 
2756
    f_pulAlignedDst = (UINT32 *)pbyDst;
 
2757
    f_pulAlignedSrc = (const UINT32 *)pbySrc;
 
2758
    
 
2759
    /* Copy 4X long words at a time if possible. */
 
2760
    while ( f_ulSize >= 4 * sizeof(UINT32) )
 
2761
    {
 
2762
        *f_pulAlignedDst++ = *f_pulAlignedSrc++;
 
2763
        *f_pulAlignedDst++ = *f_pulAlignedSrc++;
 
2764
        *f_pulAlignedDst++ = *f_pulAlignedSrc++;
 
2765
        *f_pulAlignedDst++ = *f_pulAlignedSrc++;
 
2766
        f_ulSize -= 4 * sizeof(UINT32);
 
2767
    } 
 
2768
    
 
2769
    /* Copy one long word at a time if possible. */
 
2770
    while ( f_ulSize >= sizeof(UINT32) )
 
2771
    {
 
2772
        *f_pulAlignedDst++ = *f_pulAlignedSrc++;
 
2773
        f_ulSize -= sizeof(UINT32);
 
2774
    }
 
2775
    
 
2776
    /* Pick up any residual with a byte copier. */
 
2777
    pbyDst = (CHAR *)f_pulAlignedDst;
 
2778
    pbySrc = (const CHAR *)f_pulAlignedSrc;
 
2779
    while ( f_ulSize-- )
 
2780
        *pbyDst++ = *pbySrc++;
 
2781
    
 
2782
    return f_pvDestination;
 
2783
}
 
2784
#endif
 
2785
 
 
2786
/**************************************** llm_list section **********************************************/
 
2787