/* * ======== SERVICES_Init ======== * Purpose: * Initializes SERVICES modules. */ bool SERVICES_Init(void) { bool fInit = true; bool fCFG, fCSL, fDBG, fDPC, fKFILE, fLST, fMEM; bool fREG, fSYNC, fCLK, fNTFY; DBC_Require(cRefs >= 0); if (cRefs == 0) { GT_init(); GT_create(&SERVICES_debugMask, "OS"); /* OS for OSal */ GT_0trace(SERVICES_debugMask, GT_ENTER, "SERVICES_Init: entered\n"); /* Perform required initialization of SERVICES modules. */ fMEM = MEM_Init(); fREG = REG_Init(); fCFG = CFG_Init(); fCSL = CSL_Init(); fDBG = DBG_Init(); fDPC = DPC_Init(); fKFILE = KFILE_Init(); fLST = LST_Init(); fSYNC = SYNC_Init(); fCLK = CLK_Init(); fNTFY = NTFY_Init(); fInit = fCFG && fCSL && fDBG && fDPC && fKFILE && fLST && fMEM && fREG && fSYNC && fCLK; if (!fInit) { if (fNTFY) NTFY_Exit(); if (fSYNC) SYNC_Exit(); if (fCLK) CLK_Exit(); if (fREG) REG_Exit(); if (fLST) LST_Exit(); if (fKFILE) KFILE_Exit(); if (fDPC) DPC_Exit(); if (fDBG) DBG_Exit(); if (fCSL) CSL_Exit(); if (fCFG) CFG_Exit(); if (fMEM) MEM_Exit(); } } if (fInit) cRefs++; GT_1trace(SERVICES_debugMask, GT_5CLASS, "SERVICES_Init: cRefs 0x%x\n", cRefs); DBC_Ensure((fInit && (cRefs > 0)) || (!fInit && (cRefs >= 0))); return fInit; }
int main(int argc, char* argv[]) { int res = GT_OK; char *in_file = NULL; char *out_file = NULL; char *tsa_url = NULL; unsigned char *der_in = NULL; size_t der_in_len; unsigned char *der_out = NULL; size_t der_out_len; GTTimestamp *in_timestamp = NULL; GTTimestamp *out_timestamp = NULL; /* Read arguments. */ if (argc != 4) { printf("Usage: %s timestamp_in_file timestamp_out_file verifier_url\n", argv[0]); goto cleanup; } in_file = argv[1]; out_file = argv[2]; tsa_url = argv[3]; /* Init GuardTime libraries. */ res = GT_init(); if (res != GT_OK) { fprintf(stderr, "GT_init() failed: %d (%s)\n", res, GT_getErrorString(res)); goto cleanup; } res = GTHTTP_init("C SDK example", 1); if (res != GT_OK) { fprintf(stderr, "GTHTTP_init() failed: %d (%s)\n", res, GTHTTP_getErrorString(res)); goto cleanup; } /* Read timestamp file. */ res = GT_loadFile(in_file, &der_in, &der_in_len); if (res != GT_OK) { fprintf(stderr, "Cannot load timestamp file %s: %d (%s)\n", in_file, res, GT_getErrorString(res)); if (res == GT_IO_ERROR) { fprintf(stderr, "\t%d (%s)\n", errno, strerror(errno)); } goto cleanup; } /* Decode timestamp. */ res = GTTimestamp_DERDecode(der_in, der_in_len, &in_timestamp); if (res != GT_OK) { fprintf(stderr, "GTTimestamp_DERDecode() failed: %d (%s)\n", res, GT_getErrorString(res)); goto cleanup; } /* Extend timestamp. */ res = GTHTTP_extendTimestamp(in_timestamp, tsa_url, &out_timestamp); if (res != GT_OK) { fprintf(stderr, "GTHTTP_extendTimestamp() failed: %d (%s)\n", res, GTHTTP_getErrorString(res)); goto cleanup; } /* Encode timestamp. */ res = GTTimestamp_getDEREncoded(out_timestamp, &der_out, &der_out_len); if (res != GT_OK) { fprintf(stderr, "GTTimestamp_getDEREncoded() returned %d (%s)\n", res, GT_getErrorString(res)); goto cleanup; } /* Save DER-encoded timestamp to file. */ res = GT_saveFile(out_file, der_out, der_out_len); if (res != GT_OK) { fprintf(stderr, "Cannot save extended timestamp to file %s: %d (%s)\n", out_file, res, GT_getErrorString(res)); if (res == GT_IO_ERROR) { fprintf(stderr, "\t%d (%s)\n", errno, strerror(errno)); } goto cleanup; } printf("Extending succeeded!\n"); cleanup: GT_free(der_out); GTTimestamp_free(out_timestamp); GTTimestamp_free(in_timestamp); GT_free(der_in); /* Finalize GuardTime libraries. */ GTHTTP_finalize(); GT_finalize(); return res == GT_OK ? EXIT_SUCCESS : EXIT_FAILURE; }
static int __devinit omap34xx_bridge_probe(struct platform_device *pdev) { int status; u32 initStatus; u32 temp; dev_t dev = 0 ; int result; struct dspbridge_platform_data *pdata = pdev->dev.platform_data; omap_dspbridge_dev = pdev; /* use 2.6 device model */ result = alloc_chrdev_region(&dev, 0, 1, driver_name); if (result < 0) { pr_err("%s: Can't get major %d\n", __func__, driver_major); goto err1; } driver_major = MAJOR(dev); cdev_init(&bridge_cdev, &bridge_fops); bridge_cdev.owner = THIS_MODULE; status = cdev_add(&bridge_cdev, dev, 1); if (status) { pr_err("%s: Failed to add bridge device\n", __func__); goto err2; } /* udev support */ bridge_class = class_create(THIS_MODULE, "ti_bridge"); if (IS_ERR(bridge_class)) pr_err("%s: Error creating bridge class\n", __func__); device_create(bridge_class, NULL, MKDEV(driver_major, 0), NULL, "DspBridge"); bridge_create_sysfs(); GT_init(); GT_create(&driverTrace, "LD"); #ifdef CONFIG_BRIDGE_DEBUG if (GT_str) GT_set(GT_str); #elif defined(DDSP_DEBUG_PRODUCT) && GT_TRACE GT_set("**=67"); #endif #ifdef CONFIG_PM /* Initialize the wait queue */ bridge_suspend_data.suspended = 0; init_waitqueue_head(&bridge_suspend_data.suspend_wq); #endif SERVICES_Init(); /* Autostart flag. This should be set to true if the DSP image should * be loaded and run during bridge module initialization */ if (base_img) { temp = true; REG_SetValue(AUTOSTART, (u8 *)&temp, sizeof(temp)); REG_SetValue(DEFEXEC, (u8 *)base_img, strlen(base_img) + 1); } else { temp = false; REG_SetValue(AUTOSTART, (u8 *)&temp, sizeof(temp)); REG_SetValue(DEFEXEC, (u8 *) "\0", (u32)2); } if (shm_size >= 0x10000) { /* 64 KB */ initStatus = REG_SetValue(SHMSIZE, (u8 *)&shm_size, sizeof(shm_size)); } else { initStatus = DSP_EINVALIDARG; status = -1; pr_err("%s: SHM size must be at least 64 KB\n", __func__); } GT_1trace(driverTrace, GT_7CLASS, "requested shm_size = 0x%x\n", shm_size); if (pdata->phys_mempool_base && pdata->phys_mempool_size) { phys_mempool_base = pdata->phys_mempool_base; phys_mempool_size = pdata->phys_mempool_size; } GT_1trace(driverTrace, GT_7CLASS, "phys_mempool_base = 0x%x \n", phys_mempool_base); GT_1trace(driverTrace, GT_7CLASS, "phys_mempool_size = 0x%x\n", phys_mempool_base); if ((phys_mempool_base > 0x0) && (phys_mempool_size > 0x0)) MEM_ExtPhysPoolInit(phys_mempool_base, phys_mempool_size); if (tc_wordswapon) { GT_0trace(driverTrace, GT_7CLASS, "TC Word Swap is enabled\n"); REG_SetValue(TCWORDSWAP, (u8 *)&tc_wordswapon, sizeof(tc_wordswapon)); } else { GT_0trace(driverTrace, GT_7CLASS, "TC Word Swap is disabled\n"); REG_SetValue(TCWORDSWAP, (u8 *)&tc_wordswapon, sizeof(tc_wordswapon)); } if (DSP_SUCCEEDED(initStatus)) { #ifdef CONFIG_BRIDGE_DVFS clk_handle = clk_get(NULL, "iva2_ck"); if (!clk_handle) pr_err("%s: clk_get failed to get iva2_ck\n", __func__); if (clk_notifier_register(clk_handle, &iva_clk_notifier)) pr_err("%s: clk_notifier_register failed for iva2_ck\n", __func__); if (!min_dsp_freq) min_dsp_freq = pdata->mpu_min_speed; #endif driverContext = DSP_Init(&initStatus); if (DSP_FAILED(initStatus)) { status = -1; pr_err("DSP Bridge driver initialization failed\n"); } else { pr_info("DSP Bridge driver loaded\n"); } } #ifdef CONFIG_BRIDGE_RECOVERY bridge_rec_queue = create_workqueue("bridge_rec_queue"); INIT_WORK(&bridge_recovery_work, bridge_recover); INIT_COMPLETION(bridge_comp); #endif DBC_Assert(status == 0); DBC_Assert(DSP_SUCCEEDED(initStatus)); return 0; err2: unregister_chrdev_region(dev, 1); err1: return result; }
/* ARGSUSED - this line tells the compiler not to warn about unused args. */ IRES_Status IRESMAN_MEMTCM_init(IRESMAN_Params * initArgs) { SMGRMP_Attrs attrs; IRESMAN_MemTcmParams * resmanArgs = (IRESMAN_MemTcmParams *)initArgs; /* CMEM_AllocParams params; */ GT_assert(ti_sdo_fc_ires_memtcm, initArgs != NULL); /* * Check if already initialized */ if (_initialized) { GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_EEXISTS)\n"); return (IRES_EEXISTS); } if (gtInit == 0) { GT_init(); GT_create(&CURTRACE, "ti.sdo.fc.ires.memtcm"); gtInit = 1; } GT_1trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Enter (initArgs=0x%x)\n", initArgs); /* * Information regarding the memory allocation/free functions * is stored as part of the internal state of the resource * manager */ if (NULL == _MEMTCM_lock) { /* Create a lock for protecting MEMTCM internal state object */ _MEMTCM_lock = LockMP_create(_MEMTCM_LOCKID); if (_MEMTCM_lock == NULL) { GT_1trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Failed to create IPC lock, " "key = 0x%x\n", _MEMTCM_LOCKID); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=" "IRES_EFAIL)\n"); return (IRES_EFAIL); } } getInternalState(); if (NULL == _resmanInternalState) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init>Failed to obtain Internal state Object\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=" "IRES_EFAIL)\n"); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } /* * Information regarding the memory allocation/free functions */ _allocFxn = resmanArgs->baseConfig.allocFxn; _freeFxn = resmanArgs->baseConfig.freeFxn; if (0 != CMEM_init()) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Could not initialize CMEM\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_EFAIL)\n"); freeInternalState(); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } /* TODO: Figure out how to populate the params */ if (_resmanInternalState->numOpens == 0) { armtcmAddr = CMEM_alloc2(MEMTCM_blockId, MEMTCM_size, NULL); _resmanInternalState->armtcmAddr = (void *)CMEM_getPhys(armtcmAddr); } else { armtcmAddr = CMEM_registerAlloc( (unsigned long)_resmanInternalState->armtcmAddr); } if (NULL == armtcmAddr) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Could not allocate TCM memory from CMEM" "\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_EFAIL)\n"); freeInternalState(); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } if (NULL == smgr) { attrs.numScratchGroups = MEMTCM_NUM_GROUPS; attrs.numResources = (MEMTCM_NUMRES); /* One resource corresponds to a 1/2 K chunk of memory (0x200), Manage memory in chunks of 0x200 */ attrs.lock = _MEMTCM_lock; attrs.key = (void *)_MEMTCM_MEMID; /* A key specific to the resource being managed */ /* This will create a new resource manager or return a process-specific handle to an existing smgr */ smgr = SMGRMP_create(&attrs); if (NULL == smgr) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Error creating" " scratch resource manager.\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=" "IRES_EFAIL)\n"); freeInternalState(); LockMP_delete(_MEMTCM_lock); return (IRES_EFAIL); } } _resmanInternalState->numOpens++; /* * Set Initalized flag to 1 if successful */ _initialized = 1; GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status=IRES_OK)\n"); return (IRES_OK); }