static void azalia_pch_init(struct device *dev, u8 *base) { u8 reg8; u16 reg16; u32 reg32; if (RCBA32(0x2030) & (1 << 31)) { reg32 = pci_read_config32(dev, 0x120); reg32 &= 0xf8ffff01; reg32 |= (1 << 25); reg32 |= RCBA32(0x2030) & 0xfe; pci_write_config32(dev, 0x120, reg32); if (!pch_is_lp()) { reg16 = pci_read_config16(dev, 0x78); reg16 &= ~(1 << 11); pci_write_config16(dev, 0x78, reg16); } } else printk(BIOS_DEBUG, "Azalia: V1CTL disabled.\n"); reg32 = pci_read_config32(dev, 0x114); reg32 &= ~0xfe; pci_write_config32(dev, 0x114, reg32); // Set VCi enable bit if (pci_read_config32(dev, 0x120) & ((1 << 24) | (1 << 25) | (1 << 26))) { reg32 = pci_read_config32(dev, 0x120); if (pch_is_lp()) reg32 &= ~(1 << 31); else reg32 |= (1 << 31); pci_write_config32(dev, 0x120, reg32); } reg8 = pci_read_config8(dev, 0x43); if (pch_is_lp()) reg8 &= ~(1 << 6); else reg8 |= (1 << 4); pci_write_config8(dev, 0x43, reg8); if (!pch_is_lp()) { reg32 = pci_read_config32(dev, 0xc0); reg32 |= (1 << 17); pci_write_config32(dev, 0xc0, reg32); } /* Additional programming steps */ reg32 = pci_read_config32(dev, 0xc4); if (pch_is_lp()) reg32 |= (1 << 24); else reg32 |= (1 << 14); pci_write_config32(dev, 0xc4, reg32); if (!pch_is_lp()) { reg32 = pci_read_config32(dev, 0xd0); reg32 &= ~(1 << 31); pci_write_config32(dev, 0xd0, reg32); } reg8 = pci_read_config8(dev, 0x40); // Audio Control reg8 |= 1; // Select Azalia mode pci_write_config8(dev, 0x40, reg8); reg8 = pci_read_config8(dev, 0x4d); // Docking Status reg8 &= ~(1 << 7); // Docking not supported pci_write_config8(dev, 0x4d, reg8); if (pch_is_lp()) { reg16 = read32(base + 0x0012); reg16 |= (1 << 0); write32(base + 0x0012, reg16); /* disable Auto Voltage Detector */ reg8 = pci_read_config8(dev, 0x42); reg8 |= (1 << 2); pci_write_config8(dev, 0x42, reg8); } }
static void udelay(unsigned usecs) { uint32_t start = read32(timer_us_ptr); while (read32(timer_us_ptr) - start < usecs) ; }
static uint32_t get_wakeup_vector(void) { return read32(pmc_ctlr_scratch41_ptr); }
uint8_t OpenDMLHeader::indexReindex(uint32_t vidTrack,uint32_t audioTrack,uint32_t audioTrackNumber) { uint32_t fcc,len,shortFCC,track; uint64_t pos; uint32_t achunk=0,vchunk=0; uint8_t end=0; uint32_t shortTotal,shortCur,highFCC; UNUSED_ARG(audioTrackNumber); UNUSED_ARG(vidTrack); printf("Re-indexing the file, it can take a while....\n"); // jump to the movi chunk if(!_movi.offset) { printf("No movi chunk!\n"); return 0; } fseeko(_fd,_movi.offset,SEEK_SET); pos=ftello(_fd); #define MAXX 4*30*3600 // we build ~ 4 hour worth of video and audio _idx=new odmlIndex[MAXX]; _audioIdx=new odmlIndex[MAXX]; shortTotal=(_fileSize)>>20; DIA_working *working=new DIA_working(QT_TR_NOOP("Indexing")); // while(pos<_fileSize-20 && achunk<MAXX-1 && vchunk < MAXX-1 && !end) { shortCur=pos>>20; working->update(shortCur,shortTotal); if(!working->isAlive()) { delete working; return 0; } fcc=read32(); len=read32(); aprintf("%s size:%lu (%llx/%llx)\n",fourCC::tostring(fcc),len,pos,ftello(_fd)); shortFCC=fcc>>16; track=((fcc>>8)&0xff)-'0'; pos+=8; highFCC=fcc&0xffff; if(highFCC==MKFCC('i','x',0,0)) { printf("OpenDML index found, skipping it\n"); fseeko(_fd,len,SEEK_CUR); pos+=len; continue; } switch(shortFCC) { case MKFCC('d','c',0,0): // video tracks case MKFCC('d','b',0,0): aprintf("\tVid.\n"); _idx[vchunk].offset=pos; _idx[vchunk].size=len; _idx[vchunk].intra=AVI_KEY_FRAME; vchunk++; if(len&1) len++; fseeko(_fd,len,SEEK_CUR); pos+=len; break; case MKFCC('w','b',0,0): if(track==audioTrack) { aprintf("\tAud.\n"); _audioIdx[achunk].offset=pos; _audioIdx[achunk].size=len; achunk++; } if(len&1) len++; fseeko(_fd,len,SEEK_CUR); pos+=len; break; default: printf("\n unknown fcc: ");fourCC::print(fcc);printf("\n"); printf("\n ShortFcc: ");fourCC::print(shortFCC);printf("\n"); printf("\n HighFCC: ");fourCC::print(highFCC);printf("\n"); end=1; break; } } printf("%lu audio and %lu video chunks found\n",(unsigned long int)vchunk,(unsigned long int)achunk); // update stuff _videostream.dwLength= _mainaviheader.dwTotalFrames=vchunk; _nbAudioChunk=achunk; delete working; return 1; }
static inline void setbits32(uint32_t bits, void *addr) { write32(addr, read32(addr) | bits); }
void read_token(T* tok) { *(unsigned*)tok = read32(); }
void read_op(sm4_op* pop) { sm4_op& op = *pop; sm4_token_operand optok; read_token(&optok); assert(optok.file < SM4_FILE_COUNT); op.swizzle[0] = 0; op.swizzle[1] = 1; op.swizzle[2] = 2; op.swizzle[3] = 3; op.mask = 0xf; switch(optok.comps_enum) { case SM4_OPERAND_COMPNUM_0: op.comps = 0; break; case SM4_OPERAND_COMPNUM_1: op.comps = 1; break; case SM4_OPERAND_COMPNUM_4: op.comps = 4; op.mode = optok.mode; switch(optok.mode) { case SM4_OPERAND_MODE_MASK: op.mask = SM4_OPERAND_SEL_MASK(optok.sel); break; case SM4_OPERAND_MODE_SWIZZLE: op.swizzle[0] = SM4_OPERAND_SEL_SWZ(optok.sel, 0); op.swizzle[1] = SM4_OPERAND_SEL_SWZ(optok.sel, 1); op.swizzle[2] = SM4_OPERAND_SEL_SWZ(optok.sel, 2); op.swizzle[3] = SM4_OPERAND_SEL_SWZ(optok.sel, 3); break; case SM4_OPERAND_MODE_SCALAR: op.swizzle[0] = op.swizzle[1] = op.swizzle[2] = op.swizzle[3] = SM4_OPERAND_SEL_SCALAR(optok.sel); break; } break; case SM4_OPERAND_COMPNUM_N: fail("Unhandled operand component type"); } op.file = (sm4_file)optok.file; op.num_indices = optok.num_indices; if(optok.extended) { sm4_token_operand_extended optokext; read_token(&optokext); if(optokext.type == 0) {} else if(optokext.type == 1) { op.neg = optokext.neg; op.abs= optokext.abs; } else fail("Unhandled extended operand token type"); } for(unsigned i = 0; i < op.num_indices; ++i) { unsigned repr; if(i == 0) repr = optok.index0_repr; else if(i == 1) repr = optok.index1_repr; else if(i == 2) repr = optok.index2_repr; else fail("Unhandled operand index representation"); op.indices[0].disp = 0; // TODO: is disp supposed to be signed here?? switch(repr) { case SM4_OPERAND_INDEX_REPR_IMM32: op.indices[i].disp = (int32_t)read32(); break; case SM4_OPERAND_INDEX_REPR_IMM64: op.indices[i].disp = read64(); break; case SM4_OPERAND_INDEX_REPR_REG: relative: op.indices[i].reg.reset(new sm4_op()); read_op(&*op.indices[0].reg); break; case SM4_OPERAND_INDEX_REPR_REG_IMM32: op.indices[i].disp = (int32_t)read32(); goto relative; case SM4_OPERAND_INDEX_REPR_REG_IMM64: op.indices[i].disp = read64(); goto relative; } } if(op.file == SM4_FILE_IMMEDIATE32) { for(unsigned i = 0; i < op.comps; ++i) op.imm_values[i].i32 = read32(); } else if(op.file == SM4_FILE_IMMEDIATE64) { for(unsigned i = 0; i < op.comps; ++i) op.imm_values[i].i64 = read64(); } }
/* * Given the state of the current frame as stored in REGS, execute the unwind * operations in unwind_info until the location counter reaches POS. The result is * stored back into REGS. OUT_CFA will receive the value of the CFA. * If SAVE_LOCATIONS is non-NULL, it should point to an array of size SAVE_LOCATIONS_LEN. * On return, the nth entry will point to the address of the stack slot where register * N was saved, or NULL, if it was not saved by this frame. * This function is signal safe. */ void mono_unwind_frame (guint8 *unwind_info, guint32 unwind_info_len, guint8 *start_ip, guint8 *end_ip, guint8 *ip, mgreg_t *regs, int nregs, mgreg_t **save_locations, int save_locations_len, guint8 **out_cfa) { Loc locations [NUM_REGS]; int i, pos, reg, cfa_reg, cfa_offset; guint8 *p; guint8 *cfa_val; for (i = 0; i < NUM_REGS; ++i) locations [i].loc_type = LOC_SAME; p = unwind_info; pos = 0; cfa_reg = -1; cfa_offset = -1; while (pos <= ip - start_ip && p < unwind_info + unwind_info_len) { int op = *p & 0xc0; switch (op) { case DW_CFA_advance_loc: UNW_DEBUG (print_dwarf_state (cfa_reg, cfa_offset, pos, nregs, locations)); pos += *p & 0x3f; p ++; break; case DW_CFA_offset: reg = *p & 0x3f; p ++; locations [reg].loc_type = LOC_OFFSET; locations [reg].offset = decode_uleb128 (p, &p) * DWARF_DATA_ALIGN; break; case 0: { int ext_op = *p; p ++; switch (ext_op) { case DW_CFA_def_cfa: cfa_reg = decode_uleb128 (p, &p); cfa_offset = decode_uleb128 (p, &p); break; case DW_CFA_def_cfa_offset: cfa_offset = decode_uleb128 (p, &p); break; case DW_CFA_def_cfa_register: cfa_reg = decode_uleb128 (p, &p); break; case DW_CFA_offset_extended_sf: reg = decode_uleb128 (p, &p); locations [reg].loc_type = LOC_OFFSET; locations [reg].offset = decode_sleb128 (p, &p) * DWARF_DATA_ALIGN; break; case DW_CFA_advance_loc4: pos += read32 (p); p += 4; break; default: g_assert_not_reached (); } break; } default: g_assert_not_reached (); } } if (save_locations) memset (save_locations, 0, save_locations_len * sizeof (mgreg_t*)); cfa_val = (guint8*)regs [mono_dwarf_reg_to_hw_reg (cfa_reg)] + cfa_offset; for (i = 0; i < NUM_REGS; ++i) { if (locations [i].loc_type == LOC_OFFSET) { int hreg = mono_dwarf_reg_to_hw_reg (i); g_assert (hreg < nregs); regs [hreg] = *(mgreg_t*)(cfa_val + locations [i].offset); if (save_locations && hreg < save_locations_len) save_locations [hreg] = (mgreg_t*)(cfa_val + locations [i].offset); } } *out_cfa = cfa_val; }
static inline u32 read_timer(void) { return read32(&tmr0->val); }
/*********************************************************** Function: mem_comp() // 函数名称 Description: 对比指定的两段内存段。 Calls: read32 ; read8 ; printf // 被本函数调用的函数清单(建议描述) Called By: // 调用本函数的函数清单(建议描述) Table Accessed: 无// 被访问的表(此项仅对于牵扯到数据库操作的程序) Table Updated: 无// 被修改的表(此项仅对于牵扯到数据库操作的程序) Input: addr1:需要对比的地址段1首地址,32bit addr2:需要对比的地址段2首地址,32bit num_byte:对比内存段的长度,单位byt Output: 无 // 对输出参数的说明。 Return: cnt3:两块memory 上不同数据的个数 Others: 可以通过宏定义debug 来确定是否打印两块memory 上不同数据的具体情况。 ***********************************************************/ int edmac_mem_comp( UINT32 src_addr, UINT32 des_addr, UINT32 num_byte, UINT32 trans_type) { int cnt1 ; int cnt2 ; int cnt3 ; UINT32 read_data1 ; UINT32 read_data2 ; UINT8 read_data_byte1 ; UINT8 read_data_byte2 ; UINT32 ch_state; UINT32 addr1; UINT32 addr2; addr1 = src_addr; addr2 = des_addr; cnt1 = 0 ; cnt2 = 0 ; cnt3 = 0 ; do { ch_state = read32(EDMAC_BASEADDR+CH_STAT); } while (ch_state != 0); //printf("EDMAC: Memory Transmit complete\n"); for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4) { if(cnt1 >= 0x4) { read_data1 = read32( addr1 ); read_data2 = read32( addr2 ); if ( read_data1 != read_data2 ) { cnt3 = cnt3 + 0x1 ; /*判断是否打印两块memory 上不同数据的具体情况*/ //#ifdef debug printf("EDMAC error %d!\n" , cnt3 ); printf("addr1=%x,data1=%x\n",addr1,read_data1); printf("addr2=%x,data2=%x\n",addr2,read_data2); //#endif } addr1 = addr1 + 0x4 ; addr2 = addr2 + 0x4 ; } else { cnt2 = cnt1; while ( cnt2 ) { read_data_byte1 = read8 ( addr1 ); read_data_byte2 = read8 ( addr2 ); if ( read_data_byte1 != read_data_byte2 ) { cnt3 = cnt3 + 0x1 ; /*判断是否打印两块memory 上不同数据的具体情况*/ //#ifdef _UNIT_DEBUG printf("error %d!\n" , cnt3 ); printf("addr1=%x,data1=%x\n",addr1, read_data_byte1); printf("addr2=%x,data2=%x\n",addr2, read_data_byte2); //#endif } addr1 = addr1 + 0x1 ; addr2 = addr2 + 0x1 ; cnt2 = cnt2 - 0x1 ; } } } #ifdef _UNIT_DEBUG if ( 0 == cnt3 ) { printf("Memory Compare OK!\n"); } else { printf("Memory Compare FAILED!\n"); } #endif if (cnt3 == 0) { #ifdef V9R1_DEBUG if (trans_type == 0) { printf ("---- EDMAC OK ----\n"); } else if(trans_type == 1) { printf ("---- BBP OK ----\n"); } #endif return 0; } else { if (trans_type == 0) { printf ("EDMAC ERROR\n"); } else if(trans_type == 1) { printf ("BBP TRANSFER ERROR\n"); } return 1; } }
int mem_test( UINT32 src_addr, /* Memory Address*/ long int num_byte, /* Number of Data in Byte*/ int test_num ) /*检查的次数*/ { long int cnt1 ; int cnt2 ; int cnt3 ; UINT32 data1 ; UINT32 data2 ; UINT32 read_data1 ; UINT32 read_data2 ; UINT32 addr1 ; UINT32 addr2 ; cnt1 = 0 ; cnt2 = 0 ; cnt3 = 0 ; // srand((unsigned)time()); for(cnt3 = test_num ; cnt3 >0 ; cnt3 = cnt3 - 0x1 ) { addr1 = src_addr ; addr2 = src_addr + 0x4 ; for (cnt1 = num_byte ; cnt1 >0 ; cnt1 = cnt1 - 0x8) { /* data1 = rand() ; data1 = data1 <<16; data1_low = rand() ; data1 = data1 | data1_low ;*/ data1 = 0x5a5a5a5a; set32(addr1, data1); if (cnt1 >4) { /* data2 = rand() ; data2 = data2 <<16; data2_low = rand() ; data2 = data2 | data2_low ;*/ data2 = 0xa5a5a5a5; set32( addr2, data2); } read_data1 = read32( addr1); if ( read_data1 != data1) { cnt2 = cnt2 + 0x1 ; } addr1 = addr1 + 0x8 ; if (cnt1 >4) { read_data2 = read32( addr2); if ( read_data2 != data2) { cnt2 = cnt2 + 0x1 ; } addr2 = addr2 + 0x8 ; } } #ifdef _UNIT_DEBUG printf("test %x!\n",cnt3 ); #endif } return cnt2 ; }
/*********************************************************** Function: mem_comp() // 函数名称 Description: 对比指定的两段内存段。 Calls: read32 ; read8 ; printf // 被本函数调用的函数清单(建议描述) Called By: // 调用本函数的函数清单(建议描述) Table Accessed: 无// 被访问的表(此项仅对于牵扯到数据库操作的程序) Table Updated: 无// 被修改的表(此项仅对于牵扯到数据库操作的程序) Input: addr1:需要对比的地址段1首地址,32bit addr2:需要对比的地址段2首地址,32bit num_byte:对比内存段的长度,单位byt Output: 无 // 对输出参数的说明。 Return: cnt3:两块memory 上不同数据的个数 Others: 可以通过宏定义debug 来确定是否打印两块memory 上不同数据的具体情况。 ***********************************************************/ int mem_comp( UINT32 addr1, UINT32 addr2, UINT32 num_byte ) { int cnt1 ; int cnt2 ; int cnt3 ; UINT32 read_data1 ; UINT32 read_data2 ; UINT8 read_data_byte1 ; UINT8 read_data_byte2 ; cnt1 = 0 ; cnt2 = 0 ; cnt3 = 0 ; for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4) { if(cnt1 >= 0x4) { read_data1 = read32( addr1 ); read_data2 = read32( addr2 ); if ( read_data1 != read_data2 ) { cnt3 = cnt3 + 0x1 ; /*判断是否打印两块memory 上不同数据的具体情况*/ //#ifdef debug printf("error %d!\n" , cnt3 ); printf("addr1=%x,data1=%x\n",addr1,read_data1); printf("addr2=%x,data2=%x\n",addr2,read_data2); //#endif } /*else { printf("Compare right!!\n"); }*/ addr1 = addr1 + 0x4 ; addr2 = addr2 + 0x4 ; } else { cnt2 = cnt1; while ( cnt2 ) { read_data_byte1 = read8 ( addr1 ); read_data_byte2 = read8 ( addr2 ); if ( read_data_byte1 != read_data_byte2 ) { cnt3 = cnt3 + 0x1 ; /*判断是否打印两块memory 上不同数据的具体情况*/ //#ifdef _UNIT_DEBUG printf("error %d!\n" , cnt3 ); printf("addr1=%x,data1=%x\n",addr1, read_data_byte1); printf("addr2=%x,data2=%x\n",addr2, read_data_byte2); //#endif } /*else { printf("Compare right!!\n"); }*/ addr1 = addr1 + 0x1 ; addr2 = addr2 + 0x1 ; cnt2 = cnt2 - 0x1 ; } } } #ifdef _UNIT_DEBUG if ( 0 == cnt3 ) { printf("Memory Compare OK!\n"); } else { printf("Memory Compare FAILED!\n"); } #endif return cnt3 ; }
int mem_clr( UINT32 src_addr, /*Memory Address*/ int num_byte ) /*Number of Data to clear in Byte*/ { int cnt1 ; int cnt2 ; #ifdef _UNIT_DEBUG int cnt3 = 0 ; #endif UINT32 addr ; cnt1 = 0 ; cnt2 = 0 ; addr = src_addr ; /*将一块 以src_addr 为起始地址、以num_byte 为大小的memory 的值清零 */ for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4) { if(cnt1 >= 0x4) { set32(addr, 0x0); addr = addr + 0x4 ; } else { cnt2 = cnt1; while ( cnt2 ) { set8(addr, 0x0); addr = addr + 0x1 ; cnt2 = cnt2 - 0x1 ; } } } addr = src_addr ; /*如果需要判断memory 初始化是否正确,请define debug*/ #ifdef _UNIT_DEBUG /*读清零后的memory ,判断clear 操作是否成功*/ for (cnt1 = num_byte; cnt1 >0; cnt1 = cnt1 - 0x4) { if(cnt1 >= 0x4) { read_data = read32( addr ); addr = addr + 0x4 ; if ( 0x0 != read_data ) { cnt3 = cnt3 + 0x4 ; } } else { cnt2 = cnt1; while ( cnt2 ) { read_data_byte = read8 ( addr ); addr = addr + 0x1 ; cnt2 = cnt2 - 0x1 ; if ( 0x0 != read_data_byte ) { cnt3 = cnt3 + 0x1 ; } } } } if ( 0 == cnt3 ) { //#ifdef _UNIT_DEBUG printf("Memory Clear OK!\n"); return 0; //#endif } else { printf("Memory Clear FAILED!\n"); return 1; } #endif return 0; }
static int read_header(AVFormatContext *s) { BRSTMDemuxContext *b = s->priv_data; int bom, major, minor, codec, chunk; int64_t h1offset, pos, toffset; uint32_t size, asize, start = 0; AVStream *st; int ret = AVERROR_EOF; int loop = 0; int bfstm = !strcmp("bfstm", s->iformat->name); st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; avio_skip(s->pb, 4); bom = avio_rb16(s->pb); if (bom != 0xFEFF && bom != 0xFFFE) { av_log(s, AV_LOG_ERROR, "invalid byte order: %X\n", bom); return AVERROR_INVALIDDATA; } if (bom == 0xFFFE) b->little_endian = 1; if (!bfstm) { major = avio_r8(s->pb); minor = avio_r8(s->pb); avio_skip(s->pb, 4); // size of file size = read16(s); if (size < 14) return AVERROR_INVALIDDATA; avio_skip(s->pb, size - 14); pos = avio_tell(s->pb); if (avio_rl32(s->pb) != MKTAG('H','E','A','D')) return AVERROR_INVALIDDATA; } else { uint32_t info_offset = 0; uint16_t section_count, header_size, i; header_size = read16(s); // 6 avio_skip(s->pb, 4); // Unknown constant 0x00030000 avio_skip(s->pb, 4); // size of file section_count = read16(s); avio_skip(s->pb, 2); // padding for (i = 0; avio_tell(s->pb) < header_size && !(start && info_offset) && i < section_count; i++) { uint16_t flag = read16(s); avio_skip(s->pb, 2); switch (flag) { case 0x4000: info_offset = read32(s); /*info_size =*/ read32(s); break; case 0x4001: avio_skip(s->pb, 4); // seek offset avio_skip(s->pb, 4); // seek size break; case 0x4002: start = read32(s) + 8; avio_skip(s->pb, 4); //data_size = read32(s); break; case 0x4003: avio_skip(s->pb, 4); // REGN offset avio_skip(s->pb, 4); // REGN size break; } } if (!info_offset || !start) return AVERROR_INVALIDDATA; avio_skip(s->pb, info_offset - avio_tell(s->pb)); pos = avio_tell(s->pb); if (avio_rl32(s->pb) != MKTAG('I','N','F','O')) return AVERROR_INVALIDDATA; } size = read32(s); if (size < 192) return AVERROR_INVALIDDATA; avio_skip(s->pb, 4); // unknown h1offset = read32(s); if (h1offset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, 12); toffset = read32(s) + 16LL; if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + h1offset + 8 - avio_tell(s->pb)); codec = avio_r8(s->pb); switch (codec) { case 0: codec = AV_CODEC_ID_PCM_S8_PLANAR; break; case 1: codec = b->little_endian ? AV_CODEC_ID_PCM_S16LE_PLANAR : AV_CODEC_ID_PCM_S16BE_PLANAR; break; case 2: codec = b->little_endian ? AV_CODEC_ID_ADPCM_THP_LE : AV_CODEC_ID_ADPCM_THP; break; default: avpriv_request_sample(s, "codec %d", codec); return AVERROR_PATCHWELCOME; } loop = avio_r8(s->pb); // loop flag st->codec->codec_id = codec; st->codec->channels = avio_r8(s->pb); if (!st->codec->channels) return AVERROR_INVALIDDATA; avio_skip(s->pb, 1); // padding st->codec->sample_rate = bfstm ? read32(s) : read16(s); if (!st->codec->sample_rate) return AVERROR_INVALIDDATA; if (!bfstm) avio_skip(s->pb, 2); // padding if (loop) { if (av_dict_set_int(&s->metadata, "loop_start", av_rescale(read32(s), AV_TIME_BASE, st->codec->sample_rate), 0) < 0) return AVERROR(ENOMEM); } else { avio_skip(s->pb, 4); } st->start_time = 0; st->duration = read32(s); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); if (!bfstm) start = read32(s); b->current_block = 0; b->block_count = read32(s); if (b->block_count > UINT16_MAX) { av_log(s, AV_LOG_WARNING, "too many blocks: %u\n", b->block_count); return AVERROR_INVALIDDATA; } b->block_size = read32(s); if (b->block_size > UINT32_MAX / st->codec->channels) return AVERROR_INVALIDDATA; b->samples_per_block = read32(s); b->last_block_used_bytes = read32(s); b->last_block_samples = read32(s); b->last_block_size = read32(s); if (b->last_block_size > UINT32_MAX / st->codec->channels) return AVERROR_INVALIDDATA; if (b->last_block_used_bytes > b->last_block_size) return AVERROR_INVALIDDATA; if (codec == AV_CODEC_ID_ADPCM_THP || codec == AV_CODEC_ID_ADPCM_THP_LE) { int ch; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); if (!bfstm) toffset = read32(s) + 16LL; else toffset = toffset + read32(s) + st->codec->channels * 8 - 8; if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); b->table = av_mallocz(32 * st->codec->channels); if (!b->table) return AVERROR(ENOMEM); for (ch = 0; ch < st->codec->channels; ch++) { if (avio_read(s->pb, b->table + ch * 32, 32) != 32) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, bfstm ? 14 : 24); } } if (size < (avio_tell(s->pb) - pos)) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, size - (avio_tell(s->pb) - pos)); while (!avio_feof(s->pb)) { chunk = avio_rl32(s->pb); size = read32(s); if (size < 8) { ret = AVERROR_INVALIDDATA; goto fail; } size -= 8; switch (chunk) { case MKTAG('S','E','E','K'): case MKTAG('A','D','P','C'): if (codec != AV_CODEC_ID_ADPCM_THP && codec != AV_CODEC_ID_ADPCM_THP_LE) goto skip; asize = b->block_count * st->codec->channels * 4; if (size < asize) { ret = AVERROR_INVALIDDATA; goto fail; } if (b->adpc) { av_log(s, AV_LOG_WARNING, "skipping additional ADPC chunk\n"); goto skip; } else { b->adpc = av_mallocz(asize); if (!b->adpc) { ret = AVERROR(ENOMEM); goto fail; } if (bfstm && codec != AV_CODEC_ID_ADPCM_THP_LE) { // Big-endian BFSTMs have little-endian SEEK tables // for some strange reason. int i; for (i = 0; i < asize; i += 2) { b->adpc[i+1] = avio_r8(s->pb); b->adpc[i] = avio_r8(s->pb); } } else { avio_read(s->pb, b->adpc, asize); } avio_skip(s->pb, size - asize); } break; case MKTAG('D','A','T','A'): if ((start < avio_tell(s->pb)) || (!b->adpc && (codec == AV_CODEC_ID_ADPCM_THP || codec == AV_CODEC_ID_ADPCM_THP_LE))) { ret = AVERROR_INVALIDDATA; goto fail; } avio_skip(s->pb, start - avio_tell(s->pb)); if (bfstm && (codec == AV_CODEC_ID_ADPCM_THP || codec == AV_CODEC_ID_ADPCM_THP_LE)) avio_skip(s->pb, 24); b->data_start = avio_tell(s->pb); if (!bfstm && (major != 1 || minor)) avpriv_request_sample(s, "Version %d.%d", major, minor); return 0; default: av_log(s, AV_LOG_WARNING, "skipping unknown chunk: %X\n", chunk); skip: avio_skip(s->pb, size); } } fail: read_close(s); return ret; }
/** * \brief Read a single byte from the UART. * * Blocks until at least a byte is available. */ static u8 a10_uart_rx_blocking(struct a10_uart *uart) { while (rx_fifo_empty(uart)); return read32(&uart->rbr); }
/* Set D3Hot Power State in ACPI mode */ static void serialio_enable_d3hot(struct resource *res) { u32 reg32 = read32(res2mmio(res, PCH_PCS, 0)); reg32 |= PCH_PCS_PS_D3HOT; write32(res2mmio(res, PCH_PCS, 0), reg32); }
void do_parse() { read_token(&program.version); unsigned lentok = read32(); tokens_end = tokens - 2 + lentok; while(tokens != tokens_end) { sm4_token_instruction insntok; read_token(&insntok); unsigned* insn_end = tokens - 1 + insntok.length; sm4_opcode opcode = (sm4_opcode)insntok.opcode; check(opcode < SM4_OPCODE_COUNT); if(opcode == SM4_OPCODE_CUSTOMDATA) { unsigned customlen = read32() - 2; skip(customlen); continue; } if((opcode >= SM4_OPCODE_DCL_RESOURCE && opcode <= SM4_OPCODE_DCL_GLOBAL_FLAGS) || (opcode >= SM4_OPCODE_DCL_STREAM && opcode <= SM4_OPCODE_DCL_RESOURCE_STRUCTURED)) { sm4_dcl& dcl = *new sm4_dcl; program.dcls.push_back(&dcl); (sm4_token_instruction&)dcl = insntok; sm4_token_instruction_extended exttok; memcpy(&exttok, &insntok, sizeof(exttok)); while(exttok.extended) { read_token(&exttok); } #define READ_OP_ANY dcl.op.reset(new sm4_op()); read_op(&*dcl.op); #define READ_OP(FILE) READ_OP_ANY //check(dcl.op->file == SM4_FILE_##FILE); switch(opcode) { case SM4_OPCODE_DCL_GLOBAL_FLAGS: break; case SM4_OPCODE_DCL_RESOURCE: READ_OP(RESOURCE); read_token(&dcl.rrt); break; case SM4_OPCODE_DCL_SAMPLER: READ_OP(SAMPLER); break; case SM4_OPCODE_DCL_INPUT: case SM4_OPCODE_DCL_INPUT_PS: READ_OP(INPUT); break; case SM4_OPCODE_DCL_INPUT_SIV: case SM4_OPCODE_DCL_INPUT_SGV: case SM4_OPCODE_DCL_INPUT_PS_SIV: case SM4_OPCODE_DCL_INPUT_PS_SGV: READ_OP(INPUT); dcl.sv = (sm4_sv)(uint16_t)read32(); break; case SM4_OPCODE_DCL_OUTPUT: READ_OP(OUTPUT); break; case SM4_OPCODE_DCL_OUTPUT_SIV: case SM4_OPCODE_DCL_OUTPUT_SGV: READ_OP(OUTPUT); dcl.sv = (sm4_sv)(uint16_t)read32(); break; case SM4_OPCODE_DCL_INDEX_RANGE: READ_OP_ANY; check(dcl.op->file == SM4_FILE_INPUT || dcl.op->file == SM4_FILE_OUTPUT); dcl.num = read32(); break; case SM4_OPCODE_DCL_TEMPS: dcl.num = read32(); break; case SM4_OPCODE_DCL_INDEXABLE_TEMP: READ_OP(INDEXABLE_TEMP); dcl.indexable_temp.num = read32(); dcl.indexable_temp.comps = read32(); break; case SM4_OPCODE_DCL_CONSTANT_BUFFER: READ_OP(CONSTANT_BUFFER); break; case SM4_OPCODE_DCL_GS_INPUT_PRIMITIVE: case SM4_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY: break; case SM4_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT: dcl.num = read32(); break; case SM4_OPCODE_DCL_GS_INSTANCE_COUNT: dcl.num = read32(); break; case SM4_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT: case SM4_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT: case SM4_OPCODE_DCL_TESS_DOMAIN: case SM4_OPCODE_DCL_TESS_PARTITIONING: case SM4_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE: break; case SM4_OPCODE_DCL_HS_MAX_TESSFACTOR: dcl.f32 = read32(); break; case SM4_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT: dcl.num = read32(); break; case SM4_OPCODE_DCL_FUNCTION_BODY: dcl.num = read32(); break; case SM4_OPCODE_DCL_FUNCTION_TABLE: dcl.num = read32(); dcl.data = malloc(dcl.num * sizeof(uint32_t)); for(unsigned i = 0; i < dcl.num; ++i) ((uint32_t*)dcl.data)[i] = read32(); break; case SM4_OPCODE_DCL_INTERFACE: dcl.intf.id = read32(); dcl.intf.expected_function_table_length = read32(); { uint32_t v = read32(); dcl.intf.table_length = v & 0xffff; dcl.intf.array_length = v >> 16; } dcl.data = malloc(dcl.intf.table_length * sizeof(uint32_t)); for(unsigned i = 0; i < dcl.intf.table_length; ++i) ((uint32_t*)dcl.data)[i] = read32(); break; case SM4_OPCODE_DCL_THREAD_GROUP: dcl.thread_group_size[0] = read32(); dcl.thread_group_size[1] = read32(); dcl.thread_group_size[2] = read32(); break; case SM4_OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED: READ_OP(UNORDERED_ACCESS_VIEW); read_token(&dcl.rrt); break; case SM4_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW: READ_OP(UNORDERED_ACCESS_VIEW); break; case SM4_OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED: READ_OP(UNORDERED_ACCESS_VIEW); dcl.structured.stride = read32(); break; case SM4_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW: READ_OP(THREAD_GROUP_SHARED_MEMORY); dcl.num = read32(); break; case SM4_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED: READ_OP(THREAD_GROUP_SHARED_MEMORY); dcl.structured.stride = read32(); dcl.structured.count = read32(); break; case SM4_OPCODE_DCL_RESOURCE_RAW: READ_OP(RESOURCE); break; case SM4_OPCODE_DCL_RESOURCE_STRUCTURED: READ_OP(RESOURCE); dcl.structured.stride = read32(); break; case SM4_OPCODE_DCL_STREAM: /* TODO: dcl_stream is undocumented: what is it? */ fail("Unhandled dcl_stream since it's undocumented"); default: fail("Unhandled declaration"); } check(tokens == insn_end); } else {
/* Enable clock in PCI mode */ static void serialio_enable_clock(struct resource *bar0) { u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0)); reg32 |= SIO_REG_PPR_CLOCK_EN; write32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0), reg32); }
uint64_t read64() { unsigned a = read32(); unsigned b = read32(); return (uint64_t)a | ((uint64_t)b << 32); }
static void evaluateCommand(void) { uint32_t i, j, tmp, junk; #ifdef GPS uint8_t wp_no; int32_t lat = 0, lon = 0, alt = 0; #endif const char *build = __DATE__; switch (currentPortState->cmdMSP) { case MSP_SET_RAW_RC: for (i = 0; i < 8; i++) rcData[i] = read16(); headSerialReply(0); mspFrameRecieve(); break; case MSP_SET_ACC_TRIM: cfg.angleTrim[PITCH] = read16(); cfg.angleTrim[ROLL] = read16(); headSerialReply(0); break; #ifdef GPS case MSP_SET_RAW_GPS: f.GPS_FIX = read8(); GPS_numSat = read8(); GPS_coord[LAT] = read32(); GPS_coord[LON] = read32(); GPS_altitude = read16(); GPS_speed = read16(); GPS_update |= 2; // New data signalisation to GPS functions headSerialReply(0); break; #endif case MSP_SET_PID: for (i = 0; i < PIDITEMS; i++) { cfg.P8[i] = read8(); cfg.I8[i] = read8(); cfg.D8[i] = read8(); } headSerialReply(0); break; case MSP_SET_BOX: for (i = 0; i < numberBoxItems; i++) cfg.activate[availableBoxes[i]] = read16(); headSerialReply(0); break; case MSP_SET_RC_TUNING: cfg.rcRate8 = read8(); cfg.rcExpo8 = read8(); read8(); // Legacy pitch-roll rate, read but not set. cfg.yawRate = read8(); cfg.dynThrPID = read8(); cfg.thrMid8 = read8(); cfg.thrExpo8 = read8(); headSerialReply(0); break; case MSP_SET_MISC: tmp = read16(); // sanity check if (tmp < 1600 && tmp > 1400) mcfg.midrc = tmp; mcfg.minthrottle = read16(); mcfg.maxthrottle = read16(); mcfg.mincommand = read16(); cfg.failsafe_throttle = read16(); mcfg.gps_type = read8(); mcfg.gps_baudrate = read8(); mcfg.gps_ubx_sbas = read8(); mcfg.multiwiicurrentoutput = read8(); mcfg.rssi_aux_channel = read8(); read8(); cfg.mag_declination = read16() * 10; mcfg.vbatscale = read8(); // actual vbatscale as intended mcfg.vbatmincellvoltage = read8(); // vbatlevel_warn1 in MWC2.3 GUI mcfg.vbatmaxcellvoltage = read8(); // vbatlevel_warn2 in MWC2.3 GUI mcfg.vbatwarningcellvoltage = read8(); // vbatlevel when buzzer starts to alert headSerialReply(0); break; case MSP_SET_MOTOR: for (i = 0; i < 8; i++) motor_disarmed[i] = read16(); headSerialReply(0); break; case MSP_SELECT_SETTING: if (!f.ARMED) { mcfg.current_profile = read8(); if (mcfg.current_profile > 2) mcfg.current_profile = 0; // this writes new profile index and re-reads it writeEEPROM(0, false); } headSerialReply(0); break; case MSP_SET_HEAD: magHold = read16(); headSerialReply(0); break; case MSP_IDENT: headSerialReply(7); serialize8(VERSION); // multiwii version serialize8(mcfg.mixerConfiguration); // type of multicopter serialize8(MSP_VERSION); // MultiWii Serial Protocol Version serialize32(CAP_PLATFORM_32BIT | CAP_BASEFLIGHT_CONFIG | CAP_DYNBALANCE | CAP_FW_FLAPS); // "capability" break; case MSP_STATUS: headSerialReply(11); serialize16(cycleTime); serialize16(i2cGetErrorCounter()); serialize16(sensors(SENSOR_ACC) | sensors(SENSOR_BARO) << 1 | sensors(SENSOR_MAG) << 2 | sensors(SENSOR_GPS) << 3 | sensors(SENSOR_SONAR) << 4); // OK, so you waste all the f*****g time to have BOXNAMES and BOXINDEXES etc, and then you go ahead and serialize enabled shit simply by stuffing all // the bits in order, instead of setting the enabled bits based on BOXINDEX. WHERE IS THE F*****G LOGIC IN THIS, FUCKWADS. // Serialize the boxes in the order we delivered them, until multiwii retards fix their shit junk = 0; tmp = f.ANGLE_MODE << BOXANGLE | f.HORIZON_MODE << BOXHORIZON | f.BARO_MODE << BOXBARO | f.MAG_MODE << BOXMAG | f.HEADFREE_MODE << BOXHEADFREE | rcOptions[BOXHEADADJ] << BOXHEADADJ | rcOptions[BOXCAMSTAB] << BOXCAMSTAB | rcOptions[BOXCAMTRIG] << BOXCAMTRIG | f.GPS_HOME_MODE << BOXGPSHOME | f.GPS_HOLD_MODE << BOXGPSHOLD | f.PASSTHRU_MODE << BOXPASSTHRU | rcOptions[BOXBEEPERON] << BOXBEEPERON | rcOptions[BOXLEDMAX] << BOXLEDMAX | rcOptions[BOXLLIGHTS] << BOXLLIGHTS | rcOptions[BOXVARIO] << BOXVARIO | rcOptions[BOXCALIB] << BOXCALIB | rcOptions[BOXGOV] << BOXGOV | rcOptions[BOXOSD] << BOXOSD | rcOptions[BOXTELEMETRY] << BOXTELEMETRY | rcOptions[BOXSERVO1] << BOXSERVO1 | rcOptions[BOXSERVO2] << BOXSERVO2 | rcOptions[BOXSERVO3] << BOXSERVO3 | f.ARMED << BOXARM; for (i = 0; i < numberBoxItems; i++) { int flag = (tmp & (1 << availableBoxes[i])); if (flag) junk |= 1 << i; } serialize32(junk); serialize8(mcfg.current_profile); break; case MSP_RAW_IMU: headSerialReply(18); // Retarded hack until multiwiidorks start using real units for sensor data if (acc_1G > 1024) { for (i = 0; i < 3; i++) serialize16(accSmooth[i] / 8); } else { for (i = 0; i < 3; i++) serialize16(accSmooth[i]); } for (i = 0; i < 3; i++) serialize16(gyroData[i]); for (i = 0; i < 3; i++) serialize16(magADC[i]); break; case MSP_SERVO: s_struct((uint8_t *)&servo, 16); break; case MSP_SERVO_CONF: headSerialReply(MAX_SERVOS * 9); for (i = 0; i < MAX_SERVOS; i++) { serialize16(cfg.servoConf[i].min); serialize16(cfg.servoConf[i].max); serialize16(cfg.servoConf[i].middle); serialize8(cfg.servoConf[i].rate); serialize16(cfg.servoConf[i].direction); } break; case MSP_SET_SERVO_CONF: headSerialReply(0); for (i = 0; i < MAX_SERVOS; i++) { cfg.servoConf[i].min = read16(); cfg.servoConf[i].max = read16(); cfg.servoConf[i].middle = read16(); cfg.servoConf[i].rate = read8(); cfg.servoConf[i].direction = read16(); } break; case MSP_SERVOMIX_CONF: headSerialReply(MAX_SERVO_RULES * sizeof(servoMixer_t)); for (i = 0; i < MAX_SERVO_RULES; i++) { serialize8(mcfg.customServoMixer[i].targetChannel); serialize8(mcfg.customServoMixer[i].fromChannel); serialize8(mcfg.customServoMixer[i].rate); serialize8(mcfg.customServoMixer[i].speed); serialize8(mcfg.customServoMixer[i].min); serialize8(mcfg.customServoMixer[i].max); serialize8(mcfg.customServoMixer[i].box); } break; case MSP_SET_SERVOMIX_CONF: headSerialReply(0); for (i = 0; i < MAX_SERVO_RULES; i++) { mcfg.customServoMixer[i].targetChannel = read8(); mcfg.customServoMixer[i].fromChannel = read8(); mcfg.customServoMixer[i].rate = read8(); mcfg.customServoMixer[i].speed = read8(); mcfg.customServoMixer[i].min = read8(); mcfg.customServoMixer[i].max = read8(); mcfg.customServoMixer[i].box = read8(); } loadCustomServoMixer(); break; case MSP_FW_CONFIG: headSerialReply(47); serialize8(mcfg.fw_althold_dir); serialize32(cfg.fw_roll_throw); serialize32(cfg.fw_pitch_throw); serialize8(cfg.fw_vector_trust); serialize16(cfg.fw_gps_maxcorr); serialize16(cfg.fw_gps_rudder); serialize16(cfg.fw_gps_maxclimb); serialize16(cfg.fw_gps_maxdive); serialize16(cfg.fw_climb_throttle); serialize16(cfg.fw_cruise_throttle); serialize16(cfg.fw_idle_throttle); serialize16(cfg.fw_scaler_throttle); serialize32(cfg.fw_roll_comp); serialize8(cfg.fw_rth_alt); // next added for future use serialize32(0); serialize32(0); serialize32(0); serialize32(0); break; case MSP_SET_FW_CONFIG: headSerialReply(0); mcfg.fw_althold_dir = read8(); cfg.fw_roll_throw = read32(); cfg.fw_pitch_throw = read32(); cfg.fw_vector_trust = read8(); cfg.fw_gps_maxcorr = read16(); cfg.fw_gps_rudder = read16(); cfg.fw_gps_maxclimb = read16(); cfg.fw_gps_maxdive = read16(); cfg.fw_climb_throttle = read16(); cfg.fw_cruise_throttle = read16(); cfg.fw_idle_throttle = read16(); cfg.fw_scaler_throttle = read16(); cfg.fw_roll_comp = read32(); cfg.fw_rth_alt = read8(); // next added for future use read32(); read32(); read32(); read32(); break; case MSP_MOTOR: s_struct((uint8_t *)motor, 16); break; case MSP_RC: headSerialReply(16); for (i = 0; i < 8; i++) serialize16(rcData[i]); break; #ifdef GPS case MSP_RAW_GPS: headSerialReply(16); serialize8(f.GPS_FIX); serialize8(GPS_numSat); serialize32(GPS_coord[LAT]); serialize32(GPS_coord[LON]); serialize16(GPS_altitude); serialize16(GPS_speed); serialize16(GPS_ground_course); break; case MSP_COMP_GPS: headSerialReply(5); serialize16(GPS_distanceToHome); serialize16(GPS_directionToHome); serialize8(GPS_update & 1); break; #endif case MSP_ATTITUDE: headSerialReply(6); for (i = 0; i < 2; i++) serialize16(angle[i]); serialize16(heading); break; case MSP_ALTITUDE: headSerialReply(6); serialize32(EstAlt); serialize16(vario); break; case MSP_ANALOG: headSerialReply(7); serialize8((uint8_t)constrain(vbat, 0, 255)); serialize16((uint16_t)constrain(mAhdrawn, 0, 0xFFFF)); // milliamphours drawn from battery serialize16(rssi); if (mcfg.multiwiicurrentoutput) serialize16((uint16_t)constrain((abs(amperage) * 10), 0, 0xFFFF)); // send amperage in 0.001 A steps else serialize16((uint16_t)constrain(abs(amperage), 0, 0xFFFF)); // send amperage in 0.01 A steps break; case MSP_RC_TUNING: headSerialReply(7); serialize8(cfg.rcRate8); serialize8(cfg.rcExpo8); serialize8(cfg.rollPitchRate[0]); // here for legacy support serialize8(cfg.yawRate); serialize8(cfg.dynThrPID); serialize8(cfg.thrMid8); serialize8(cfg.thrExpo8); break; case MSP_PID: headSerialReply(3 * PIDITEMS); for (i = 0; i < PIDITEMS; i++) { serialize8(cfg.P8[i]); serialize8(cfg.I8[i]); serialize8(cfg.D8[i]); } break; case MSP_PIDNAMES: headSerialReply(sizeof(pidnames) - 1); serializeNames(pidnames); break; case MSP_BOX: headSerialReply(2 * numberBoxItems); for (i = 0; i < numberBoxItems; i++) serialize16(cfg.activate[availableBoxes[i]]); break; case MSP_BOXNAMES: // headSerialReply(sizeof(boxnames) - 1); serializeBoxNamesReply(); break; case MSP_BOXIDS: headSerialReply(numberBoxItems); for (i = 0; i < numberBoxItems; i++) { for (j = 0; j < CHECKBOXITEMS; j++) { if (boxes[j].permanentId == availableBoxes[i]) serialize8(boxes[j].permanentId); } } break; case MSP_MISC: headSerialReply(2 * 6 + 4 + 2 + 4); serialize16(mcfg.midrc); serialize16(mcfg.minthrottle); serialize16(mcfg.maxthrottle); serialize16(mcfg.mincommand); serialize16(cfg.failsafe_throttle); serialize8(mcfg.gps_type); serialize8(mcfg.gps_baudrate); serialize8(mcfg.gps_ubx_sbas); serialize8(mcfg.multiwiicurrentoutput); serialize8(mcfg.rssi_aux_channel); serialize8(0); serialize16(cfg.mag_declination / 10); // TODO check this shit serialize8(mcfg.vbatscale); serialize8(mcfg.vbatmincellvoltage); serialize8(mcfg.vbatmaxcellvoltage); serialize8(mcfg.vbatwarningcellvoltage); break; case MSP_MOTOR_PINS: headSerialReply(8); for (i = 0; i < 8; i++) serialize8(i + 1); break; #ifdef GPS case MSP_WP: wp_no = read8(); // get the wp number headSerialReply(18); if (wp_no == 0) { lat = GPS_home[LAT]; lon = GPS_home[LON]; } else if (wp_no == 16) { lat = GPS_hold[LAT]; lon = GPS_hold[LON]; } serialize8(wp_no); serialize32(lat); serialize32(lon); serialize32(AltHold); // altitude (cm) will come here -- temporary implementation to test feature with apps serialize16(0); // heading will come here (deg) serialize16(0); // time to stay (ms) will come here serialize8(0); // nav flag will come here break; case MSP_SET_WP: wp_no = read8(); //get the wp number lat = read32(); lon = read32(); alt = read32(); // to set altitude (cm) read16(); // future: to set heading (deg) read16(); // future: to set time to stay (ms) read8(); // future: to set nav flag if (wp_no == 0) { GPS_home[LAT] = lat; GPS_home[LON] = lon; f.GPS_HOME_MODE = 0; // with this flag, GPS_set_next_wp will be called in the next loop -- OK with SERIAL GPS / OK with I2C GPS f.GPS_FIX_HOME = 1; if (alt != 0) AltHold = alt; // temporary implementation to test feature with apps } else if (wp_no == 16) { // OK with SERIAL GPS -- NOK for I2C GPS / needs more code dev in order to inject GPS coord inside I2C GPS GPS_hold[LAT] = lat; GPS_hold[LON] = lon; if (alt != 0) AltHold = alt; // temporary implementation to test feature with apps nav_mode = NAV_MODE_WP; GPS_set_next_wp(&GPS_hold[LAT], &GPS_hold[LON]); } headSerialReply(0); break; #endif /* GPS */ case MSP_RESET_CONF: if (!f.ARMED) checkFirstTime(true); headSerialReply(0); break; case MSP_ACC_CALIBRATION: if (!f.ARMED) calibratingA = CALIBRATING_ACC_CYCLES; headSerialReply(0); break; case MSP_MAG_CALIBRATION: if (!f.ARMED) f.CALIBRATE_MAG = 1; headSerialReply(0); break; case MSP_EEPROM_WRITE: if (f.ARMED) { headSerialError(0); } else { writeEEPROM(0, true); headSerialReply(0); } break; case MSP_DEBUG: headSerialReply(8); // make use of this crap, output some useful QA statistics debug[3] = ((hse_value / 1000000) * 1000) + (SystemCoreClock / 1000000); // XX0YY [crystal clock : core clock] for (i = 0; i < 4; i++) serialize16(debug[i]); // 4 variables are here for general monitoring purpose break; // Additional commands that are not compatible with MultiWii case MSP_ACC_TRIM: headSerialReply(4); serialize16(cfg.angleTrim[PITCH]); serialize16(cfg.angleTrim[ROLL]); break; case MSP_UID: headSerialReply(12); serialize32(U_ID_0); serialize32(U_ID_1); serialize32(U_ID_2); break; #ifdef GPS case MSP_GPSSVINFO: headSerialReply(1 + (GPS_numCh * 4)); serialize8(GPS_numCh); for (i = 0; i < GPS_numCh; i++) { serialize8(GPS_svinfo_chn[i]); serialize8(GPS_svinfo_svid[i]); serialize8(GPS_svinfo_quality[i]); serialize8(GPS_svinfo_cno[i]); } // Poll new SVINFO from GPS gpsPollSvinfo(); break; case MSP_GPSDEBUGINFO: headSerialReply(16); if (sensors(SENSOR_GPS)) { serialize32(GPS_update_rate[1] - GPS_update_rate[0]); serialize32(GPS_svinfo_rate[1] - GPS_svinfo_rate[0]); } else { serialize32(0); serialize32(0); } serialize32(GPS_HorizontalAcc); serialize32(GPS_VerticalAcc); break; #endif /* GPS */ case MSP_SET_CONFIG: headSerialReply(0); mcfg.mixerConfiguration = read8(); // multitype featureClearAll(); featureSet(read32()); // features bitmap mcfg.serialrx_type = read8(); // serialrx_type mcfg.board_align_roll = read16(); // board_align_roll mcfg.board_align_pitch = read16(); // board_align_pitch mcfg.board_align_yaw = read16(); // board_align_yaw mcfg.currentscale = read16(); mcfg.currentoffset = read16(); mcfg.motor_pwm_rate = read16(); cfg.rollPitchRate[0] = read8(); cfg.rollPitchRate[1] = read8(); mcfg.power_adc_channel = read8(); /// ??? break; case MSP_CONFIG: headSerialReply(1 + 4 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 1); serialize8(mcfg.mixerConfiguration); serialize32(featureMask()); serialize8(mcfg.serialrx_type); serialize16(mcfg.board_align_roll); serialize16(mcfg.board_align_pitch); serialize16(mcfg.board_align_yaw); serialize16(mcfg.currentscale); serialize16(mcfg.currentoffset); serialize16(mcfg.motor_pwm_rate); serialize8(cfg.rollPitchRate[0]); serialize8(cfg.rollPitchRate[1]); serialize8(mcfg.power_adc_channel); /// ??? break; case MSP_RCMAP: headSerialReply(MAX_INPUTS); // TODO fix this for (i = 0; i < MAX_INPUTS; i++) serialize8(mcfg.rcmap[i]); break; case MSP_SET_RCMAP: headSerialReply(0); for (i = 0; i < MAX_INPUTS; i++) mcfg.rcmap[i] = read8(); break; case MSP_REBOOT: headSerialReply(0); pendReboot = true; break; case MSP_BUILDINFO: headSerialReply(11 + 4 + 4); for (i = 0; i < 11; i++) serialize8(build[i]); // MMM DD YYYY as ascii, MMM = Jan/Feb... etc serialize32(0); // future exp serialize32(0); // future exp break; default: // we do not know how to handle the (valid) message, indicate error MSP $M! headSerialError(0); break; } tailSerialReply(); }
/* * After every write one needs to perform a read an innocuous register to * ensure the writes are completed for certain ports. This is done for * all ports so that the callers don't need the per-port knowledge for * each transaction. */ static inline void complete_write(void) { /* Read the general control and function disable register. */ const size_t R_PCH_PCR_LPC_GCFD = 0x3418; read32(pcr_reg_address(PID_LPC, R_PCH_PCR_LPC_GCFD)); }
static void sata_init(struct device *dev) { u8 byte; u16 word; u32 dword; u8 rev_id; void *sata_bar5; u16 sata_bar0, sata_bar1, sata_bar2, sata_bar3, sata_bar4; int i, j; struct southbridge_ati_sb800_config *conf; conf = dev->chip_info; struct device *sm_dev; /* SATA SMBus Disable */ sm_dev = pcidev_on_root(0x14, 0); /* get rev_id */ rev_id = pci_read_config8(sm_dev, 0x08) - 0x2F; /* get base address */ sata_bar5 = (void *)(pci_read_config32(dev, 0x24) & ~0x3FF); sata_bar0 = pci_read_config16(dev, 0x10) & ~0x7; sata_bar1 = pci_read_config16(dev, 0x14) & ~0x3; sata_bar2 = pci_read_config16(dev, 0x18) & ~0x7; sata_bar3 = pci_read_config16(dev, 0x1C) & ~0x3; sata_bar4 = pci_read_config16(dev, 0x20) & ~0xf; printk(BIOS_SPEW, "sata_bar0=%x\n", sata_bar0); /* 3030 */ printk(BIOS_SPEW, "sata_bar1=%x\n", sata_bar1); /* 3070 */ printk(BIOS_SPEW, "sata_bar2=%x\n", sata_bar2); /* 3040 */ printk(BIOS_SPEW, "sata_bar3=%x\n", sata_bar3); /* 3080 */ printk(BIOS_SPEW, "sata_bar4=%x\n", sata_bar4); /* 3000 */ printk(BIOS_SPEW, "sata_bar5=%p\n", sata_bar5); /* e0309000 */ /* SERR-Enable */ word = pci_read_config16(dev, 0x04); word |= (1 << 8); pci_write_config16(dev, 0x04, word); /* Set SATA Operation Mode, Set to IDE mode */ byte = pci_read_config8(dev, 0x40); byte |= (1 << 0); //byte |= (1 << 4); pci_write_config8(dev, 0x40, byte); dword = 0x01018f00; pci_write_config32(dev, 0x8, dword); /* Program the 2C to 0x43801002 */ dword = 0x43801002; pci_write_config32(dev, 0x2c, dword); pci_write_config8(dev, 0x34, 0x70); /* 8.11 SATA MSI and D3 Power State Capability */ dword = read32(sata_bar5 + 0xFC); dword &= ~(1 << 11); /* rpr 8.8. Disabling Aggressive Link Power Management */ dword &= ~(1 << 12); /* rpr 8.9.1 Disabling Port Multiplier support. */ dword &= ~(1 << 10); /* rpr 8.9.2 disabling FIS-based Switching support */ dword &= ~(1 << 19); /* rpr 8.10. Disabling CCC (Command Completion Coalescing) Support */ write32((sata_bar5 + 0xFC), dword); dword = read32(sata_bar5 + 0xF8); dword &= ~(0x3F << 22); /* rpr 8.9.2 disabling FIS-based Switching support */ write32(sata_bar5 + 0xF8, dword); byte = pci_read_config8(dev, 0x40); byte &= ~(1 << 0); pci_write_config8(dev, 0x40, byte); /* rpr 8.3 */ printk(BIOS_SPEW, "rev_id=%x\n", rev_id); dword = pci_read_config32(dev, 0x84); if (rev_id == 0x11) /* A11 */ dword |= 1 << 22; pci_write_config32(dev, 0x84, dword); /* rpr8.12 Program the watchdog counter to 0x20 */ byte = pci_read_config8(dev, 0x44); byte |= 1 << 0; pci_write_config8(dev, 0x44, byte); pci_write_config8(dev, 0x46, 0x20); sb800_setup_sata_phys(dev); /* Enable the I/O, MM, BusMaster access for SATA */ byte = pci_read_config8(dev, 0x4); byte |= 7 << 0; pci_write_config8(dev, 0x4, byte); /* RPR7.7 SATA drive detection. */ /* Use BAR5+0x128,BAR0 for Primary Slave */ /* Use BAR5+0x1A8,BAR0 for Primary Slave */ /* Use BAR5+0x228,BAR2 for Secondary Master */ /* Use BAR5+0x2A8,BAR2 for Secondary Slave */ /* Use BAR5+0x328,PATA_BAR0/2 for Primary/Secondary master emulation */ /* Use BAR5+0x3A8,PATA_BAR0/2 for Primary/Secondary Slave emulation */ /* TODO: port 4,5, which are PATA emulations. What are PATA_BARs? */ for (i = 0; i < 4; i++) { byte = read8(sata_bar5 + 0x128 + 0x80 * i); printk(BIOS_SPEW, "SATA port %i status = %x\n", i, byte); byte &= 0xF; if (byte == 0x1) { /* If the drive status is 0x1 then we see it but we aren't talking to it. */ /* Try to do something about it. */ printk(BIOS_SPEW, "SATA device detected but not talking. Trying lower speed.\n"); /* Read in Port-N Serial ATA Control Register */ byte = read8(sata_bar5 + 0x12C + 0x80 * i); /* Set Reset Bit and 1.5g bit */ byte |= 0x11; write8((sata_bar5 + 0x12C + 0x80 * i), byte); /* Wait 1ms */ mdelay(1); /* Clear Reset Bit */ byte &= ~0x01; write8((sata_bar5 + 0x12C + 0x80 * i), byte); /* Wait 1ms */ mdelay(1); /* Reread status */ byte = read8(sata_bar5 + 0x128 + 0x80 * i); printk(BIOS_SPEW, "SATA port %i status = %x\n", i, byte); byte &= 0xF; } if (byte == 0x3) { for (j = 0; j < 10; j++) { if (!sata_drive_detect(i, ((i / 2) == 0) ? sata_bar0 : sata_bar2)) break; } printk(BIOS_DEBUG, "%s %s device is %sready after %i tries\n", (i / 2) ? "Secondary" : "Primary", (i % 2) ? "Slave" : "Master", (j == 10) ? "not " : "", (j == 10) ? j : j + 1); } else { printk(BIOS_DEBUG, "No %s %s SATA drive on Slot%i\n", (i / 2) ? "Secondary" : "Primary", (i % 2) ? "Slave" : "Master", i); } } /* Below is CIM InitSataLateFar */ /* Enable interrupts from the HBA */ byte = read8(sata_bar5 + 0x4); byte |= 1 << 1; write8((sata_bar5 + 0x4), byte); /* Clear error status */ write32((sata_bar5 + 0x130), 0xFFFFFFFF); write32((sata_bar5 + 0x1b0), 0xFFFFFFFF); write32((sata_bar5 + 0x230), 0xFFFFFFFF); write32((sata_bar5 + 0x2b0), 0xFFFFFFFF); write32((sata_bar5 + 0x330), 0xFFFFFFFF); write32((sata_bar5 + 0x3b0), 0xFFFFFFFF); /* Clear SATA status,Firstly we get the AcpiGpe0BlkAddr */ /* ????? why CIM does not set the AcpiGpe0BlkAddr, but use it??? */ /* word = 0x0000; */ /* word = pm_ioread(0x28); */ /* byte = pm_ioread(0x29); */ /* word |= byte<<8; */ /* printk(BIOS_DEBUG, "AcpiGpe0Blk addr = %x\n", word); */ /* write32(word, 0x80000000); */ }
} static unsigned get_osc_freq(void) { return (read32(clk_rst_osc_ctrl_ptr) & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT; } /* Clock configuration. */ static void config_oscillator(void) { // Read oscillator drive strength from OSC_EDPD_OVER.XOFS and copy // to OSC_CTRL.XOFS and set XOE. uint32_t xofs = (read32(pmc_ctlr_osc_edpd_over_ptr) & PMC_XOFS_MASK) >> PMC_XOFS_SHIFT; uint32_t osc_ctrl = read32(clk_rst_osc_ctrl_ptr); osc_ctrl &= ~OSC_XOFS_MASK; osc_ctrl |= (xofs << OSC_XOFS_SHIFT); osc_ctrl |= OSC_XOE; write32(clk_rst_osc_ctrl_ptr, osc_ctrl); } static void config_pllu(void) { // Figure out what parameters to use for PLLU. uint32_t divm, divn, cpcon, lfcon; switch (get_osc_freq()) { case OSC_FREQ_12:
u32 DIUpdateRegisters( void ) { u32 read,i; static u32 PatchState = 0; static u32 DOLReadSize= 0; if( read32(DI_CONTROL) != 0xdeadbeef ) { write32( DI_SCONTROL, read32(DI_CONTROL) & 3 ); clear32( DI_SSTATUS, 0x14 ); write32( DI_CONTROL, 0xdeadbeef ); if( read32(DI_SCONTROL) & 1 ) { if( ConfigGetConfig(DML_CFG_ACTIVITY_LED) ) set32( HW_GPIO_OUT, 1<<5 ); if( read32(DI_CMD_0) != 0xdeadbeef ) { write32( DI_SCMD_0, read32(DI_CMD_0) ); write32( DI_CMD_0, 0xdeadbeef ); } if( read32(DI_CMD_1) != 0xdeadbeef ) { write32( DI_SCMD_1, read32(DI_CMD_1) ); write32( DI_CMD_1, 0xdeadbeef ); } if( read32(DI_CMD_2) != 0xdeadbeef ) { write32( DI_SCMD_2, read32(DI_CMD_2) ); write32( DI_CMD_2, 0xdeadbeef ); } if( read32(DI_DMA_ADR) != 0xdeadbeef ) { write32( DI_SDMA_ADR, read32(DI_DMA_ADR) ); write32( DI_DMA_ADR, 0xdeadbeef ); } if( read32(DI_DMA_LEN) != 0xdeadbeef ) { write32( DI_SDMA_LEN, read32(DI_DMA_LEN) ); write32( DI_DMA_LEN, 0xdeadbeef ); } if( read32(DI_IMM) != 0xdeadbeef ) { write32( DI_SIMM, read32(DI_IMM) ); write32( DI_IMM, 0xdeadbeef ); } switch( read32(DI_SCMD_0) >> 24 ) { case 0xA7: case 0xA9: //dbgprintf("DIP:Async!\n"); case 0xA8: { u32 Buffer = P2C(read32(DI_SDMA_ADR)); u32 Length = read32(DI_SCMD_2); u32 Offset = read32(DI_SCMD_1) << 2; // dbgprintf("DIP:DVDRead( 0x%08x, 0x%08x, 0x%08x )\n", Offset, Length, Buffer|0x80000000 ); // udelay(250); if( GameFile.fptr != Offset ) if( f_lseek( &GameFile, Offset ) != FR_OK ) { EXIControl(1); dbgprintf("DIP:Failed to seek to 0x%08x\n", Offset ); while(1); } if( f_read( &GameFile, (char*)Buffer, Length, &read ) != FR_OK ) { EXIControl(1); dbgprintf("DIP:Failed to read from 0x%08x to 0x%08X\n", Offset, Buffer ); while(1); } //if( ((read+31)&(~31)) != Length ) //{ // dbgprintf("DIP:DVDLowRead Offset:%08X Size:%08d Dst:%08X\n", Offset, Length, Buffer ); // dbgprintf("DIP:Failed to read %d bytes, only got %d\n", Length, read ); // break; //} if( (u32)Buffer == 0x01300000 ) { DoPatchesLoader( (char*)(0x01300000), Length ); } if( PatchState == 0 ) { if( Length == 0x100 ) { if( read32( (u32)Buffer ) == 0x100 ) { //quickly calc the size DOLSize = sizeof(dolhdr); dolhdr *dol = (dolhdr*)Buffer; for( i=0; i < 7; ++i ) DOLSize += dol->sizeText[i]; for( i=0; i < 11; ++i ) DOLSize += dol->sizeData[i]; DOLReadSize = sizeof(dolhdr); DOLMinOff=0x81800000; DOLMaxOff=0; for( i=0; i < 7; ++i ) { if( dol->addressText[i] == 0 ) continue; if( DOLMinOff > dol->addressText[i]) DOLMinOff = dol->addressText[i]; if( DOLMaxOff < dol->addressText[i] + dol->sizeText[i] ) DOLMaxOff = dol->addressText[i] + dol->sizeText[i]; } DOLMinOff -= 0x80000000; DOLMaxOff -= 0x80000000; dbgprintf("DIP:DOLSize:%d DOLMinOff:0x%08X DOLMaxOff:0x%08X\n", DOLSize, DOLMinOff, DOLMaxOff ); PatchState = 1; } } else if( read32(Buffer) == 0x7F454C46 ) { if (getfilenamebyoffset(Offset) != NULL) { dbgprintf("DIP:The Game is loading %s\n", getfilenamebyoffset(Offset)); } else { dbgprintf("DIP:The Game is loading some .elf that is not in the fst...\n"); } for (i = ((*(u32 *)0x00000038) & ~0x80000000) + 16; i < 0x01800000; i+=12) // Search the fst for the dvd offset of the .elf file { if (*(u32 *)i == Offset) { DOLSize = *(u32 *)(i+4); DOLReadSize = Length; if( DOLReadSize == DOLSize ) // The .elf is read completely already { dbgprintf("DIP:The .elf is read completely, file size: %u bytes\n", DOLSize); DoPatches( (char*)(Buffer), Length, 0x80000000 ); } else // a part of the .elf is read { PatchState = 2; DOLMinOff=Buffer; DOLMaxOff=Buffer+Length; if (Length <= 4096) // The .elf header is read { ELFNumberOfSections = read16(Buffer+0x2c) -2; // Assume that 2 sections are .bss and .sbss which are not read dbgprintf("DIP:The .elf header is read(%u bytes), .elf file size: %u bytes, number of sections to load: %u\n", Length, DOLSize, ELFNumberOfSections); } else // The .elf is read into a buffer { ELFNumberOfSections = -1; // Make sure that ELFNumberOfSections == 0 does not become true dbgprintf("DIP:The .elf is read into a buffer, read progress: %u/%u bytes\n", Length, DOLSize); } } break; } } } } else if ( PatchState != 0 ) { DOLReadSize += Length; if (PatchState == 2) { ELFNumberOfSections--; // DOLMinOff and DOLMaxOff are optimised when loading .dol files if (DOLMinOff > Buffer) DOLMinOff = Buffer; if (DOLMaxOff < Buffer+Length) DOLMaxOff = Buffer+Length; if (ELFNumberOfSections < 0) { dbgprintf("DIP:.elf read progress: %u/%u bytes\n", DOLReadSize, DOLSize); } else { dbgprintf("DIP:.elf read progress: %u/%u bytes, sections left: %u\n", DOLReadSize, DOLSize, ELFNumberOfSections); } } //dbgprintf("DIP:DOLSize:%d DOLReadSize:%d\n", DOLSize, DOLReadSize ); if( DOLReadSize >= DOLSize || (PatchState == 2 && ELFNumberOfSections == 0)) { DoPatches( (char*)(DOLMinOff), DOLMaxOff-DOLMinOff, 0x80000000 ); PatchState = 0; } } write32( DI_SDMA_LEN, 0 ); while( read32(DI_SCONTROL) & 1 ) clear32( DI_SCONTROL, 1 ); set32( DI_SSTATUS, 0x3A ); if( ConfigGetConfig(DML_CFG_NODISC) ) { write32( 0x0d80000C, (1<<0) | (1<<4) ); write32( HW_PPCIRQFLAG, read32(HW_PPCIRQFLAG) ); write32( HW_ARMIRQFLAG, read32(HW_ARMIRQFLAG) ); set32( 0x0d80000C, (1<<2) ); } else { if( (read32(DI_SCMD_0) >> 24) == 0xA7 ) { write32( 0x0d80000C, (1<<0) | (1<<4) ); write32( HW_PPCIRQFLAG, read32(HW_PPCIRQFLAG) ); write32( HW_ARMIRQFLAG, read32(HW_ARMIRQFLAG) ); set32( 0x0d80000C, (1<<2) ); } } } break; default: { EXIControl(1); dbgprintf("DIP:Unknown CMD:%08X %08X %08X %08X %08X %08X\n", read32(DI_SCMD_0), read32(DI_SCMD_1), read32(DI_SCMD_2), read32(DI_SIMM), read32(DI_SDMA_ADR), read32(DI_SDMA_LEN) ); while(1); } break; } if( ConfigGetConfig(DML_CFG_ACTIVITY_LED) ) clear32( HW_GPIO_OUT, 1<<5 ); return 1; } else {
static inline void clrbits32(uint32_t bits, void *addr) { write32(addr, read32(addr) & ~bits); }
static inline u32 gtt_read(u32 reg) { return read32(gtt_res->base + reg); }
static int wakeup_on_lp(void) { return !!(read32(pmc_ctlr_scratch4_ptr) & PMC_SCRATCH4_LP); }
static int rx_fifo_empty(struct a10_uart *uart) { return !(read32(&uart->lsr) & UART8250_LSR_DR); }
static unsigned get_osc_freq(void) { return (read32(clk_rst_osc_ctrl_ptr) & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT; }
u32_t s5p4418_timer_read(int ch) { physical_addr_t base = s5p4418_timer_base(ch); return read32(phys_to_virt(base + TIMER_TCNTO)); }