1
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
5
Copyright (c) 2001-2007 Octasic Inc.
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.
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.
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
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.
27
$Octasic_Release: OCT612xAPI-01.00-PR49 $
29
$Octasic_Revision: 22 $
31
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
32
#include "octapi_llman_private.h"
33
#include "apilib/octapi_llman.h"
34
#include "apilib/octapi_largmath.h"
37
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
40
| Function: OctapiLlmAllocGetSize.
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.
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.
52
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
53
#if !SKIP_OctapiLlmAllocGetSize
54
UINT32 OctapiLlmAllocGetSize(UINT32 number_of_items,UINT32 * l_size)
56
if (number_of_items == 0) return(GENERIC_BAD_PARAM);
58
*l_size = (sizeof(LLM_ALLOC)) + (number_of_items * sizeof(UINT32));
64
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
67
| Function: OctapiLlmAllocInit.
69
| Description: This function intializes the LLM_ALLOC structure.
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.
77
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
78
#if !SKIP_OctapiLlmAllocInit
79
UINT32 OctapiLlmAllocInit(void ** l,UINT32 number_of_items)
84
/* Check the number of items required.*/
85
if (number_of_items == 0) return(GENERIC_BAD_PARAM);
87
/* If no memory has been allocated yet:*/
88
if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
90
/* Build the structure before starting.*/
91
ls = (LLM_ALLOC *)(*l);
92
ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
94
ls->number_of_items = number_of_items;
96
/* Linked list links all structures in ascending order.*/
97
for(i=0;i<number_of_items;i++)
99
ls->linked_list[i] = i+1;
102
ls->linked_list[number_of_items - 1] = 0xFFFFFFFF; /* Invalid link.*/
104
/* Next avail is 0.*/
105
ls->next_avail_num = 0;
107
/* Number of allocated items is null.*/
108
ls->allocated_items = 0;
114
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
117
| Function: OctapiLlmAllocInfo.
119
| Description: This function returns the number of free and allocated
120
| block in the LLMAN list.
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.
129
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
130
#if !SKIP_OctapiLlmAllocInfo
131
UINT32 OctapiLlmAllocInfo(void * l,UINT32 * allocated_items,UINT32 * available_items)
135
/* Build the structure before starting.*/
137
ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
139
*allocated_items = ls->allocated_items;
140
*available_items = ls->number_of_items - ls->allocated_items;
145
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
148
| Function: OctapiLlmAllocInfo.
150
| Description: This function allocates the resource indicated by blocknum.
151
| If the resource can be allocated then GENERIC_OK is returned.
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.
160
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
161
#if !SKIP_OctapiLlmAllocAlloc
162
UINT32 OctapiLlmAllocAlloc(void * l,UINT32 * blocknum)
165
UINT32 allocated_block;
168
/* Build the structure before starting.*/
170
ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
172
/* Get next available block number.*/
173
allocated_block = ls->next_avail_num;
175
/* Check if block is invalid.*/
176
if (allocated_block == 0xFFFFFFFF)
178
/* Make blocknum NULL.*/
179
*blocknum = 0xFFFFFFFF;
181
return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
184
node = &ls->linked_list[allocated_block];
186
/* Copy next block number.*/
187
ls->next_avail_num = *node;
189
/* Tag as used the current block number.*/
192
/* Return proper block number.*/
193
*blocknum = allocated_block;
195
/* Update block usage number.*/
196
ls->allocated_items++;
202
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
205
| Function: OctapiLlmAllocDealloc.
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.
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.
217
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
218
#if !SKIP_OctapiLlmAllocDealloc
219
UINT32 OctapiLlmAllocDealloc(void * l,UINT32 blocknum)
224
/* Build the structure before starting.*/
226
ls->linked_list = (UINT32 *)((BYTE *)ls + sizeof(LLM_ALLOC));
228
/* Check for null item pointer.*/
229
if (blocknum == 0xFFFFFFFF) return(GENERIC_OK);
231
/* Check if blocknum is within specified item range.*/
232
if (blocknum >= ls->number_of_items) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
234
node = &ls->linked_list[blocknum];
236
/* Check if block is really used as of now.*/
237
if (*node != 0xFFFFFFFE) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
239
/* Add link to list.*/
240
*node = ls->next_avail_num;
242
/* Point to returned block.*/
243
ls->next_avail_num = blocknum;
245
/* Update block usage number.*/
246
ls->allocated_items--;
253
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
256
| Function: OctApiTllmAllocGetSize.
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.
262
| This version is a time manage version of llman.
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.
270
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
271
#if !SKIP_OctApiTllmAllocGetSize
272
UINT32 OctApiTllmAllocGetSize(UINT32 number_of_items,UINT32 * l_size)
274
if (number_of_items == 0) return(GENERIC_BAD_PARAM);
276
*l_size = (sizeof(TLLM_ALLOC)) + (number_of_items * sizeof(TLLM_ALLOC_NODE));
282
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
285
| Function: OctApiTllmAllocInit.
287
| Description: This function intializes the TLLM_ALLOC structure.
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.
295
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
296
#if !SKIP_OctApiTllmAllocInit
297
UINT32 OctApiTllmAllocInit(void ** l,UINT32 number_of_items)
302
/* Check the number of items required.*/
303
if (number_of_items == 0) return(GENERIC_BAD_PARAM);
305
/* If no memory has been allocated yet.*/
306
if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
308
/* Build the structure before starting.*/
309
ls = (TLLM_ALLOC *)(*l);
310
ls->linked_list = (TLLM_ALLOC_NODE *)((BYTE *)ls + sizeof(TLLM_ALLOC));
312
ls->number_of_items = number_of_items;
314
/* Linked list links all structures in ascending order.*/
315
for(i=0;i<number_of_items;i++)
317
ls->linked_list[i].value = i+1;
320
ls->linked_list[number_of_items - 1].value = 0xFFFFFFFF; /* Invalid link.*/
322
/* Next avail is 0.*/
323
ls->next_avail_num = 0;
325
/* Number of allocated items is null.*/
326
ls->allocated_items = 0;
328
/* Set the number of timeout entry.*/
329
ls->number_of_timeout = 0;
331
/* Next timeout is 0.*/
332
ls->next_timeout_num = 0xFFFFFFFF;
333
ls->last_timeout_num = 0xFFFFFFFF;
335
/* Set the known time to 0.*/
336
ls->last_known_time[ 0 ] = 0;
337
ls->last_known_time[ 1 ] = 0;
343
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
346
| Function: OctApiTllmAllocInfo.
348
| Description: This function returns the number of free and allocated
349
| block in the TLLMAN list.
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.
358
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
359
#if !SKIP_OctApiTllmAllocInfo
360
UINT32 OctApiTllmAllocInfo(void * l,UINT32 * allocated_items,UINT32 * available_items)
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;
373
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
376
| Function: OctApiTllmAllocAlloc.
378
| Description: This function allocates the resource indicated by blocknum.
379
| If the resource can be allocated then GENERIC_OK is returned.
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
389
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
390
#if !SKIP_OctApiTllmAllocAlloc
391
UINT32 OctApiTllmAllocAlloc(void * l,UINT32 * blocknum, UINT32 *current_time)
394
UINT32 allocated_block;
395
TLLM_ALLOC_NODE* node;
397
/* Build the structure before starting.*/
398
ls = (TLLM_ALLOC *)l;
399
ls->linked_list = (TLLM_ALLOC_NODE *)((BYTE *)ls + sizeof(TLLM_ALLOC));
401
if ( ls->allocated_items == ls->number_of_items &&
402
ls->next_timeout_num != 0xFFFFFFFF )
405
l_ulResult = OctApiTllmCheckTimeoutList( ls, current_time );
406
if ( l_ulResult != GENERIC_OK )
410
/* Get next available block number.*/
411
allocated_block = ls->next_avail_num;
413
/* Check if block is invalid.*/
414
if (allocated_block == 0xFFFFFFFF)
416
/* Make blocknum NULL.*/
417
*blocknum = 0xFFFFFFFF;
419
return(OCTAPI_LLM_NO_STRUCTURES_LEFT);
422
node = &ls->linked_list[allocated_block];
424
/* Copy next block number.*/
425
ls->next_avail_num = node->value;
427
/* Tag as used the current block number.*/
428
node->value = 0xFFFFFFFE;
430
/* Return proper block number.*/
431
*blocknum = allocated_block;
433
/* Update block usage number.*/
434
ls->allocated_items++;
440
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
443
| Function: OctApiTllmAllocDealloc.
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.
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.
455
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
456
#if !SKIP_OctApiTllmAllocDealloc
457
UINT32 OctApiTllmAllocDealloc(void * l,UINT32 blocknum, UINT32 timeout_value, UINT32 current_time[2])
460
TLLM_ALLOC_NODE* node;
463
/* Build the structure before starting.*/
464
ls = (TLLM_ALLOC *)l;
465
ls->linked_list = (TLLM_ALLOC_NODE *)((BYTE *)ls + sizeof(TLLM_ALLOC));
467
/* Check for null item pointer.*/
468
if (blocknum == 0xFFFFFFFF) return(GENERIC_OK);
470
/* Check if blocknum is within specified item range.*/
471
if (blocknum >= ls->number_of_items) return(OCTAPI_LLM_BLOCKNUM_OUT_OF_RANGE);
473
if ( ls->next_timeout_num != 0xFFFFFFFF )
475
l_ulResult = OctApiTllmCheckTimeoutList( ls, current_time );
476
if ( l_ulResult != GENERIC_OK )
480
node = &ls->linked_list[blocknum];
482
/* Check if block is really used as of now.*/
483
if (node->value != 0xFFFFFFFE) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
485
/* Add link to timeout list.*/
486
if ( ls->last_timeout_num != 0xFFFFFFFF )
488
TLLM_ALLOC_NODE* last_node;
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;
497
/* The node is alone in the list.*/
498
node->value = 0xFFFFFFFF;
499
ls->next_timeout_num = blocknum;
502
ls->last_timeout_num = blocknum;
503
ls->number_of_timeout++;
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)
514
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
517
| Function: OctApiTllmCheckTimeoutList.
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.
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.
530
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
531
#if !SKIP_OctApiTllmCheckTimeoutList
532
UINT32 OctApiTllmCheckTimeoutList(TLLM_ALLOC *ls, UINT32 current_time[2])
535
UINT32 fConditionFlag = TRUE;
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.*/
542
TLLM_ALLOC_NODE *pcurrent_node;
546
/* Remember time for next time!*/
547
ls->last_known_time[0] = current_time[0];
548
ls->last_known_time[1] = current_time[1];
551
while ( fConditionFlag == TRUE )
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;
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);
561
/* if the timeout tiem was exceeded, set the block as free.*/
564
/* set the next node pointer.*/
565
ls->next_timeout_num = pcurrent_node->value;
566
ls->number_of_timeout--;
568
/* reset the last pointer of the timeout list.*/
569
if ( ls->number_of_timeout == 0 )
570
ls->last_timeout_num = 0xFFFFFFFF;
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--;
577
else /* node not in timeout */
579
fConditionFlag = FALSE;
583
if ( ls->next_timeout_num == 0xFFFFFFFF )
585
fConditionFlag = FALSE;
586
break; /* end of timeout list.*/
594
/**************************************** llm_alloc section **********************************************/
602
/**************************************** llm_list section **********************************************/
603
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
606
| Function: OctApiLlmListGetSize
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
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
620
| *l_size UINT32 UINT32 The amount of memory needed, returned.
622
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
623
#if !SKIP_OctApiLlmListGetSize
624
UINT32 OctApiLlmListGetSize(UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size,UINT32 * l_size)
626
UINT32 head_alloc_size;
628
UINT32 user_info_size_roundup;
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);
634
user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
636
result = OctapiLlmAllocGetSize(number_of_lists,&head_alloc_size);
637
if(result != GENERIC_OK) return(result);
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));
645
#if !SKIP_OctApiLlmListGetItemPointer
646
LLM_LIST_ITEM * OctApiLlmListGetItemPointer(LLM_LIST * ls, UINT32 item_number)
648
return (LLM_LIST_ITEM *) (((BYTE *)ls->li) + (ls->item_size * item_number)) ;
653
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
656
| Function: OctApiLlmListInit.
658
| Description: This function intializes the LLM_TALLOC structure.
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
669
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
670
#if !SKIP_OctApiLlmListInit
671
UINT32 OctApiLlmListInit(void ** l,UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size)
676
UINT32 head_alloc_size;
678
UINT32 user_info_size_roundup;
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);
687
user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
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);
693
if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
695
/* Built the structure based on the base address:*/
696
ls = (LLM_LIST *)(*l);
698
total_lists = ls->total_lists;
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);
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;
715
/* Complete the build!*/
716
ls = (LLM_LIST *)(*l);
718
total_lists = ls->total_lists;
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);
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);
728
/* Initialize the linked list of the items:*/
729
for(i=0; i<number_of_items; i++)
731
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * i);
733
if (i == (number_of_items - 1))
734
item->forward_link = 0xFFFFFFFF;
736
item->forward_link = i + 1;
743
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
746
| Function: OctApiLlmListInfo.
748
| Description: This function returns the status of the LLM_LIST structure.
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.
759
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
760
#if !SKIP_OctApiLlmListInfo
761
UINT32 OctApiLlmListInfo(void * l,UINT32 * allocated_lists,UINT32 * allocated_items,
762
UINT32 * free_lists,UINT32 * free_items)
768
/* Built the structure based on the base address:*/
771
total_lists = ls->total_lists;
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);
777
*allocated_items = ls->assigned_items;
778
*free_items = ls->total_items - ls->assigned_items;
780
*allocated_lists = ls->assigned_lists;
781
*free_lists = ls->total_lists - ls->assigned_lists;
787
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
790
| Function: OctApiLlmListCreate.
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.
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.
803
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
804
#if !SKIP_OctApiLlmListCreate
805
UINT32 OctApiLlmListCreate(void * l,UINT32 * list_handle)
814
/* Built the structure based on the base address:*/
817
total_lists = ls->total_lists;
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);
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);
827
/* The handle is the block number.*/
828
*list_handle = blocknum;
830
/* Initialize the list head structure.*/
831
lh = &ls->lh[blocknum];
833
lh->head_pointer = 0xFFFFFFFF;
834
lh->tail_pointer = 0xFFFFFFFF;
835
lh->cache_item_number = 0xFFFFFFFF;
836
lh->cache_item_pointer = 0xFFFFFFFF;
838
ls->assigned_lists++;
844
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
847
| Function: OctApiLlmListDelete.
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.
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.
859
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
860
#if !SKIP_OctApiLlmListDelete
861
UINT32 OctApiLlmListDelete(void * l,UINT32 list_handle)
869
/* Built the structure based on the base address:*/
872
total_lists = ls->total_lists;
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);
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);
882
/* Release internal list header handle...*/
883
result = OctapiLlmAllocDealloc(ls->list_head_alloc,list_handle);
884
if (result != GENERIC_OK) return(result);
886
lh = &ls->lh[list_handle];
888
/* Deallocate all items in the list!*/
889
if (lh->list_length != 0)
891
LLM_LIST_ITEM * item;
893
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->tail_pointer);
895
/* Release the items using only the links.*/
896
item->forward_link = ls->next_empty_item;
897
ls->next_empty_item = lh->head_pointer;
899
/* Remove items from item counter.*/
900
ls->assigned_items -= lh->list_length;
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;
909
ls->assigned_lists--;
915
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
918
| Function: OctApiLlmListLength.
920
| Description: This function returns the number of items allocated to the
921
| list indicated by the handle list_handle.
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.
930
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
931
#if !SKIP_OctApiLlmListLength
932
UINT32 OctApiLlmListLength(void * l,UINT32 list_handle, UINT32 * number_of_items_in_list)
939
/* Built the structure based on the base address:*/
942
total_lists = ls->total_lists;
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);
948
lh = &ls->lh[list_handle];
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);
953
*number_of_items_in_list = lh->list_length;
959
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
962
| Function: OctApiLlmListItemData
964
| Description: This function returns a pointer to the user data associated
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.
975
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
976
#if !SKIP_OctApiLlmListItemData
977
UINT32 OctApiLlmListItemData(void * l,UINT32 list_handle,UINT32 item_number,void ** item_data_pnt)
987
UINT32 fConditionFlag = TRUE;
989
/* Built the structure based on the base address:*/
992
total_lists = ls->total_lists;
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);
998
lh = &ls->lh[list_handle];
999
list_length = lh->list_length;
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);
1006
/* Determine where the search will start.*/
1007
if (list_length == (item_number + 1)) /* Last item in list:*/
1009
cur_list_pnt = lh->tail_pointer;
1010
cur_list_num = item_number;
1012
else if (lh->cache_item_number <= item_number) /* Start at cache:*/
1014
cur_list_pnt = lh->cache_item_pointer;
1015
cur_list_num = lh->cache_item_number;
1017
else /* Start at beginning:*/
1019
cur_list_pnt = lh->head_pointer;
1023
/* Start search from cur_list_pnt and cur_list_num.*/
1024
while ( fConditionFlag == TRUE )
1026
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
1028
if (cur_list_num == item_number) /* Item number found.*/
1030
/* Write new cache entry.*/
1031
lh->cache_item_pointer = cur_list_pnt;
1032
lh->cache_item_number = cur_list_num;
1035
*item_data_pnt = (void *)item->user_info;
1039
else if(item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
1041
return(OCTAPI_LLM_INTERNAL_ERROR0);
1043
else /* Item was not found, but continue searching.*/
1045
cur_list_pnt = item->forward_link;
1055
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1058
| Function: OctApiLlmListInsertItem.
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.
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.
1073
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1074
#if !SKIP_OctApiLlmListInsertItem
1075
UINT32 OctApiLlmListInsertItem(void * l,UINT32 list_handle,UINT32 item_number,void ** item_data_pnt)
1079
LLM_LIST_ITEM* free_item;
1080
UINT32 free_item_pnt;
1083
UINT32 fConditionFlag = TRUE;
1085
/* Built the structure based on the base address:*/
1087
lsbyte = (BYTE *)ls;
1088
total_lists = ls->total_lists;
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);
1094
lh = &ls->lh[list_handle];
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);
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;
1108
if (item_number == 0xFFFFFFFF)
1109
item_number = lh->list_length;
1111
if (lh->list_length == 0) /* First item and only item:*/
1113
free_item->forward_link = 0xFFFFFFFF;
1114
lh->tail_pointer = free_item_pnt;
1115
lh->head_pointer = free_item_pnt;
1117
else if (item_number == 0) /* First item and but list not empty:*/
1119
free_item->forward_link = lh->head_pointer;
1120
lh->head_pointer = free_item_pnt;
1122
else if (item_number == lh->list_length) /* Append:*/
1124
LLM_LIST_ITEM * last_item;
1125
last_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->tail_pointer);
1127
last_item->forward_link = free_item_pnt;
1128
free_item->forward_link = 0xFFFFFFFF;
1129
lh->tail_pointer = free_item_pnt;
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;
1139
if (lh->cache_item_number < item_number) /* Start at cache:*/
1141
cur_list_pnt = lh->cache_item_pointer;
1142
cur_list_num = lh->cache_item_number;
1144
else /* Start at beginning:*/
1146
cur_list_pnt = lh->head_pointer;
1150
last_list_pnt = 0xFFFFFFFF;
1152
/* Start search from cur_list_pnt and cur_list_num.*/
1153
while ( fConditionFlag == TRUE )
1155
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
1157
if (cur_list_num == item_number) /* Item number found.*/
1159
if (last_list_pnt == 0xFFFFFFFF) return(OCTAPI_LLM_INTERNAL_ERROR1);
1161
free_item->forward_link = cur_list_pnt;
1162
last_item->forward_link = free_item_pnt;
1164
fConditionFlag = FALSE;
1167
else if (item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
1169
return(OCTAPI_LLM_INTERNAL_ERROR0);
1171
else /* Item was not found, but continue searching.*/
1174
last_list_pnt = cur_list_pnt;
1175
cur_list_pnt = item->forward_link;
1182
/* Increase the list length.*/
1184
ls->assigned_items++;
1185
*item_data_pnt = (void *)free_item->user_info;
1187
/* Write new cache entry.*/
1188
lh->cache_item_pointer = free_item_pnt;
1189
lh->cache_item_number = item_number;
1195
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1198
| Function: OctApiLlmListCreateFull.
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.
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)
1219
LLM_LIST_ITEM* free_item;
1220
LLM_LIST_ITEM* last_item = NULL;
1221
UINT32 free_item_pnt = 0xFFFFFFFF;
1224
UINT32 list_length_m1;
1225
UINT32 next_empty_item;
1231
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1232
/* Build the structure based on the base address:*/
1234
lsbyte = (BYTE *)ls;
1235
total_lists = ls->total_lists;
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1244
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1245
/* Make sure another list can be created.*/
1246
if (ls->assigned_lists == ls->total_lists)
1247
return(OCTAPI_LLM_ELEMENT_ALREADY_ASSIGNED);
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
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);
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;
1268
ls->assigned_lists++;
1269
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
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;
1279
for (i=0; i<list_length; i++)
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;
1286
/* Branch according to whether the node is the first in list, last, or in
1291
free_item->forward_link = 0xFFFFFFFF;
1292
lh->head_pointer = free_item_pnt;
1293
lh->tail_pointer = free_item_pnt;
1295
else if (i == list_length_m1)
1298
last_item->forward_link = free_item_pnt;
1299
free_item->forward_link = 0xFFFFFFFF;
1300
lh->tail_pointer = free_item_pnt;
1304
/* Node somewhere in the middle.*/
1305
last_item->forward_link = free_item_pnt;
1308
/* Store pointer to free item as pointer to last item (for next iteration).*/
1309
last_item = free_item;
1312
/* Store new value of next_empty_item.*/
1313
ls->next_empty_item = next_empty_item;
1315
/* Write new cache entry.*/
1316
lh->cache_item_pointer = free_item_pnt;
1317
lh->cache_item_number = list_length_m1;
1319
/* Set the list length.*/
1320
lh->list_length = list_length;
1321
ls->assigned_items += list_length;
1323
/* Return pointer to new list.*/
1324
*plist_handle = list_handle;
1330
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1333
| Function: OctApiLlmListAppendItems.
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.
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)
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;
1359
UINT32 next_empty_item;
1365
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1366
/* Build the structure based on the base address:*/
1368
lsbyte = (BYTE *)ls;
1369
total_lists = ls->total_lists;
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1378
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1379
/* Make sure list handle is valid.*/
1380
if (list_handle >= ls->total_lists)
1381
return(OCTAPI_LLM_INVALID_LIST_HANDLE);
1383
/* Make sure there is at least one item.*/
1385
return(OCTAPI_LLM_INVALID_PARAMETER);
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1402
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1403
/* Add the number of requested nodes to the list.*/
1405
item_size = ls->item_size;
1406
next_empty_item = ls->next_empty_item;
1408
for (i=0; i<num_items; i++)
1412
if (lh->head_pointer == 0xFFFFFFFF)
1414
/* Current and next items are one and the same!*/
1415
curr_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
1417
/* Set new head and tail pointers.*/
1418
lh->head_pointer = next_empty_item;
1419
lh->tail_pointer = next_empty_item;
1421
/* Update current item pnt.*/
1422
curr_item_pnt = next_empty_item;
1424
/* Update next item.*/
1425
next_empty_item = curr_item->forward_link;
1427
/* Set first item to be only item in list.*/
1428
curr_item->forward_link = 0xFFFFFFFF;
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);
1436
/* Have current item point to next empty item.*/
1437
curr_item->forward_link = next_empty_item;
1439
/* Update current item pnt.*/
1440
curr_item_pnt = next_empty_item;
1442
/* Update next_empty_item.*/
1443
next_empty_item = free_item->forward_link;
1445
/* Update pointers to current item and free item.*/
1446
curr_item = free_item;
1451
/* Update pointers to current item and free item.*/
1452
free_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
1454
/* Have current item point to next empty item.*/
1455
curr_item->forward_link = next_empty_item;
1457
/* Update current item pnt.*/
1458
curr_item_pnt = next_empty_item;
1460
/* Update next_empty_item.*/
1461
next_empty_item = free_item->forward_link;
1463
/* Update pointers to current item and free item.*/
1464
curr_item = free_item;
1468
/* Terminate list.*/
1469
if ( curr_item != NULL )
1470
curr_item->forward_link = 0xFFFFFFFF;
1472
/* Update llman structure variables.*/
1473
ls->next_empty_item = next_empty_item;
1474
ls->assigned_items += num_items;
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;
1486
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1489
| Function: OctApiLlmListAppendAndSetItems.
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)
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;
1507
UINT32 next_empty_item;
1508
UINT32 user_info_bytes;
1515
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1516
/* Build the structure based on the base address:*/
1518
lsbyte = (BYTE *)ls;
1519
total_lists = ls->total_lists;
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1528
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1529
/* Make sure list handle is valid.*/
1530
if (list_handle >= ls->total_lists)
1531
return(OCTAPI_LLM_INVALID_LIST_HANDLE);
1533
/* Make sure there is at least one item.*/
1535
return(OCTAPI_LLM_INVALID_PARAMETER);
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1552
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1553
/* Add the number of requested nodes to the list.*/
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;
1560
for (i=0; i<num_items; i++)
1564
if (lh->head_pointer == 0xFFFFFFFF)
1566
/* Current and next items are one and the same!*/
1567
curr_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
1569
/* Set new head and tail pointers.*/
1570
lh->head_pointer = next_empty_item;
1571
lh->tail_pointer = next_empty_item;
1573
/* Update current item pnt.*/
1574
curr_item_pnt = next_empty_item;
1576
/* Update next item.*/
1577
next_empty_item = curr_item->forward_link;
1579
/* Set first item to be only item in list.*/
1580
curr_item->forward_link = 0xFFFFFFFF;
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);
1588
/* Have current item point to next empty item.*/
1589
curr_item->forward_link = next_empty_item;
1591
/* Update current item pnt.*/
1592
curr_item_pnt = next_empty_item;
1594
/* Update next_empty_item.*/
1595
next_empty_item = free_item->forward_link;
1597
/* Update pointers to current item and free item.*/
1598
curr_item = free_item;
1603
/* Update pointers to current item and free item.*/
1604
free_item = (LLM_LIST_ITEM *)((BYTE *)item_list + item_size * next_empty_item);
1606
/* Have current item point to next empty item.*/
1607
curr_item->forward_link = next_empty_item;
1609
/* Update current item pnt.*/
1610
curr_item_pnt = next_empty_item;
1612
/* Update next_empty_item.*/
1613
next_empty_item = free_item->forward_link;
1615
/* Update pointers to current item and free item.*/
1616
curr_item = free_item;
1619
/* Copy data to new item.*/
1620
OctApiLlmMemCpy(curr_item->user_info, data_item, user_info_bytes);
1622
/* Update data_item pointer for next iteration (item).*/
1623
data_item = (void *)((BYTE *)data_item + user_info_bytes);
1627
/* Terminate list.*/
1628
if ( curr_item != NULL )
1629
curr_item->forward_link = 0xFFFFFFFF;
1631
/* Update llman structure variables.*/
1632
ls->next_empty_item = next_empty_item;
1633
ls->assigned_items += num_items;
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;
1645
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1648
| Function: OctApiLlmListSetItems.
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).
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)
1666
LLM_LIST_ITEM* item = NULL;
1668
UINT32 item_pnt = 0xFFFFFFFF;
1671
void* pdata_item = NULL;
1674
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1675
/* Build the structure based on the base address:*/
1677
lsbyte = (BYTE *)ls;
1678
total_lists = ls->total_lists;
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
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);
1695
/* Make sure the start_entry is within limits.*/
1696
if (start_item >= lh->list_length)
1697
return(OCTAPI_LLM_INVALID_PARAMETER);
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1707
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1708
/* Set the data of each node.*/
1709
for (i=0; i<data_length; i++)
1711
/* Obtain pointer to current item.*/
1714
/* Check if location of start item is already cached. If not, must search
1716
if (start_item == (lh->cache_item_number + 1))
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);
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++)
1728
item_pnt = item->forward_link;
1729
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
1733
pdata_item = (void *)((BYTE *)pdata_list + (i * ls->user_info_bytes));
1737
item_pnt = item->forward_link;
1738
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
1740
pdata_item = (void *)((BYTE *)pdata_item + ls->user_info_bytes);
1743
/* Set the value of the item's user data.*/
1744
OctApiLlmMemCpy(item->user_info, pdata_item, ls->user_info_bytes);
1747
/* Write new cache entry.*/
1748
lh->cache_item_pointer = item_pnt;
1749
lh->cache_item_number = start_item + data_length - 1;
1755
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1758
| Function: OctApiLlmListCopyData.
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).
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)
1777
LLM_LIST_ITEM* item = NULL;
1778
UINT32 item_pnt = 0xFFFFFFFF;
1782
void* pdata_item = NULL;
1785
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1786
/* Build the structure based on the base address:*/
1788
lsbyte = (BYTE *)ls;
1789
total_lists = ls->total_lists;
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
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);
1806
/* Make sure the start_entry is within limits.*/
1807
if (start_item >= lh->list_length)
1808
return(OCTAPI_LLM_INVALID_PARAMETER);
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
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1818
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
1819
/* Set the data of each node.*/
1820
for (i=0; i<data_length; i++)
1822
/* Obtain pointer to current item.*/
1825
/* Check if location of start item is already cached. If not, must search
1827
if (start_item == (lh->cache_item_number + 1))
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);
1835
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->head_pointer);
1836
for (j=0; j<start_item; j++)
1838
item_pnt = item->forward_link;
1839
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
1843
pdata_item = (void *)((BYTE *)pdata_list + (i * ls->user_info_bytes));
1847
item_pnt = item->forward_link;
1848
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * item_pnt);
1850
pdata_item = (void *)((BYTE *)pdata_item + ls->user_info_bytes);
1853
/* Set the value of the item's user data.*/
1854
OctApiLlmMemCpy(pdata_item, item->user_info, ls->user_info_bytes);
1857
/* Write new cache entry.*/
1858
lh->cache_item_pointer = item_pnt;
1859
lh->cache_item_number = start_item + data_length - 1;
1865
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
1868
| Function: OctApiLlmListRemoveItem.
1870
| Description: This function deallocates a node of the linked list specified
1871
| by the handle list_handle.
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.
1880
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1881
#if !SKIP_OctApiLlmListRemoveItem
1882
UINT32 OctApiLlmListRemoveItem(void * l,UINT32 list_handle,UINT32 item_number)
1885
LLM_LIST_ITEM* freed_item = NULL;
1887
UINT32 freed_item_pnt = 0xFFFFFFFF;
1890
UINT32 fConditionFlag = TRUE;
1892
/* Built the structure based on the base address:*/
1894
lsbyte = (BYTE *)ls;
1895
total_lists = ls->total_lists;
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);
1901
lh = &ls->lh[list_handle];
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);
1907
if (item_number == 0 && lh->list_length == 1)/* First item and only item:*/
1909
freed_item_pnt = lh->head_pointer;
1910
freed_item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * freed_item_pnt);
1912
lh->head_pointer = 0xFFFFFFFF;
1913
lh->tail_pointer = 0xFFFFFFFF;
1915
lh->cache_item_number = 0xFFFFFFFF;
1916
lh->cache_item_pointer = 0xFFFFFFFF;
1918
else if (item_number == 0) /* First item and but list not empty:*/
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);
1923
lh->head_pointer = freed_item->forward_link;
1925
lh->cache_item_number = 0;
1926
lh->cache_item_pointer = freed_item->forward_link;
1928
else /* Discard non-first item! (Caution: this could be the last item!)*/
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;
1936
if (lh->cache_item_number < item_number) /* Start at cache:*/
1938
cur_list_pnt = lh->cache_item_pointer;
1939
cur_list_num = lh->cache_item_number;
1941
else /* Start at beginning:*/
1943
cur_list_pnt = lh->head_pointer;
1947
last_list_pnt = 0xFFFFFFFF;
1949
/* Start search from cur_list_pnt and cur_list_num.*/
1950
while( fConditionFlag == TRUE )
1952
item = (LLM_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
1954
if (cur_list_num == item_number) /* Item number found.*/
1956
if (last_list_pnt == 0xFFFFFFFF) return(OCTAPI_LLM_INTERNAL_ERROR1);
1958
if ((item_number + 1) == lh->list_length)
1960
lh->tail_pointer = last_list_pnt;
1961
last_item->forward_link = 0xFFFFFFFF;
1965
last_item->forward_link = item->forward_link;
1967
freed_item_pnt = cur_list_pnt;
1970
/* Reset cache entry.*/
1971
lh->cache_item_pointer = last_list_pnt;
1972
lh->cache_item_number = cur_list_num - 1;
1974
fConditionFlag = FALSE;
1977
else if (item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
1979
return(OCTAPI_LLM_INTERNAL_ERROR0);
1981
else /* Item was not found, but continue searching.*/
1984
last_list_pnt = cur_list_pnt;
1985
cur_list_pnt = item->forward_link;
1992
/* Decrease the list length.*/
1994
ls->assigned_items--;
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;
2004
/**************************************** llm2 function section *****************************************/
2007
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2010
| Function: OctApiLlm2ListGetSize
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.
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
2024
| *l_size UINT32 UINT32 The amount of memory needed, returned.
2026
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2027
#if !SKIP_OctApiLlm2ListGetSize
2028
UINT32 OctApiLlm2ListGetSize(UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size,UINT32 * l_size)
2030
UINT32 head_alloc_size;
2032
UINT32 user_info_size_roundup;
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);
2038
user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
2040
result = OctapiLlmAllocGetSize(number_of_lists,&head_alloc_size);
2041
if(result != GENERIC_OK) return(result);
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));
2049
#if !SKIP_OctApiLlm2ListGetItemPointer
2050
LLM2_LIST_ITEM * OctApiLlm2ListGetItemPointer(LLM2_LIST * ls, UINT32 item_number)
2052
return (LLM2_LIST_ITEM *) (((BYTE *)ls->li) + (ls->item_size * item_number)) ;
2057
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2060
| Function: OctApiLlm2ListInit.
2062
| Description: This function intializes the LLM2_TALLOC structure.
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
2073
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2074
#if !SKIP_OctApiLlm2ListInit
2075
UINT32 OctApiLlm2ListInit(void ** l,UINT32 number_of_items,UINT32 number_of_lists,UINT32 user_info_size)
2078
LLM2_LIST_ITEM* item;
2080
UINT32 head_alloc_size;
2082
UINT32 user_info_size_roundup;
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);
2091
user_info_size_roundup = ((user_info_size + 3) / 4) * 4;
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);
2097
if (*l == NULL) return(OCTAPI_LLM_MEMORY_NOT_ALLOCATED);
2099
/* Built the structure based on the base address:*/
2100
ls = (LLM2_LIST *)(*l);
2101
lsbyte = (BYTE *)ls;
2102
total_lists = ls->total_lists;
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);
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;
2119
/* Complete the build!*/
2120
ls = (LLM2_LIST *)(*l);
2121
lsbyte = (BYTE *)ls;
2122
total_lists = ls->total_lists;
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);
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);
2132
/* Initialize the linked list of the items:*/
2133
for(i=0; i<number_of_items; i++)
2135
item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * i);
2137
if (i == (number_of_items - 1))
2138
item->forward_link = 0xFFFFFFFF;
2140
item->forward_link = i + 1;
2148
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2151
| Function: OctApiLlm2ListCreate.
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.
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.
2164
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2165
#if !SKIP_OctApiLlm2ListCreate
2166
UINT32 OctApiLlm2ListCreate(void * l,UINT32 * list_handle)
2175
/* Built the structure based on the base address:*/
2176
ls = (LLM2_LIST *)l;
2177
lsbyte = (BYTE *)ls;
2178
total_lists = ls->total_lists;
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);
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);
2188
/* The handle is the block number.*/
2189
*list_handle = blocknum;
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;
2197
ls->assigned_lists++;
2203
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2206
| Function: OctApiLlmListDelete.
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.
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.
2218
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2219
#if !SKIP_OctApiLlm2ListDelete
2220
UINT32 OctApiLlm2ListDelete(void * l,UINT32 list_handle)
2228
/* Built the structure based on the base address:*/
2229
ls = (LLM2_LIST *)l;
2230
lsbyte = (BYTE *)ls;
2231
total_lists = ls->total_lists;
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);
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);
2241
/* Release internal list header handle...*/
2242
result = OctapiLlmAllocDealloc(ls->list_head_alloc,list_handle);
2243
if (result != GENERIC_OK) return(result);
2245
lh = &ls->lh[list_handle];
2247
/* Deallocate all items in the list!*/
2248
if (lh->list_length != 0)
2250
LLM2_LIST_ITEM * item;
2252
item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * lh->tail_pointer);
2254
/* Release the items using only the links.*/
2255
item->forward_link = ls->next_empty_item;
2256
ls->next_empty_item = lh->head_pointer;
2258
/* Remove items from item counter.*/
2259
ls->assigned_items -= lh->list_length;
2262
lh->list_length = 0xFFFFFFFF;
2263
lh->head_pointer = 0xFFFFFFFF;
2264
lh->tail_pointer = 0xFFFFFFFF;
2266
ls->assigned_lists--;
2272
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2275
| Function: OctApiLlmListLength.
2277
| Description: This function returns the number of items allocated to the
2278
| list indicated by the handle list_handle.
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.
2287
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2288
#if !SKIP_OctApiLlm2ListLength
2289
UINT32 OctApiLlm2ListLength(void * l,UINT32 list_handle, UINT32 * number_of_items_in_list)
2296
/* Built the structure based on the base address:*/
2297
ls = (LLM2_LIST *)l;
2298
lsbyte = (BYTE *)ls;
2299
total_lists = ls->total_lists;
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);
2305
lh = &ls->lh[list_handle];
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);
2310
*number_of_items_in_list = lh->list_length;
2316
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2319
| Function: OctApiLlm2ListItemData
2321
| Description: This function returns a pointer to the user data associated
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.
2332
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2333
#if !SKIP_OctApiLlm2ListItemData
2334
UINT32 OctApiLlm2ListItemData(void * l,UINT32 list_handle,UINT32 item_key,void ** item_data_pnt, PUINT32 item_number_pnt)
2338
LLM2_LIST_ITEM* item;
2339
UINT32 cur_list_pnt;
2340
UINT32 cur_list_key = 0xFFFFFFFF;
2344
UINT32 fConditionFlag = TRUE;
2346
/* Built the structure based on the base address:*/
2347
ls = (LLM2_LIST *)l;
2348
lsbyte = (BYTE *)ls;
2349
total_lists = ls->total_lists;
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);
2355
lh = &ls->lh[list_handle];
2356
list_length = lh->list_length;
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);
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;
2369
/* Start search from cur_list_pnt and cur_list_num.*/
2370
while ( fConditionFlag == TRUE )
2372
if (cur_list_key == item_key) /* Item key found.*/
2375
*item_data_pnt = (void *)item->user_info;
2379
else if(item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
2381
return(OCTAPI_LLM2_INTERNAL_ERROR0);
2383
else /* Item was not found, but continue searching.*/
2385
cur_list_pnt = item->forward_link;
2388
item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
2389
cur_list_key = item->key;
2390
(*item_number_pnt)++;
2397
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2400
| Function: OctApiLlm2ListInsertItem.
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.
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.
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 )
2421
LLM2_LIST_ITEM* free_item;
2422
UINT32 free_item_pnt;
2425
UINT32 ulPassCount = 0;
2426
UINT32 fConditionFlag = TRUE;
2428
/* Set the status of the insertion.*/
2429
*insert_status_pnt = OCTAPI_LLM2_INSERT_ERROR;
2431
/* Built the structure based on the base address:*/
2432
ls = (LLM2_LIST *)l;
2433
lsbyte = (BYTE *)ls;
2434
total_lists = ls->total_lists;
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);
2440
lh = &ls->lh[list_handle];
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);
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;
2453
if (lh->list_length == 0) /* First item and only item:*/
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;
2460
/* There is no previous node information to return.*/
2461
*prev_item_data_pnt = NULL;
2462
*prev_prev_item_data_pnt = NULL;
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;
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;
2478
last_list_pnt = 0xFFFFFFFF;
2480
/* Start search from cur_list_pnt and cur_list_num.*/
2481
while ( fConditionFlag == TRUE )
2483
/* Increment the pass count to determine if the addition will happen next to last.*/
2486
if (cur_list_key >= item_key) /* Item new node between the last and the curent. */
2488
if (last_list_pnt == 0xFFFFFFFF) /* Must insert at the head of the list.*/
2490
free_item->forward_link = cur_list_pnt;
2491
lh->head_pointer = free_item_pnt;
2493
else /* Standard insertion.*/
2495
free_item->forward_link = cur_list_pnt;
2496
last_item->forward_link = free_item_pnt;
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;
2503
*insert_status_pnt = OCTAPI_LLM2_INSERT_LIST_NODE;
2505
fConditionFlag = FALSE;
2508
else if (item->forward_link == 0xFFFFFFFF) /* End of list found, must insert at the end.*/
2510
free_item->forward_link = 0xFFFFFFFF;
2511
item->forward_link = free_item_pnt;
2512
lh->tail_pointer = free_item_pnt;
2514
*insert_status_pnt = OCTAPI_LLM2_INSERT_LAST_NODE;
2516
fConditionFlag = FALSE;
2519
else /* Item was not found, but continue searching.*/
2521
last_last_item = last_item;
2523
last_list_pnt = cur_list_pnt;
2524
cur_list_pnt = item->forward_link;
2527
item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
2528
cur_list_key = item->key;
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 )
2536
if ( last_item != NULL )
2537
*prev_item_data_pnt = (void *)last_item->user_info;
2539
if ( last_last_item != NULL )
2540
*prev_prev_item_data_pnt = (void *)last_last_item->user_info;
2542
*prev_prev_item_data_pnt = NULL;
2546
*prev_item_data_pnt = (void *)item->user_info;
2548
if ( ( last_last_item != NULL ) && ( last_item != NULL ) )
2549
*prev_prev_item_data_pnt = (void *)last_item->user_info;
2551
*prev_prev_item_data_pnt = NULL;
2555
/* Increase the list length.*/
2557
ls->assigned_items++;
2558
*item_data_pnt = (void *)free_item->user_info;
2564
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2567
| Function: OctApiLlm2ListRemoveItem.
2569
| Description: This function deallocates a node of the linked list specified
2570
| by the handle list_handle.
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.
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 )
2584
LLM2_LIST_ITEM* freed_item = NULL;
2586
UINT32 freed_item_pnt = 0xFFFFFFFF;
2589
UINT32 fConditionFlag = TRUE;
2590
UINT32 ulPassCount = 0;
2592
/* Built the structure based on the base address:*/
2593
ls = (LLM2_LIST *)l;
2594
lsbyte = (BYTE *)ls;
2595
total_lists = ls->total_lists;
2597
/* Set the status of the removal to error as a default value.*/
2598
*remove_status_pnt = OCTAPI_LLM2_REMOVE_ERROR;
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);
2604
lh = &ls->lh[list_handle];
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);
2609
if (lh->list_length == 1)/* First item and only item if he matches.*/
2611
freed_item_pnt = lh->head_pointer;
2612
freed_item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * freed_item_pnt);
2614
if ( freed_item->key == item_key )
2616
lh->head_pointer = 0xFFFFFFFF;
2617
lh->tail_pointer = 0xFFFFFFFF;
2620
return(OCTAPI_LLM2_INTERNAL_ERROR1);
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;
2627
else /* Discard non-first item! (Caution: this could be the last item!)*/
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;
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;
2641
last_list_pnt = 0xFFFFFFFF;
2643
/* Start search from cur_list_pnt and cur_list_num.*/
2644
while( fConditionFlag == TRUE )
2647
if (cur_list_key == item_key) /* Item number found.*/
2649
if (last_list_pnt == 0xFFFFFFFF) /* First item in the list.*/
2651
lh->head_pointer = item->forward_link;
2652
*remove_status_pnt = OCTAPI_LLM2_REMOVE_FIRST_NODE;
2654
else if ( item->forward_link == 0xFFFFFFFF) /* Last item of the list.*/
2656
last_item->forward_link = 0xFFFFFFFF;
2657
lh->tail_pointer = last_list_pnt;
2658
*remove_status_pnt = OCTAPI_LLM2_REMOVE_LAST_NODE;
2662
last_item->forward_link = item->forward_link;
2664
if ( ulPassCount == ( lh->list_length - 1 ) )
2665
*remove_status_pnt = OCTAPI_LLM2_REMOVE_BEFORE_LAST_NODE;
2667
*remove_status_pnt = OCTAPI_LLM2_REMOVE_LIST_NODE;
2670
freed_item_pnt = cur_list_pnt;
2673
fConditionFlag = FALSE;
2676
else if (item->forward_link == 0xFFFFFFFF) /* End of list found?!?*/
2678
return(OCTAPI_LLM2_INTERNAL_ERROR0);
2680
else /* Item was not found, but continue searching.*/
2682
last_last_item = last_item;
2684
last_list_pnt = cur_list_pnt;
2685
cur_list_pnt = item->forward_link;
2688
item = (LLM2_LIST_ITEM *)((BYTE *)ls->li + ls->item_size * cur_list_pnt);
2689
cur_list_key = item->key;
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;
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;
2702
*prev_prev_item_key_pnt = last_last_item->key;
2706
/* Decrease the list length.*/
2708
ls->assigned_items--;
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;
2718
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\
2721
| Function: OctApiLlmMemCpy.
2723
| Description: This function copies data from a source to a destination.
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.
2732
\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
2733
#if !SKIP_OctApiLlmMemCpy
2734
VOID * OctApiLlmMemCpy( VOID *f_pvDestination, const VOID * f_pvSource, UINT32 f_ulSize )
2737
const CHAR * pbySrc;
2738
UINT32 * f_pulAlignedDst;
2739
const UINT32 * f_pulAlignedSrc;
2741
pbyDst = (CHAR *)f_pvDestination;
2742
pbySrc = (const CHAR *)f_pvSource;
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.
2748
if ( ( f_ulSize < sizeof(UINT32) )
2749
|| ( ( (unsigned long)( pbySrc ) & ( sizeof(UINT32) - 1 ) ) | ( (unsigned long)( pbyDst ) & ( sizeof(UINT32) - 1 ) ) ) )
2751
while ( f_ulSize-- )
2752
*pbyDst++ = *pbySrc++;
2753
return f_pvDestination;
2756
f_pulAlignedDst = (UINT32 *)pbyDst;
2757
f_pulAlignedSrc = (const UINT32 *)pbySrc;
2759
/* Copy 4X long words at a time if possible. */
2760
while ( f_ulSize >= 4 * sizeof(UINT32) )
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);
2769
/* Copy one long word at a time if possible. */
2770
while ( f_ulSize >= sizeof(UINT32) )
2772
*f_pulAlignedDst++ = *f_pulAlignedSrc++;
2773
f_ulSize -= sizeof(UINT32);
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++;
2782
return f_pvDestination;
2786
/**************************************** llm_list section **********************************************/