void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) { mm_flags = mm_support(); if (avctx->dsp_mask) { if (avctx->dsp_mask & FF_MM_FORCE) mm_flags |= (avctx->dsp_mask & 0xffff); else mm_flags &= ~(avctx->dsp_mask & 0xffff); } #if 0 av_log(avctx, AV_LOG_INFO, "libavcodec: CPU flags:"); if (mm_flags & MM_MMX) av_log(avctx, AV_LOG_INFO, " mmx"); if (mm_flags & MM_MMXEXT) av_log(avctx, AV_LOG_INFO, " mmxext"); if (mm_flags & MM_3DNOW) av_log(avctx, AV_LOG_INFO, " 3dnow"); if (mm_flags & MM_SSE) av_log(avctx, AV_LOG_INFO, " sse"); if (mm_flags & MM_SSE2) av_log(avctx, AV_LOG_INFO, " sse2"); av_log(avctx, AV_LOG_INFO, "\n"); #endif if (mm_flags & MM_MMX) { const int idct_algo= avctx->idct_algo; if(avctx->lowres==0){ if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){ c->idct_put= ff_simple_idct_put_mmx; c->idct_add= ff_simple_idct_add_mmx; c->idct = ff_simple_idct_mmx; c->idct_permutation_type= FF_SIMPLE_IDCT_PERM; #ifdef CONFIG_GPL }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){ if(mm_flags & MM_MMXEXT){ c->idct_put= ff_libmpeg2mmx2_idct_put; c->idct_add= ff_libmpeg2mmx2_idct_add; c->idct = ff_mmxext_idct; }else{ c->idct_put= ff_libmpeg2mmx_idct_put; c->idct_add= ff_libmpeg2mmx_idct_add; c->idct = ff_mmx_idct; } c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; #endif }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER || ENABLE_THEORA_DECODER) && idct_algo==FF_IDCT_VP3){ if(mm_flags & MM_SSE2){ c->idct_put= ff_vp3_idct_put_sse2; c->idct_add= ff_vp3_idct_add_sse2; c->idct = ff_vp3_idct_sse2; c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM; }else{ c->idct_put= ff_vp3_idct_put_mmx; c->idct_add= ff_vp3_idct_add_mmx; c->idct = ff_vp3_idct_mmx; c->idct_permutation_type= FF_PARTTRANS_IDCT_PERM; } }else if(idct_algo==FF_IDCT_CAVS){ c->idct_permutation_type= FF_TRANSPOSE_IDCT_PERM; }else if(idct_algo==FF_IDCT_XVIDMMX){ if(mm_flags & MM_SSE2){ c->idct_put= ff_idct_xvid_sse2_put; c->idct_add= ff_idct_xvid_sse2_add; c->idct = ff_idct_xvid_sse2; c->idct_permutation_type= FF_SSE2_IDCT_PERM; }else if(mm_flags & MM_MMXEXT){ c->idct_put= ff_idct_xvid_mmx2_put; c->idct_add= ff_idct_xvid_mmx2_add; c->idct = ff_idct_xvid_mmx2; }else{ c->idct_put= ff_idct_xvid_mmx_put; c->idct_add= ff_idct_xvid_mmx_add; c->idct = ff_idct_xvid_mmx; } } } c->put_pixels_clamped = put_pixels_clamped_mmx; c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx; c->add_pixels_clamped = add_pixels_clamped_mmx; c->clear_blocks = clear_blocks_mmx; #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \ c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \ c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \ c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \ c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU SET_HPEL_FUNCS(put, 0, 16, mmx); SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx); SET_HPEL_FUNCS(avg, 0, 16, mmx); SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx); SET_HPEL_FUNCS(put, 1, 8, mmx); SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx); SET_HPEL_FUNCS(avg, 1, 8, mmx); SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx); c->gmc= gmc_mmx; c->add_bytes= add_bytes_mmx; c->add_bytes_l2= add_bytes_l2_mmx; c->draw_edges = draw_edges_mmx; if (ENABLE_ANY_H263) { c->h263_v_loop_filter= h263_v_loop_filter_mmx; c->h263_h_loop_filter= h263_h_loop_filter_mmx; } if ((ENABLE_VP3_DECODER || ENABLE_THEORA_DECODER) && !(avctx->flags & CODEC_FLAG_BITEXACT)) { c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx; c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx; } c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_rnd; c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_mmx; c->put_no_rnd_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_nornd; c->h264_idct_dc_add= c->h264_idct_add= ff_h264_idct_add_mmx; c->h264_idct8_dc_add= c->h264_idct8_add= ff_h264_idct8_add_mmx; if (mm_flags & MM_SSE2) c->h264_idct8_add= ff_h264_idct8_add_sse2; if (mm_flags & MM_MMXEXT) { c->prefetch = prefetch_mmx2; c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2; c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2; c->avg_pixels_tab[0][0] = avg_pixels16_mmx2; c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2; c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2; c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2; c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2; c->avg_pixels_tab[1][0] = avg_pixels8_mmx2; c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2; c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2; c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2; c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2; if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2; c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2; c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2; c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2; c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2; c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2; } #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \ c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \ c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \ c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \ c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \ c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \ c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \ c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2); SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2); SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2); SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2); SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2); SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2); SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2); SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2); SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2); SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2); c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2_rnd; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2; c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_mmx2; c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_mmx2; c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2; c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2; c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2; c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2; c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2; c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2; c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2; c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2; c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2; c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2; c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2; c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2; c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2; c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2; c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2; c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2; c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2; c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2; c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2; c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2; c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2; c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2; c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2; if (ENABLE_CAVS_DECODER) ff_cavsdsp_init_mmx2(c, avctx); if (ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER) ff_vc1dsp_init_mmx(c, avctx); c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2; } else if (mm_flags & MM_3DNOW) { c->prefetch = prefetch_3dnow; c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow; c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow; c->avg_pixels_tab[0][0] = avg_pixels16_3dnow; c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow; c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow; c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow; c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow; c->avg_pixels_tab[1][0] = avg_pixels8_3dnow; c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow; c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow; if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow; c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow; c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow; c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow; c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow; c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow; } SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow); SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow); SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow); SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow); SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow); SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow); SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow); SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow); SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow); SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow); c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow_rnd; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow; if (ENABLE_CAVS_DECODER) ff_cavsdsp_init_3dnow(c, avctx); } #define H264_QPEL_FUNCS(x, y, CPU)\ c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\ c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\ c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\ c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU; if((mm_flags & MM_SSE2) && !(mm_flags & MM_3DNOW)){ // these functions are slower than mmx on AMD, but faster on Intel /* FIXME works in most codecs, but crashes svq1 due to unaligned chroma c->put_pixels_tab[0][0] = put_pixels16_sse2; c->avg_pixels_tab[0][0] = avg_pixels16_sse2; */ H264_QPEL_FUNCS(0, 0, sse2); } if(mm_flags & MM_SSE2){ H264_QPEL_FUNCS(0, 1, sse2); H264_QPEL_FUNCS(0, 2, sse2); H264_QPEL_FUNCS(0, 3, sse2); H264_QPEL_FUNCS(1, 1, sse2); H264_QPEL_FUNCS(1, 2, sse2); H264_QPEL_FUNCS(1, 3, sse2); H264_QPEL_FUNCS(2, 1, sse2); H264_QPEL_FUNCS(2, 2, sse2); H264_QPEL_FUNCS(2, 3, sse2); H264_QPEL_FUNCS(3, 1, sse2); H264_QPEL_FUNCS(3, 2, sse2); H264_QPEL_FUNCS(3, 3, sse2); } #ifdef HAVE_SSSE3 if(mm_flags & MM_SSSE3){ H264_QPEL_FUNCS(1, 0, ssse3); H264_QPEL_FUNCS(1, 1, ssse3); H264_QPEL_FUNCS(1, 2, ssse3); H264_QPEL_FUNCS(1, 3, ssse3); H264_QPEL_FUNCS(2, 0, ssse3); H264_QPEL_FUNCS(2, 1, ssse3); H264_QPEL_FUNCS(2, 2, ssse3); H264_QPEL_FUNCS(2, 3, ssse3); H264_QPEL_FUNCS(3, 0, ssse3); H264_QPEL_FUNCS(3, 1, ssse3); H264_QPEL_FUNCS(3, 2, ssse3); H264_QPEL_FUNCS(3, 3, ssse3); c->put_no_rnd_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_ssse3_nornd; c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_ssse3_rnd; c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_ssse3_rnd; c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_ssse3; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_ssse3; c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3; } #endif #ifdef CONFIG_SNOW_DECODER if(mm_flags & MM_SSE2 & 0){ c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2; #ifdef HAVE_7REGS c->vertical_compose97i = ff_snow_vertical_compose97i_sse2; #endif c->inner_add_yblock = ff_snow_inner_add_yblock_sse2; } else{ if(mm_flags & MM_MMXEXT){ c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx; #ifdef HAVE_7REGS c->vertical_compose97i = ff_snow_vertical_compose97i_mmx; #endif } c->inner_add_yblock = ff_snow_inner_add_yblock_mmx; } #endif if(mm_flags & MM_3DNOW){ c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow; c->vector_fmul = vector_fmul_3dnow; if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ c->float_to_int16 = float_to_int16_3dnow; c->float_to_int16_interleave = float_to_int16_interleave_3dnow; } } if(mm_flags & MM_3DNOWEXT){ c->vector_fmul_reverse = vector_fmul_reverse_3dnow2; c->vector_fmul_window = vector_fmul_window_3dnow2; if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ c->float_to_int16_interleave = float_to_int16_interleave_3dn2; } } if(mm_flags & MM_SSE){ c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse; c->ac3_downmix = ac3_downmix_sse; c->vector_fmul = vector_fmul_sse; c->vector_fmul_reverse = vector_fmul_reverse_sse; c->vector_fmul_add_add = vector_fmul_add_add_sse; c->vector_fmul_window = vector_fmul_window_sse; c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse; c->float_to_int16 = float_to_int16_sse; c->float_to_int16_interleave = float_to_int16_interleave_sse; } if(mm_flags & MM_3DNOW) c->vector_fmul_add_add = vector_fmul_add_add_3dnow; // faster than sse if(mm_flags & MM_SSE2){ c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2; c->float_to_int16 = float_to_int16_sse2; c->float_to_int16_interleave = float_to_int16_interleave_sse2; c->add_int16 = add_int16_sse2; c->sub_int16 = sub_int16_sse2; c->scalarproduct_int16 = scalarproduct_int16_sse2; } } if (ENABLE_ENCODERS) dsputilenc_init_mmx(c, avctx); #if 0 // for speed testing get_pixels = just_return; put_pixels_clamped = just_return; add_pixels_clamped = just_return; pix_abs16x16 = just_return; pix_abs16x16_x2 = just_return; pix_abs16x16_y2 = just_return; pix_abs16x16_xy2 = just_return; put_pixels_tab[0] = just_return; put_pixels_tab[1] = just_return; put_pixels_tab[2] = just_return; put_pixels_tab[3] = just_return; put_no_rnd_pixels_tab[0] = just_return; put_no_rnd_pixels_tab[1] = just_return; put_no_rnd_pixels_tab[2] = just_return; put_no_rnd_pixels_tab[3] = just_return; avg_pixels_tab[0] = just_return; avg_pixels_tab[1] = just_return; avg_pixels_tab[2] = just_return; avg_pixels_tab[3] = just_return; avg_no_rnd_pixels_tab[0] = just_return; avg_no_rnd_pixels_tab[1] = just_return; avg_no_rnd_pixels_tab[2] = just_return; avg_no_rnd_pixels_tab[3] = just_return; //av_fdct = just_return; //ff_idct = just_return; #endif }


static void iscsi_retry_timer_expired(void *opaque) { struct IscsiTask *iTask = opaque; iTask->complete = 1; if (iTask->co) { qemu_coroutine_enter(iTask->co, NULL); } }


int qemu_shutdown_requested_get(void) { return shutdown_requested; }


static inline void RENAME(rgb15ToY)(uint8_t *dst, uint8_t *src, int width) { int i; for(i=0; i<width; i++) { int d= ((uint16_t*)src)[i]; int r= d&0x1F; int g= (d>>5)&0x1F; int b= (d>>10)&0x1F; dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16; } }


static int kvm_dirty_pages_log_change(target_phys_addr_t phys_addr, target_phys_addr_t end_addr, unsigned flags, unsigned mask) { KVMState *s = kvm_state; KVMSlot *mem = kvm_lookup_slot(s, phys_addr); if (mem == NULL) { dprintf("invalid parameters %llx-%llx\n", phys_addr, end_addr); return -EINVAL; } flags = (mem->flags & ~mask) | flags; /* Nothing changed, no need to issue ioctl */ if (flags == mem->flags) return 0; mem->flags = flags; return kvm_set_user_memory_region(s, mem); }


static void RENAME(uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, long width, long height, long lumStride, long chromStride, long srcStride) { long y; const long chromWidth= -((-width)>>1); for (y=0; y<height; y++) { RENAME(extract_even)(src+1, ydst, width); if(y&1) { RENAME(extract_even2avg)(src-srcStride, src, udst, vdst, chromWidth); udst+= chromStride; vdst+= chromStride; } src += srcStride; ydst+= lumStride; } #if COMPILE_TEMPLATE_MMX __asm__( EMMS" \n\t" SFENCE" \n\t" ::: "memory" ); #endif }


static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { const uint8_t *srcPtr= src[0]; uint8_t *dstY= dst[0]; uint8_t *dstU= dst[1]; uint8_t *dstV= dst[2]; int i; void (*copy) (const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv); void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv); switch(c->srcFormat) { #define CASE(pixfmt, prefix) \ case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \ interpolate = bayer_##prefix##_to_yv12_interpolate; \ break; CASE(AV_PIX_FMT_BAYER_BGGR8, bggr8) CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le) CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be) CASE(AV_PIX_FMT_BAYER_RGGB8, rggb8) CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le) CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be) CASE(AV_PIX_FMT_BAYER_GBRG8, gbrg8) CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le) CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be) CASE(AV_PIX_FMT_BAYER_GRBG8, grbg8) CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le) CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be) #undef CASE default: return 0; } copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table); srcPtr += 2 * srcStride[0]; dstY += 2 * dstStride[0]; dstU += dstStride[1]; dstV += dstStride[1]; for (i = 2; i < srcSliceH - 2; i += 2) { interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table); srcPtr += 2 * srcStride[0]; dstY += 2 * dstStride[0]; dstU += dstStride[1]; dstV += dstStride[1]; } copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table); return srcSliceH; }


static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic) { VAAPIEncodeContext *ctx = avctx->priv_data; VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params; VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params; VAAPIEncodeH264Context *priv = ctx->priv_data; int i; if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); vpic->frame_num = 0; priv->next_frame_num = 1; priv->cpb_delay = 0; } else { vpic->frame_num = priv->next_frame_num; if (pic->type != PICTURE_TYPE_B) { // nal_ref_idc != 0 ++priv->next_frame_num; } ++priv->cpb_delay; } priv->dpb_delay = pic->display_order - pic->encode_order + 1; vpic->frame_num = vpic->frame_num & ((1 << (4 + vseq->seq_fields.bits.log2_max_frame_num_minus4)) - 1); vpic->CurrPic.picture_id = pic->recon_surface; vpic->CurrPic.frame_idx = vpic->frame_num; vpic->CurrPic.flags = 0; vpic->CurrPic.TopFieldOrderCnt = pic->display_order; vpic->CurrPic.BottomFieldOrderCnt = pic->display_order; for (i = 0; i < pic->nb_refs; i++) { VAAPIEncodePicture *ref = pic->refs[i]; av_assert0(ref && ref->encode_order < pic->encode_order); vpic->ReferenceFrames[i].picture_id = ref->recon_surface; vpic->ReferenceFrames[i].frame_idx = ref->encode_order; vpic->ReferenceFrames[i].flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; vpic->ReferenceFrames[i].TopFieldOrderCnt = ref->display_order; vpic->ReferenceFrames[i].BottomFieldOrderCnt = ref->display_order; } for (; i < FF_ARRAY_ELEMS(vpic->ReferenceFrames); i++) { vpic->ReferenceFrames[i].picture_id = VA_INVALID_ID; vpic->ReferenceFrames[i].flags = VA_PICTURE_H264_INVALID; } vpic->coded_buf = pic->output_buffer; vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR); vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B); pic->nb_slices = 1; return 0; }


static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum) { uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8; uint8_t bitmap; if (bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap)) != sizeof(bitmap)) { return -errno; } return !!(bitmap & (1 << (bitnum % 8))); }


bool st_init(const char *file) { pthread_t thread; pthread_attr_t attr; sigset_t set, oldset; int ret; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); sigfillset(&set); pthread_sigmask(SIG_SETMASK, &set, &oldset); ret = pthread_create(&thread, &attr, writeout_thread, NULL); pthread_sigmask(SIG_SETMASK, &oldset, NULL); if (ret != 0) { return false; } atexit(st_flush_trace_buffer); st_set_trace_file(file); return true; }


static int libquvi_close(AVFormatContext *s) { LibQuviContext *qc = s->priv_data; if (qc->fmtctx) avformat_close_input(&qc->fmtctx); return 0; }


static void aspeed_soc_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc); sc->info = (AspeedSoCInfo *) data; dc->realize = aspeed_soc_realize; }


static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer, struct in_addr my_ip) { AVFormatContext *avc; AVStream avs[MAX_STREAMS]; int i; avc = avformat_alloc_context(); if (avc == NULL) { return -1; } av_metadata_set2(&avc->metadata, "title", stream->title[0] ? stream->title : "No Title", 0); avc->nb_streams = stream->nb_streams; if (stream->is_multicast) { snprintf(avc->filename, 1024, "rtp://%s:%d?multicast=1?ttl=%d", inet_ntoa(stream->multicast_ip), stream->multicast_port, stream->multicast_ttl); } else { snprintf(avc->filename, 1024, "rtp://0.0.0.0"); } for(i = 0; i < stream->nb_streams; i++) { avc->streams[i] = &avs[i]; avc->streams[i]->codec = stream->streams[i]->codec; } *pbuffer = av_mallocz(2048); avf_sdp_create(&avc, 1, *pbuffer, 2048); av_free(avc); return strlen(*pbuffer); }


static int dvdsub_decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { DVDSubContext *ctx = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AVSubtitle *sub = data; int is_menu; if (ctx->buf) { int ret = append_to_cached_buf(avctx, buf, buf_size); if (ret < 0) { *data_size = 0; return ret; } buf = ctx->buf; buf_size = ctx->buf_size; } is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size); if (is_menu == AVERROR(EAGAIN)) { *data_size = 0; return append_to_cached_buf(avctx, buf, buf_size); } if (is_menu < 0) { no_subtitle: reset_rects(sub); *data_size = 0; return buf_size; } if (!is_menu && find_smallest_bounding_rectangle(sub) == 0) goto no_subtitle; if (ctx->forced_subs_only && !(sub->rects[0]->flags & AV_SUBTITLE_FLAG_FORCED)) goto no_subtitle; #if defined(DEBUG) { char ppm_name[32]; snprintf(ppm_name, sizeof(ppm_name), "/tmp/%05d.ppm", ctx->sub_id++); av_dlog(NULL, "start=%d ms end =%d ms\n", sub->start_display_time, sub->end_display_time); ppm_save(ppm_name, sub->rects[0]->pict.data[0], sub->rects[0]->w, sub->rects[0]->h, (uint32_t*) sub->rects[0]->pict.data[1]); } #endif av_freep(&ctx->buf); ctx->buf_size = 0; *data_size = 1; return buf_size; }


static void ibm_40p_init(MachineState *machine) { CPUPPCState *env = NULL; uint16_t cmos_checksum; PowerPCCPU *cpu; DeviceState *dev; SysBusDevice *pcihost; Nvram *m48t59 = NULL; PCIBus *pci_bus; ISABus *isa_bus; void *fw_cfg; int i; uint32_t kernel_base = 0, initrd_base = 0; long kernel_size = 0, initrd_size = 0; char boot_device; /* init CPU */ if (!machine->cpu_model) { machine->cpu_model = "604"; } cpu = POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, machine->cpu_model)); if (!cpu) { error_report("could not initialize CPU '%s'", machine->cpu_model); exit(1); } env = &cpu->env; if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { error_report("only 6xx bus is supported on this machine"); exit(1); } if (env->flags & POWERPC_FLAG_RTC_CLK) { /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */ cpu_ppc_tb_init(env, 7812500UL); } else { /* Set time-base frequency to 100 Mhz */ cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); } qemu_register_reset(ppc_prep_reset, cpu); /* PCI host */ dev = qdev_create(NULL, "raven-pcihost"); if (!bios_name) { bios_name = BIOS_FILENAME; } qdev_prop_set_string(dev, "bios-name", bios_name); qdev_prop_set_uint32(dev, "elf-machine", PPC_ELF_MACHINE); pcihost = SYS_BUS_DEVICE(dev); object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL); qdev_init_nofail(dev); pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci.0")); if (!pci_bus) { error_report("could not create PCI host controller"); exit(1); } /* PCI -> ISA bridge */ dev = DEVICE(pci_create_simple(pci_bus, PCI_DEVFN(11, 0), "i82378")); qdev_connect_gpio_out(dev, 0, cpu->env.irq_inputs[PPC6xx_INPUT_INT]); sysbus_connect_irq(pcihost, 0, qdev_get_gpio_in(dev, 15)); sysbus_connect_irq(pcihost, 1, qdev_get_gpio_in(dev, 13)); sysbus_connect_irq(pcihost, 2, qdev_get_gpio_in(dev, 15)); sysbus_connect_irq(pcihost, 3, qdev_get_gpio_in(dev, 13)); isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0")); /* Memory controller */ dev = DEVICE(isa_create(isa_bus, "rs6000-mc")); qdev_prop_set_uint32(dev, "ram-size", machine->ram_size); qdev_init_nofail(dev); /* initialize CMOS checksums */ cmos_checksum = 0x6aa9; qbus_walk_children(BUS(isa_bus), prep_set_cmos_checksum, NULL, NULL, NULL, &cmos_checksum); /* add some more devices */ if (defaults_enabled()) { isa_create_simple(isa_bus, "i8042"); m48t59 = NVRAM(isa_create_simple(isa_bus, "isa-m48t59")); dev = DEVICE(isa_create(isa_bus, "cs4231a")); qdev_prop_set_uint32(dev, "iobase", 0x830); qdev_prop_set_uint32(dev, "irq", 10); qdev_init_nofail(dev); dev = DEVICE(isa_create(isa_bus, "pc87312")); qdev_prop_set_uint32(dev, "config", 12); qdev_init_nofail(dev); dev = DEVICE(isa_create(isa_bus, "prep-systemio")); qdev_prop_set_uint32(dev, "ibm-planar-id", 0xfc); qdev_prop_set_uint32(dev, "equipment", 0xc0); qdev_init_nofail(dev); pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "lsi53c810"); /* XXX: s3-trio at PCI_DEVFN(2, 0) */ pci_vga_init(pci_bus); for (i = 0; i < nb_nics; i++) { pci_nic_init_nofail(&nd_table[i], pci_bus, "pcnet", i == 0 ? "3" : NULL); } } /* Prepare firmware configuration for OpenBIOS */ fw_cfg = fw_cfg_init_mem(CFG_ADDR, CFG_ADDR + 2); if (machine->kernel_filename) { /* load kernel */ kernel_base = KERNEL_LOAD_ADDR; kernel_size = load_image_targphys(machine->kernel_filename, kernel_base, machine->ram_size - kernel_base); if (kernel_size < 0) { error_report("could not load kernel '%s'", machine->kernel_filename); exit(1); } fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base); fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); /* load initrd */ if (machine->initrd_filename) { initrd_base = INITRD_LOAD_ADDR; initrd_size = load_image_targphys(machine->initrd_filename, initrd_base, machine->ram_size - initrd_base); if (initrd_size < 0) { error_report("could not load initial ram disk '%s'", machine->initrd_filename); exit(1); } fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base); fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); } if (machine->kernel_cmdline && *machine->kernel_cmdline) { fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR); pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, machine->kernel_cmdline); fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, machine->kernel_cmdline); fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(machine->kernel_cmdline) + 1); } boot_device = 'm'; } else { boot_device = machine->boot_order[0]; } fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size); fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_PREP); fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_WIDTH, graphic_width); fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_HEIGHT, graphic_height); fw_cfg_add_i16(fw_cfg, FW_CFG_PPC_DEPTH, graphic_depth); fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_IS_KVM, kvm_enabled()); if (kvm_enabled()) { #ifdef CONFIG_KVM uint8_t *hypercall; fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, kvmppc_get_tbfreq()); hypercall = g_malloc(16); kvmppc_get_hypercall(env, hypercall, 16); fw_cfg_add_bytes(fw_cfg, FW_CFG_PPC_KVM_HC, hypercall, 16); fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_KVM_PID, getpid()); #endif } else { fw_cfg_add_i32(fw_cfg, FW_CFG_PPC_TBFREQ, NANOSECONDS_PER_SECOND); } fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device); qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); /* Prepare firmware configuration for Open Hack'Ware */ if (m48t59) { PPC_NVRAM_set_params(m48t59, NVRAM_SIZE, "PREP", ram_size, boot_device, kernel_base, kernel_size, machine->kernel_cmdline, initrd_base, initrd_size, /* XXX: need an option to load a NVRAM image */ 0, graphic_width, graphic_height, graphic_depth); } }


static void *iommu_init(target_phys_addr_t addr, uint32_t version, qemu_irq irq) { DeviceState *dev; SysBusDevice *s; dev = qdev_create(NULL, "iommu"); qdev_prop_set_uint32(dev, "version", version); qdev_init(dev); s = sysbus_from_qdev(dev); sysbus_connect_irq(s, 0, irq); sysbus_mmio_map(s, 0, addr); return s; }


static void test_qemu_strtoull_full_empty(void) { const char *str = ""; uint64_t res = 999; int err; err = qemu_strtoull(str, NULL, 0, &res); g_assert_cmpint(err, ==, 0); g_assert_cmpint(res, ==, 0); }


static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { int32_t *filterPos = c->hChrFilterPos; int16_t *filter = c->hChrFilter; void *mmx2FilterCode= c->chrMmx2FilterCode; int i; #if defined(PIC) DECLARE_ALIGNED(8, uint64_t, ebxsave); #endif __asm__ volatile( #if defined(PIC) "mov %%"REG_b", %7 \n\t" #endif "pxor %%mm7, %%mm7 \n\t" "mov %0, %%"REG_c" \n\t" "mov %1, %%"REG_D" \n\t" "mov %2, %%"REG_d" \n\t" "mov %3, %%"REG_b" \n\t" "xor %%"REG_a", %%"REG_a" \n\t" // i PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE "xor %%"REG_a", %%"REG_a" \n\t" // i "mov %5, %%"REG_c" \n\t" // src "mov %6, %%"REG_D" \n\t" // buf2 PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE #if defined(PIC) "mov %7, %%"REG_b" \n\t" #endif :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos), "m" (mmx2FilterCode), "m" (src2), "m"(dst2) #if defined(PIC) ,"m" (ebxsave) #endif : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D #if !defined(PIC) ,"%"REG_b #endif ); for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { dst1[i] = src1[srcW-1]*128; dst2[i] = src2[srcW-1]*128; } }


static void get_pointer(Object *obj, Visitor *v, Property *prop, const char *(*print)(void *ptr), const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); void **ptr = qdev_get_prop_ptr(dev, prop); char *p; p = (char *) (*ptr ? print(*ptr) : ""); visit_type_str(v, &p, name, errp); }


static uint64_t jazz_led_read(void *opaque, target_phys_addr_t addr, unsigned int size) { LedState *s = opaque; uint8_t val; val = s->segments; trace_jazz_led_read(addr, val); return val; }


float32 HELPER(ucf64_divs)(float32 a, float32 b, CPUUniCore32State *env) { return float32_div(a, b, &env->ucf64.fp_status); }


static void scsi_generic_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass); sc->realize = scsi_generic_realize; sc->unrealize = scsi_unrealize; sc->alloc_req = scsi_new_request; sc->parse_cdb = scsi_generic_parse_cdb; dc->fw_name = "disk"; dc->desc = "pass through generic scsi device (/dev/sg*)"; dc->reset = scsi_generic_reset; dc->props = scsi_generic_properties; dc->vmsd = &vmstate_scsi_device; }


START_TEST(qlist_destroy_test) { int i; QList *qlist; qlist = qlist_new(); for (i = 0; i < 42; i++) qlist_append(qlist, qint_from_int(i)); QDECREF(qlist); }


static void vnc_client_read(void *opaque) { VncState *vs = opaque; long ret; buffer_reserve(&vs->input, 4096); #ifdef CONFIG_VNC_TLS if (vs->tls_session) { ret = gnutls_read(vs->tls_session, buffer_end(&vs->input), 4096); if (ret < 0) { if (ret == GNUTLS_E_AGAIN) errno = EAGAIN; else errno = EIO; ret = -1; } } else #endif /* CONFIG_VNC_TLS */ ret = recv(vs->csock, buffer_end(&vs->input), 4096, 0); ret = vnc_client_io_error(vs, ret, socket_error()); if (!ret) return; vs->input.offset += ret; while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) { size_t len = vs->read_handler_expect; int ret; ret = vs->read_handler(vs, vs->input.buffer, len); if (vs->csock == -1) return; if (!ret) { memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len)); vs->input.offset -= len; } else { vs->read_handler_expect = ret; } } }


POWERPC_FAMILY(e5500)(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc); dc->desc = "e5500 core"; pcc->init_proc = init_proc_e5500; pcc->check_pow = check_pow_none; pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_WRTEE | PPC_RFDI | PPC_RFMCI | PPC_CACHE | PPC_CACHE_LOCK | PPC_CACHE_ICBI | PPC_CACHE_DCBZ | PPC_CACHE_DCBA | PPC_FLOAT | PPC_FLOAT_FRES | PPC_FLOAT_FRSQRTE | PPC_FLOAT_FSEL | PPC_FLOAT_STFIWX | PPC_WAIT | PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC | PPC_64B | PPC_POPCNTB | PPC_POPCNTWD; pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206; pcc->msr_mask = (1ull << MSR_CM) | (1ull << MSR_GS) | (1ull << MSR_UCLE) | (1ull << MSR_CE) | (1ull << MSR_EE) | (1ull << MSR_PR) | (1ull << MSR_FP) | (1ull << MSR_ME) | (1ull << MSR_FE0) | (1ull << MSR_DE) | (1ull << MSR_FE1) | (1ull << MSR_IR) | (1ull << MSR_DR) | (1ull << MSR_PX) | (1ull << MSR_RI); pcc->mmu_model = POWERPC_MMU_BOOKE206; pcc->excp_model = POWERPC_EXCP_BOOKE; pcc->bus_model = PPC_FLAGS_INPUT_BookE; /* FIXME: figure out the correct flag for e5500 */ pcc->bfd_mach = bfd_mach_ppc_e500; pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE | POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK; }


void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len) { const uint8_t *end; int j; j = ctx->len & 63; ctx->len += len; if (j) { int cnt = FFMIN(len, 64 - j); memcpy(ctx->block + j, src, cnt); src += cnt; len -= cnt; if (j + cnt < 64) return; body(ctx->ABCD, (uint32_t *)ctx->block); } end = src + (len & ~63); if (HAVE_BIGENDIAN || (!HAVE_FAST_UNALIGNED && ((intptr_t)src & 3))) { while (src < end) { memcpy(ctx->block, src, 64); body(ctx->ABCD, (uint32_t *) ctx->block); src += 64; } } else { while (src < end) { body(ctx->ABCD, (uint32_t *)src); src += 64; } } len &= 63; if (len > 0) memcpy(ctx->block, src, len); }


int main() { int rt, rs; int achi, acli; int dsp; int acho, aclo; int resulth, resultl; int resdsp; achi = 0x05; acli = 0xB4CB; rs = 0xFF06; rt = 0xCB00; resulth = 0x04; resultl = 0x947438CB; __asm ("mthi %2, $ac1\n\t" "mtlo %3, $ac1\n\t" "maq_s.w.phr $ac1, %4, %5\n\t" "mfhi %0, $ac1\n\t" "mflo %1, $ac1\n\t" : "=r"(acho), "=r"(aclo) : "r"(achi), "r"(acli), "r"(rs), "r"(rt) ); assert(resulth == acho); assert(resultl == aclo); achi = 0x06; acli = 0xB4CB; rs = 0x8000; rt = 0x8000; resulth = 0x6; resultl = 0x8000b4ca; resdsp = 1; __asm ("mthi %3, $ac1\n\t" "mtlo %4, $ac1\n\t" "maq_s.w.phr $ac1, %5, %6\n\t" "mfhi %0, $ac1\n\t" "mflo %1, $ac1\n\t" "rddsp %2\n\t" : "=r"(acho), "=r"(aclo), "=r"(dsp) : "r"(achi), "r"(acli), "r"(rs), "r"(rt) ); assert(resulth == acho); assert(resultl == aclo); assert(((dsp >> 17) & 0x01) == resdsp); return 0; }


int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, const char *version, const char *serial) { int cylinders, heads, secs; uint64_t nb_sectors; s->bs = bs; s->drive_kind = kind; bdrv_get_geometry(bs, &nb_sectors); bdrv_guess_geometry(bs, &cylinders, &heads, &secs); if (cylinders < 1 || cylinders > 16383) { error_report("cyls must be between 1 and 16383"); return -1; } if (heads < 1 || heads > 16) { error_report("heads must be between 1 and 16"); return -1; } if (secs < 1 || secs > 63) { error_report("secs must be between 1 and 63"); return -1; } s->cylinders = cylinders; s->heads = heads; s->sectors = secs; s->nb_sectors = nb_sectors; /* The SMART values should be preserved across power cycles but they aren't. */ s->smart_enabled = 1; s->smart_autosave = 1; s->smart_errors = 0; s->smart_selftest_count = 0; if (kind == IDE_CD) { bdrv_set_dev_ops(bs, &ide_cd_block_ops, s); bdrv_set_buffer_alignment(bs, 2048); } else { if (!bdrv_is_inserted(s->bs)) { error_report("Device needs media, but drive is empty"); return -1; } if (bdrv_is_read_only(bs)) { error_report("Can't use a read-only drive"); return -1; } } if (serial) { strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str)); } else { snprintf(s->drive_serial_str, sizeof(s->drive_serial_str), "QM%05d", s->drive_serial); } if (version) { pstrcpy(s->version, sizeof(s->version), version); } else { pstrcpy(s->version, sizeof(s->version), QEMU_VERSION); } ide_reset(s); bdrv_iostatus_enable(bs); return 0; }


int subch_device_load(SubchDev *s, QEMUFile *f) { SubchDev *old_s; Error *err = NULL; uint16_t old_schid = s->schid; uint16_t old_devno = s->devno; int i; s->cssid = qemu_get_byte(f); s->ssid = qemu_get_byte(f); s->schid = qemu_get_be16(f); s->devno = qemu_get_be16(f); if (s->devno != old_devno) { /* Only possible if machine < 2.7 (no css_dev_path) */ error_setg(&err, "%x != %x", old_devno, s->devno); error_append_hint(&err, "Devno mismatch, tried to load wrong section!" " Likely reason: some sequences of plug and unplug" " can break migration for machine versions prior to" " 2.7 (known design flaw).\n"); error_report_err(err); return -EINVAL; } /* Re-assign subch. */ if (old_schid != s->schid) { old_s = channel_subsys.css[s->cssid]->sch_set[s->ssid]->sch[old_schid]; /* * (old_s != s) means that some other device has its correct * subchannel already assigned (in load). */ if (old_s == s) { css_subch_assign(s->cssid, s->ssid, old_schid, s->devno, NULL); } /* It's OK to re-assign without a prior de-assign. */ css_subch_assign(s->cssid, s->ssid, s->schid, s->devno, s); } s->thinint_active = qemu_get_byte(f); /* SCHIB */ /* PMCW */ s->curr_status.pmcw.intparm = qemu_get_be32(f); s->curr_status.pmcw.flags = qemu_get_be16(f); s->curr_status.pmcw.devno = qemu_get_be16(f); s->curr_status.pmcw.lpm = qemu_get_byte(f); s->curr_status.pmcw.pnom = qemu_get_byte(f); s->curr_status.pmcw.lpum = qemu_get_byte(f); s->curr_status.pmcw.pim = qemu_get_byte(f); s->curr_status.pmcw.mbi = qemu_get_be16(f); s->curr_status.pmcw.pom = qemu_get_byte(f); s->curr_status.pmcw.pam = qemu_get_byte(f); qemu_get_buffer(f, s->curr_status.pmcw.chpid, 8); s->curr_status.pmcw.chars = qemu_get_be32(f); /* SCSW */ s->curr_status.scsw.flags = qemu_get_be16(f); s->curr_status.scsw.ctrl = qemu_get_be16(f); s->curr_status.scsw.cpa = qemu_get_be32(f); s->curr_status.scsw.dstat = qemu_get_byte(f); s->curr_status.scsw.cstat = qemu_get_byte(f); s->curr_status.scsw.count = qemu_get_be16(f); s->curr_status.mba = qemu_get_be64(f); qemu_get_buffer(f, s->curr_status.mda, 4); /* end SCHIB */ qemu_get_buffer(f, s->sense_data, 32); s->channel_prog = qemu_get_be64(f); /* last cmd */ s->last_cmd.cmd_code = qemu_get_byte(f); s->last_cmd.flags = qemu_get_byte(f); s->last_cmd.count = qemu_get_be16(f); s->last_cmd.cda = qemu_get_be32(f); s->last_cmd_valid = qemu_get_byte(f); s->id.reserved = qemu_get_byte(f); s->id.cu_type = qemu_get_be16(f); s->id.cu_model = qemu_get_byte(f); s->id.dev_type = qemu_get_be16(f); s->id.dev_model = qemu_get_byte(f); s->id.unused = qemu_get_byte(f); for (i = 0; i < ARRAY_SIZE(s->id.ciw); i++) { s->id.ciw[i].type = qemu_get_byte(f); s->id.ciw[i].command = qemu_get_byte(f); s->id.ciw[i].count = qemu_get_be16(f); } s->ccw_fmt_1 = qemu_get_byte(f); s->ccw_no_data_cnt = qemu_get_byte(f); /* * Hack alert. We don't migrate the channel subsystem status (no * device!), but we need to find out if the guest enabled mss/mcss-e. * If the subchannel is enabled, it certainly was able to access it, * so adjust the max_ssid/max_cssid values for relevant ssid/cssid * values. This is not watertight, but better than nothing. */ if (s->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA) { if (s->ssid) { channel_subsys.max_ssid = MAX_SSID; } if (s->cssid != channel_subsys.default_cssid) { channel_subsys.max_cssid = MAX_CSSID; } } return 0; }


void bdrv_init(void) { module_call_init(MODULE_INIT_BLOCK); }


void hmp_change(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); const char *target = qdict_get_str(qdict, "target"); const char *arg = qdict_get_try_str(qdict, "arg"); Error *err = NULL; if (strcmp(device, "vnc") == 0 && (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0)) { if (!arg) { monitor_read_password(mon, hmp_change_read_arg, NULL); return; } } qmp_change(device, target, !!arg, arg, &err); if (error_is_type(err, QERR_DEVICE_ENCRYPTED)) { monitor_printf(mon, "%s (%s) is encrypted.\n", error_get_field(err, "device"), error_get_field(err, "filename")); if (!monitor_get_rs(mon)) { monitor_printf(mon, "terminal does not support password prompting\n"); error_free(err); return; } readline_start(monitor_get_rs(mon), "Password: ", 1, cb_hmp_change_bdrv_pwd, err); return; } hmp_handle_error(mon, &err); }


static void gen_loop(DisasContext *ctx, int r1, int32_t offset) { int l1; l1 = gen_new_label(); tcg_gen_subi_tl(cpu_gpr_a[r1], cpu_gpr_a[r1], 1); tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr_a[r1], -1, l1); gen_goto_tb(ctx, 1, ctx->pc + offset); gen_set_label(l1); gen_goto_tb(ctx, 0, ctx->next_pc); }


static void tight_send_compact_size(VncState *vs, size_t len) { int lpc = 0; int bytes = 0; char buf[3] = {0, 0, 0}; buf[bytes++] = len & 0x7F; if (len > 0x7F) { buf[bytes-1] |= 0x80; buf[bytes++] = (len >> 7) & 0x7F; if (len > 0x3FFF) { buf[bytes-1] |= 0x80; buf[bytes++] = (len >> 14) & 0xFF; } } for (lpc = 0; lpc < bytes; lpc++) { vnc_write_u8(vs, buf[lpc]); } }


static inline void gen_evmwsmi(DisasContext *ctx) { TCGv_i64 t0, t1; if (unlikely(!ctx->spe_enabled)) { gen_exception(ctx, POWERPC_EXCP_APU); return; } t0 = tcg_temp_new_i64(); t1 = tcg_temp_new_i64(); /* t0 := rA; t1 := rB */ #if defined(TARGET_PPC64) tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); #else tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); #endif tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ tcg_temp_free_i64(t0); tcg_temp_free_i64(t1); }


static uint64_t subpage_ram_read(void *opaque, target_phys_addr_t addr, unsigned size) { ram_addr_t raddr = addr; void *ptr = qemu_get_ram_ptr(raddr); switch (size) { case 1: return ldub_p(ptr); case 2: return lduw_p(ptr); case 4: return ldl_p(ptr); default: abort(); } }


static int xan_decode_init(AVCodecContext *avctx) { XanContext *s = avctx->priv_data; int i; s->avctx = avctx; if ((avctx->codec->id == CODEC_ID_XAN_WC3) && (s->avctx->palctrl == NULL)) { av_log(avctx, AV_LOG_ERROR, " WC3 Xan video: palette expected.\n"); return -1; } avctx->pix_fmt = PIX_FMT_PAL8; avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); /* initialize the RGB -> YUV tables */ for (i = 0; i < 256; i++) { y_r_table[i] = Y_R * i; y_g_table[i] = Y_G * i; y_b_table[i] = Y_B * i; u_r_table[i] = U_R * i; u_g_table[i] = U_G * i; u_b_table[i] = U_B * i; v_r_table[i] = V_R * i; v_g_table[i] = V_G * i; v_b_table[i] = V_B * i; } if(avcodec_check_dimensions(avctx, avctx->width, avctx->height)) return -1; s->buffer1 = av_malloc(avctx->width * avctx->height); s->buffer2 = av_malloc(avctx->width * avctx->height); if (!s->buffer1 || !s->buffer2) return -1; return 0; }


void gen_intermediate_code_internal(XtensaCPU *cpu, TranslationBlock *tb, bool search_pc) { CPUState *cs = CPU(cpu); CPUXtensaState *env = &cpu->env; DisasContext dc; int insn_count = 0; int j, lj = -1; int max_insns = tb->cflags & CF_COUNT_MASK; uint32_t pc_start = tb->pc; uint32_t next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; if (max_insns == 0) { max_insns = CF_COUNT_MASK; } dc.config = env->config; dc.singlestep_enabled = cs->singlestep_enabled; dc.tb = tb; dc.pc = pc_start; dc.ring = tb->flags & XTENSA_TBFLAG_RING_MASK; dc.cring = (tb->flags & XTENSA_TBFLAG_EXCM) ? 0 : dc.ring; dc.lbeg = env->sregs[LBEG]; dc.lend = env->sregs[LEND]; dc.is_jmp = DISAS_NEXT; dc.ccount_delta = 0; dc.debug = tb->flags & XTENSA_TBFLAG_DEBUG; dc.icount = tb->flags & XTENSA_TBFLAG_ICOUNT; dc.cpenable = (tb->flags & XTENSA_TBFLAG_CPENABLE_MASK) >> XTENSA_TBFLAG_CPENABLE_SHIFT; dc.window = ((tb->flags & XTENSA_TBFLAG_WINDOW_MASK) >> XTENSA_TBFLAG_WINDOW_SHIFT); init_litbase(&dc); init_sar_tracker(&dc); if (dc.icount) { dc.next_icount = tcg_temp_local_new_i32(); } gen_tb_start(tb); if (tb->flags & XTENSA_TBFLAG_EXCEPTION) { tcg_gen_movi_i32(cpu_pc, dc.pc); gen_exception(&dc, EXCP_DEBUG); } do { check_breakpoint(env, &dc); if (search_pc) { j = tcg_op_buf_count(); if (lj < j) { lj++; while (lj < j) { tcg_ctx.gen_opc_instr_start[lj++] = 0; } } tcg_ctx.gen_opc_pc[lj] = dc.pc; tcg_ctx.gen_opc_instr_start[lj] = 1; tcg_ctx.gen_opc_icount[lj] = insn_count; } if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { tcg_gen_debug_insn_start(dc.pc); } ++dc.ccount_delta; if (insn_count + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { gen_io_start(); } if (dc.icount) { int label = gen_new_label(); tcg_gen_addi_i32(dc.next_icount, cpu_SR[ICOUNT], 1); tcg_gen_brcondi_i32(TCG_COND_NE, dc.next_icount, 0, label); tcg_gen_mov_i32(dc.next_icount, cpu_SR[ICOUNT]); if (dc.debug) { gen_debug_exception(&dc, DEBUGCAUSE_IC); } gen_set_label(label); } if (dc.debug) { gen_ibreak_check(env, &dc); } disas_xtensa_insn(env, &dc); ++insn_count; if (dc.icount) { tcg_gen_mov_i32(cpu_SR[ICOUNT], dc.next_icount); } if (cs->singlestep_enabled) { tcg_gen_movi_i32(cpu_pc, dc.pc); gen_exception(&dc, EXCP_DEBUG); break; } } while (dc.is_jmp == DISAS_NEXT && insn_count < max_insns && dc.pc < next_page_start && dc.pc + xtensa_insn_len(env, &dc) <= next_page_start && !tcg_op_buf_full()); reset_litbase(&dc); reset_sar_tracker(&dc); if (dc.icount) { tcg_temp_free(dc.next_icount); } if (tb->cflags & CF_LAST_IO) { gen_io_end(); } if (dc.is_jmp == DISAS_NEXT) { gen_jumpi(&dc, dc.pc, 0); } gen_tb_end(tb, insn_count); #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); log_target_disas(env, pc_start, dc.pc - pc_start, 0); qemu_log("\n"); } #endif if (search_pc) { j = tcg_op_buf_count(); memset(tcg_ctx.gen_opc_instr_start + lj + 1, 0, (j - lj) * sizeof(tcg_ctx.gen_opc_instr_start[0])); } else { tb->size = dc.pc - pc_start; tb->icount = insn_count; } }


static void restore_median_il(uint8_t *src, int step, int stride, int width, int height, int slices, int rmode) { int i, j, slice; int A, B, C; uint8_t *bsrc; int slice_start, slice_height; const int cmask = ~(rmode ? 3 : 1); const int stride2 = stride << 1; for (slice = 0; slice < slices; slice++) { slice_start = ((slice * height) / slices) & cmask; slice_height = ((((slice + 1) * height) / slices) & cmask) - slice_start; slice_height >>= 1; bsrc = src + slice_start * stride; // first line - left neighbour prediction bsrc[0] += 0x80; A = bsrc[0]; for (i = step; i < width * step; i += step) { bsrc[i] += A; A = bsrc[i]; } for (i = 0; i < width * step; i += step) { bsrc[stride + i] += A; A = bsrc[stride + i]; } bsrc += stride2; if (slice_height == 1) // second line - first element has top prediction, the rest uses median C = bsrc[-stride2]; bsrc[0] += C; A = bsrc[0]; for (i = step; i < width * step; i += step) { B = bsrc[i - stride2]; bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); C = B; A = bsrc[i]; } for (i = 0; i < width * step; i += step) { B = bsrc[i - stride]; bsrc[stride + i] += mid_pred(A, B, (uint8_t)(A + B - C)); C = B; A = bsrc[stride + i]; } bsrc += stride2; // the rest of lines use continuous median prediction for (j = 2; j < slice_height; j++) { for (i = 0; i < width * step; i += step) { B = bsrc[i - stride2]; bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); C = B; A = bsrc[i]; } for (i = 0; i < width * step; i += step) { B = bsrc[i - stride]; bsrc[i + stride] += mid_pred(A, B, (uint8_t)(A + B - C)); C = B; A = bsrc[i + stride]; } bsrc += stride2; } } }


static target_ulong h_put_tce_indirect(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { int i; target_ulong liobn = args[0]; target_ulong ioba = args[1]; target_ulong ioba1 = ioba; target_ulong tce_list = args[2]; target_ulong npages = args[3]; target_ulong ret = H_PARAMETER, tce = 0; sPAPRTCETable *tcet = spapr_tce_find_by_liobn(liobn); CPUState *cs = CPU(cpu); hwaddr page_mask, page_size; if (!tcet) { return H_PARAMETER; } if ((npages > 512) || (tce_list & SPAPR_TCE_PAGE_MASK)) { return H_PARAMETER; } page_mask = IOMMU_PAGE_MASK(tcet->page_shift); page_size = IOMMU_PAGE_SIZE(tcet->page_shift); ioba &= page_mask; for (i = 0; i < npages; ++i, ioba += page_size) { target_ulong off = (tce_list & ~SPAPR_TCE_RW) + i * sizeof(target_ulong); tce = ldq_be_phys(cs->as, off); ret = put_tce_emu(tcet, ioba, tce); if (ret) { break; } } /* Trace last successful or the first problematic entry */ i = i ? (i - 1) : 0; if (SPAPR_IS_PCI_LIOBN(liobn)) { trace_spapr_iommu_pci_indirect(liobn, ioba1, tce_list, i, tce, ret); } else { trace_spapr_iommu_indirect(liobn, ioba1, tce_list, i, tce, ret); } return ret; }


ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[]) { int c; unsigned long long v; Error *errp = NULL; while ((c = getopt(argc, argv, "h" /* help */ "v" /* verbose */ "F" /* foreground */ "p:" /* pid_file */ "S:" /* unix_socket_path */ "m:" /* shm_path */ "l:" /* shm_size */ "n:" /* n_vectors */ )) != -1) { switch (c) { case 'h': /* help */ ivshmem_server_usage(argv[0], 0); break; case 'v': /* verbose */ args->verbose = 1; break; case 'F': /* foreground */ args->foreground = 1; break; case 'p': /* pid_file */ args->pid_file = strdup(optarg); break; case 'S': /* unix_socket_path */ args->unix_socket_path = strdup(optarg); break; case 'm': /* shm_path */ args->shm_path = strdup(optarg); break; case 'l': /* shm_size */ parse_option_size("shm_size", optarg, &args->shm_size, &errp); if (errp) { fprintf(stderr, "cannot parse shm size: %s\n", error_get_pretty(errp)); error_free(errp); ivshmem_server_usage(argv[0], 1); } break; case 'n': /* n_vectors */ if (parse_uint_full(optarg, &v, 0) < 0) { fprintf(stderr, "cannot parse n_vectors\n"); ivshmem_server_usage(argv[0], 1); } args->n_vectors = v; break; default: ivshmem_server_usage(argv[0], 1); break; } } if (args->n_vectors > IVSHMEM_SERVER_MAX_VECTORS) { fprintf(stderr, "too many requested vectors (max is %d)\n", IVSHMEM_SERVER_MAX_VECTORS); ivshmem_server_usage(argv[0], 1); } if (args->verbose == 1 && args->foreground == 0) { fprintf(stderr, "cannot use verbose in daemon mode\n"); ivshmem_server_usage(argv[0], 1); } }


static int nbd_negotiate_options(NBDClient *client, uint16_t myflags, Error **errp) { uint32_t flags; bool fixedNewstyle = false; bool no_zeroes = false; /* Client sends: [ 0 .. 3] client flags Then we loop until NBD_OPT_EXPORT_NAME or NBD_OPT_GO: [ 0 .. 7] NBD_OPTS_MAGIC [ 8 .. 11] NBD option [12 .. 15] Data length ... Rest of request [ 0 .. 7] NBD_OPTS_MAGIC [ 8 .. 11] Second NBD option [12 .. 15] Data length ... Rest of request */ if (nbd_read(client->ioc, &flags, sizeof(flags), errp) < 0) { error_prepend(errp, "read failed: "); return -EIO; } be32_to_cpus(&flags); trace_nbd_negotiate_options_flags(flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { fixedNewstyle = true; flags &= ~NBD_FLAG_C_FIXED_NEWSTYLE; } if (flags & NBD_FLAG_C_NO_ZEROES) { no_zeroes = true; flags &= ~NBD_FLAG_C_NO_ZEROES; } if (flags != 0) { error_setg(errp, "Unknown client flags 0x%" PRIx32 " received", flags); return -EINVAL; } while (1) { int ret; uint32_t option, length; uint64_t magic; if (nbd_read(client->ioc, &magic, sizeof(magic), errp) < 0) { error_prepend(errp, "read failed: "); return -EINVAL; } magic = be64_to_cpu(magic); trace_nbd_negotiate_options_check_magic(magic); if (magic != NBD_OPTS_MAGIC) { error_setg(errp, "Bad magic received"); return -EINVAL; } if (nbd_read(client->ioc, &option, sizeof(option), errp) < 0) { error_prepend(errp, "read failed: "); return -EINVAL; } option = be32_to_cpu(option); client->opt = option; if (nbd_read(client->ioc, &length, sizeof(length), errp) < 0) { error_prepend(errp, "read failed: "); return -EINVAL; } length = be32_to_cpu(length); client->optlen = length; if (length > NBD_MAX_BUFFER_SIZE) { error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u)", length, NBD_MAX_BUFFER_SIZE); return -EINVAL; } trace_nbd_negotiate_options_check_option(option, nbd_opt_lookup(option)); if (client->tlscreds && client->ioc == (QIOChannel *)client->sioc) { QIOChannel *tioc; if (!fixedNewstyle) { error_setg(errp, "Unsupported option 0x%" PRIx32, option); return -EINVAL; } switch (option) { case NBD_OPT_STARTTLS: if (length) { /* Unconditionally drop the connection if the client * can't start a TLS negotiation correctly */ return nbd_reject_length(client, true, errp); } tioc = nbd_negotiate_handle_starttls(client, errp); if (!tioc) { return -EIO; } ret = 0; object_unref(OBJECT(client->ioc)); client->ioc = QIO_CHANNEL(tioc); break; case NBD_OPT_EXPORT_NAME: /* No way to return an error to client, so drop connection */ error_setg(errp, "Option 0x%x not permitted before TLS", option); return -EINVAL; default: if (nbd_drop(client->ioc, length, errp) < 0) { return -EIO; } ret = nbd_negotiate_send_rep_err(client, NBD_REP_ERR_TLS_REQD, errp, "Option 0x%" PRIx32 "not permitted before TLS", option); /* Let the client keep trying, unless they asked to * quit. In this mode, we've already sent an error, so * we can't ack the abort. */ if (option == NBD_OPT_ABORT) { return 1; } break; } } else if (fixedNewstyle) { switch (option) { case NBD_OPT_LIST: if (length) { ret = nbd_reject_length(client, false, errp); } else { ret = nbd_negotiate_handle_list(client, errp); } break; case NBD_OPT_ABORT: /* NBD spec says we must try to reply before * disconnecting, but that we must also tolerate * guests that don't wait for our reply. */ nbd_negotiate_send_rep(client, NBD_REP_ACK, NULL); return 1; case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, myflags, no_zeroes, errp); case NBD_OPT_INFO: case NBD_OPT_GO: ret = nbd_negotiate_handle_info(client, myflags, errp); if (ret == 1) { assert(option == NBD_OPT_GO); return 0; } break; case NBD_OPT_STARTTLS: if (length) { ret = nbd_reject_length(client, false, errp); } else if (client->tlscreds) { ret = nbd_negotiate_send_rep_err(client, NBD_REP_ERR_INVALID, errp, "TLS already enabled"); } else { ret = nbd_negotiate_send_rep_err(client, NBD_REP_ERR_POLICY, errp, "TLS not configured"); } break; case NBD_OPT_STRUCTURED_REPLY: if (length) { ret = nbd_reject_length(client, false, errp); } else if (client->structured_reply) { ret = nbd_negotiate_send_rep_err( client, NBD_REP_ERR_INVALID, errp, "structured reply already negotiated"); } else { ret = nbd_negotiate_send_rep(client, NBD_REP_ACK, errp); client->structured_reply = true; myflags |= NBD_FLAG_SEND_DF; } break; default: if (nbd_drop(client->ioc, length, errp) < 0) { return -EIO; } ret = nbd_negotiate_send_rep_err(client, NBD_REP_ERR_UNSUP, errp, "Unsupported option 0x%" PRIx32 " (%s)", option, nbd_opt_lookup(option)); break; } } else { /* * If broken new-style we should drop the connection * for anything except NBD_OPT_EXPORT_NAME */ switch (option) { case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, myflags, no_zeroes, errp); default: error_setg(errp, "Unsupported option 0x%" PRIx32 " (%s)", option, nbd_opt_lookup(option)); return -EINVAL; } } if (ret < 0) { return ret; } } }


static int svq1_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MpegEncContext *s = avctx->priv_data; uint8_t *current, *previous; int result, i, x, y, width, height; AVFrame *pict = data; svq1_pmv *pmv; /* initialize bit buffer */ init_get_bits(&s->gb, buf, buf_size * 8); /* decode frame header */ s->f_code = get_bits(&s->gb, 22); if ((s->f_code & ~0x70) || !(s->f_code & 0x60)) return AVERROR_INVALIDDATA; /* swap some header bytes (why?) */ if (s->f_code != 0x20) { uint32_t *src = (uint32_t *)(buf + 4); if (buf_size < 36) return AVERROR_INVALIDDATA; for (i = 0; i < 4; i++) src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; } result = svq1_decode_frame_header(&s->gb, s); if (result != 0) { av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n", result); return result; } avcodec_set_dimensions(avctx, s->width, s->height); /* FIXME: This avoids some confusion for "B frames" without 2 references. * This should be removed after libavcodec can handle more flexible * picture types & ordering */ if (s->pict_type == AV_PICTURE_TYPE_B && s->last_picture_ptr == NULL) return buf_size; if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) || avctx->skip_frame >= AVDISCARD_ALL) return buf_size; if ((result = ff_MPV_frame_start(s, avctx)) < 0) return result; pmv = av_malloc((FFALIGN(s->width, 16) / 8 + 3) * sizeof(*pmv)); if (!pmv) return AVERROR(ENOMEM); /* decode y, u and v components */ for (i = 0; i < 3; i++) { int linesize; if (i == 0) { width = FFALIGN(s->width, 16); height = FFALIGN(s->height, 16); linesize = s->linesize; } else { if (s->flags & CODEC_FLAG_GRAY) break; width = FFALIGN(s->width / 4, 16); height = FFALIGN(s->height / 4, 16); linesize = s->uvlinesize; } current = s->current_picture.f.data[i]; if (s->pict_type == AV_PICTURE_TYPE_B) previous = s->next_picture.f.data[i]; else previous = s->last_picture.f.data[i]; if (s->pict_type == AV_PICTURE_TYPE_I) { /* keyframe */ for (y = 0; y < height; y += 16) { for (x = 0; x < width; x += 16) { result = svq1_decode_block_intra(&s->gb, &current[x], linesize); if (result != 0) { av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n", result); goto err; } } current += 16 * linesize; } } else { /* delta frame */ memset(pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv)); for (y = 0; y < height; y += 16) { for (x = 0; x < width; x += 16) { result = svq1_decode_delta_block(s, &s->gb, &current[x], previous, linesize, pmv, x, y); if (result != 0) { av_dlog(s->avctx, "Error in svq1_decode_delta_block %i\n", result); goto err; } } pmv[0].x = pmv[0].y = 0; current += 16 * linesize; } } } *pict = s->current_picture.f; ff_MPV_frame_end(s); *data_size = sizeof(AVFrame); result = buf_size; err: av_free(pmv); return result; }


static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) { BDRVSheepdogState *s = bs->opaque; BDRVSheepdogState *old_s; char tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid = 0; int ret = 0; old_s = g_malloc(sizeof(BDRVSheepdogState)); memcpy(old_s, s, sizeof(BDRVSheepdogState)); snapid = strtoul(snapshot_id, NULL, 10); if (snapid) { tag[0] = 0; } else { pstrcpy(tag, sizeof(tag), snapshot_id); } ret = reload_inode(s, snapid, tag); if (ret) { goto out; } ret = sd_create_branch(s); if (ret) { goto out; } g_free(old_s); return 0; out: /* recover bdrv_sd_state */ memcpy(s, old_s, sizeof(BDRVSheepdogState)); g_free(old_s); error_report("failed to open. recover old bdrv_sd_state."); return ret; }


static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) { RMContext *rm = s->priv_data; AVStream *st; ByteIOContext *pb = &s->pb; unsigned int tag, v; int tag_size, size, codec_data_size, i; int64_t codec_pos; unsigned int h263_hack_version, start_time, duration; char buf[128]; int flags = 0; tag = get_le32(pb); if (tag == MKTAG('.', 'r', 'a', 0xfd)) { /* very old .ra format */ return rm_read_header_old(s, ap); } else if (tag != MKTAG('.', 'R', 'M', 'F')) { return AVERROR_IO; get_be32(pb); /* header size */ get_be16(pb); get_be32(pb); get_be32(pb); /* number of headers */ for(;;) { if (url_feof(pb)) goto fail; tag = get_le32(pb); tag_size = get_be32(pb); get_be16(pb); #if 0 printf("tag=%c%c%c%c (%08x) size=%d\n", (tag) & 0xff, (tag >> 8) & 0xff, (tag >> 16) & 0xff, (tag >> 24) & 0xff, tag, tag_size); #endif if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) goto fail; switch(tag) { case MKTAG('P', 'R', 'O', 'P'): /* file header */ get_be32(pb); /* max bit rate */ get_be32(pb); /* avg bit rate */ get_be32(pb); /* max packet size */ get_be32(pb); /* avg packet size */ get_be32(pb); /* nb packets */ get_be32(pb); /* duration */ get_be32(pb); /* preroll */ get_be32(pb); /* index offset */ get_be32(pb); /* data offset */ get_be16(pb); /* nb streams */ flags = get_be16(pb); /* flags */ break; case MKTAG('C', 'O', 'N', 'T'): get_str(pb, s->title, sizeof(s->title)); get_str(pb, s->author, sizeof(s->author)); get_str(pb, s->copyright, sizeof(s->copyright)); get_str(pb, s->comment, sizeof(s->comment)); break; case MKTAG('M', 'D', 'P', 'R'): st = av_new_stream(s, 0); if (!st) goto fail; st->id = get_be16(pb); get_be32(pb); /* max bit rate */ st->codec->bit_rate = get_be32(pb); /* bit rate */ get_be32(pb); /* max packet size */ get_be32(pb); /* avg packet size */ start_time = get_be32(pb); /* start time */ get_be32(pb); /* preroll */ duration = get_be32(pb); /* duration */ st->start_time = start_time; st->duration = duration; get_str8(pb, buf, sizeof(buf)); /* desc */ get_str8(pb, buf, sizeof(buf)); /* mimetype */ codec_data_size = get_be32(pb); codec_pos = url_ftell(pb); st->codec->codec_type = CODEC_TYPE_DATA; av_set_pts_info(st, 64, 1, 1000); v = get_be32(pb); if (v == MKTAG(0xfd, 'a', 'r', '.')) { /* ra type header */ rm_read_audio_stream_info(s, st, 0); } else { int fps, fps2; if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { fail1: av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n"); goto skip; st->codec->codec_tag = get_le32(pb); // av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0')); if ( st->codec->codec_tag != MKTAG('R', 'V', '1', '0') && st->codec->codec_tag != MKTAG('R', 'V', '2', '0') && st->codec->codec_tag != MKTAG('R', 'V', '3', '0') && st->codec->codec_tag != MKTAG('R', 'V', '4', '0')) goto fail1; st->codec->width = get_be16(pb); st->codec->height = get_be16(pb); st->codec->time_base.num= 1; fps= get_be16(pb); st->codec->codec_type = CODEC_TYPE_VIDEO; get_be32(pb); fps2= get_be16(pb); get_be16(pb); st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos); st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); get_buffer(pb, st->codec->extradata, st->codec->extradata_size); // av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2); st->codec->time_base.den = fps * st->codec->time_base.num; /* modification of h263 codec version (!) */ #ifdef WORDS_BIGENDIAN h263_hack_version = ((uint32_t*)st->codec->extradata)[1]; #else h263_hack_version = bswap_32(((uint32_t*)st->codec->extradata)[1]); #endif st->codec->sub_id = h263_hack_version; switch((h263_hack_version>>28)){ case 1: st->codec->codec_id = CODEC_ID_RV10; break; case 2: st->codec->codec_id = CODEC_ID_RV20; break; case 3: st->codec->codec_id = CODEC_ID_RV30; break; case 4: st->codec->codec_id = CODEC_ID_RV40; break; default: goto fail1; skip: /* skip codec info */ size = url_ftell(pb) - codec_pos; url_fskip(pb, codec_data_size - size); break; case MKTAG('D', 'A', 'T', 'A'): goto header_end; default: /* unknown tag: skip it */ url_fskip(pb, tag_size - 10); break; header_end: rm->nb_packets = get_be32(pb); /* number of packets */ if (!rm->nb_packets && (flags & 4)) rm->nb_packets = 3600 * 25; get_be32(pb); /* next data header */ return 0; fail: for(i=0;i<s->nb_streams;i++) { av_free(s->streams[i]); return AVERROR_IO;


static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { BDRVParallelsState *s = bs->opaque; uint32_t idx, to_allocate, i; int64_t pos, space; pos = block_status(s, sector_num, nb_sectors, pnum); if (pos > 0) { return pos; } idx = sector_num / s->tracks; if (idx >= s->bat_size) { return -EINVAL; } to_allocate = DIV_ROUND_UP(sector_num + *pnum, s->tracks) - idx; space = to_allocate * s->tracks; if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) { int ret; space += s->prealloc_size; if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) { ret = bdrv_pwrite_zeroes(bs->file, s->data_end << BDRV_SECTOR_BITS, space << BDRV_SECTOR_BITS, 0); } else { ret = bdrv_truncate(bs->file, (s->data_end + space) << BDRV_SECTOR_BITS); } if (ret < 0) { return ret; } } for (i = 0; i < to_allocate; i++) { s->bat_bitmap[idx + i] = cpu_to_le32(s->data_end / s->off_multiplier); s->data_end += s->tracks; bitmap_set(s->bat_dirty_bmap, bat_entry_off(idx + i) / s->bat_dirty_block, 1); } return bat2sect(s, idx) + sector_num % s->tracks; }


static void send_scsi_cdb_read10(QPCIDevice *dev, void *ide_base, uint64_t lba, int nblocks) { Read10CDB pkt = { .padding = 0 }; int i; g_assert_cmpint(lba, <=, UINT32_MAX); g_assert_cmpint(nblocks, <=, UINT16_MAX); g_assert_cmpint(nblocks, >=, 0); /* Construct SCSI CDB packet */ pkt.opcode = 0x28; pkt.lba = cpu_to_be32(lba); pkt.nblocks = cpu_to_be16(nblocks); /* Send Packet */ for (i = 0; i < sizeof(Read10CDB)/2; i++) { qpci_io_writew(dev, ide_base + reg_data, le16_to_cpu(((uint16_t *)&pkt)[i])); } }


static int vobsub_read_header(AVFormatContext *s) { int i, ret = 0, header_parsed = 0, langidx = 0; MpegDemuxContext *vobsub = s->priv_data; char *sub_name = NULL; size_t fname_len; char *ext, *header_str; AVBPrint header; int64_t delay = 0; AVStream *st = NULL; sub_name = av_strdup(s->filename); fname_len = strlen(sub_name); ext = sub_name - 3 + fname_len; if (fname_len < 4 || *(ext - 1) != '.') { av_log(s, AV_LOG_ERROR, "The input index filename is too short " "to guess the associated .SUB file\n"); ret = AVERROR_INVALIDDATA; goto end; } memcpy(ext, !strncmp(ext, "IDX", 3) ? "SUB" : "sub", 3); av_log(s, AV_LOG_VERBOSE, "IDX/SUB: %s -> %s\n", s->filename, sub_name); ret = avformat_open_input(&vobsub->sub_ctx, sub_name, &ff_mpegps_demuxer, NULL); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Unable to open %s as MPEG subtitles\n", sub_name); goto end; } av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED); while (!url_feof(s->pb)) { char line[2048]; int len = ff_get_line(s->pb, line, sizeof(line)); if (!len) break; line[strcspn(line, "\r\n")] = 0; if (!strncmp(line, "id:", 3)) { int n, stream_id = 0; char id[64] = {0}; n = sscanf(line, "id: %63[^,], index: %u", id, &stream_id); if (n != 2) { av_log(s, AV_LOG_WARNING, "Unable to parse index line '%s', " "assuming 'id: und, index: 0'\n", line); strcpy(id, "und"); stream_id = 0; } if (stream_id >= FF_ARRAY_ELEMS(vobsub->q)) { av_log(s, AV_LOG_ERROR, "Maximum number of subtitles streams reached\n"); ret = AVERROR(EINVAL); goto end; } st = avformat_new_stream(s, NULL); if (!st) { ret = AVERROR(ENOMEM); goto end; } st->id = stream_id; st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id = AV_CODEC_ID_DVD_SUBTITLE; avpriv_set_pts_info(st, 64, 1, 1000); av_dict_set(&st->metadata, "language", id, 0); av_log(s, AV_LOG_DEBUG, "IDX stream[%d] id=%s\n", stream_id, id); header_parsed = 1; } else if (st && !strncmp(line, "timestamp:", 10)) { AVPacket *sub; int hh, mm, ss, ms; int64_t pos, timestamp; const char *p = line + 10; if (!s->nb_streams) { av_log(s, AV_LOG_ERROR, "Timestamp declared before any stream\n"); ret = AVERROR_INVALIDDATA; goto end; } if (sscanf(p, "%02d:%02d:%02d:%03d, filepos: %"SCNx64, &hh, &mm, &ss, &ms, &pos) != 5) { av_log(s, AV_LOG_ERROR, "Unable to parse timestamp line '%s', " "abort parsing\n", line); break; } timestamp = (hh*3600LL + mm*60LL + ss) * 1000LL + ms + delay; timestamp = av_rescale_q(timestamp, av_make_q(1, 1000), st->time_base); sub = ff_subtitles_queue_insert(&vobsub->q[s->nb_streams - 1], "", 0, 0); if (!sub) { ret = AVERROR(ENOMEM); goto end; } sub->pos = pos; sub->pts = timestamp; sub->stream_index = s->nb_streams - 1; } else if (st && !strncmp(line, "alt:", 4)) { const char *p = line + 4; while (*p == ' ') p++; av_dict_set(&st->metadata, "title", p, 0); av_log(s, AV_LOG_DEBUG, "IDX stream[%d] name=%s\n", st->id, p); header_parsed = 1; } else if (!strncmp(line, "delay:", 6)) { int sign = 1, hh = 0, mm = 0, ss = 0, ms = 0; const char *p = line + 6; while (*p == ' ') p++; if (*p == '-' || *p == '+') { sign = *p == '-' ? -1 : 1; p++; } sscanf(p, "%d:%d:%d:%d", &hh, &mm, &ss, &ms); delay = ((hh*3600LL + mm*60LL + ss) * 1000LL + ms) * sign; } else if (!strncmp(line, "langidx:", 8)) { const char *p = line + 8; if (sscanf(p, "%d", &langidx) != 1) av_log(s, AV_LOG_ERROR, "Invalid langidx specified\n"); } else if (!header_parsed) { if (line[0] && line[0] != '#') av_bprintf(&header, "%s\n", line); } } if (langidx < s->nb_streams) s->streams[langidx]->disposition |= AV_DISPOSITION_DEFAULT; for (i = 0; i < s->nb_streams; i++) { vobsub->q[i].sort = SUB_SORT_POS_TS; ff_subtitles_queue_finalize(&vobsub->q[i]); } if (!av_bprint_is_complete(&header)) { av_bprint_finalize(&header, NULL); ret = AVERROR(ENOMEM); goto end; } av_bprint_finalize(&header, &header_str); for (i = 0; i < s->nb_streams; i++) { AVStream *sub_st = s->streams[i]; sub_st->codec->extradata = av_strdup(header_str); sub_st->codec->extradata_size = header.len; } av_free(header_str); end: av_free(sub_name); return ret; }


QBool *qobject_to_qbool(const QObject *obj) { if (qobject_type(obj) != QTYPE_QBOOL) return NULL; return container_of(obj, QBool, base); }


static av_always_inline int mvd_decode(HEVCContext *s) { int ret = 2; int k = 1; while (k < CABAC_MAX_BIN && get_cabac_bypass(&s->HEVClc->cc)) { ret += 1 << k; k++; } if (k == CABAC_MAX_BIN) av_log(s->avctx, AV_LOG_ERROR, "CABAC_MAX_BIN : %d\n", k); while (k--) ret += get_cabac_bypass(&s->HEVClc->cc) << k; return get_cabac_bypass_sign(&s->HEVClc->cc, -ret); }


static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) { CPUS390XState *env = &cpu->env; cpu_synchronize_state(CPU(cpu)); env->regs[2] = s390_virtio_hypercall(env); return 0; }


av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v) { MpegEncContext *s = &v->s; int i; int mb_height = FFALIGN(s->mb_height, 2); /* Allocate mb bitplanes */ v->mv_type_mb_plane = av_malloc (s->mb_stride * mb_height); v->direct_mb_plane = av_malloc (s->mb_stride * mb_height); v->forward_mb_plane = av_malloc (s->mb_stride * mb_height); v->fieldtx_plane = av_mallocz(s->mb_stride * mb_height); v->acpred_plane = av_malloc (s->mb_stride * mb_height); v->over_flags_plane = av_malloc (s->mb_stride * mb_height); v->n_allocated_blks = s->mb_width + 2; v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks); v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride); v->cbp = v->cbp_base + s->mb_stride; v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride); v->ttblk = v->ttblk_base + s->mb_stride; v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride); v->is_intra = v->is_intra_base + s->mb_stride; v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride); v->luma_mv = v->luma_mv_base + s->mb_stride; /* allocate block type info in that way so it could be used with s->block_index[] */ v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); v->mb_type[0] = v->mb_type_base + s->b8_stride + 1; v->mb_type[1] = v->mb_type_base + s->b8_stride * (mb_height * 2 + 1) + s->mb_stride + 1; v->mb_type[2] = v->mb_type[1] + s->mb_stride * (mb_height + 1); /* allocate memory to store block level MV info */ v->blk_mv_type_base = av_mallocz( s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1; v->mv_f_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2)); v->mv_f[0] = v->mv_f_base + s->b8_stride + 1; v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2)); v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1; v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2); ff_intrax8_common_init(&v->x8,s); if (s->avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || s->avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { for (i = 0; i < 4; i++) if (!(v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width))) return -1; } if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->acpred_plane || !v->over_flags_plane || !v->block || !v->cbp_base || !v->ttblk_base || !v->is_intra_base || !v->luma_mv_base || !v->mb_type_base) { goto error; } return 0; error: ff_vc1_decode_end(s->avctx); return AVERROR(ENOMEM); }


static int vapic_prepare(VAPICROMState *s) { vapic_map_rom_writable(s); if (patch_hypercalls(s) < 0) { return -1; } vapic_enable_tpr_reporting(true); return 0; }


void ahci_uninit(AHCIState *s) { int i, j; for (i = 0; i < s->ports; i++) { AHCIDevice *ad = &s->dev[i]; for (j = 0; j < 2; j++) { IDEState *s = &ad->port.ifs[j]; ide_exit(s); } } g_free(s->dev); }


int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size; size = RAW_PACKET_SIZE; if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM); pkt->pos= avio_tell(s->pb); pkt->stream_index = 0; ret = ffio_read_partial(s->pb, pkt->data, size); if (ret < 0) { av_free_packet(pkt); return ret; } pkt->size = ret; return ret; }


static av_cold int nvenc_setup_device(AVCodecContext *avctx) { NvencContext *ctx = avctx->priv_data; NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs; CUresult cu_res; CUcontext cu_context_curr; switch (avctx->codec->id) { case AV_CODEC_ID_H264: ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_H264_GUID; break; case AV_CODEC_ID_HEVC: ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_HEVC_GUID; break; default: return AVERROR_BUG; } ctx->data_pix_fmt = avctx->pix_fmt; #if CONFIG_CUDA if (avctx->pix_fmt == AV_PIX_FMT_CUDA) { AVHWFramesContext *frames_ctx; AVCUDADeviceContext *device_hwctx; if (!avctx->hw_frames_ctx) { av_log(avctx, AV_LOG_ERROR, "hw_frames_ctx must be set when using GPU frames as input\n"); return AVERROR(EINVAL); } frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; device_hwctx = frames_ctx->device_ctx->hwctx; ctx->cu_context = device_hwctx->cuda_ctx; ctx->data_pix_fmt = frames_ctx->sw_format; return 0; } #endif if (ctx->gpu >= dl_fn->nvenc_device_count) { av_log(avctx, AV_LOG_FATAL, "Requested GPU %d, but only %d GPUs are available!\n", ctx->gpu, dl_fn->nvenc_device_count); return AVERROR(EINVAL); } ctx->cu_context = NULL; cu_res = dl_fn->cu_ctx_create(&ctx->cu_context_internal, 4, dl_fn->nvenc_devices[ctx->gpu]); // CU_CTX_SCHED_BLOCKING_SYNC=4, avoid CPU spins if (cu_res != CUDA_SUCCESS) { av_log(avctx, AV_LOG_FATAL, "Failed creating CUDA context for NVENC: 0x%x\n", (int)cu_res); return AVERROR_EXTERNAL; } cu_res = dl_fn->cu_ctx_pop_current(&cu_context_curr); if (cu_res != CUDA_SUCCESS) { av_log(avctx, AV_LOG_FATAL, "Failed popping CUDA context: 0x%x\n", (int)cu_res); return AVERROR_EXTERNAL; } ctx->cu_context = ctx->cu_context_internal; return 0; }


static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c) { GetBitContext *gb = &ctx->gb; ALSChannelData *current = cd; unsigned int channels = ctx->avctx->channels; int entries = 0; while (entries < channels && !(current->stop_flag = get_bits1(gb))) { current->master_channel = get_bits_long(gb, av_ceil_log2(channels)); if (current->master_channel >= channels) { av_log(ctx->avctx, AV_LOG_ERROR, "Invalid master channel!\n"); return -1; } if (current->master_channel != c) { current->time_diff_flag = get_bits1(gb); current->weighting[0] = als_weighting(gb, 1, 16); current->weighting[1] = als_weighting(gb, 2, 14); current->weighting[2] = als_weighting(gb, 1, 16); if (current->time_diff_flag) { current->weighting[3] = als_weighting(gb, 1, 16); current->weighting[4] = als_weighting(gb, 1, 16); current->weighting[5] = als_weighting(gb, 1, 16); current->time_diff_sign = get_bits1(gb); current->time_diff_index = get_bits(gb, ctx->ltp_lag_length - 3) + 3; } } current++; entries++; } if (entries == channels) { av_log(ctx->avctx, AV_LOG_ERROR, "Damaged channel data!\n"); return -1; } align_get_bits(gb); return 0; }


static void cpu_unregister_map_client(void *_client) { MapClient *client = (MapClient *)_client; QLIST_REMOVE(client, link); g_free(client); }


static int rv34_decoder_alloc(RV34DecContext *r) { r->intra_types_stride = r->s.mb_width * 4 + 4; r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs)); r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist)); r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type)); if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs && r->intra_types_hist && r->mb_type)) { rv34_decoder_free(r); return AVERROR(ENOMEM); } r->intra_types = r->intra_types_hist + r->intra_types_stride * 4; return 0; }


static int dvbsub_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { DVBSubParseContext *pc = s->priv_data; uint8_t *p, *p_end; int i, len, buf_pos = 0; av_dlog(avctx, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n", s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); for (i=0; i < buf_size; i++) { av_dlog(avctx, "%02x ", buf[i]); if (i % 16 == 15) av_dlog(avctx, "\n"); } if (i % 16 != 0) av_dlog(avctx, "\n"); *poutbuf = NULL; *poutbuf_size = 0; s->fetch_timestamp = 1; if (s->last_pts != s->pts && s->pts != AV_NOPTS_VALUE) /* Start of a new packet */ { if (pc->packet_index != pc->packet_start) { av_dlog(avctx, "Discarding %d bytes\n", pc->packet_index - pc->packet_start); } pc->packet_start = 0; pc->packet_index = 0; if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) { av_dlog(avctx, "Bad packet header\n"); return -1; } buf_pos = 2; pc->in_packet = 1; } else { if (pc->packet_start != 0) { if (pc->packet_index != pc->packet_start) { memmove(pc->packet_buf, pc->packet_buf + pc->packet_start, pc->packet_index - pc->packet_start); pc->packet_index -= pc->packet_start; pc->packet_start = 0; } else { pc->packet_start = 0; pc->packet_index = 0; } } } if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE) return -1; /* if not currently in a packet, discard data */ if (pc->in_packet == 0) return buf_size; memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos); pc->packet_index += buf_size - buf_pos; p = pc->packet_buf; p_end = pc->packet_buf + pc->packet_index; while (p < p_end) { if (*p == 0x0f) { if (p + 6 <= p_end) { len = AV_RB16(p + 4); if (p + len + 6 <= p_end) { *poutbuf_size += len + 6; p += len + 6; } else break; } else break; } else if (*p == 0xff) { if (p + 1 < p_end) { av_dlog(avctx, "Junk at end of packet\n"); } pc->packet_index = p - pc->packet_buf; pc->in_packet = 0; break; } else { av_log(avctx, AV_LOG_ERROR, "Junk in packet\n"); pc->packet_index = p - pc->packet_buf; pc->in_packet = 0; break; } } if (*poutbuf_size > 0) { *poutbuf = pc->packet_buf; pc->packet_start = *poutbuf_size; } if (s->pts == AV_NOPTS_VALUE) s->pts = s->last_pts; return buf_size; }


static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags, ID3v2ExtraMeta **extra_meta) { int isv34, unsync; unsigned tlen; char tag[5]; int64_t next, end = avio_tell(s->pb) + len; int taghdrlen; const char *reason = NULL; AVIOContext pb; AVIOContext *pbx; unsigned char *buffer = NULL; int buffer_size = 0; const ID3v2EMFunc *extra_func = NULL; unsigned char *uncompressed_buffer = NULL; int uncompressed_buffer_size = 0; av_log(s, AV_LOG_DEBUG, "id3v2 ver:%d flags:%02X len:%d\n", version, flags, len); switch (version) { case 2: if (flags & 0x40) { reason = "compression"; goto error; } isv34 = 0; taghdrlen = 6; break; case 3: case 4: isv34 = 1; taghdrlen = 10; break; default: reason = "version"; goto error; } unsync = flags & 0x80; if (isv34 && flags & 0x40) { /* Extended header present, just skip over it */ int extlen = get_size(s->pb, 4); if (version == 4) /* In v2.4 the length includes the length field we just read. */ extlen -= 4; if (extlen < 0) { reason = "invalid extended header length"; goto error; } avio_skip(s->pb, extlen); len -= extlen + 4; if (len < 0) { reason = "extended header too long."; goto error; } } while (len >= taghdrlen) { unsigned int tflags = 0; int tunsync = 0; int tcomp = 0; int tencr = 0; unsigned long dlen; if (isv34) { avio_read(s->pb, tag, 4); tag[4] = 0; if (version == 3) { tlen = avio_rb32(s->pb); } else tlen = get_size(s->pb, 4); tflags = avio_rb16(s->pb); tunsync = tflags & ID3v2_FLAG_UNSYNCH; } else { avio_read(s->pb, tag, 3); tag[3] = 0; tlen = avio_rb24(s->pb); } if (tlen > (1<<28)) break; len -= taghdrlen + tlen; if (len < 0) break; next = avio_tell(s->pb) + tlen; if (!tlen) { if (tag[0]) av_log(s, AV_LOG_DEBUG, "Invalid empty frame %s, skipping.\n", tag); continue; } if (tflags & ID3v2_FLAG_DATALEN) { if (tlen < 4) break; dlen = avio_rb32(s->pb); tlen -= 4; } else dlen = tlen; tcomp = tflags & ID3v2_FLAG_COMPRESSION; tencr = tflags & ID3v2_FLAG_ENCRYPTION; /* skip encrypted tags and, if no zlib, compressed tags */ if (tencr || (!CONFIG_ZLIB && tcomp)) { const char *type; if (!tcomp) type = "encrypted"; else if (!tencr) type = "compressed"; else type = "encrypted and compressed"; av_log(s, AV_LOG_WARNING, "Skipping %s ID3v2 frame %s.\n", type, tag); avio_skip(s->pb, tlen); /* check for text tag or supported special meta tag */ } else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) { pbx = s->pb; if (unsync || tunsync || tcomp) { av_fast_malloc(&buffer, &buffer_size, tlen); if (!buffer) { av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen); goto seek; } } if (unsync || tunsync) { int64_t end = avio_tell(s->pb) + tlen; uint8_t *b; b = buffer; while (avio_tell(s->pb) < end && b - buffer < tlen && !s->pb->eof_reached) { *b++ = avio_r8(s->pb); if (*(b - 1) == 0xff && avio_tell(s->pb) < end - 1 && b - buffer < tlen && !s->pb->eof_reached ) { uint8_t val = avio_r8(s->pb); *b++ = val ? val : avio_r8(s->pb); } } ffio_init_context(&pb, buffer, b - buffer, 0, NULL, NULL, NULL, NULL); tlen = b - buffer; pbx = &pb; // read from sync buffer } #if CONFIG_ZLIB if (tcomp) { int err; av_log(s, AV_LOG_DEBUG, "Compresssed frame %s tlen=%d dlen=%ld\n", tag, tlen, dlen); av_fast_malloc(&uncompressed_buffer, &uncompressed_buffer_size, dlen); if (!uncompressed_buffer) { av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", dlen); goto seek; } if (!(unsync || tunsync)) { err = avio_read(s->pb, buffer, tlen); if (err < 0) { av_log(s, AV_LOG_ERROR, "Failed to read compressed tag\n"); goto seek; } tlen = err; } err = uncompress(uncompressed_buffer, &dlen, buffer, tlen); if (err != Z_OK) { av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: %d\n", err); goto seek; } ffio_init_context(&pb, uncompressed_buffer, dlen, 0, NULL, NULL, NULL, NULL); tlen = dlen; pbx = &pb; // read from sync buffer } #endif if (tag[0] == 'T') /* parse text tag */ read_ttag(s, pbx, tlen, &s->metadata, tag); else /* parse special meta tag */ extra_func->read(s, pbx, tlen, tag, extra_meta); } else if (!tag[0]) { if (tag[1]) av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding\n"); avio_skip(s->pb, tlen); break; } /* Skip to end of tag */ seek: avio_seek(s->pb, next, SEEK_SET); } /* Footer preset, always 10 bytes, skip over it */ if (version == 4 && flags & 0x10) end += 10; error: if (reason) av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); avio_seek(s->pb, end, SEEK_SET); av_free(buffer); av_free(uncompressed_buffer); return; }


static void decode_band_structure(GetBitContext *gbc, int blk, int eac3, int ecpl, int start_subband, int end_subband, const uint8_t *default_band_struct, uint8_t *band_struct, int *num_subbands, int *num_bands, uint8_t *band_sizes) { int subbnd, bnd, n_subbands, n_bands; uint8_t bnd_sz[22]; n_subbands = end_subband - start_subband; /* decode band structure from bitstream or use default */ if (!eac3 || get_bits1(gbc)) { for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) { band_struct[subbnd] = get_bits1(gbc); } } else if (!blk) { memcpy(band_struct, &default_band_struct[start_subband+1], n_subbands-1); } band_struct[n_subbands-1] = 0; /* calculate number of bands and band sizes based on band structure. note that the first 4 subbands in enhanced coupling span only 6 bins instead of 12. */ if (num_bands || band_sizes ) { n_bands = n_subbands; bnd_sz[0] = ecpl ? 6 : 12; for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) { int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12; if (band_struct[subbnd-1]) { n_bands--; bnd_sz[bnd] += subbnd_size; } else { bnd_sz[++bnd] = subbnd_size; } } } /* set optional output params */ if (num_subbands) *num_subbands = n_subbands; if (num_bands) *num_bands = n_bands; if (band_sizes) memcpy(band_sizes, bnd_sz, n_bands); }


static void dump_iterate(DumpState *s, Error **errp) { GuestPhysBlock *block; int64_t size; int ret; Error *local_err = NULL; while (1) { block = s->next_block; size = block->target_end - block->target_start; if (s->has_filter) { size -= s->start; if (s->begin + s->length < block->target_end) { size -= block->target_end - (s->begin + s->length); } } write_memory(s, block, s->start, size, &local_err); if (local_err) { error_propagate(errp, local_err); return; } ret = get_next_block(s, block); if (ret == 1) { dump_completed(s); } } }


fdctrl_t *fdctrl_init_sysbus(qemu_irq irq, int dma_chann, target_phys_addr_t mmio_base, DriveInfo **fds) { fdctrl_t *fdctrl; DeviceState *dev; fdctrl_sysbus_t *sys; dev = qdev_create(NULL, "sysbus-fdc"); sys = DO_UPCAST(fdctrl_sysbus_t, busdev.qdev, dev); fdctrl = &sys->state; fdctrl->dma_chann = dma_chann; /* FIXME */ qdev_prop_set_drive(dev, "driveA", fds[0]); qdev_prop_set_drive(dev, "driveB", fds[1]); if (qdev_init(dev) != 0) return NULL; sysbus_connect_irq(&sys->busdev, 0, irq); sysbus_mmio_map(&sys->busdev, 0, mmio_base); return fdctrl; }


static void uhci_async_complete(USBPort *port, USBPacket *packet) { UHCIAsync *async = container_of(packet, UHCIAsync, packet); UHCIState *s = async->queue->uhci; if (async->isoc) { UHCI_TD td; uint32_t link = async->td; uint32_t int_mask = 0, val; pci_dma_read(&s->dev, link & ~0xf, &td, sizeof(td)); le32_to_cpus(&td.link); le32_to_cpus(&td.ctrl); le32_to_cpus(&td.token); le32_to_cpus(&td.buffer); uhci_async_unlink(async); uhci_complete_td(s, &td, async, &int_mask); s->pending_int_mask |= int_mask; /* update the status bits of the TD */ val = cpu_to_le32(td.ctrl); pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); uhci_async_free(async); } else { async->done = 1; uhci_process_frame(s); } }


int coroutine_fn thread_pool_submit_co(ThreadPoolFunc *func, void *arg) { ThreadPoolCo tpc = { .co = qemu_coroutine_self(), .ret = -EINPROGRESS }; assert(qemu_in_coroutine()); thread_pool_submit_aio(func, arg, thread_pool_co_cb, &tpc); qemu_coroutine_yield(); return tpc.ret; }


static void uhci_process_frame(UHCIState *s) { uint32_t frame_addr, link, old_td_ctrl, val, int_mask; uint32_t curr_qh; int cnt, ret; UHCI_TD td; UHCI_QH qh; QhDb qhdb; frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2); DPRINTF("uhci: processing frame %d addr 0x%x\n" , s->frnum, frame_addr); cpu_physical_memory_read(frame_addr, (uint8_t *)&link, 4); le32_to_cpus(&link); int_mask = 0; curr_qh = 0; qhdb_reset(&qhdb); for (cnt = FRAME_MAX_LOOPS; is_valid(link) && cnt; cnt--) { if (is_qh(link)) { /* QH */ if (qhdb_insert(&qhdb, link)) { /* * We're going in circles. Which is not a bug because * HCD is allowed to do that as part of the BW management. * In our case though it makes no sense to spin here. Sync transations * are already done, and async completion handler will re-process * the frame when something is ready. */ DPRINTF("uhci: detected loop. qh 0x%x\n", link); break; } cpu_physical_memory_read(link & ~0xf, (uint8_t *) &qh, sizeof(qh)); le32_to_cpus(&qh.link); le32_to_cpus(&qh.el_link); DPRINTF("uhci: QH 0x%x load. link 0x%x elink 0x%x\n", link, qh.link, qh.el_link); if (!is_valid(qh.el_link)) { /* QH w/o elements */ curr_qh = 0; link = qh.link; } else { /* QH with elements */ curr_qh = link; link = qh.el_link; } continue; } /* TD */ cpu_physical_memory_read(link & ~0xf, (uint8_t *) &td, sizeof(td)); le32_to_cpus(&td.link); le32_to_cpus(&td.ctrl); le32_to_cpus(&td.token); le32_to_cpus(&td.buffer); DPRINTF("uhci: TD 0x%x load. link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n", link, td.link, td.ctrl, td.token, curr_qh); old_td_ctrl = td.ctrl; ret = uhci_handle_td(s, link, &td, &int_mask); if (old_td_ctrl != td.ctrl) { /* update the status bits of the TD */ val = cpu_to_le32(td.ctrl); cpu_physical_memory_write((link & ~0xf) + 4, (const uint8_t *)&val, sizeof(val)); } if (ret < 0) { /* interrupted frame */ break; } if (ret == 2 || ret == 1) { DPRINTF("uhci: TD 0x%x %s. link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n", link, ret == 2 ? "pend" : "skip", td.link, td.ctrl, td.token, curr_qh); link = curr_qh ? qh.link : td.link; continue; } /* completed TD */ DPRINTF("uhci: TD 0x%x done. link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n", link, td.link, td.ctrl, td.token, curr_qh); link = td.link; if (curr_qh) { /* update QH element link */ qh.el_link = link; val = cpu_to_le32(qh.el_link); cpu_physical_memory_write((curr_qh & ~0xf) + 4, (const uint8_t *)&val, sizeof(val)); if (!depth_first(link)) { /* done with this QH */ DPRINTF("uhci: QH 0x%x done. link 0x%x elink 0x%x\n", curr_qh, qh.link, qh.el_link); curr_qh = 0; link = qh.link; } } /* go to the next entry */ } s->pending_int_mask |= int_mask; }


int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { AVFrame tmp; AVFrame *padded_frame = NULL; int ret; AVPacket user_pkt = *avpkt; int needs_realloc = !user_pkt.data; *got_packet_ptr = 0; if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { av_free_packet(avpkt); av_init_packet(avpkt); return 0; } /* ensure that extended_data is properly set */ if (frame && !frame->extended_data) { if (av_sample_fmt_is_planar(avctx->sample_fmt) && avctx->channels > AV_NUM_DATA_POINTERS) { av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, " "with more than %d channels, but extended_data is not set.\n", AV_NUM_DATA_POINTERS); return AVERROR(EINVAL); } av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n"); tmp = *frame; tmp.extended_data = tmp.data; frame = &tmp; } /* check for valid frame size */ if (frame) { if (avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { if (frame->nb_samples > avctx->frame_size) { av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n"); return AVERROR(EINVAL); } } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) { if (frame->nb_samples < avctx->frame_size && !avctx->internal->last_audio_frame) { ret = pad_last_frame(avctx, &padded_frame, frame); if (ret < 0) return ret; frame = padded_frame; avctx->internal->last_audio_frame = 1; } if (frame->nb_samples != avctx->frame_size) { av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size); ret = AVERROR(EINVAL); goto end; } } } ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); if (!ret) { if (*got_packet_ptr) { if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { if (avpkt->pts == AV_NOPTS_VALUE) avpkt->pts = frame->pts; if (!avpkt->duration) avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); } avpkt->dts = avpkt->pts; } else { avpkt->size = 0; } } if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) { needs_realloc = 0; if (user_pkt.data) { if (user_pkt.size >= avpkt->size) { memcpy(user_pkt.data, avpkt->data, avpkt->size); } else { av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size); avpkt->size = user_pkt.size; ret = -1; } avpkt->buf = user_pkt.buf; avpkt->data = user_pkt.data; avpkt->destruct = user_pkt.destruct; } else { if (av_dup_packet(avpkt) < 0) { ret = AVERROR(ENOMEM); } } } if (!ret) { if (needs_realloc && avpkt->data) { ret = av_buffer_realloc(&avpkt->buf, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); if (ret >= 0) avpkt->data = avpkt->buf->data; } avctx->frame_number++; } if (ret < 0 || !*got_packet_ptr) { av_free_packet(avpkt); av_init_packet(avpkt); goto end; } /* NOTE: if we add any audio encoders which output non-keyframe packets, * this needs to be moved to the encoders, but for now we can do it * here to simplify things */ avpkt->flags |= AV_PKT_FLAG_KEY; end: av_frame_free(&padded_frame); return ret; }


static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq) { VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(vdev); VirtIOInput *vinput = VIRTIO_INPUT(vdev); virtio_input_event event; VirtQueueElement elem; int len; while (virtqueue_pop(vinput->sts, &elem)) { memset(&event, 0, sizeof(event)); len = iov_to_buf(elem.out_sg, elem.out_num, 0, &event, sizeof(event)); if (vic->handle_status) { vic->handle_status(vinput, &event); } virtqueue_push(vinput->sts, &elem, len); } virtio_notify(vdev, vinput->sts); }


void qmp_guest_file_close(int64_t handle, Error **err) { GuestFileHandle *gfh = guest_file_handle_find(handle, err); int ret; slog("guest-file-close called, handle: %ld", handle); if (!gfh) { return; } ret = fclose(gfh->fh); if (ret == -1) { error_set(err, QERR_QGA_COMMAND_FAILED, "fclose() failed"); return; } QTAILQ_REMOVE(&guest_file_state.filehandles, gfh, next); g_free(gfh); }


static int convert_read(ImgConvertState *s, int64_t sector_num, int nb_sectors, uint8_t *buf) { int n; int ret; if (s->status == BLK_ZERO || s->status == BLK_BACKING_FILE) { return 0; } assert(nb_sectors <= s->buf_sectors); while (nb_sectors > 0) { BlockBackend *blk; int64_t bs_sectors; /* In the case of compression with multiple source files, we can get a * nb_sectors that spreads into the next part. So we must be able to * read across multiple BDSes for one convert_read() call. */ convert_select_part(s, sector_num); blk = s->src[s->src_cur]; bs_sectors = s->src_sectors[s->src_cur]; n = MIN(nb_sectors, bs_sectors - (sector_num - s->src_cur_offset)); ret = blk_read(blk, sector_num - s->src_cur_offset, buf, n); if (ret < 0) { return ret; } sector_num += n; nb_sectors -= n; buf += n * BDRV_SECTOR_SIZE; } return 0; }


static void qemu_announce_self_once(void *opaque) { static int count = SELF_ANNOUNCE_ROUNDS; QEMUTimer *timer = *(QEMUTimer **)opaque; qemu_foreach_nic(qemu_announce_self_iter, NULL); if (--count) { /* delay 50ms, 150ms, 250ms, ... */ qemu_mod_timer(timer, qemu_get_clock(rt_clock) + 50 + (SELF_ANNOUNCE_ROUNDS - count - 1) * 100); } else { qemu_del_timer(timer); qemu_free_timer(timer); } }


static int nvme_init(PCIDevice *pci_dev) { NvmeCtrl *n = NVME(pci_dev); NvmeIdCtrl *id = &n->id_ctrl; int i; int64_t bs_size; uint8_t *pci_conf; if (!(n->conf.bs)) { return -1; } bs_size = bdrv_getlength(n->conf.bs); if (bs_size < 0) { return -1; } blkconf_serial(&n->conf, &n->serial); if (!n->serial) { return -1; } pci_conf = pci_dev->config; pci_conf[PCI_INTERRUPT_PIN] = 1; pci_config_set_prog_interface(pci_dev->config, 0x2); pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS); pcie_endpoint_cap_init(&n->parent_obj, 0x80); n->num_namespaces = 1; n->num_queues = 64; n->reg_size = 1 << qemu_fls(0x1004 + 2 * (n->num_queues + 1) * 4); n->ns_size = bs_size / (uint64_t)n->num_namespaces; n->namespaces = g_new0(NvmeNamespace, n->num_namespaces); n->sq = g_new0(NvmeSQueue *, n->num_queues); n->cq = g_new0(NvmeCQueue *, n->num_queues); memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", n->reg_size); pci_register_bar(&n->parent_obj, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, &n->iomem); msix_init_exclusive_bar(&n->parent_obj, n->num_queues, 4); id->vid = cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID)); id->ssvid = cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID)); strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' '); strpadcpy((char *)id->fr, sizeof(id->fr), "1.0", ' '); strpadcpy((char *)id->sn, sizeof(id->sn), n->serial, ' '); id->rab = 6; id->ieee[0] = 0x00; id->ieee[1] = 0x02; id->ieee[2] = 0xb3; id->oacs = cpu_to_le16(0); id->frmw = 7 << 1; id->lpa = 1 << 0; id->sqes = (0x6 << 4) | 0x6; id->cqes = (0x4 << 4) | 0x4; id->nn = cpu_to_le32(n->num_namespaces); id->psd[0].mp = cpu_to_le16(0x9c4); id->psd[0].enlat = cpu_to_le32(0x10); id->psd[0].exlat = cpu_to_le32(0x4); n->bar.cap = 0; NVME_CAP_SET_MQES(n->bar.cap, 0x7ff); NVME_CAP_SET_CQR(n->bar.cap, 1); NVME_CAP_SET_AMS(n->bar.cap, 1); NVME_CAP_SET_TO(n->bar.cap, 0xf); NVME_CAP_SET_CSS(n->bar.cap, 1); n->bar.vs = 0x00010001; n->bar.intmc = n->bar.intms = 0; for (i = 0; i < n->num_namespaces; i++) { NvmeNamespace *ns = &n->namespaces[i]; NvmeIdNs *id_ns = &ns->id_ns; id_ns->nsfeat = 0; id_ns->nlbaf = 0; id_ns->flbas = 0; id_ns->mc = 0; id_ns->dpc = 0; id_ns->dps = 0; id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; id_ns->ncap = id_ns->nuse = id_ns->nsze = cpu_to_le64(n->ns_size >> id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); } return 0; }


int blk_get_max_transfer_length(BlockBackend *blk) { BlockDriverState *bs = blk_bs(blk); if (bs) { return bs->bl.max_transfer_length; } else { return 0; } }


START_TEST(qstring_append_chr_test) { int i; QString *qstring; const char *str = "qstring append char unit-test"; qstring = qstring_new(); for (i = 0; str[i]; i++) qstring_append_chr(qstring, str[i]); fail_unless(strcmp(str, qstring_get_str(qstring)) == 0); QDECREF(qstring); }


static int ftp_get_line(FTPContext *s, char *line, int line_size) { int ch; char *q = line; int ori_block_flag = s->conn_control_block_flag; for (;;) { ch = ftp_getc(s); if (ch < 0) { s->conn_control_block_flag = ori_block_flag; return ch; } if (ch == '\n') { /* process line */ if (q > line && q[-1] == '\r') q--; *q = '\0'; s->conn_control_block_flag = ori_block_flag; return 0; } else { s->conn_control_block_flag = 0; /* line need to be finished */ if ((q - line) < line_size - 1) *q++ = ch; } } }


static int raw_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s = bs->opaque; if (s->offset || s->has_size) { return -ENOTSUP; } return bdrv_co_ioctl(bs->file->bs, req, buf); }


static void lsi_io_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { LSIState *s = opaque; lsi_reg_writeb(s, addr & 0xff, val); }


void input_type_enum(Visitor *v, int *obj, const char *strings[], const char *kind, const char *name, Error **errp) { int64_t value = 0; char *enum_str; assert(strings); visit_type_str(v, &enum_str, name, errp); if (error_is_set(errp)) { return; } while (strings[value] != NULL) { if (strcmp(strings[value], enum_str) == 0) { break; } value++; } if (strings[value] == NULL) { error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); g_free(enum_str); return; } g_free(enum_str); *obj = value; }