1 /*
2  *  Copyright 2001-2008 Texas Instruments - http://www.ti.com/
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16 
17 
18 /*
19  * qosregistry.h
20  *
21  * DSP-BIOS Bridge driver support functions for TI OMAP processors.
22  */
23 
24 
25 #ifndef __QOSTI_H__
26 
27 #define __QOSTI_H__
28 
29 #include <dbapi.h>
30 
31 /*  ============================================================================
32 
33   name   TLoadMode
34 
35 
36 
37   desc   The node load mode for qos.
38 
39  ============================================================================ */
40 
41 enum TLoadMode
42 {
43 
44 	EStaticLoad,
45 
46 	EDynamicLoad
47 };
48 
49 /*  ============================================================================
50 
51   name    CQosTI
52 
53 
54 
55   desc    An example class that uses the DSP BIOS/Bridge interfaces.and
56 
57           demonstrates creating an xDAIS Socket Node on the DSP. It sends
58 
59           messages and data buffers to the DSP, and then receives the qosd
60 
61           data back from the DSP for display.
62 
63 
64 
65   ============================================================================
66 
67 	RHwaOmap            iDsp ;
68 
69   ============================================================================
70 
71   name   TQosResourceID
72 
73 
74 
75   desc   List of available resource types
76 
77   ============================================================================
78  */
79 
80 typedef enum _QOSDATATYPE {
81 
82 	QOSDataType_Memory_DynLoad = 0,
83 
84 	QOSDataType_Memory_DynAlloc,
85 
86 	QOSDataType_Memory_Scratch,
87 
88 	QOSDataType_Processor_C55X,
89 
90 	QOSDataType_Processor_C6X,
91 
92 	QOSDataType_Peripheral_DMA,
93 
94 	QOSDataType_Stream,
95 
96 	QOSDataType_Component,
97 
98 	QOSDataType_Registry,
99 
100 	QOSDataType_DynDependentLibrary
101 } QOSDATATYPE;
102 
103 #define QOS_USER_DATA_TYPE	0x80000000	/* Flag indicating a application-defined
104 										   data type ID */
105 
106 /*  ============================================================================
107 
108   name   QOSDATA
109 
110 
111 
112   desc   Generic data for resource management is described by the following
113   structure
114 
115   ============================================================================
116 */
117 struct QOSDATA {
118 
119 	ULONG Id;
120 
121 	struct QOSDATA *Next;
122 
123 	 ULONG(*TypeSpecific)(struct QOSDATA *DataObject, ULONG FunctionCode,
124 			 											ULONG Parameter1);
125 	 /* ptr to type-specific func. */
126 
127 	ULONG Size;		/* size of data plus this header */
128 
129 	char Data[];
130 
131 };
132 
133 //  ============================================================================
134 
135 //  name   QOSFNTYPESPECIFIC
136 
137 //
138 
139 //  desc   Pointer to type-specific function handler for the data object
140 
141 //  ============================================================================
142 
143 typedef ULONG(*QOSFNTYPESPECIFIC)(struct QOSDATA *DataObject,ULONG FunctionCode,
144 															ULONG Parameter1);
145 
146 ULONG QOS_Memory_Scratch_FunctionHandler(struct QOSDATA *DataObject,
147 										ULONG FunctionCode, ULONG Parameter1);
148 
149 ULONG QOS_Memory_DynAlloc_FunctionHandler(struct QOSDATA *DataObject,
150 										ULONG FunctionCode, ULONG Parameter1);
151 
152 ULONG QOS_Memory_DynLoad_FunctionHandler(struct QOSDATA *DataObject,
153 										ULONG FunctionCode, ULONG Parameter1);
154 
155 ULONG QOS_Processor_FunctionHandler(struct QOSDATA *DataObject,
156 										ULONG FunctionCode, ULONG Parameter1);
157 
158 ULONG QOS_Resource_DefaultFunctionHandler(struct QOSDATA *DataObject,
159 										  ULONG FunctionCode, ULONG Parameter1);
160 
161 ULONG QOS_Component_DefaultFunctionHandler(struct QOSDATA *DataObject,
162 										ULONG FunctionCode, ULONG Parameter1);
163 
164 ULONG QOS_DynDependentLibrary_FunctionHandler(struct QOSDATA *DataObject,
165 									      ULONG FunctionCode, ULONG Parameter1);
166 
167 ULONG QOS_Registry_FunctionHandler(struct QOSDATA *DataObject,
168 										ULONG FunctionCode, ULONG Parameter1);
169 
170 /*  ============================================================================
171 
172   name   QOSREGISTRY
173 
174 
175 
176   desc   The QOSREGISTRY structure contains a list of all resources and
177   components in the system
178 
179 
180   ============================================================================
181 */
182 
183 struct QOSREGISTRY {
184 
185 	struct QOSDATA data;
186 
187 	struct QOSDATA *ResourceRegistry;
188 
189 	struct QOSDATA *ComponentRegistry;
190 
191 };
192 
193 //  ============================================================================
194 
195 //  name   QOSRESOURCE_MEMORY
196 
197 //
198 
199 //  desc   System memory resources are characterized by the following structure
200 
201 //  ============================================================================
202 
203 struct QOSRESOURCE_MEMORY {
204 
205 	struct QOSDATA data;
206 
207 	UINT align;		/* alignment of memory heap */
208 
209 	UINT heapId;		/* resource heap ID */
210 
211 	UINT size;		/* size of memory heap */
212 
213 	UINT type;		/* type of memory: prefer/require/scratch/persist */
214 
215 	UINT allocated;		/* size of heap in use (not free) */
216 
217 	UINT largestfree;	/* size of largest contiguous free block */
218 
219 	UINT group;		/* scratch group ID (only for scratch memory) */
220 
221 };
222 
223 /*  ============================================================================
224 
225   name   QOSRESOURCE_PROCESSOR
226 
227 
228 
229   desc   Each processor is described by its processor type, hardware
230   attributes, and available processing cycles (MIPS).
231 
232   ============================================================================*/
233 
234 struct QOSRESOURCE_PROCESSOR {
235 
236 	struct QOSDATA data;
237 
238 	UINT MaxMips;		/* max cpu cycles required for component */
239 
240 	UINT TypicalMips;	/* typical cpu cycles required */
241 
242 	UINT MaxCycles;		/* max cpu cycles for single iteration */
243 
244 	UINT TypicalCycles;	/* typical cpu cycles for single iteration */
245 
246 	UINT Utilization;	/* percentage of time cpu is idle */
247 
248 	UINT currentLoad;
249 
250 	UINT predLoad;
251 
252 	UINT currDspFreq;
253 
254 	UINT predictedFreq;
255 
256 
257 } ;
258 
259 /*  ============================================================================
260 
261   name   QOSRESOURCE_STREAM
262 
263 
264 
265   desc   Bridge Streams are introduced as a QoS resource structure
266 
267   ============================================================================
268 */
269 
270 struct QOSRESOURCE_STREAM {
271 
272 	struct QOSDATA data;
273 
274 	struct DSP_STRMATTR Attrs;	/* Stream attributes for this stream */
275 
276 	UINT Direction;		/* DSP_TONODE or DSP_FROMNODE */
277 
278 };
279 
280  struct QOSDYNDEPLIB {
281 
282 	struct QOSDATA data;
283 
284 	struct DSP_UUID depLibUuid;	/* UUID of Dynamic Dependent Library */
285 
286 	const CHAR *depLibPath;	/* Path to Dynamic Dependent Library */
287 
288 };
289 
290 /*  ============================================================================
291 
292   name   QOSCOMPONENT
293 
294 
295 
296   desc   Bridge Streams are introduced as a QoS resource structure
297 
298   ============================================================================
299 */
300 
301 struct QOSCOMPONENT {
302 
303 	struct QOSDATA data;
304 
305 	UINT InUse;		/* Count of instances of this component in use */
306 
307 	UINT aTaskId;
308 
309 	UINT VariantID;
310 
311 	UINT InterfaceID;
312 
313 	struct DSP_UUID NodeUuid;
314 
315 	PVOID dynNodePath;
316 
317 	struct QOSDATA *resourceList;
318 
319 	struct QOSDYNDEPLIB *dynDepLibList;
320 
321 };
322 
323 /*  ============================================================================
324 
325   name   Registry-specific QOS_FN_xxx definitions
326 
327 
328 
329   desc   These are defines for the registry-specific function codes
330 
331   ============================================================================
332  */
333 
334 #define QOS_FN_GetNumDynAllocMemHeaps 		1
335 
336 #define QOS_FN_HasAvailableResource			2
337 
338 /*  ============================================================================
339 
340   name   Resource-specific QOS_FN_xxx definitions
341 
342 
343 
344   desc   These are defines for the resource-specific function codes
345 
346   ============================================================================
347 */
348 
349 #define QOS_FN_ResourceIsAvailable	1
350 
351 #define QOS_FN_ResourceUpdateInfo	2
352 
353 //  ============================================================================
354 
355 /*  name        DSPRegistry_Create
356 
357 
358 
359 	Implementation
360 
361 		Creates empty Registry, then adds all the default system resources
362 
363 	Parameters
364 
365 		none
366 
367 	Return
368 
369 		QOSREGISTRY*	ptr to new system registry
370 
371 		NULL			Failure (out of memory)
372 
373 	Requirement Coverage
374 
375 		This method addresses requirement(s):  SR10085
376 
377 */
378 
379 struct QOSREGISTRY *DSPRegistry_Create();
380 
381 /*  ============================================================================
382 
383   name        DSPRegistry_Delete
384 
385 
386 
387 	Implementation
388 
389 		Deletes Registry and cleans up QoS Gateway & Registry objects that it
390 		owns.
391 
392 	Parameters
393 
394 		registry		ptr to previously created registry
395 
396 	Return
397 
398 		none
399 
400 	Requirement Coverage
401 
402 		This method addresses requirement(s):  SR10085
403 
404 */
405 
406 void DSPRegistry_Delete(struct QOSREGISTRY *registry);
407 
408 /*  ============================================================================
409 
410   name        DSPRegistry_Find
411 
412 
413 
414 	Implementation
415 
416 		Finds resource(s) or component(s) that match the given Id. For
417 		resources, each matching
418 
419 		resource's TypeSpecific function is called with the function
420 		ID QOS_FN_ResourceUpdateInfo to
421 
422 		ensure that all resources have current data in their structures.
423 
424 	Parameters
425 
426 		Id	requested Id
427 
428 		registry		system registry
429 
430 		ResultList		ptr to results array
431 
432 		Size			ptr to ULONG number of entries available in array
433 
434 	Return
435 
436 		DSP_OK			successful
437 
438 		DSP_ESIZE		block for results is too small
439 
440 		DSP_ENOTFOUND	item not found
441 
442 	Requirement Coverage
443 
444 		This method addresses requirement(s):  SR10008
445 
446 */
447 
448 DSP_STATUS DSPRegistry_Find(UINT Id, struct QOSREGISTRY *registry,
449 									struct QOSDATA **ResultList, ULONG *Size);
450 
451 /*  ============================================================================
452 
453   name        DSPRegistry_Add
454 
455 
456 
457 	Implementation
458 
459 		Add given resource or component to the list
460 
461 	Parameters
462 
463 		listhead		system registry (in the case of adding resources or
464 		components to the system)
465 
466 						or component (in the case of adding required resources
467 						to a component)
468 
469 		entry			entry to add in list
470 
471 	Return
472 
473 		DSP_STATUS		Error code or DSP_SOK for success
474 
475 	Requirement Coverage
476 
477 		This method addresses requirement(s):  SR10085
478 
479 */
480 
481 DSP_STATUS DSPRegistry_Add(struct QOSDATA *listhead, struct QOSDATA *entry);
482 
483 /* ============================================================================
484 
485   name        DSPRegistry_Remove
486 
487 
488 
489 	Implementation
490 
491 		Removes given resource or component from the list
492 
493 	Parameters
494 
495 		listhead		system registry (in the case of removing resources or
496 		components from the system)
497 
498 						or component (in the case of removing required
499 						resources from a component)
500 
501 		entry			resource or component to remove
502 
503 	Return
504 
505 		DSP_STATUS	Error code or DSP_SOK for success
506 
507 	Requirement Coverage
508 
509 		This method addresses requirement(s):  SR10085
510 
511 */
512 
513 DSP_STATUS DSPRegistry_Remove(struct QOSDATA *listhead, struct QOSDATA *entry);
514 
515 /*  ============================================================================
516 
517   name        DSPQos_TypeSpecific
518 
519 
520 
521 	Implementation
522 
523 		Calls the type-specific function defined for this data type.
524 		Internally, this is implemented
525 
526 		as a call to the QOSDATA structure's TypeSpecific() function.
527 
528 	Parameters
529 
530 		DataObject		Far pointer to the structure for the data object
531 
532 		FunctionCode	Type-specific function code
533 
534 		Parameter1		Function-specific parameter
535 
536 	Return
537 
538 		ULONG			Function-specific return code.
539 
540 	Requirement Coverage
541 
542 		This method addresses requirement(s):  SR10085, SR10008
543 
544 */
545 
546 ULONG DSPQos_TypeSpecific(struct QOSDATA *DataObject, ULONG FunctionCode,
547 															ULONG Parameter1);
548 
549 /*  ============================================================================
550 
551   name        DSPComponent_Register
552 
553 
554 
555 	Implementation
556 
557 		Informs Registry that the given component is using system resources.
558 		Internally, this
559 
560 		increments the InUse field of the QOSCOMPONENT structure.
561 
562 	Parameters
563 
564 		registry		system registry
565 
566 		comp			component using system resources
567 
568 	Return
569 
570 		DSP_STATUS		Error code or DSP_SOK for success
571 
572 	Requirement Coverage
573 
574 		This method addresses requirement(s):  SR10085
575 
576 */
577 
578 DSP_STATUS DSPComponent_Register(struct QOSREGISTRY *registry,
579 													struct QOSCOMPONENT *comp);
580 
581 /*  ============================================================================
582 
583   name        DSPComponent_Unregister
584 
585 
586 
587 	Implementation
588 
589 		Informs Registry that component is no longer using system resources.
590 		Internally, this
591 
592 		decrements the InUse field of the QOSCOMPONENT structure.
593 
594 	Parameters
595 
596 		registry		system registry
597 
598 		comp			component releasing system resources
599 
600 	Return
601 
602 		DSP_STATUS		Error code or DSP_SOK for success
603 
604 	Requirement Coverage
605 
606 		This method addresses requirement(s):  SR10085
607 
608 */
609 
610 DSP_STATUS DSPComponent_Unregister(struct QOSREGISTRY *registry,
611 													struct QOSCOMPONENT *comp);
612 
613 /*  ============================================================================
614 
615   name        DSPData_Create
616 
617 
618 
619 	Implementation
620 
621 		Allocates and initializes a QOSDATA structure.
622 
623 	Parameters
624 
625 		id				type of data
626 
627 	Return
628 
629 		QOSDATA *		ptr to data structure or NULL for failure
630 
631 	Requirement Coverage
632 
633 		This method addresses requirement(s):
634 
635 */
636 
637 struct QOSDATA *DSPData_Create(ULONG id);
638 
639 /*  ============================================================================
640 
641   name        DSPData_Delete
642 
643 
644 
645 	Implementation
646 
647 		Deletes a QOSDATA structure, recursively deleting any associated lists.
648 
649 	Parameters
650 
651 		data			ptr to data structure to delete
652 
653 	Return
654 
655 		DSP_STATUS		Error code or DSP_SOK for success
656 
657 	Requirement Coverage
658 
659 		This method addresses requirement(s):
660 
661 */
662 
663 DSP_STATUS DSPData_Delete(struct QOSDATA *data);
664 
665 /*  ============================================================================
666 
667   name        DSPData_IsResource
668 
669 
670 
671 	Implementation
672 
673 		Determines whether a QOSDATA structure Id is a "resource" type ID.
674 
675 	Parameters
676 
677 		Id				type ID to check
678 
679 	Return
680 
681 		bool			TRUE for resources, FALSE otherwise.
682 
683 	Requirement Coverage
684 
685 		This method addresses requirement(s):
686 
687 */
688 
689 bool DSPData_IsResource(ULONG Id);
690 
691 #endif
692 
693