drv.c 58.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
/*
 * drv.c
 *
 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
 *
 * Copyright (C) 2005-2006 Texas Instruments, Inc.
 *
 * This package is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */


/*
 *  ======== drv.c ========
 *  Description:
 *      DSP/BIOS Bridge resource allocation module.
 *
 *  Public Functions:
 *      DRV_Create
 *      DRV_Destroy
 *      DRV_Exit
 *      DRV_GetDevObject
 *      DRV_GetDevExtension
 *      DRV_GetFirstDevObject
 *      DRV_GetNextDevObject
 *      DRV_GetNextDevExtension
 *      DRV_Init
 *      DRV_InsertDevObject
 *      DRV_RemoveDevObject
 *      DRV_RequestResources
 *      DRV_ReleaseResources
 *
 *! Revision History
 *! ======== ========
 *! 19-Apr-2004 sb: Replaced OS specific APIs with MEM_AllocPhysMem and
		    MEM_FreePhysMem. Fixed warnings. Cosmetic updates.
 *! 12-Apr-2004 hp: IVA clean up during bridge-uninstall
 *! 05-Jan-2004 vp: Updated for 24xx platform
 *! 21-Mar-2003 sb: Get SHM size from registry
 *! 10-Feb-2003 vp: Code review updates
 *! 18-Oct-2002 vp: Ported to Linux platform
 *! 30-Oct-2000 kc: Modified usage of REG_SetValue.
 *! 06-Sep-2000 jeh Read channel info into struct CFG_HOSTRES in
 *! 					RequestISAResources()
 *! 21-Sep-2000 rr: numwindows is calculated instead of default value in
 *!		 RequestISAResources.
 *! 07-Aug-2000 rr: static list of dev objects removed.
 *! 27-Jul-2000 rr: RequestResources split into two(Request and Release)
 *!		 Device extension created to hold the DevNodeString.
 *! 17-Jul-2000 rr: Driver Object holds the list of Device Objects.
 *!		 Added DRV_Create, DRV_Destroy, DRV_GetDevObject,
 *!		 DRV_GetFirst/NextDevObject, DRV_Insert/RemoveDevObject.
 *! 09-May-2000 rr: PCI Support is not L301 specific.Use of MEM_Calloc
 *!		 instead of MEM_Alloc.
 *! 28-Mar-2000 rr: PCI Support added. L301 Specific. TBD.
 *! 03-Feb-2000 rr: GT and Module Init/exit Changes. Merged with kc.
 *! 19-Jan-2000 rr: DBC_Ensure in RequestPCMCIA moved within PCCARD ifdef
 *! 29-Dec-1999 rr: PCCard support for any slot.Bus type stored in the
 *!		 struct CFG_HOSTRES Structure.
 *! 17-Dec-1999 rr: if PCCARD_Init fails we return DSP_EFAIL.
 *!		 DBC_Ensure checks for sucess and pDevice != NULL
 *! 11-Dec-1999 ag: #define "Isa" renamed to "IsaBus".
 *! 09-Dec-1999 rr: windows.h included to remove warnings.
 *! 02-Dec-1999 rr: struct GT_Mask is with in if DEBUG. Request resources checks
 *!		 status while making call to Reg functions.
 *! 23-Nov-1999 rr: windows.h included
 *! 19-Nov-1999 rr: DRV_RELEASE bug while setting the registry to zero.
 *!		 fixed.
 *! 12-Nov-1999 rr: RequestResources() reads values from the registry.
 *!		 Hardcoded bIRQRegister define removed.
 *! 05-Nov-1999 rr: Added hardcoded device interrupt.
 *! 25-Oct-1999 rr: Resource structure removed. Now it uses the Host
 *!		 Resource structure directly.
 *! 15-Oct-1999 rr: Resource Structure modified. See drv.h
 *!		 dwBusType taken from the registry.Hard coded
 *!		 registry entries removed.
 *! 05-Oct-1999 rr: Calling DEV_StartDevice moved to wcdce.c. DRV_Register
 *!		 MiniDriver has been renamed to DRV_RequestResources.
 *!		 DRV_UnRegisterMiniDriver fxn removed.
 *! 24-Sep-1999 rr: Significant changes to the RegisterMiniDriver fxns.
 *!		 Now it is simpler. IT stores the dev node in the
 *!		 registry, assign resources and calls the DEV_Start.
 *! 10-Sep-1999 rr: Register Minidriver modified.
 *!		 - Resource structure follows the NT model
 *! 08-Aug-1999 rr: Adopted for WinCE. Exports Fxns removed. Hull Created.
 */

/*  ----------------------------------- Host OS */
#include <dspbridge/host_os.h>

/*  ----------------------------------- DSP/BIOS Bridge */
#include <dspbridge/std.h>
#include <dspbridge/dbdefs.h>
#include <dspbridge/errbase.h>

/*  ----------------------------------- Trace & Debug */
#include <dspbridge/dbc.h>
#include <dspbridge/gt.h>

/*  ----------------------------------- OS Adaptation Layer */
#include <dspbridge/cfg.h>
#include <dspbridge/csl.h>
#include <dspbridge/list.h>
#include <dspbridge/mem.h>
#include <dspbridge/reg.h>

/*  ----------------------------------- Others */
#include <dspbridge/dbreg.h>

/*  ----------------------------------- This */
#include <dspbridge/drv.h>
#include <dspbridge/dev.h>

#ifndef RES_CLEANUP_DISABLE
#include <dspbridge/node.h>
#include <dspbridge/proc.h>
#include <dspbridge/strm.h>
#include <dspbridge/nodepriv.h>
#include <dspbridge/wmdchnl.h>
#include <dspbridge/resourcecleanup.h>
#endif

/*  ----------------------------------- Defines, Data Structures, Typedefs */
#define SIGNATURE   0x5f52474d	/* "DRV_" (in reverse) */

struct DRV_OBJECT {
	u32 dwSignature;
	struct LST_LIST *devList;
	struct LST_LIST *devNodeString;
#ifndef RES_CLEANUP_DISABLE
	struct PROCESS_CONTEXT  *procCtxtList;
#endif
};

/*
 *  This is the Device Extension. Named with the Prefix
 *  DRV_ since it is living in this module
 */
struct DRV_EXT {
	struct LST_ELEM link;
	char szString[MAXREGPATHLENGTH];
};

/*  ----------------------------------- Globals */
static s32 cRefs;

#if GT_TRACE
extern struct GT_Mask curTrace;
#endif

/*  ----------------------------------- Function Prototypes */
static DSP_STATUS RequestBridgeResources(u32 dwContext, s32 fRequest);
static DSP_STATUS RequestBridgeResourcesDSP(u32 dwContext, s32 fRequest);

#ifndef RES_CLEANUP_DISABLE
/* GPP PROCESS CLEANUP CODE */

static DSP_STATUS PrintProcessInformation(void);
static DSP_STATUS DRV_ProcFreeNodeRes(HANDLE hPCtxt);
static DSP_STATUS  DRV_ProcFreeSTRMRes(HANDLE hPCtxt);
extern enum NODE_STATE NODE_GetState(HANDLE hNode);

/* Get the process context list from driver object */

/* Set the Process ID */
DSP_STATUS DRV_ProcSetPID(HANDLE hPCtxt, s32 hProcess)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;

	DBC_Assert(hPCtxt != NULL);

	pCtxt->pid = hProcess;
	return status;
}


/* Getting the head of the process context list */
DSP_STATUS DRV_GetProcCtxtList(struct PROCESS_CONTEXT **pPctxt,
				struct DRV_OBJECT *hDrvObject)
{
	DSP_STATUS status = DSP_SOK;
	struct DRV_OBJECT *pDrvObject = (struct DRV_OBJECT *)hDrvObject;

	DBC_Assert(hDrvObject != NULL);
	GT_2trace(curTrace, GT_ENTER,
		"DRV_GetProcCtxtList: 2 *pPctxt:%x, pDrvObject"
		":%x", *pPctxt, pDrvObject);
	*pPctxt = pDrvObject->procCtxtList;
	GT_2trace(curTrace, GT_ENTER,
		"DRV_GetProcCtxtList: 3 *pPctxt:%x, pDrvObject"
		":%x", *pPctxt, pDrvObject);
	return status;
}



/* Get a particular process context based on process handle (phProcess) */
DSP_STATUS DRV_GetProcContext(u32 phProcess,
				struct DRV_OBJECT *hDrvObject,
				HANDLE hPCtxt, DSP_HNODE hNode,
				u32 pMapAddr)
{
	struct PROCESS_CONTEXT **pCtxt = (struct PROCESS_CONTEXT **)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct PROCESS_CONTEXT *pCtxtList = NULL;
	struct DRV_OBJECT *pDrvObject = (struct DRV_OBJECT *)hDrvObject;
	struct NODE_RES_OBJECT *pTempNode2 = NULL;
	struct NODE_RES_OBJECT *pTempNode = NULL;
	struct DMM_RES_OBJECT *pTempDMM2 = NULL;
	struct DMM_RES_OBJECT *pTempDMM = NULL;
	s32 pCtxtFound = 0;

	DBC_Assert(pDrvObject != NULL);
	pCtxtList = pDrvObject->procCtxtList;
	GT_0trace(curTrace, GT_ENTER, "2DRV_GetProcContext: 2");
	while ((pCtxtList != NULL) && (pCtxtList->pid != phProcess)) {
		pCtxtList = pCtxtList->next;
		GT_0trace(curTrace, GT_ENTER, "2DRV_GetProcContext: 3");
	}
	if (pCtxtList == NULL) {
		if (hNode != NULL) {
			pCtxtList = pDrvObject->procCtxtList;
			while ((pCtxtList != NULL) && (pCtxtFound == 0)) {
				pTempNode = pCtxtList->pNodeList;
				while ((pTempNode != NULL) &&
				      (pTempNode->hNode != hNode)) {
					pTempNode2 = pTempNode;
					pTempNode = pTempNode->next;
				}
				if (pTempNode != NULL) {
					pCtxtFound = 1;
					status = DSP_SOK;
				} else {
					pCtxtList = pCtxtList->next;
				}
			}
		} else if ((pMapAddr != 0) && (pCtxtFound == 0)) {
			pCtxtList = pDrvObject->procCtxtList;
			while ((pCtxtList != NULL) && (pCtxtFound == 0)) {
				pTempDMM = pCtxtList->pDMMList;
				while ((pTempDMM != NULL) &&
				     (pTempDMM->ulDSPAddr != pMapAddr)) {
					pTempDMM2 = pTempDMM;
					pTempDMM = pTempDMM->next;
				}
				if (pTempDMM != NULL) {
					pCtxtFound = 1;
					status = DSP_SOK;
				} else {
					pCtxtList = pCtxtList->next;
				}
			}
			if (pCtxtList == NULL)
				status = DSP_ENOTFOUND;

		}
	} else{
		status = DSP_SOK;
	}
	GT_0trace(curTrace, GT_ENTER, "2DRV_GetProcContext: 4");
	*pCtxt = pCtxtList;
	return status;
}


/* Add a new process context to process context list */
DSP_STATUS DRV_InsertProcContext(struct DRV_OBJECT *hDrVObject, HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT **pCtxt = (struct PROCESS_CONTEXT **)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct PROCESS_CONTEXT *pCtxtList = NULL;
	struct DRV_OBJECT	     *hDRVObject;

	GT_0trace(curTrace, GT_ENTER, "\n In DRV_InsertProcContext\n");
	status = CFG_GetObject((u32 *)&hDRVObject, REG_DRV_OBJECT);
	DBC_Assert(hDRVObject != NULL);
	*pCtxt = MEM_Calloc(1 * sizeof(struct PROCESS_CONTEXT), MEM_PAGED);
	GT_0trace(curTrace, GT_ENTER,
		 "\n In DRV_InsertProcContext Calling "
		 "DRV_GetProcCtxtList\n");
	DRV_GetProcCtxtList(&pCtxtList, hDRVObject);
	GT_0trace(curTrace, GT_ENTER,
		 "\n In DRV_InsertProcContext After Calling "
		 "DRV_GetProcCtxtList\n");
	if (pCtxtList != NULL) {
		GT_0trace(curTrace, GT_ENTER,
			 "\n In DRV_InsertProcContext and pCtxt is "
			 "not Null\n");
		while (pCtxtList->next != NULL)
			pCtxtList = pCtxtList->next;

		pCtxtList->next = *pCtxt;
	} else {
		GT_0trace(curTrace, GT_ENTER,
			 "\n In DRV_InsertProcContext and "
			 "pCtxt is Null\n");
		hDRVObject->procCtxtList = *pCtxt;
	}
	return status;
}

/* Delete a process context from process resource context list */
DSP_STATUS DRV_RemoveProcContext(struct DRV_OBJECT *hDRVObject,
				     HANDLE hPCtxt, HANDLE hProcess)
{
	DSP_STATUS status = DSP_SOK;
	struct PROCESS_CONTEXT    *pCtxt2 = NULL;
	struct PROCESS_CONTEXT    *pTmp = NULL;
	struct PROCESS_CONTEXT    *pCtxtList = NULL;

	DBC_Assert(hDRVObject != NULL);
	DRV_GetProcContext((u32)hProcess, hDRVObject, &pCtxt2, NULL, 0);

	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveProcContext: 12");
	DRV_GetProcCtxtList(&pCtxtList, hDRVObject);
	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveProcContext: 13");
	pTmp = pCtxtList;
	while ((pCtxtList != NULL) && (pCtxtList != pCtxt2)) {
		pTmp = pCtxtList;
		pCtxtList = pCtxtList->next;
		GT_0trace(curTrace, GT_ENTER,
			 "DRV_RemoveProcContext: 2");
	}
	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveProcContext: 3");
	if (hDRVObject->procCtxtList == pCtxt2)
		hDRVObject->procCtxtList = pCtxt2->next;

	if (pCtxtList == NULL)
		return DSP_ENOTFOUND;
	else if (pTmp->next != NULL)
		pTmp->next = pTmp->next->next;

	MEM_Free(pCtxt2);
	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveProcContext: 7");

	return status;
}

/* Update the state of process context */
DSP_STATUS DRV_ProcUpdatestate(HANDLE hPCtxt, enum GPP_PROC_RES_STATE status)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status1 = DSP_SOK;
	if (pCtxt != NULL) {
		pCtxt->resState = status;
	} else {
		GT_0trace(curTrace, GT_ENTER,
			 "DRV_ProcUpdatestate: Failed to update "
			 "process state");
	}
	return status1;
}

/* Allocate and add a node resource element
* This function is called from .Node_Allocate.  */
DSP_STATUS DRV_InsertNodeResElement(HANDLE hNode, HANDLE hNodeRes,
					HANDLE hPCtxt)
{
	struct NODE_RES_OBJECT **pNodeRes = (struct NODE_RES_OBJECT **)hNodeRes;
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct NODE_RES_OBJECT   *pTempNodeRes = NULL;
	GT_0trace(curTrace, GT_ENTER, "DRV_InsertNodeResElement: 1");
	*pNodeRes = (struct NODE_RES_OBJECT *)MEM_Calloc
		    (1 * sizeof(struct NODE_RES_OBJECT), MEM_PAGED);
	DBC_Assert(hPCtxt != NULL);
	if ((*pNodeRes == NULL) || (hPCtxt == NULL)) {
		GT_0trace(curTrace, GT_ENTER, "DRV_InsertNodeResElement: 12");
		status = DSP_EHANDLE;
	}
	if (DSP_SUCCEEDED(status)) {
		(*pNodeRes)->hNode = hNode;
		if (pCtxt->pNodeList != NULL) {
			pTempNodeRes = pCtxt->pNodeList;
			while (pTempNodeRes->next != NULL)
				pTempNodeRes = pTempNodeRes->next;

			pTempNodeRes->next = *pNodeRes;
			GT_0trace(curTrace, GT_ENTER,
				 "DRV_InsertNodeResElement: 2");
		} else {
			pCtxt->pNodeList = *pNodeRes;
			GT_0trace(curTrace, GT_ENTER,
				 "DRV_InsertNodeResElement: 3");
		}
	}
	GT_0trace(curTrace, GT_ENTER, "DRV_InsertNodeResElement: 4");
	return status;
}

/* Release all Node resources and its context
* This is called from .Node_Delete.  */
DSP_STATUS DRV_RemoveNodeResElement(HANDLE hNodeRes, HANDLE hPCtxt)
{
	struct NODE_RES_OBJECT *pNodeRes = (struct NODE_RES_OBJECT *)hNodeRes;
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS	status = DSP_SOK;
	struct NODE_RES_OBJECT *pTempNode2 = pCtxt->pNodeList;
	struct NODE_RES_OBJECT *pTempNode = pCtxt->pNodeList;

	DBC_Assert(hPCtxt != NULL);
	GT_0trace(curTrace, GT_ENTER, "\nDRV_RemoveNodeResElement: 1\n");
	while ((pTempNode != NULL) && (pTempNode != pNodeRes)) {
		pTempNode2 = pTempNode;
		pTempNode = pTempNode->next;
	}
	if (pCtxt->pNodeList == pNodeRes)
		pCtxt->pNodeList = pNodeRes->next;

	if (pTempNode == NULL)
		return DSP_ENOTFOUND;
	else if (pTempNode2->next != NULL)
		pTempNode2->next = pTempNode2->next->next;

	MEM_Free(pTempNode);
	return status;
}

/* Actual Node De-Allocation */
static DSP_STATUS DRV_ProcFreeNodeRes(HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct NODE_RES_OBJECT *pNodeList = NULL;
	struct NODE_RES_OBJECT *pNodeRes = NULL;
	u32  nState;

	DBC_Assert(hPCtxt != NULL);
	pNodeList = pCtxt->pNodeList;
	while (pNodeList != NULL) {
		GT_0trace(curTrace, GT_ENTER, "DRV_ProcFreeNodeRes: 1");
		pNodeRes = pNodeList;
		pNodeList = pNodeList->next;
		if (pNodeRes->nodeAllocated) {
			nState = NODE_GetState(pNodeRes->hNode) ;
			GT_1trace(curTrace, GT_5CLASS,
				"DRV_ProcFreeNodeRes: Node state %x\n", nState);
			if (nState <= NODE_DELETING) {
				if ((nState == NODE_RUNNING) ||
					(nState == NODE_PAUSED) ||
					(nState == NODE_TERMINATING)) {
					GT_1trace(curTrace, GT_5CLASS,
					"Calling Node_Terminate for Node:"
					" 0x%x\n", pNodeRes->hNode);
					status = NODE_Terminate
						(pNodeRes->hNode, &status);
					GT_1trace(curTrace, GT_5CLASS,
						 "Calling Node_Delete for Node:"
						 " 0x%x\n", pNodeRes->hNode);
					status = NODE_Delete(pNodeRes->hNode);
					GT_1trace(curTrace, GT_5CLASS,
					"the status after the NodeDelete %x\n",
					status);
				} else if ((nState == NODE_ALLOCATED)
					|| (nState == NODE_CREATED))
					status = NODE_Delete(pNodeRes->hNode);
			}
		}
		pNodeRes->nodeAllocated = 0;
	}
	return status;
}

/* Allocate the DMM resource element
* This is called from Proc_Map. after the actual resource is allocated */
DSP_STATUS DRV_InsertDMMResElement(HANDLE hDMMRes, HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	struct DMM_RES_OBJECT **pDMMRes = (struct DMM_RES_OBJECT **)hDMMRes;
	DSP_STATUS	status = DSP_SOK;
	struct DMM_RES_OBJECT *pTempDMMRes = NULL;

	*pDMMRes = (struct DMM_RES_OBJECT *)
		    MEM_Calloc(1 * sizeof(struct DMM_RES_OBJECT), MEM_PAGED);
	DBC_Assert(hPCtxt != NULL);
	GT_0trace(curTrace, GT_ENTER, "DRV_InsertDMMResElement: 1");
	if ((*pDMMRes == NULL) || (hPCtxt == NULL)) {
		GT_0trace(curTrace, GT_5CLASS, "DRV_InsertDMMResElement: 2");
		status = DSP_EHANDLE;
	}
	if (DSP_SUCCEEDED(status)) {
		if (pCtxt->pDMMList != NULL) {
			GT_0trace(curTrace, GT_5CLASS,
				 "DRV_InsertDMMResElement: 3");
			pTempDMMRes = pCtxt->pDMMList;
			while (pTempDMMRes->next != NULL)
				pTempDMMRes = pTempDMMRes->next;

			pTempDMMRes->next = *pDMMRes;
		} else {
			pCtxt->pDMMList = *pDMMRes;
			GT_0trace(curTrace, GT_5CLASS,
				 "DRV_InsertDMMResElement: 4");
		}
	}
	GT_0trace(curTrace, GT_ENTER, "DRV_InsertDMMResElement: 5");
	return status;
}



/* Release DMM resource element context
* This is called from Proc_UnMap. after the actual resource is freed */
DSP_STATUS 	DRV_RemoveDMMResElement(HANDLE hDMMRes, HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	struct DMM_RES_OBJECT *pDMMRes = (struct DMM_RES_OBJECT *)hDMMRes;
	DSP_STATUS status = DSP_SOK;
	struct DMM_RES_OBJECT *pTempDMMRes2 = NULL;
	struct DMM_RES_OBJECT *pTempDMMRes = NULL;

	DBC_Assert(hPCtxt != NULL);
	pTempDMMRes2 = pCtxt->pDMMList;
	pTempDMMRes = pCtxt->pDMMList;
	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveDMMResElement: 1");
	while ((pTempDMMRes != NULL) && (pTempDMMRes != pDMMRes)) {
		GT_0trace(curTrace, GT_ENTER, "DRV_RemoveDMMResElement: 2");
		pTempDMMRes2 = pTempDMMRes;
		pTempDMMRes = pTempDMMRes->next;
	}
	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveDMMResElement: 3");
	if (pCtxt->pDMMList == pTempDMMRes)
		pCtxt->pDMMList = pTempDMMRes->next;

	if (pTempDMMRes == NULL)
		return DSP_ENOTFOUND;
	else if (pTempDMMRes2->next != NULL)
		pTempDMMRes2->next = pTempDMMRes2->next->next;

	MEM_Free(pDMMRes);
	GT_0trace(curTrace, GT_ENTER, "DRV_RemoveDMMResElement: 4");
	return status;
}

/* Update DMM resource status */
DSP_STATUS DRV_UpdateDMMResElement(HANDLE hDMMRes, u32 pMpuAddr, u32 ulSize,
				  u32 pReqAddr, u32 pMapAddr,
				  HANDLE hProcessor)
{
	struct DMM_RES_OBJECT *pDMMRes = (struct DMM_RES_OBJECT *)hDMMRes;
	DSP_STATUS status = DSP_SOK;

	DBC_Assert(hDMMRes != NULL);
	pDMMRes->ulMpuAddr = pMpuAddr;
	pDMMRes->ulDSPAddr = pMapAddr;
	pDMMRes->ulDSPResAddr = pReqAddr;
	pDMMRes->dmmSize = ulSize;
	pDMMRes->hProcessor = hProcessor;
	pDMMRes->dmmAllocated = 1;

	return status;
}

/* Actual DMM De-Allocation */
DSP_STATUS  DRV_ProcFreeDMMRes(HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct DMM_RES_OBJECT *pDMMList = pCtxt->pDMMList;
	struct DMM_RES_OBJECT *pDMMRes = NULL;

	DBC_Assert(hPCtxt != NULL);
	GT_0trace(curTrace, GT_ENTER, "\nDRV_ProcFreeDMMRes: 1\n");
	while (pDMMList != NULL) {
		pDMMRes = pDMMList;
		pDMMList = pDMMList->next;
		if (pDMMRes->dmmAllocated) {
			status = PROC_UnMap(pDMMRes->hProcessor,
				 (void *)pDMMRes->ulDSPResAddr);
			status = PROC_UnReserveMemory(pDMMRes->hProcessor,
				 (void *)pDMMRes->ulDSPResAddr);
			pDMMRes->dmmAllocated = 0;
		}
	}
	return status;
}


/* Release all DMM resources and its context
* This is called from .bridge_release. */
DSP_STATUS DRV_RemoveAllDMMResElements(HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct DMM_RES_OBJECT *pTempDMMRes2 = NULL;
	struct DMM_RES_OBJECT *pTempDMMRes = NULL;

	DBC_Assert(pCtxt != NULL);
	DRV_ProcFreeDMMRes(pCtxt);
	pTempDMMRes = pCtxt->pDMMList;
	while (pTempDMMRes != NULL) {
		pTempDMMRes2 = pTempDMMRes;
		pTempDMMRes = pTempDMMRes->next;
		MEM_Free(pTempDMMRes2);
	}
	pCtxt->pDMMList = NULL;
	return status;
}

DSP_STATUS DRV_GetDMMResElement(u32 pMapAddr, HANDLE hDMMRes, HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	struct DMM_RES_OBJECT **pDMMRes = (struct DMM_RES_OBJECT **)hDMMRes;
	DSP_STATUS status = DSP_SOK;
	struct DMM_RES_OBJECT *pTempDMM2 = NULL;
	struct DMM_RES_OBJECT *pTempDMM = NULL;

	DBC_Assert(hPCtxt != NULL);
	pTempDMM = pCtxt->pDMMList;
	while ((pTempDMM != NULL) && (pTempDMM->ulDSPAddr != pMapAddr)) {
		GT_3trace(curTrace, GT_ENTER,
			 "DRV_GetDMMResElement: 2 pTempDMM:%x "
			 "pTempDMM->ulDSPAddr:%x pMapAddr:%x\n", pTempDMM,
			 pTempDMM->ulDSPAddr, pMapAddr);
		pTempDMM2 = pTempDMM;
		pTempDMM = pTempDMM->next;
	}
	if (pTempDMM != NULL) {
		GT_0trace(curTrace, GT_ENTER, "DRV_GetDMMResElement: 3");
		*pDMMRes = pTempDMM;
	} else {
		status = DSP_ENOTFOUND;
	} GT_0trace(curTrace, GT_ENTER, "DRV_GetDMMResElement: 4");
	return status;
}

/* Update Node allocation status */
void DRV_ProcNodeUpdateStatus(HANDLE hNodeRes, s32 status)
{
	struct NODE_RES_OBJECT *pNodeRes = (struct NODE_RES_OBJECT *)hNodeRes;
	DBC_Assert(hNodeRes != NULL);
	pNodeRes->nodeAllocated = status;
}

/* Update Node Heap status */
void DRV_ProcNodeUpdateHeapStatus(HANDLE hNodeRes, s32 status)
{
	struct NODE_RES_OBJECT *pNodeRes = (struct NODE_RES_OBJECT *)hNodeRes;
	DBC_Assert(hNodeRes != NULL);
	pNodeRes->heapAllocated = status;
}

/* Release all Node resources and its context
* This is called from .bridge_release.
*/
DSP_STATUS 	DRV_RemoveAllNodeResElements(HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct NODE_RES_OBJECT *pTempNode2 = NULL;
	struct NODE_RES_OBJECT *pTempNode = NULL;

	DBC_Assert(hPCtxt != NULL);
	DRV_ProcFreeNodeRes(pCtxt);
	pTempNode = pCtxt->pNodeList;
	while (pTempNode != NULL) {
		pTempNode2 = pTempNode;
		pTempNode = pTempNode->next;
		MEM_Free(pTempNode2);
	}
	pCtxt->pNodeList = NULL;
	return status;
}

/* Getting the node resource element */

DSP_STATUS DRV_GetNodeResElement(HANDLE hNode, HANDLE hNodeRes, HANDLE hPCtxt)
{
	struct NODE_RES_OBJECT **nodeRes = (struct NODE_RES_OBJECT **)hNodeRes;
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct NODE_RES_OBJECT *pTempNode2 = NULL;
	struct NODE_RES_OBJECT *pTempNode = NULL;

	DBC_Assert(hPCtxt != NULL);
	pTempNode = pCtxt->pNodeList;
	GT_0trace(curTrace, GT_ENTER, "DRV_GetNodeResElement: 1");
	while ((pTempNode != NULL) && (pTempNode->hNode != hNode)) {
		pTempNode2 = pTempNode;
		pTempNode = pTempNode->next;
	}
	if (pTempNode != NULL)
		*nodeRes = pTempNode;
	else
		status = DSP_ENOTFOUND;

	return status;
}



/* Allocate the STRM resource element
* This is called after the actual resource is allocated
*/
DSP_STATUS DRV_ProcInsertSTRMResElement(HANDLE hStreamHandle, HANDLE hSTRMRes,
					HANDLE hPCtxt)
{
	struct STRM_RES_OBJECT **pSTRMRes = (struct STRM_RES_OBJECT **)hSTRMRes;
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct STRM_RES_OBJECT *pTempSTRMRes = NULL;
	DBC_Assert(hPCtxt != NULL);

	*pSTRMRes = (struct STRM_RES_OBJECT *)
		    MEM_Calloc(1 * sizeof(struct STRM_RES_OBJECT), MEM_PAGED);
	if ((*pSTRMRes == NULL) || (hPCtxt == NULL)) {
		GT_0trace(curTrace, GT_ENTER, "DRV_InsertSTRMResElement: 2");
		status = DSP_EHANDLE;
	}
	if (DSP_SUCCEEDED(status)) {
		(*pSTRMRes)->hStream = hStreamHandle;
		if (pCtxt->pSTRMList != NULL) {
			GT_0trace(curTrace, GT_ENTER,
				 "DRV_InsertiSTRMResElement: 3");
			pTempSTRMRes = pCtxt->pSTRMList;
			while (pTempSTRMRes->next != NULL)
				pTempSTRMRes = pTempSTRMRes->next;

			pTempSTRMRes->next = *pSTRMRes;
		} else {
			pCtxt->pSTRMList = *pSTRMRes;
			GT_0trace(curTrace, GT_ENTER,
				 "DRV_InsertSTRMResElement: 4");
		}
	}
	return status;
}



/* Release Stream resource element context
* This function called after the actual resource is freed
*/
DSP_STATUS 	DRV_ProcRemoveSTRMResElement(HANDLE hSTRMRes, HANDLE hPCtxt)
{
	struct STRM_RES_OBJECT *pSTRMRes = (struct STRM_RES_OBJECT *)hSTRMRes;
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct STRM_RES_OBJECT *pTempSTRMRes2 = pCtxt->pSTRMList;
	struct STRM_RES_OBJECT *pTempSTRMRes = pCtxt->pSTRMList;

	DBC_Assert(hPCtxt != NULL);
	while ((pTempSTRMRes != NULL) && (pTempSTRMRes != pSTRMRes)) {
		pTempSTRMRes2 = pTempSTRMRes;
		pTempSTRMRes = pTempSTRMRes->next;
	}
	if (pCtxt->pSTRMList == pTempSTRMRes)
		pCtxt->pSTRMList = pTempSTRMRes->next;

	if (pTempSTRMRes == NULL)
		status = DSP_ENOTFOUND;
	else if (pTempSTRMRes2->next != NULL)
		pTempSTRMRes2->next = pTempSTRMRes2->next->next;

	MEM_Free(pSTRMRes);
	return status;
}


/* Actual Stream De-Allocation */
static DSP_STATUS  DRV_ProcFreeSTRMRes(HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	DSP_STATUS status1 = DSP_SOK;
	u8 **apBuffer = NULL;
	struct STRM_RES_OBJECT *pSTRMList = NULL;
	struct STRM_RES_OBJECT *pSTRMRes = NULL;
	u8 *pBufPtr;
	u32 ulBytes;
	u32 dwArg;
	s32 ulBufSize;


	DBC_Assert(hPCtxt != NULL);
	pSTRMList = pCtxt->pSTRMList;
	while (pSTRMList != NULL) {
		pSTRMRes = pSTRMList;
		pSTRMList = pSTRMList->next;
		if (pSTRMRes->uNumBufs != 0) {
			apBuffer = MEM_Alloc((pSTRMRes->uNumBufs *
					    sizeof(u8 *)), MEM_NONPAGED);
			status = STRM_FreeBuffer(pSTRMRes->hStream, apBuffer,
						pSTRMRes->uNumBufs);
			MEM_Free(apBuffer);
		}
		status = STRM_Close(pSTRMRes->hStream);
		if (DSP_FAILED(status)) {
			if (status == DSP_EPENDING) {
				status = STRM_Reclaim(pSTRMRes->hStream,
						     &pBufPtr, &ulBytes,
						     (u32 *)&ulBufSize, &dwArg);
				if (DSP_SUCCEEDED(status))
					status = STRM_Close(pSTRMRes->hStream);

			}
		}
	}
	return status1;
}

/* Release all Stream resources and its context
* This is called from .bridge_release.
*/
DSP_STATUS	DRV_RemoveAllSTRMResElements(HANDLE hPCtxt)
{
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct STRM_RES_OBJECT *pTempSTRMRes2 = NULL;
	struct STRM_RES_OBJECT *pTempSTRMRes = NULL;

	DBC_Assert(hPCtxt != NULL);
	DRV_ProcFreeSTRMRes(pCtxt);
	pTempSTRMRes = pCtxt->pSTRMList;
	while (pTempSTRMRes != NULL) {
		pTempSTRMRes2 = pTempSTRMRes;
		pTempSTRMRes = pTempSTRMRes->next;
		MEM_Free(pTempSTRMRes2);
	}
	pCtxt->pSTRMList = NULL;
	return status;
}


/* Getting the stream resource element */
DSP_STATUS DRV_GetSTRMResElement(HANDLE hStrm, HANDLE hSTRMRes, HANDLE hPCtxt)
{
	struct STRM_RES_OBJECT **STRMRes = (struct STRM_RES_OBJECT **)hSTRMRes;
	struct PROCESS_CONTEXT *pCtxt = (struct PROCESS_CONTEXT *)hPCtxt;
	DSP_STATUS status = DSP_SOK;
	struct STRM_RES_OBJECT *pTempSTRM2 = NULL;
	struct STRM_RES_OBJECT *pTempSTRM = pCtxt->pSTRMList;

	DBC_Assert(hPCtxt != NULL);
	while ((pTempSTRM != NULL) && (pTempSTRM->hStream != hStrm)) {
		GT_0trace(curTrace, GT_ENTER, "DRV_GetSTRMResElement: 2");
		pTempSTRM2 = pTempSTRM;
		pTempSTRM = pTempSTRM->next;
	}
	if (pTempSTRM != NULL) {
		GT_0trace(curTrace, GT_ENTER, "DRV_GetSTRMResElement: 3");
		*STRMRes = pTempSTRM;
	} else {
		GT_0trace(curTrace, GT_ENTER, "DRV_GetSTRMResElement: 4");
		status = DSP_ENOTFOUND;
	}
	GT_0trace(curTrace, GT_ENTER, "DRV_GetSTRMResElement: 5");
	return status;
}

/* Updating the stream resource element */
DSP_STATUS DRV_ProcUpdateSTRMRes(u32 uNumBufs, HANDLE hSTRMRes, HANDLE hPCtxt)
{
	DSP_STATUS status = DSP_SOK;
	struct STRM_RES_OBJECT **STRMRes = (struct STRM_RES_OBJECT **)hSTRMRes;

	DBC_Assert(hPCtxt != NULL);
	(*STRMRes)->uNumBufs = uNumBufs;
	return status;
}

/* Displaying the resources allocated by a process */
DSP_STATUS DRV_ProcDisplayResInfo(u8 *pBuf1, u32 *pSize)
{
	struct PROCESS_CONTEXT *pCtxt = NULL;
	struct NODE_RES_OBJECT *pNodeRes = NULL;
	struct DMM_RES_OBJECT *pDMMRes = NULL;
	struct STRM_RES_OBJECT *pSTRMRes = NULL;
	struct DSPHEAP_RES_OBJECT *pDSPHEAPRes = NULL;
	u32 tempCount = 1;
	HANDLE hDrvObject = NULL;
	void *pBuf = pBuf1;
	u8 pTempBuf[250];
	u32 tempStrLen = 0, tempStrLen2 = 0;
	DSP_STATUS status = DSP_SOK;

	CFG_GetObject((u32 *)&hDrvObject, REG_DRV_OBJECT);
	DRV_GetProcCtxtList(&pCtxt, (struct DRV_OBJECT *)hDrvObject);
	GT_0trace(curTrace, GT_ENTER, "*********************"
		 "DRV_ProcDisplayResourceInfo:*\n");
	while (pCtxt != NULL) {
		tempStrLen2 = sprintf((char *)pTempBuf,
				     "-------------------------------------"
				     "-----------------------------------\n");
		tempStrLen2 += 2;
		memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
		tempStrLen += tempStrLen2;
		if (pCtxt->resState == PROC_RES_ALLOCATED) {
			tempStrLen2 = sprintf((char *)pTempBuf,
					"GPP Process Resource State: "
					"pCtxt->resState = PROC_RES_ALLOCATED, "
					" Process ID: %d\n", pCtxt->pid);
			tempStrLen2 += 2;
			memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
			tempStrLen += tempStrLen2;
		} else {
			tempStrLen2 = sprintf((char *)pTempBuf,
				"GPP Resource State: pCtxt->resState"
				" = PROC_RES_DEALLOCATED, Process ID:%d\n",
				pCtxt->pid);
			tempStrLen2 += 2;
			memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
			tempStrLen += tempStrLen2;
		}
		pNodeRes = pCtxt->pNodeList;
		tempCount = 1;
		while (pNodeRes != NULL) {
			GT_2trace(curTrace, GT_ENTER,
				 "DRV_ProcDisplayResourceInfo: #:%d "
				 "pCtxt->pNodeList->hNode:%x\n",
				 tempCount, pNodeRes->hNode);
			tempStrLen2 = sprintf((char *)pTempBuf,
					"Node Resource Information: Node #"
					" %d Node Handle hNode:0X%x\n",
					tempCount, (u32)pNodeRes->hNode);
			pNodeRes = pNodeRes->next;
			tempStrLen2 += 2;
			memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
			tempStrLen += tempStrLen2;
			tempCount++;
		}
		tempCount = 1;
		pDSPHEAPRes = pCtxt->pDSPHEAPList;
		while (pDSPHEAPRes != NULL) {
			GT_2trace(curTrace, GT_ENTER,
				 "DRV_ProcDisplayResourceInfo: #:%d "
				 "pCtxt->pDSPHEAPRList->ulMpuAddr:%x\n",
				 tempCount, pDSPHEAPRes->ulMpuAddr);
			tempStrLen2 = sprintf((char *)pTempBuf,
				 "DSP Heap Resource Info: HEAP # %d"
				 " Mapped GPP Address: 0x%x, size: 0x%x\n",
				 tempCount, (u32)pDSPHEAPRes->ulMpuAddr,
				 (u32)pDSPHEAPRes->heapSize);
			pDSPHEAPRes = pDSPHEAPRes->next;
			tempStrLen2 += 2;
			memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
			tempStrLen += tempStrLen2;
			tempCount++;
		}
		tempCount = 1;
		pDMMRes = pCtxt->pDMMList;
		while (pDMMRes != NULL) {
			GT_2trace(curTrace, GT_ENTER,
					"DRV_ProcDisplayResourceInfo: #:%d "
					" pCtxt->pDMMList->ulMpuAddr:%x\n",
					tempCount,
					pDMMRes->ulMpuAddr);
			tempStrLen2 = sprintf((char *)pTempBuf,
					 "DMM Resource Info: DMM # %d Mapped"
					 " GPP Address: 0x%x, size: 0x%x\n",
					 tempCount, (u32)pDMMRes->ulMpuAddr,
					 (u32)pDMMRes->dmmSize);
			pDMMRes = pDMMRes->next;
			tempStrLen2 += 2;
			memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
			tempStrLen += tempStrLen2;
			tempCount++;
		}
		tempCount = 1;
		pSTRMRes = pCtxt->pSTRMList;
		while (pSTRMRes != NULL) {
			GT_2trace(curTrace, GT_ENTER,
				 "DRV_ProcDisplayResourceInfo: #:%d "
				 "pCtxt->pSTRMList->hStream:%x\n", tempCount,
				 pSTRMRes->hStream);
			tempStrLen2 = sprintf((char *)pTempBuf,
					     "Stream Resource info: STRM # %d "
					     "Stream Handle: 0x%x \n",
					     tempCount, (u32)pSTRMRes->hStream);
			pSTRMRes = pSTRMRes->next;
			tempStrLen2 += 2;
			memmove(pBuf+tempStrLen, pTempBuf, tempStrLen2);
			tempStrLen += tempStrLen2;
			tempCount++;
		}
		pCtxt = pCtxt->next;
	}
	*pSize = tempStrLen;
	status = PrintProcessInformation();
	GT_0trace(curTrace, GT_ENTER, "*********************"
		"DRV_ProcDisplayResourceInfo:**\n");
	return status;
}

/*
 *  ======== PrintProcessInformation ========
 *  Purpose:
 *      This function prints the Process's information stored in
 *      the process context list. Some of the information that
 *      it displays is Process's state, Node, Stream, DMM, and
 *      Heap information.
 */
static DSP_STATUS PrintProcessInformation(void)
{
	struct DRV_OBJECT *hDrvObject = NULL;
	struct PROCESS_CONTEXT *pCtxtList = NULL;
	struct NODE_RES_OBJECT *pNodeRes = NULL;
	struct DMM_RES_OBJECT *pDMMRes = NULL;
	struct STRM_RES_OBJECT *pSTRMRes = NULL;
	struct DSPHEAP_RES_OBJECT *pDSPHEAPRes = NULL;
	DSP_STATUS status = DSP_SOK;
	u32 tempCount;
	u32  procID;

	/* Get the Process context list */
	CFG_GetObject((u32 *)&hDrvObject, REG_DRV_OBJECT);
	DRV_GetProcCtxtList(&pCtxtList, hDrvObject);
	GT_0trace(curTrace, GT_4CLASS, "\n### Debug information"
			" for DSP bridge ##\n");
	GT_0trace(curTrace, GT_4CLASS, " \n ###The  processes"
			" information is as follows ### \n") ;
	GT_0trace(curTrace, GT_4CLASS, "  ====================="
			"============ \n");
	/* Go through the entries in the Process context list */
	while (pCtxtList  != NULL) {
		GT_1trace(curTrace, GT_4CLASS, "\nThe process"
				" id is %d\n", pCtxtList->pid);
		GT_0trace(curTrace, GT_4CLASS, " -------------------"
				"---------\n");
		if (pCtxtList->resState == PROC_RES_ALLOCATED) {
			GT_0trace(curTrace, GT_4CLASS, " \nThe Process"
					" is in Allocated state\n");
		} else {
			GT_0trace(curTrace, GT_4CLASS, "\nThe Process"
					" is in DeAllocated state\n");
		}
		GT_1trace(curTrace, GT_4CLASS, "\nThe  hProcessor"
				" handle is: 0X%x\n",
				(u32)pCtxtList->hProcessor);
		if (pCtxtList->hProcessor != NULL) {
			PROC_GetProcessorId(pCtxtList->hProcessor, &procID);
			if (procID == DSP_UNIT) {
				GT_0trace(curTrace, GT_4CLASS,
					"\nProcess connected to"
					" DSP Processor\n");
			} else if (procID == IVA_UNIT) {
				GT_0trace(curTrace, GT_4CLASS,
					"\nProcess connected to"
					" IVA Processor\n");
			} else {
				GT_0trace(curTrace, GT_7CLASS,
					"\n***ERROR:Invalid Processor Id***\n");
			}
		}
		pNodeRes = pCtxtList->pNodeList;
		tempCount = 1;
		while (pNodeRes != NULL) {
			if (tempCount == 1)
				GT_0trace(curTrace, GT_4CLASS,
					"\n***The Nodes allocated by"
					" this Process are***\n");
			GT_2trace(curTrace, GT_4CLASS,
					"Node # %d Node Handle hNode:0x%x\n",
					tempCount, (u32)pNodeRes->hNode);
			pNodeRes = pNodeRes->next;
			tempCount++;
		}
		if (tempCount == 1)
			GT_0trace(curTrace, GT_4CLASS,
					"\n ***There are no Nodes"
					" allocated by this Process***\n");
		tempCount = 1;
		pDSPHEAPRes = pCtxtList->pDSPHEAPList;
		while (pDSPHEAPRes != NULL) {
			if (tempCount == 1)
				GT_0trace(curTrace, GT_4CLASS,
						"\n***The Heaps allocated by"
						" this Process are***\n");
			GT_3trace(curTrace, GT_4CLASS,
				"DSP Heap Resource Info: HEAP # %d "
				"Mapped GPP Address:0x%x, Size: 0x%lx\n",
				tempCount, (u32)pDSPHEAPRes->ulMpuAddr,
				pDSPHEAPRes->heapSize);
			pDSPHEAPRes = pDSPHEAPRes->next;
			tempCount++;
		}
		if (tempCount == 1)
			GT_0trace(curTrace, GT_4CLASS,
				"\n ***There are no Heaps allocated"
				" by this Process***\n");
		tempCount = 1;
		pDMMRes = pCtxtList->pDMMList;
		while (pDMMRes != NULL) {
			if (tempCount == 1)
				GT_0trace(curTrace, GT_4CLASS,
					"\n ***The DMM resources allocated by"
					" this Process are***\n");
			GT_3trace(curTrace, GT_4CLASS,
				"DMM Resource Info: DMM # %d "
				"Mapped GPP Address:0X%lx, Size: 0X%lx\n",
				tempCount, pDMMRes->ulMpuAddr,
				pDMMRes->dmmSize);
			pDMMRes = pDMMRes->next;
			tempCount++;
		}
		if (tempCount == 1)
			GT_0trace(curTrace, GT_4CLASS,
				"\n ***There are no DMM resources"
				" allocated by this Process***\n");
		tempCount = 1;
		pSTRMRes = pCtxtList->pSTRMList;
		while (pSTRMRes != NULL) {
			if (tempCount == 1)
				GT_0trace(curTrace, GT_4CLASS,
					"\n***The Stream resources allocated by"
					" this Process are***\n");
			GT_2trace(curTrace, GT_4CLASS,
				"Stream Resource info: STRM # %d"
				"Stream Handle:0X%x\n",	tempCount,
				(u32)pSTRMRes->hStream);
			pSTRMRes = pSTRMRes->next;
			tempCount++;
		}
		if (tempCount == 1)
			GT_0trace(curTrace, GT_4CLASS,
				"\n ***There are no Stream resources"
				"allocated by this Process***\n");
		pCtxtList = pCtxtList->next;
	}
	return status;
}

/* GPP PROCESS CLEANUP CODE END */
#endif

/*
 *  ======== = DRV_Create ======== =
 *  Purpose:
 *      DRV Object gets created only once during Driver Loading.
 */
DSP_STATUS DRV_Create(OUT struct DRV_OBJECT **phDRVObject)
{
	DSP_STATUS status = DSP_SOK;
	struct DRV_OBJECT *pDRVObject = NULL;

	DBC_Require(phDRVObject != NULL);
	DBC_Require(cRefs > 0);
	GT_1trace(curTrace, GT_ENTER, "Entering DRV_Create"
			" phDRVObject 0x%x\n", phDRVObject);
	MEM_AllocObject(pDRVObject, struct DRV_OBJECT, SIGNATURE);
	if (pDRVObject) {
		/* Create and Initialize List of device objects */
		pDRVObject->devList = LST_Create();
		if (pDRVObject->devList) {
			/* Create and Initialize List of device Extension */
			pDRVObject->devNodeString = LST_Create();
			if (!(pDRVObject->devNodeString)) {
				status = DSP_EFAIL;
				GT_0trace(curTrace, GT_7CLASS,
					 "Failed to Create DRV_EXT list ");
				MEM_FreeObject(pDRVObject);
			}
		} else {
			status = DSP_EFAIL;
			GT_0trace(curTrace, GT_7CLASS,
				 "Failed to Create Dev List ");
			MEM_FreeObject(pDRVObject);
		}
	} else {
		status = DSP_EFAIL;
		GT_0trace(curTrace, GT_7CLASS,
			 "Failed to Allocate Memory for DRV Obj");
	}
	if (DSP_SUCCEEDED(status)) {
		/* Store the DRV Object in the Registry */
		if (DSP_SUCCEEDED
		    (CFG_SetObject((u32) pDRVObject, REG_DRV_OBJECT))) {
			GT_1trace(curTrace, GT_1CLASS,
				 "DRV Obj Created pDrvObject 0x%x\n ",
				 pDRVObject);
			*phDRVObject = pDRVObject;
		} else {
			/* Free the DRV Object */
			status = DSP_EFAIL;
			MEM_Free(pDRVObject);
			GT_0trace(curTrace, GT_7CLASS,
				 "Failed to update the Registry with "
				 "DRV Object ");
		}
	}
	GT_2trace(curTrace, GT_ENTER,
		 "Exiting DRV_Create: phDRVObject: 0x%x\tstatus:"
		 "0x%x\n", phDRVObject, status);
	DBC_Ensure(DSP_FAILED(status) ||
		  MEM_IsValidHandle(pDRVObject, SIGNATURE));
	return status;
}

/*
 *  ======== DRV_Exit ========
 *  Purpose:
 *      Discontinue usage of the DRV module.
 */
void DRV_Exit(void)
{
	DBC_Require(cRefs > 0);

	GT_0trace(curTrace, GT_5CLASS, "Entering DRV_Exit \n");

	cRefs--;

	DBC_Ensure(cRefs >= 0);
}

/*
 *  ======== = DRV_Destroy ======== =
 *  purpose:
 *      Invoked during bridge de-initialization
 */
DSP_STATUS DRV_Destroy(struct DRV_OBJECT *hDRVObject)
{
	DSP_STATUS status = DSP_SOK;
	struct DRV_OBJECT *pDRVObject = (struct DRV_OBJECT *)hDRVObject;

	DBC_Require(cRefs > 0);
	DBC_Require(MEM_IsValidHandle(pDRVObject, SIGNATURE));

	GT_1trace(curTrace, GT_ENTER, "Entering DRV_Destroy"
			" hDRVObject 0x%x\n", hDRVObject);
	/*
	 *  Delete the List if it exists.Should not come here
	 *  as the DRV_RemoveDevObject and the Last DRV_RequestResources
	 *  removes the list if the lists are empty.
	 */
	if (pDRVObject->devList) {
		/* Could assert if the list is not empty  */
		LST_Delete(pDRVObject->devList);
	}
	if (pDRVObject->devNodeString) {
		/* Could assert if the list is not empty */
		LST_Delete(pDRVObject->devNodeString);
	}
	MEM_FreeObject(pDRVObject);
	/* Update the DRV Object in Registry to be 0 */
	(void)CFG_SetObject(0, REG_DRV_OBJECT);
	GT_2trace(curTrace, GT_ENTER,
		 "Exiting DRV_Destroy: hDRVObject: 0x%x\tstatus:"
		 "0x%x\n", hDRVObject, status);
	DBC_Ensure(!MEM_IsValidHandle(pDRVObject, SIGNATURE));
	return status;
}

/*
 *  ======== DRV_GetDevObject ========
 *  Purpose:
 *      Given a index, returns a handle to DevObject from the list.
 */
DSP_STATUS DRV_GetDevObject(u32 uIndex, struct DRV_OBJECT *hDrvObject,
			   struct DEV_OBJECT **phDevObject)
{
	DSP_STATUS status = DSP_SOK;
#if GT_TRACE	/* pDrvObject is used only for Assertions and debug messages.*/
	struct DRV_OBJECT *pDrvObject = (struct DRV_OBJECT *)hDrvObject;
#endif
	struct DEV_OBJECT *pDevObject;
	u32 i;
	DBC_Require(MEM_IsValidHandle(pDrvObject, SIGNATURE));
	DBC_Require(phDevObject != NULL);
	DBC_Require(uIndex >= 0);
	DBC_Require(cRefs > 0);
	DBC_Assert(!(LST_IsEmpty(pDrvObject->devList)));
	GT_3trace(curTrace, GT_ENTER,
		 "Entered DRV_GetDevObject, args:\n\tuIndex: "
		 "0x%x\n\thDrvObject:  0x%x\n\tphDevObject:  0x%x\n",
		 uIndex, hDrvObject, phDevObject);
	pDevObject = (struct DEV_OBJECT *)DRV_GetFirstDevObject();
	for (i = 0; i < uIndex; i++) {
		pDevObject =
		   (struct DEV_OBJECT *)DRV_GetNextDevObject((u32)pDevObject);
	}
	if (pDevObject) {
		*phDevObject = (struct DEV_OBJECT *) pDevObject;
		status = DSP_SOK;
	} else {
		*phDevObject = NULL;
		status = DSP_EFAIL;
		GT_0trace(curTrace, GT_7CLASS,
			 "DRV: Could not get the DevObject\n");
	}
	GT_2trace(curTrace, GT_ENTER,
		 "Exiting Drv_GetDevObject\n\tstatus: 0x%x\n\t"
		 "hDevObject: 0x%x\n", status, *phDevObject);
	return status;
}

/*
 *  ======== DRV_GetFirstDevObject ========
 *  Purpose:
 *      Retrieve the first Device Object handle from an internal linked list of
 *      of DEV_OBJECTs maintained by DRV.
 */
u32 DRV_GetFirstDevObject(void)
{
	u32 dwDevObject = 0;
	struct DRV_OBJECT *pDrvObject;

	if (DSP_SUCCEEDED
	    (CFG_GetObject((u32 *)&pDrvObject, REG_DRV_OBJECT))) {
		if ((pDrvObject->devList != NULL) &&
		   !LST_IsEmpty(pDrvObject->devList))
			dwDevObject = (u32) LST_First(pDrvObject->devList);
	}

	return dwDevObject;
}

/*
 *  ======== DRV_GetFirstDevNodeString ========
 *  Purpose:
 *      Retrieve the first Device Extension from an internal linked list of
 *      of Pointer to DevNode Strings maintained by DRV.
 */
u32 DRV_GetFirstDevExtension(void)
{
	u32 dwDevExtension = 0;
	struct DRV_OBJECT *pDrvObject;

	if (DSP_SUCCEEDED
	    (CFG_GetObject((u32 *)&pDrvObject, REG_DRV_OBJECT))) {

		if ((pDrvObject->devNodeString != NULL) &&
		   !LST_IsEmpty(pDrvObject->devNodeString)) {
			dwDevExtension = (u32)LST_First(pDrvObject->
							devNodeString);
		}
	}

	return dwDevExtension;
}

/*
 *  ======== DRV_GetNextDevObject ========
 *  Purpose:
 *      Retrieve the next Device Object handle from an internal linked list of
 *      of DEV_OBJECTs maintained by DRV, after having previously called
 *      DRV_GetFirstDevObject() and zero or more DRV_GetNext.
 */
u32 DRV_GetNextDevObject(u32 hDevObject)
{
	u32 dwNextDevObject = 0;
	struct DRV_OBJECT *pDrvObject;

	DBC_Require(hDevObject != 0);

	if (DSP_SUCCEEDED
	    (CFG_GetObject((u32 *)&pDrvObject, REG_DRV_OBJECT))) {

		if ((pDrvObject->devList != NULL) &&
		   !LST_IsEmpty(pDrvObject->devList)) {
			dwNextDevObject = (u32)LST_Next(pDrvObject->devList,
					  (struct LST_ELEM *)hDevObject);
		}
	}
	return dwNextDevObject;
}

/*
 *  ======== DRV_GetNextDevExtension ========
 *  Purpose:
 *      Retrieve the next Device Extension from an internal linked list of
 *      of pointer to DevNodeString maintained by DRV, after having previously
 *      called DRV_GetFirstDevExtension() and zero or more
 *      DRV_GetNextDevExtension().
 */
u32 DRV_GetNextDevExtension(u32 hDevExtension)
{
	u32 dwDevExtension = 0;
	struct DRV_OBJECT *pDrvObject;

	DBC_Require(hDevExtension != 0);

	if (DSP_SUCCEEDED(CFG_GetObject((u32 *)&pDrvObject,
	   REG_DRV_OBJECT))) {
		if ((pDrvObject->devNodeString != NULL) &&
		   !LST_IsEmpty(pDrvObject->devNodeString)) {
			dwDevExtension = (u32)LST_Next(pDrvObject->
				devNodeString,
				(struct LST_ELEM *)hDevExtension);
		}
	}

	return dwDevExtension;
}

/*
 *  ======== DRV_Init ========
 *  Purpose:
 *      Initialize DRV module private state.
 */
DSP_STATUS DRV_Init(void)
{
	s32 fRetval = 1;	/* function return value */

	DBC_Require(cRefs >= 0);

	if (fRetval)
		cRefs++;

	GT_1trace(curTrace, GT_5CLASS, "Entering DRV_Entry  crefs 0x%x \n",
		 cRefs);

	DBC_Ensure((fRetval && (cRefs > 0)) || (!fRetval && (cRefs >= 0)));

	return fRetval;
}

/*
 *  ======== DRV_InsertDevObject ========
 *  Purpose:
 *      Insert a DevObject into the list of Manager object.
 */
DSP_STATUS DRV_InsertDevObject(struct DRV_OBJECT *hDRVObject,
			       struct DEV_OBJECT *hDevObject)
{
	DSP_STATUS status = DSP_SOK;
	struct DRV_OBJECT *pDRVObject = (struct DRV_OBJECT *)hDRVObject;

	DBC_Require(cRefs > 0);
	DBC_Require(hDevObject != NULL);
	DBC_Require(MEM_IsValidHandle(pDRVObject, SIGNATURE));
	DBC_Assert(pDRVObject->devList);

	GT_2trace(curTrace, GT_ENTER,
		 "Entering DRV_InsertProcObject hDRVObject "
		 "0x%x\n, hDevObject 0x%x\n", hDRVObject, hDevObject);

	LST_PutTail(pDRVObject->devList, (struct LST_ELEM *)hDevObject);

	GT_1trace(curTrace, GT_ENTER,
		 "Exiting InsertDevObject status 0x%x\n", status);

	DBC_Ensure(DSP_SUCCEEDED(status) && !LST_IsEmpty(pDRVObject->devList));

	return status;
}

/*
 *  ======== DRV_RemoveDevObject ========
 *  Purpose:
 *      Search for and remove a DeviceObject from the given list of DRV
 *      objects.
 */
DSP_STATUS DRV_RemoveDevObject(struct DRV_OBJECT *hDRVObject,
			       struct DEV_OBJECT *hDevObject)
{
	DSP_STATUS status = DSP_EFAIL;
	struct DRV_OBJECT *pDRVObject = (struct DRV_OBJECT *)hDRVObject;
	struct LST_ELEM *pCurElem;

	DBC_Require(cRefs > 0);
	DBC_Require(MEM_IsValidHandle(pDRVObject, SIGNATURE));
	DBC_Require(hDevObject != NULL);

	DBC_Require(pDRVObject->devList != NULL);
	DBC_Require(!LST_IsEmpty(pDRVObject->devList));

	GT_2trace(curTrace, GT_ENTER,
		 "Entering DRV_RemoveDevObject hDevObject "
		 "0x%x\n, hDRVObject 0x%x\n", hDevObject, hDRVObject);
	/* Search list for pProcObject: */
	for (pCurElem = LST_First(pDRVObject->devList); pCurElem != NULL;
	    pCurElem = LST_Next(pDRVObject->devList, pCurElem)) {
		/* If found, remove it. */
		if ((struct DEV_OBJECT *) pCurElem == hDevObject) {
			LST_RemoveElem(pDRVObject->devList, pCurElem);
			status = DSP_SOK;
			break;
		}
	}
	/* Remove list if empty. */
	if (LST_IsEmpty(pDRVObject->devList)) {
		LST_Delete(pDRVObject->devList);
		pDRVObject->devList = NULL;
	}
	DBC_Ensure((pDRVObject->devList == NULL) ||
		  !LST_IsEmpty(pDRVObject->devList));
	GT_1trace(curTrace, GT_ENTER,
		 "DRV_RemoveDevObject returning 0x%x\n", status);
	return status;
}

/*
 *  ======== DRV_RequestResources ========
 *  Purpose:
 *      Requests  resources from the OS.
 */
DSP_STATUS DRV_RequestResources(u32 dwContext, u32 *pDevNodeString)
{
	DSP_STATUS status = DSP_SOK;
	struct DRV_OBJECT *pDRVObject;
	struct DRV_EXT *pszdevNode;

	DBC_Require(dwContext != 0);
	DBC_Require(pDevNodeString != NULL);
	GT_0trace(curTrace, GT_ENTER, "Entering DRV_RequestResources\n");
	/*
	 *  Allocate memory to hold the string. This will live untill
	 *  it is freed in the Release resources. Update the driver object
	 *  list.
	 */
	if (DSP_SUCCEEDED(CFG_GetObject((u32 *)&pDRVObject,
	   REG_DRV_OBJECT))) {
		pszdevNode = MEM_Calloc(sizeof(struct DRV_EXT), MEM_NONPAGED);
		if (pszdevNode) {
			LST_InitElem(&pszdevNode->link);
                       strncpy((char *) pszdevNode->szString,
				 (char *)dwContext, MAXREGPATHLENGTH);
			/* Update the Driver Object List */
			*pDevNodeString = (u32)pszdevNode->szString;
			LST_PutTail(pDRVObject->devNodeString,
				(struct LST_ELEM *)pszdevNode);
		} else {
			GT_0trace(curTrace, GT_7CLASS,
				"Failed to Allocate Memory devNodeString ");
			status = DSP_EFAIL;
			*pDevNodeString = 0;
		}
	} else {
		status = DSP_EFAIL;
		GT_0trace(curTrace, GT_7CLASS,
			 "Failed to get Driver Object from Registry");
		*pDevNodeString = 0;
	}

       if (!(strcmp((char *) dwContext, "TIOMAP1510"))) {
		GT_0trace(curTrace, GT_1CLASS,
			  " Allocating resources for UMA \n");
		status = RequestBridgeResourcesDSP(dwContext, DRV_ASSIGN);
	} else {
		status = DSP_EFAIL;
		GT_0trace(curTrace, GT_7CLASS, "Unknown Device ");
	}

	if (DSP_FAILED(status)) {
		GT_0trace(curTrace, GT_7CLASS,
			 "Failed to reserve bridge resources ");
	}
	DBC_Ensure((DSP_SUCCEEDED(status) && pDevNodeString != NULL &&
		  !LST_IsEmpty(pDRVObject->devNodeString)) ||
		  (DSP_FAILED(status) && *pDevNodeString == 0));

	return status;
}

/*
 *  ======== DRV_ReleaseResources ========
 *  Purpose:
 *      Releases  resources from the OS.
 */
DSP_STATUS DRV_ReleaseResources(u32 dwContext, struct DRV_OBJECT *hDrvObject)
{
	DSP_STATUS status = DSP_SOK;
	struct DRV_OBJECT *pDRVObject = (struct DRV_OBJECT *)hDrvObject;
	struct DRV_EXT *pszdevNode;

	GT_0trace(curTrace, GT_ENTER, "Entering DRV_Release Resources\n");

       if (!(strcmp((char *)((struct DRV_EXT *)dwContext)->szString,
	   "TIOMAP1510"))) {
		GT_0trace(curTrace, GT_1CLASS,
			 " Releasing DSP-Bridge resources \n");
		status = RequestBridgeResources(dwContext, DRV_RELEASE);
	} else {
		GT_0trace(curTrace, GT_1CLASS, " Unknown device\n");
	}

	if (DSP_SUCCEEDED(status)) {
		GT_0trace(curTrace, GT_1CLASS,
			 "Failed to relese bridge resources\n");
	}

	/*
	 *  Irrespective of the status go ahead and clean it
	 *  The following will over write the status.
	 */
	for (pszdevNode = (struct DRV_EXT *)DRV_GetFirstDevExtension();
	    pszdevNode != NULL; pszdevNode = (struct DRV_EXT *)
	    DRV_GetNextDevExtension((u32)pszdevNode)) {
		if ((u32)pszdevNode == dwContext) {
			/* Found it */
			/* Delete from the Driver object list */
			LST_RemoveElem(pDRVObject->devNodeString,
				      (struct LST_ELEM *)pszdevNode);
			MEM_Free((void *) pszdevNode);
			break;
		}
		/* Delete the List if it is empty */
		if (LST_IsEmpty(pDRVObject->devNodeString)) {
			LST_Delete(pDRVObject->devNodeString);
			pDRVObject->devNodeString = NULL;
		}
	}
	return status;
}

/*
 *  ======== RequestBridgeResources ========
 *  Purpose:
 *      Reserves shared memory for bridge.
 */
static DSP_STATUS RequestBridgeResources(u32 dwContext, s32 bRequest)
{
	DSP_STATUS status = DSP_SOK;
	struct CFG_HOSTRES *pResources;
	u32 dwBuffSize;

	struct DRV_EXT *driverExt;
	u32 shm_size;

	DBC_Require(dwContext != 0);

	GT_0trace(curTrace, GT_ENTER, "->RequestBridgeResources \n");

	if (!bRequest) {
		driverExt = (struct DRV_EXT *)dwContext;
		/* Releasing resources by deleting the registry key  */
		dwBuffSize = sizeof(struct CFG_HOSTRES);
		pResources = MEM_Calloc(dwBuffSize, MEM_NONPAGED);
		if (DSP_FAILED(REG_GetValue(NULL, (char *)driverExt->szString,
		   CURRENTCONFIG, (u8 *)pResources, &dwBuffSize))) {
			status = CFG_E_RESOURCENOTAVAIL;
			GT_0trace(curTrace, GT_1CLASS,
				 "REG_GetValue Failed \n");
		} else {
			GT_0trace(curTrace, GT_1CLASS,
				 "REG_GetValue Succeeded \n");
		}

		if (pResources != NULL) {
			dwBuffSize = sizeof(shm_size);
			status = REG_GetValue(NULL, CURRENTCONFIG, SHMSIZE,
				(u8 *)&shm_size, &dwBuffSize);
			if (DSP_SUCCEEDED(status)) {
				if ((pResources->dwMemBase[1]) &&
				   (pResources->dwMemPhys[1])) {
					MEM_FreePhysMem((void *)pResources->
					dwMemBase[1], pResources->dwMemPhys[1],
					shm_size);
				}
			} else {
				GT_1trace(curTrace, GT_7CLASS,
					"Error getting SHM size from registry: "
					"%x. Not calling MEM_FreePhysMem\n",
					status);
			}
			pResources->dwMemBase[1] = 0;
			pResources->dwMemPhys[1] = 0;

			if (pResources->dwPrmBase)
				iounmap(pResources->dwPrmBase);
1657
#ifdef OMAP_3430
1658
			if (pResources->dwCmBase)
1659 1660 1661 1662 1663 1664 1665 1666
				iounmap((void *)pResources->dwCmBase);
#endif
#ifdef OMAP_44XX
			if (pResources->dwCm1Base)
				iounmap((void *)pResources->dwCm1Base);
			if (pResources->dwCm2Base)
				iounmap((void *)pResources->dwCm2Base);
#endif
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
			if (pResources->dwMboxBase)
				iounmap(pResources->dwMboxBase);
			if (pResources->dwMemBase[0])
				iounmap((void *)pResources->dwMemBase[0]);
			if (pResources->dwMemBase[2])
				iounmap((void *)pResources->dwMemBase[2]);
			if (pResources->dwMemBase[3])
				iounmap((void *)pResources->dwMemBase[3]);
			if (pResources->dwMemBase[4])
				iounmap((void *)pResources->dwMemBase[4]);
			if (pResources->dwWdTimerDspBase)
				iounmap(pResources->dwWdTimerDspBase);
			if (pResources->dwDmmuBase)
				iounmap(pResources->dwDmmuBase);
			if (pResources->dwPerBase)
				iounmap(pResources->dwPerBase);
                       if (pResources->dwPerPmBase)
                               iounmap((void *)pResources->dwPerPmBase);
                       if (pResources->dwCorePmBase)
                               iounmap((void *)pResources->dwCorePmBase);
			if (pResources->dwSysCtrlBase) {
				iounmap(pResources->dwSysCtrlBase);
				/* don't set pResources->dwSysCtrlBase to null
				 * as it is used in BOARD_Stop */
			}
			pResources->dwPrmBase = NULL;
1693
#ifdef OMAP_3430
1694
			pResources->dwCmBase = NULL;
1695 1696 1697 1698 1699
#endif
#ifdef OMAP_44XX
			pResources->dwCm1Base = (u32) NULL;
			pResources->dwCm2Base = (u32) NULL;
#endif
1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726
			pResources->dwMboxBase = NULL;
			pResources->dwMemBase[0] = (u32) NULL;
			pResources->dwMemBase[2] = (u32) NULL;
			pResources->dwMemBase[3] = (u32) NULL;
			pResources->dwMemBase[4] = (u32) NULL;
			pResources->dwWdTimerDspBase = NULL;
			pResources->dwDmmuBase = NULL;

			dwBuffSize = sizeof(struct CFG_HOSTRES);
			status = REG_SetValue(NULL, (char *)driverExt->szString,
				 CURRENTCONFIG, REG_BINARY, (u8 *)pResources,
				 (u32)dwBuffSize);
			/*  Set all the other entries to NULL */
			MEM_Free(pResources);
		}
		GT_0trace(curTrace, GT_ENTER, " <- RequestBridgeResources \n");
		return status;
	}
	dwBuffSize = sizeof(struct CFG_HOSTRES);
	pResources = MEM_Calloc(dwBuffSize, MEM_NONPAGED);
	if (pResources != NULL) {
		/* wNumMemWindows must not be more than CFG_MAXMEMREGISTERS */
		pResources->wNumMemWindows = 2;
		/* First window is for DSP internal memory */

		pResources->dwPrmBase = ioremap(OMAP_IVA2_PRM_BASE,
							OMAP_IVA2_PRM_SIZE);
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737

#ifdef OMAP44XX
                pResources->dwCm1Base = (u32)ioremap(OMAP_IVA2_CM1_BASE,
                                                        OMAP_IVA2_CM1_SIZE);
                pResources->dwCm2Base = (u32)ioremap(OMAP_IVA2_CM2_BASE,
                                                        OMAP_IVA2_CM2_SIZE);
#else
				pResources->dwCmBase = ioremap(OMAP_IVA2_CM_BASE,
													OMAP_IVA2_CM_SIZE);
#endif

1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
		pResources->dwMboxBase = ioremap(OMAP_MBOX_BASE,
							OMAP_MBOX_SIZE);
		pResources->dwSysCtrlBase = ioremap(OMAP_SYSC_BASE,
							OMAP_SYSC_SIZE);
		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[0] 0x%x\n",
			 pResources->dwMemBase[0]);
		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[3] 0x%x\n",
			 pResources->dwMemBase[3]);
		GT_1trace(curTrace, GT_2CLASS, "dwPrmBase 0x%x\n",
							pResources->dwPrmBase);
1748 1749 1750 1751 1752 1753
#ifdef OMAP44XX
		GT_1trace(curTrace, GT_2CLASS, "dwCm1Base 0x%x\n",
							pResources->dwCm1Base);
		GT_1trace(curTrace, GT_2CLASS, "dwCm2Base 0x%x\n",
							pResources->dwCm2Base);
#else
1754 1755
		GT_1trace(curTrace, GT_2CLASS, "dwCmBase 0x%x\n",
							pResources->dwCmBase);
1756
#endif
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
		GT_1trace(curTrace, GT_2CLASS, "dwWdTimerDspBase 0x%x\n",
						pResources->dwWdTimerDspBase);
		GT_1trace(curTrace, GT_2CLASS, "dwMboxBase 0x%x\n",
						pResources->dwMboxBase);
		GT_1trace(curTrace, GT_2CLASS, "dwDmmuBase 0x%x\n",
						pResources->dwDmmuBase);

		/* for 24xx base port is not mapping the mamory for DSP
		 * internal memory TODO Do a ioremap here */
		/* Second window is for DSP external memory shared with MPU */
		if (DSP_SUCCEEDED(status)) {
			/* for Linux, these are hard-coded values */
			pResources->bIRQRegisters = 0;
			pResources->bIRQAttrib = 0;
			pResources->dwOffsetForMonitor = 0;
			pResources->dwChnlOffset = 0;
			/* CHNL_MAXCHANNELS */
			pResources->dwNumChnls = CHNL_MAXCHANNELS;
			pResources->dwChnlBufSize = 0x400;
			dwBuffSize = sizeof(struct CFG_HOSTRES);
			status = REG_SetValue(NULL, (char *) dwContext,
					     CURRENTCONFIG, REG_BINARY,
					     (u8 *)pResources,
					     sizeof(struct CFG_HOSTRES));
			if (DSP_SUCCEEDED(status)) {
				GT_0trace(curTrace, GT_1CLASS,
					 " Successfully set the registry "
					 "value for CURRENTCONFIG\n");
			} else {
				GT_0trace(curTrace, GT_7CLASS,
					 " Failed to set the registry "
					 "value for CURRENTCONFIG\n");
			}
		}
		MEM_Free(pResources);
	}
	/* End Mem alloc */
	return status;
}

/*
 *  ======== RequestBridgeResourcesDSP ========
 *  Purpose:
 *      Reserves shared memory for bridge.
 */
static DSP_STATUS RequestBridgeResourcesDSP(u32 dwContext, s32 bRequest)
{
	DSP_STATUS status = DSP_SOK;
	struct CFG_HOSTRES *pResources;
	u32 dwBuffSize;
	u32 dmaAddr;
	u32 shm_size;

	DBC_Require(dwContext != 0);

	GT_0trace(curTrace, GT_ENTER, "->RequestBridgeResourcesDSP \n");

	dwBuffSize = sizeof(struct CFG_HOSTRES);

	pResources = MEM_Calloc(dwBuffSize, MEM_NONPAGED);

	if (pResources != NULL) {
		if (DSP_FAILED(CFG_GetHostResources((struct CFG_DEVNODE *)
		   dwContext, pResources))) {
			/* Call CFG_GetHostResources to get reserve resouces */
			status = RequestBridgeResources(dwContext, bRequest);
			if (DSP_SUCCEEDED(status)) {
				status = CFG_GetHostResources
					((struct CFG_DEVNODE *) dwContext,
					pResources);
			}
		}
		/* wNumMemWindows must not be more than CFG_MAXMEMREGISTERS */
		pResources->wNumMemWindows = 4;

		pResources->dwMemBase[0] = 0;
		pResources->dwMemBase[2] = (u32)ioremap(OMAP_DSP_MEM1_BASE,
							OMAP_DSP_MEM1_SIZE);
		pResources->dwMemBase[3] = (u32)ioremap(OMAP_DSP_MEM2_BASE,
							OMAP_DSP_MEM2_SIZE);
		pResources->dwMemBase[4] = (u32)ioremap(OMAP_DSP_MEM3_BASE,
							OMAP_DSP_MEM3_SIZE);
1839
#ifdef OMAP_3430
1840 1841
		pResources->dwPerBase = ioremap(OMAP_PER_CM_BASE,
							OMAP_PER_CM_SIZE);
1842 1843 1844
        pResources->dwPerPmBase = (u32)ioremap(OMAP_PER_PRM_BASE,
                                                     OMAP_PER_PRM_SIZE);
        pResources->dwCorePmBase = (u32)ioremap(OMAP_CORE_PRM_BASE,
1845
                                                       OMAP_CORE_PRM_SIZE);
1846 1847 1848 1849 1850 1851 1852
#else

        pResources->dwCm1Base = (u32)ioremap(OMAP_IVA2_CM1_BASE,
                            OMAP_IVA2_CM1_SIZE);
        pResources->dwCm2Base = (u32)ioremap(OMAP_IVA2_CM2_BASE,
                            OMAP_IVA2_CM2_SIZE);
#endif
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868
		pResources->dwDmmuBase = ioremap(OMAP_DMMU_BASE,
							OMAP_DMMU_SIZE);
		pResources->dwWdTimerDspBase = NULL;

		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[0] 0x%x\n",
						pResources->dwMemBase[0]);
		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[1] 0x%x\n",
						pResources->dwMemBase[1]);
		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[2] 0x%x\n",
						pResources->dwMemBase[2]);
		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[3] 0x%x\n",
						pResources->dwMemBase[3]);
		GT_1trace(curTrace, GT_2CLASS, "dwMemBase[4] 0x%x\n",
						pResources->dwMemBase[4]);
		GT_1trace(curTrace, GT_2CLASS, "dwPrmBase 0x%x\n",
						pResources->dwPrmBase);
1869 1870 1871 1872 1873 1874
#ifdef OMAP44XX
		GT_1trace(curTrace, GT_2CLASS, "dwCm1Base 0x%x\n",
							pResources->dwCm1Base);
		GT_1trace(curTrace, GT_2CLASS, "dwCm2Base 0x%x\n",
							pResources->dwCm2Base);
#else
1875 1876
		GT_1trace(curTrace, GT_2CLASS, "dwCmBase 0x%x\n",
						pResources->dwCmBase);
1877
#endif
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
		GT_1trace(curTrace, GT_2CLASS, "dwWdTimerDspBase 0x%x\n",
						pResources->dwWdTimerDspBase);
		GT_1trace(curTrace, GT_2CLASS, "dwMboxBase 0x%x\n",
						pResources->dwMboxBase);
		GT_1trace(curTrace, GT_2CLASS, "dwDmmuBase 0x%x\n",
						pResources->dwDmmuBase);
		dwBuffSize = sizeof(shm_size);
		status = REG_GetValue(NULL, CURRENTCONFIG, SHMSIZE,
				     (u8 *)&shm_size, &dwBuffSize);
		if (DSP_SUCCEEDED(status)) {
			/* Allocate Physically contiguous,
			 * non-cacheable  memory */
			pResources->dwMemBase[1] =
				(u32)MEM_AllocPhysMem(shm_size, 0x100000,
							&dmaAddr);
			if (pResources->dwMemBase[1] == 0) {
				status = DSP_EMEMORY;
				GT_0trace(curTrace, GT_7CLASS,
					 "SHM reservation Failed\n");
			} else {
				pResources->dwMemLength[1] = shm_size;
				pResources->dwMemPhys[1] = dmaAddr;

				GT_3trace(curTrace, GT_1CLASS,
					 "Bridge SHM address 0x%x dmaAddr"
					 " %x size %x\n",
					 pResources->dwMemBase[1],
					 dmaAddr, shm_size);
			}
		}
		if (DSP_SUCCEEDED(status)) {
			/* for Linux, these are hard-coded values */
			pResources->bIRQRegisters = 0;
			pResources->bIRQAttrib = 0;
			pResources->dwOffsetForMonitor = 0;
			pResources->dwChnlOffset = 0;
			/* CHNL_MAXCHANNELS */
			pResources->dwNumChnls = CHNL_MAXCHANNELS;
			pResources->dwChnlBufSize = 0x400;
			dwBuffSize = sizeof(struct CFG_HOSTRES);
			status = REG_SetValue(NULL, (char *)dwContext,
					     CURRENTCONFIG, REG_BINARY,
					     (u8 *)pResources,
					     sizeof(struct CFG_HOSTRES));
			if (DSP_SUCCEEDED(status)) {
				GT_0trace(curTrace, GT_1CLASS,
					 " Successfully set the registry"
					 " value for CURRENTCONFIG\n");
			} else {
				GT_0trace(curTrace, GT_7CLASS,
					 " Failed to set the registry value"
					 " for CURRENTCONFIG\n");
			}
		}
		MEM_Free(pResources);
	}
	/* End Mem alloc */
	return status;
}