block_crypto_open_opts_init(QCryptoBlockFormat format, QemuOpts *opts, Error **errp) { Visitor *v; QCryptoBlockOpenOptions *ret = NULL; Error *local_err = NULL; ret = g_new0(QCryptoBlockOpenOptions, 1); ret->format = format; v = opts_visitor_new(opts); visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { goto out; } switch (format) { case Q_CRYPTO_BLOCK_FORMAT_LUKS: visit_type_QCryptoBlockOptionsLUKS_members( v, &ret->u.luks, &local_err); break; default: error_setg(&local_err, "Unsupported block format %d", format); break; } if (!local_err) { visit_check_struct(v, &local_err); } visit_end_struct(v, NULL); out: if (local_err) { error_propagate(errp, local_err); qapi_free_QCryptoBlockOpenOptions(ret); ret = NULL; } visit_free(v); return ret; }


gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb, bool search_pc) { CPUState *cs = CPU(cpu); CPUCRISState *env = &cpu->env; uint32_t pc_start; unsigned int insn_len; int j, lj; struct DisasContext ctx; struct DisasContext *dc = &ctx; uint32_t next_page_start; target_ulong npc; int num_insns; int max_insns; if (env->pregs[PR_VR] == 32) { dc->decoder = crisv32_decoder; dc->clear_locked_irq = 0; } else { dc->decoder = crisv10_decoder; dc->clear_locked_irq = 1; } /* Odd PC indicates that branch is rexecuting due to exception in the * delayslot, like in real hw. */ pc_start = tb->pc & ~1; dc->cpu = cpu; dc->tb = tb; dc->is_jmp = DISAS_NEXT; dc->ppc = pc_start; dc->pc = pc_start; dc->singlestep_enabled = cs->singlestep_enabled; dc->flags_uptodate = 1; dc->flagx_known = 1; dc->flags_x = tb->flags & X_FLAG; dc->cc_x_uptodate = 0; dc->cc_mask = 0; dc->update_cc = 0; dc->clear_prefix = 0; cris_update_cc_op(dc, CC_OP_FLAGS, 4); dc->cc_size_uptodate = -1; /* Decode TB flags. */ dc->tb_flags = tb->flags & (S_FLAG | P_FLAG | U_FLAG \ | X_FLAG | PFIX_FLAG); dc->delayed_branch = !!(tb->flags & 7); if (dc->delayed_branch) { dc->jmp = JMP_INDIRECT; } else { dc->jmp = JMP_NOJMP; } dc->cpustate_changed = 0; if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log( "srch=%d pc=%x %x flg=%" PRIx64 " bt=%x ds=%u ccs=%x\n" "pid=%x usp=%x\n" "%x.%x.%x.%x\n" "%x.%x.%x.%x\n" "%x.%x.%x.%x\n" "%x.%x.%x.%x\n", search_pc, dc->pc, dc->ppc, (uint64_t)tb->flags, env->btarget, (unsigned)tb->flags & 7, env->pregs[PR_CCS], env->pregs[PR_PID], env->pregs[PR_USP], env->regs[0], env->regs[1], env->regs[2], env->regs[3], env->regs[4], env->regs[5], env->regs[6], env->regs[7], env->regs[8], env->regs[9], env->regs[10], env->regs[11], env->regs[12], env->regs[13], env->regs[14], env->regs[15]); qemu_log("--------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); } next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; lj = -1; num_insns = 0; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) { max_insns = CF_COUNT_MASK; } gen_tb_start(tb); 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; } } if (dc->delayed_branch == 1) { tcg_ctx.gen_opc_pc[lj] = dc->ppc | 1; } else { tcg_ctx.gen_opc_pc[lj] = dc->pc; } tcg_ctx.gen_opc_instr_start[lj] = 1; tcg_ctx.gen_opc_icount[lj] = num_insns; } /* Pretty disas. */ LOG_DIS("%8.8x:\t", dc->pc); if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { gen_io_start(); } dc->clear_x = 1; insn_len = dc->decoder(env, dc); dc->ppc = dc->pc; dc->pc += insn_len; if (dc->clear_x) { cris_clear_x_flag(dc); } num_insns++; /* Check for delayed branches here. If we do it before actually generating any host code, the simulator will just loop doing nothing for on this program location. */ if (dc->delayed_branch) { dc->delayed_branch--; if (dc->delayed_branch == 0) { if (tb->flags & 7) { t_gen_mov_env_TN(dslot, tcg_const_tl(0)); } if (dc->cpustate_changed || !dc->flagx_known || (dc->flags_x != (tb->flags & X_FLAG))) { cris_store_direct_jmp(dc); } if (dc->clear_locked_irq) { dc->clear_locked_irq = 0; t_gen_mov_env_TN(locked_irq, tcg_const_tl(0)); } if (dc->jmp == JMP_DIRECT_CC) { int l1; l1 = gen_new_label(); cris_evaluate_flags(dc); /* Conditional jmp. */ tcg_gen_brcondi_tl(TCG_COND_EQ, env_btaken, 0, l1); gen_goto_tb(dc, 1, dc->jmp_pc); gen_set_label(l1); gen_goto_tb(dc, 0, dc->pc); dc->is_jmp = DISAS_TB_JUMP; dc->jmp = JMP_NOJMP; } else if (dc->jmp == JMP_DIRECT) { cris_evaluate_flags(dc); gen_goto_tb(dc, 0, dc->jmp_pc); dc->is_jmp = DISAS_TB_JUMP; dc->jmp = JMP_NOJMP; } else { t_gen_cc_jmp(env_btarget, tcg_const_tl(dc->pc)); dc->is_jmp = DISAS_JUMP; } break; } } /* If we are rexecuting a branch due to exceptions on delay slots dont break. */ if (!(tb->pc & 1) && cs->singlestep_enabled) { break; } } while (!dc->is_jmp && !dc->cpustate_changed && !tcg_op_buf_full() && !singlestep && (dc->pc < next_page_start) && num_insns < max_insns); if (dc->clear_locked_irq) { t_gen_mov_env_TN(locked_irq, tcg_const_tl(0)); } npc = dc->pc; if (tb->cflags & CF_LAST_IO) gen_io_end(); /* Force an update if the per-tb cpu state has changed. */ if (dc->is_jmp == DISAS_NEXT && (dc->cpustate_changed || !dc->flagx_known || (dc->flags_x != (tb->flags & X_FLAG)))) { dc->is_jmp = DISAS_UPDATE; tcg_gen_movi_tl(env_pc, npc); } /* Broken branch+delayslot sequence. */ if (dc->delayed_branch == 1) { /* Set env->dslot to the size of the branch insn. */ t_gen_mov_env_TN(dslot, tcg_const_tl(dc->pc - dc->ppc)); cris_store_direct_jmp(dc); } cris_evaluate_flags(dc); if (unlikely(cs->singlestep_enabled)) { if (dc->is_jmp == DISAS_NEXT) { tcg_gen_movi_tl(env_pc, npc); } t_gen_raise_exception(EXCP_DEBUG); } else { switch (dc->is_jmp) { case DISAS_NEXT: gen_goto_tb(dc, 1, npc); break; default: case DISAS_JUMP: case DISAS_UPDATE: /* indicate that the hash table must be used to find the next TB */ tcg_gen_exit_tb(0); break; case DISAS_SWI: case DISAS_TB_JUMP: /* nothing more to generate */ break; } } gen_tb_end(tb, num_insns); if (search_pc) { j = tcg_op_buf_count(); lj++; while (lj <= j) { tcg_ctx.gen_opc_instr_start[lj++] = 0; } } else { tb->size = dc->pc - pc_start; tb->icount = num_insns; } #ifdef DEBUG_DISAS #if !DISAS_CRIS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { log_target_disas(env, pc_start, dc->pc - pc_start, env->pregs[PR_VR]); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); } #endif #endif }


uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM) { int64_t v; v = int64_to_float64(INT64_MIN STATUS_VAR); v = float64_to_int64_round_to_zero((a + v) STATUS_VAR); return v - INT64_MIN; }


static AHCIQState *ahci_boot(void) { AHCIQState *s; const char *cli; s = g_malloc0(sizeof(AHCIQState)); cli = "-drive if=none,id=drive0,file=%s,cache=writeback,serial=%s" ",format=raw" " -M q35 " "-device ide-hd,drive=drive0 " "-global ide-hd.ver=%s"; s->parent = qtest_pc_boot(cli, tmp_path, "testdisk", "version"); /* Verify that we have an AHCI device present. */ s->dev = get_ahci_device(&s->fingerprint); return s; }


static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, int buf_size, AVCodecContext *avctx) { HEVCParserContext *ctx = s->priv_data; HEVCContext *h = &ctx->h; GetBitContext *gb; SliceHeader *sh = &h->sh; HEVCParamSets *ps = &h->ps; HEVCPacket *pkt = &ctx->pkt; const uint8_t *buf_end = buf + buf_size; int state = -1, i; HEVCNAL *nal; int is_global = buf == avctx->extradata; if (!h->HEVClc) h->HEVClc = av_mallocz(sizeof(HEVCLocalContext)); if (!h->HEVClc) return AVERROR(ENOMEM); gb = &h->HEVClc->gb; /* set some sane default values */ s->pict_type = AV_PICTURE_TYPE_I; s->key_frame = 0; s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; h->avctx = avctx; if (!buf_size) return 0; if (pkt->nals_allocated < 1) { HEVCNAL *tmp = av_realloc_array(pkt->nals, 1, sizeof(*tmp)); if (!tmp) return AVERROR(ENOMEM); pkt->nals = tmp; memset(pkt->nals, 0, sizeof(*tmp)); pkt->nals_allocated = 1; } nal = &pkt->nals[0]; for (;;) { int src_length, consumed; buf = avpriv_find_start_code(buf, buf_end, &state); if (--buf + 2 >= buf_end) break; src_length = buf_end - buf; h->nal_unit_type = (*buf >> 1) & 0x3f; h->temporal_id = (*(buf + 1) & 0x07) - 1; if (h->nal_unit_type <= NAL_CRA_NUT) { // Do not walk the whole buffer just to decode slice segment header if (src_length > 20) src_length = 20; } consumed = ff_hevc_extract_rbsp(NULL, buf, src_length, nal); if (consumed < 0) return consumed; init_get_bits8(gb, nal->data + 2, nal->size); switch (h->nal_unit_type) { case NAL_VPS: ff_hevc_decode_nal_vps(gb, avctx, ps); break; case NAL_SPS: ff_hevc_decode_nal_sps(gb, avctx, ps, 1); break; case NAL_PPS: ff_hevc_decode_nal_pps(gb, avctx, ps); break; case NAL_SEI_PREFIX: case NAL_SEI_SUFFIX: ff_hevc_decode_nal_sei(h); break; case NAL_TRAIL_N: case NAL_TRAIL_R: case NAL_TSA_N: case NAL_TSA_R: case NAL_STSA_N: case NAL_STSA_R: case NAL_RADL_N: case NAL_RADL_R: case NAL_RASL_N: case NAL_RASL_R: case NAL_BLA_W_LP: case NAL_BLA_W_RADL: case NAL_BLA_N_LP: case NAL_IDR_W_RADL: case NAL_IDR_N_LP: case NAL_CRA_NUT: if (is_global) { av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", h->nal_unit_type); return AVERROR_INVALIDDATA; } sh->first_slice_in_pic_flag = get_bits1(gb); s->picture_structure = h->picture_struct; s->field_order = h->picture_struct; if (IS_IRAP(h)) { s->key_frame = 1; sh->no_output_of_prior_pics_flag = get_bits1(gb); } sh->pps_id = get_ue_golomb(gb); if (sh->pps_id >= MAX_PPS_COUNT || !ps->pps_list[sh->pps_id]) { av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); return AVERROR_INVALIDDATA; } ps->pps = (HEVCPPS*)ps->pps_list[sh->pps_id]->data; if (ps->pps->sps_id >= MAX_SPS_COUNT || !ps->sps_list[ps->pps->sps_id]) { av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", ps->pps->sps_id); return AVERROR_INVALIDDATA; } if (ps->sps != (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data) { ps->sps = (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data; ps->vps = (HEVCVPS*)ps->vps_list[ps->sps->vps_id]->data; } if (!sh->first_slice_in_pic_flag) { int slice_address_length; if (ps->pps->dependent_slice_segments_enabled_flag) sh->dependent_slice_segment_flag = get_bits1(gb); else sh->dependent_slice_segment_flag = 0; slice_address_length = av_ceil_log2_c(ps->sps->ctb_width * ps->sps->ctb_height); sh->slice_segment_addr = slice_address_length ? get_bits(gb, slice_address_length) : 0; if (sh->slice_segment_addr >= ps->sps->ctb_width * ps->sps->ctb_height) { av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n", sh->slice_segment_addr); return AVERROR_INVALIDDATA; } } else sh->dependent_slice_segment_flag = 0; if (sh->dependent_slice_segment_flag) break; for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++) skip_bits(gb, 1); // slice_reserved_undetermined_flag[] sh->slice_type = get_ue_golomb(gb); if (!(sh->slice_type == I_SLICE || sh->slice_type == P_SLICE || sh->slice_type == B_SLICE)) { av_log(avctx, AV_LOG_ERROR, "Unknown slice type: %d.\n", sh->slice_type); return AVERROR_INVALIDDATA; } s->pict_type = sh->slice_type == B_SLICE ? AV_PICTURE_TYPE_B : sh->slice_type == P_SLICE ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; if (ps->pps->output_flag_present_flag) sh->pic_output_flag = get_bits1(gb); if (ps->sps->separate_colour_plane_flag) sh->colour_plane_id = get_bits(gb, 2); if (!IS_IDR(h)) { sh->pic_order_cnt_lsb = get_bits(gb, ps->sps->log2_max_poc_lsb); s->output_picture_number = h->poc = ff_hevc_compute_poc(h, sh->pic_order_cnt_lsb); } else s->output_picture_number = h->poc = 0; if (h->temporal_id == 0 && h->nal_unit_type != NAL_TRAIL_N && h->nal_unit_type != NAL_TSA_N && h->nal_unit_type != NAL_STSA_N && h->nal_unit_type != NAL_RADL_N && h->nal_unit_type != NAL_RASL_N && h->nal_unit_type != NAL_RADL_R && h->nal_unit_type != NAL_RASL_R) h->pocTid0 = h->poc; return 0; /* no need to evaluate the rest */ } buf += consumed; } /* didn't find a picture! */ if (!is_global) av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n"); return -1; }


static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){ int x, y; GetBitContext *gb = &v->s.gb; for (x=0; x<width; x++){ if (!get_bits(gb, 1)) //colskip for (y=0; y<height; y++) plane[y*stride] = 0; else for (y=0; y<height; y++) plane[y*stride] = get_bits(gb, 1); plane ++; } }


gen_intermediate_code_internal (CPUState *env, TranslationBlock *tb, int search_pc) { DisasContext ctx; target_ulong pc_start; uint16_t *gen_opc_end; int j, lj = -1; if (search_pc && loglevel) fprintf (logfile, "search pc %d\n", search_pc); pc_start = tb->pc; gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; ctx.pc = pc_start; ctx.saved_pc = -1; ctx.tb = tb; ctx.bstate = BS_NONE; /* Restore delay slot state from the tb context. */ ctx.hflags = (uint32_t)tb->flags; /* FIXME: maybe use 64 bits here? */ restore_cpu_state(env, &ctx); #if defined(CONFIG_USER_ONLY) ctx.mem_idx = MIPS_HFLAG_UM; #else ctx.mem_idx = ctx.hflags & MIPS_HFLAG_KSU; #endif #ifdef DEBUG_DISAS if (loglevel & CPU_LOG_TB_CPU) { fprintf(logfile, "------------------------------------------------\n"); /* FIXME: This may print out stale hflags from env... */ cpu_dump_state(env, logfile, fprintf, 0); } #endif #ifdef MIPS_DEBUG_DISAS if (loglevel & CPU_LOG_TB_IN_ASM) fprintf(logfile, "\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags); #endif while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) { if (env->nb_breakpoints > 0) { for(j = 0; j < env->nb_breakpoints; j++) { if (env->breakpoints[j] == ctx.pc) { save_cpu_state(&ctx, 1); ctx.bstate = BS_BRANCH; gen_op_debug(); /* Include the breakpoint location or the tb won't * be flushed when it must be. */ ctx.pc += 4; goto done_generating; } } } if (search_pc) { j = gen_opc_ptr - gen_opc_buf; if (lj < j) { lj++; while (lj < j) gen_opc_instr_start[lj++] = 0; } gen_opc_pc[lj] = ctx.pc; gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK; gen_opc_instr_start[lj] = 1; } ctx.opcode = ldl_code(ctx.pc); decode_opc(env, &ctx); ctx.pc += 4; if (env->singlestep_enabled) break; if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) break; #if defined (MIPS_SINGLE_STEP) break; #endif } if (env->singlestep_enabled) { save_cpu_state(&ctx, ctx.bstate == BS_NONE); gen_op_debug(); } else { switch (ctx.bstate) { case BS_STOP: tcg_gen_helper_0_0(do_interrupt_restart); gen_goto_tb(&ctx, 0, ctx.pc); break; case BS_NONE: save_cpu_state(&ctx, 0); gen_goto_tb(&ctx, 0, ctx.pc); break; case BS_EXCP: tcg_gen_helper_0_0(do_interrupt_restart); tcg_gen_exit_tb(0); break; case BS_BRANCH: default: break; } } done_generating: *gen_opc_ptr = INDEX_op_end; if (search_pc) { j = gen_opc_ptr - gen_opc_buf; lj++; while (lj <= j) gen_opc_instr_start[lj++] = 0; } else { tb->size = ctx.pc - pc_start; } #ifdef DEBUG_DISAS #if defined MIPS_DEBUG_DISAS if (loglevel & CPU_LOG_TB_IN_ASM) fprintf(logfile, "\n"); #endif if (loglevel & CPU_LOG_TB_IN_ASM) { fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start)); target_disas(logfile, pc_start, ctx.pc - pc_start, 0); fprintf(logfile, "\n"); } if (loglevel & CPU_LOG_TB_CPU) { fprintf(logfile, "---------------- %d %08x\n", ctx.bstate, ctx.hflags); } #endif return 0; }


e1000_autoneg_timer(void *opaque) { E1000State *s = opaque; qemu_get_queue(s->nic)->link_down = false; e1000_link_up(s); s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE; DBGOUT(PHY, "Auto negotiation is completed\n"); }


blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BDRVBlkdebugState *s = bs->opaque; BlkdebugRule *rule = NULL; QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) { uint64_t inject_offset = rule->options.inject.offset; if (inject_offset == -1 || (inject_offset >= offset && inject_offset < offset + bytes)) { break; if (rule && rule->options.inject.error) { return inject_error(bs, rule); return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);


static void vc1_h_overlap_c(uint8_t* src, int stride) { int i; int a, b, c, d; int d1, d2; int rnd = 1; for(i = 0; i < 8; i++) { a = src[-2]; b = src[-1]; c = src[0]; d = src[1]; d1 = (a - d + 3 + rnd) >> 3; d2 = (a - d + b - c + 4 - rnd) >> 3; src[-2] = a - d1; src[-1] = b - d2; src[0] = c + d2; src[1] = d + d1; src += stride; rnd = !rnd; } }


int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, int n, int coded, const uint8_t *scan_table) { int level, i, last, run, run_diff; int av_uninit(dc_pred_dir); RLTable *rl; RL_VLC_ELEM *rl_vlc; int qmul, qadd; if (s->mb_intra) { qmul=1; qadd=0; /* DC coef */ level = msmpeg4_decode_dc(s, n, &dc_pred_dir); if (level < 0){ av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale); if(s->inter_intra_pred) level=0; else return -1; } if (n < 4) { rl = &ff_rl_table[s->rl_table_index]; if(level > 256*s->y_dc_scale){ av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale); if(!s->inter_intra_pred) return -1; } } else { rl = &ff_rl_table[3 + s->rl_chroma_table_index]; if(level > 256*s->c_dc_scale){ av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale); if(!s->inter_intra_pred) return -1; } } block[0] = level; run_diff = s->msmpeg4_version >= 4; i = 0; if (!coded) { goto not_coded; } if (s->ac_pred) { if (dc_pred_dir == 0) scan_table = s->intra_v_scantable.permutated; /* left */ else scan_table = s->intra_h_scantable.permutated; /* top */ } else { scan_table = s->intra_scantable.permutated; } rl_vlc= rl->rl_vlc[0]; } else { qmul = s->qscale << 1; qadd = (s->qscale - 1) | 1; i = -1; rl = &ff_rl_table[3 + s->rl_table_index]; if(s->msmpeg4_version==2) run_diff = 0; else run_diff = 1; if (!coded) { s->block_last_index[n] = i; return 0; } if(!scan_table) scan_table = s->inter_scantable.permutated; rl_vlc= rl->rl_vlc[s->qscale]; } { OPEN_READER(re, &s->gb); for(;;) { UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); if (level==0) { int cache; cache= GET_CACHE(re, &s->gb); /* escape */ if (s->msmpeg4_version==1 || (cache&0x80000000)==0) { if (s->msmpeg4_version==1 || (cache&0x40000000)==0) { /* third escape */ if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2); UPDATE_CACHE(re, &s->gb); if(s->msmpeg4_version<=3){ last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); level= SHOW_SBITS(re, &s->gb, 8); SKIP_COUNTER(re, &s->gb, 1+6+8); }else{ int sign; last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); if(!s->esc3_level_length){ int ll; av_dlog(s->avctx, "ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y); if(s->qscale<8){ ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); if(ll==0){ ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); } }else{ ll=2; while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){ ll++; SKIP_BITS(re, &s->gb, 1); } if(ll<8) SKIP_BITS(re, &s->gb, 1); } s->esc3_level_length= ll; s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2); UPDATE_CACHE(re, &s->gb); } run= SHOW_UBITS(re, &s->gb, s->esc3_run_length); SKIP_BITS(re, &s->gb, s->esc3_run_length); sign= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); level= SHOW_UBITS(re, &s->gb, s->esc3_level_length); SKIP_BITS(re, &s->gb, s->esc3_level_length); if(sign) level= -level; } #if 0 // waste of time / this will detect very few errors { const int abs_level= FFABS(level); const int run1= run - rl->max_run[last][abs_level] - run_diff; if(abs_level<=MAX_LEVEL && run<=MAX_RUN){ if(abs_level <= rl->max_level[last][run]){ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); return DECODING_AC_LOST; } if(abs_level <= rl->max_level[last][run]*2){ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); return DECODING_AC_LOST; } if(run1>=0 && abs_level <= rl->max_level[last][run1]){ av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); return DECODING_AC_LOST; } } } #endif //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ; if (level>0) level= level * qmul + qadd; else level= level * qmul - qadd; #if 0 // waste of time too :( if(level>2048 || level<-2048){ av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n"); return DECODING_AC_LOST; } #endif i+= run + 1; if(last) i+=192; #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level); #endif } else { /* second escape */ SKIP_BITS(re, &s->gb, 2); GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level); #endif } } else { /* first escape */ SKIP_BITS(re, &s->gb, 1); GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); i+= run; level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level); #endif } } else { i+= run; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); #ifdef ERROR_DETAILS if(run==66) av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level); else if((i>62 && i<192) || i>192+63) av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level); #endif } if (i > 62){ i-= 192; if(i&(~63)){ const int left= get_bits_left(&s->gb); if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && left>=0){ av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); i = 63; break; }else{ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } } block[scan_table[i]] = level; break; } block[scan_table[i]] = level; } CLOSE_READER(re, &s->gb); } not_coded: if (s->mb_intra) { ff_mpeg4_pred_ac(s, block, n, dc_pred_dir); if (s->ac_pred) { i = 63; /* XXX: not optimal */ } } if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize s->block_last_index[n] = i; return 0; }


static int svq1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; SVQ1Context *s = avctx->priv_data; AVFrame *cur = data; uint8_t *current; int result, i, x, y, width, height; svq1_pmv *pmv; /* initialize bit buffer */ init_get_bits(&s->gb, buf, buf_size * 8); /* decode frame header */ s->frame_code = get_bits(&s->gb, 22); if ((s->frame_code & ~0x70) || !(s->frame_code & 0x60)) return AVERROR_INVALIDDATA; /* swap some header bytes (why?) */ if (s->frame_code != 0x20) { uint32_t *src = (uint32_t *)(buf + 4); for (i = 0; i < 4; i++) src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; } result = svq1_decode_frame_header(avctx, cur); if (result != 0) { av_dlog(avctx, "Error in svq1_decode_frame_header %i\n", result); return result; } result = ff_set_dimensions(avctx, s->width, s->height); if (result < 0) return result; if ((avctx->skip_frame >= AVDISCARD_NONREF && s->nonref) || (avctx->skip_frame >= AVDISCARD_NONKEY && cur->pict_type != AV_PICTURE_TYPE_I) || avctx->skip_frame >= AVDISCARD_ALL) return buf_size; result = ff_get_buffer(avctx, cur, s->nonref ? 0 : AV_GET_BUFFER_FLAG_REF); if (result < 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 = cur->linesize[i]; if (i == 0) { width = FFALIGN(s->width, 16); height = FFALIGN(s->height, 16); } else { if (avctx->flags & CODEC_FLAG_GRAY) break; width = FFALIGN(s->width / 4, 16); height = FFALIGN(s->height / 4, 16); } current = cur->data[i]; if (cur->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(avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n", result); goto err; } } current += 16 * linesize; } } else { /* delta frame */ uint8_t *previous = s->prev->data[i]; if (!previous || s->prev->width != s->width || s->prev->height != s->height) { av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n"); result = AVERROR_INVALIDDATA; goto err; } 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(avctx, &s->hdsp, &s->gb, &current[x], previous, linesize, pmv, x, y, width, height); if (result != 0) { av_dlog(avctx, "Error in svq1_decode_delta_block %i\n", result); goto err; } } pmv[0].x = pmv[0].y = 0; current += 16 * linesize; } } } if (!s->nonref) { av_frame_unref(s->prev); result = av_frame_ref(s->prev, cur); if (result < 0) goto err; } *got_frame = 1; result = buf_size; err: av_free(pmv); return result; }


static void pci_get_node_name(char *nodename, int len, PCIDevice *dev) { int slot = PCI_SLOT(dev->devfn); int func = PCI_FUNC(dev->devfn); uint32_t ccode = pci_default_read_config(dev, PCI_CLASS_PROG, 3); const char *name; name = pci_find_device_name((ccode >> 16) & 0xff, (ccode >> 8) & 0xff, ccode & 0xff); if (func != 0) { snprintf(nodename, len, "%s@%x,%x", name, slot, func); } else { snprintf(nodename, len, "%s@%x", name, slot); } }


void kqemu_flush_page(CPUState *env, target_ulong addr) { LOG_INT("kqemu_flush_page: addr=" TARGET_FMT_lx "\n", addr); if (nb_pages_to_flush >= KQEMU_MAX_PAGES_TO_FLUSH) nb_pages_to_flush = KQEMU_FLUSH_ALL; else pages_to_flush[nb_pages_to_flush++] = addr; }


void helper_lcall_real_T0_T1(int shift, int next_eip) { int new_cs, new_eip; uint32_t esp, esp_mask; uint8_t *ssp; new_cs = T0; new_eip = T1; esp = env->regs[R_ESP]; esp_mask = 0xffffffff; if (!(env->segs[R_SS].flags & DESC_B_MASK)) esp_mask = 0xffff; ssp = env->segs[R_SS].base; if (shift) { esp -= 4; stl(ssp + (esp & esp_mask), env->segs[R_CS].selector); esp -= 4; stl(ssp + (esp & esp_mask), next_eip); } else { esp -= 2; stw(ssp + (esp & esp_mask), env->segs[R_CS].selector); esp -= 2; stw(ssp + (esp & esp_mask), next_eip); } if (!(env->segs[R_SS].flags & DESC_B_MASK)) env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) | (esp & 0xffff); else env->regs[R_ESP] = esp; env->eip = new_eip; env->segs[R_CS].selector = new_cs; env->segs[R_CS].base = (uint8_t *)(new_cs << 4); }


static void handle_port_owner_write(EHCIState *s, int port, uint32_t owner) { USBDevice *dev = s->ports[port].dev; uint32_t *portsc = &s->portsc[port]; uint32_t orig; if (s->companion_ports[port] == NULL) return; owner = owner & PORTSC_POWNER; orig = *portsc & PORTSC_POWNER; if (!(owner ^ orig)) { return; } if (dev) { usb_attach(&s->ports[port], NULL); } *portsc &= ~PORTSC_POWNER; *portsc |= owner; if (dev) { usb_attach(&s->ports[port], dev); } }


static void test_visitor_out_native_list_str(TestOutputVisitorData *data, const void *unused) { test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_STRING); }


PCIBus *i440fx_init(const char *host_type, const char *pci_type, PCII440FXState **pi440fx_state, int *piix3_devfn, ISABus **isa_bus, qemu_irq *pic, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, ram_addr_t below_4g_mem_size, ram_addr_t above_4g_mem_size, MemoryRegion *pci_address_space, MemoryRegion *ram_memory) { DeviceState *dev; PCIBus *b; PCIDevice *d; PCIHostState *s; PIIX3State *piix3; PCII440FXState *f; unsigned i; I440FXState *i440fx; dev = qdev_create(NULL, host_type); s = PCI_HOST_BRIDGE(dev); b = pci_bus_new(dev, NULL, pci_address_space, address_space_io, 0, TYPE_PCI_BUS); s->bus = b; object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(dev), NULL); qdev_init_nofail(dev); d = pci_create_simple(b, 0, pci_type); *pi440fx_state = I440FX_PCI_DEVICE(d); f = *pi440fx_state; f->system_memory = address_space_mem; f->pci_address_space = pci_address_space; f->ram_memory = ram_memory; i440fx = I440FX_PCI_HOST_BRIDGE(dev); i440fx->pci_hole.begin = below_4g_mem_size; i440fx->pci_hole.end = IO_APIC_DEFAULT_ADDRESS; /* setup pci memory mapping */ pc_pci_as_mapping_init(OBJECT(f), f->system_memory, f->pci_address_space); /* if *disabled* show SMRAM to all CPUs */ memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region", f->pci_address_space, 0xa0000, 0x20000); memory_region_add_subregion_overlap(f->system_memory, 0xa0000, &f->smram_region, 1); memory_region_set_enabled(&f->smram_region, true); /* smram, as seen by SMM CPUs */ memory_region_init(&f->smram, OBJECT(d), "smram", 1ull << 32); memory_region_set_enabled(&f->smram, true); memory_region_init_alias(&f->low_smram, OBJECT(d), "smram-low", f->ram_memory, 0xa0000, 0x20000); memory_region_set_enabled(&f->low_smram, true); memory_region_add_subregion(&f->smram, 0xa0000, &f->low_smram); object_property_add_const_link(qdev_get_machine(), "smram", OBJECT(&f->smram), &error_abort); init_pam(dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[0], PAM_BIOS_BASE, PAM_BIOS_SIZE); for (i = 0; i < 12; ++i) { init_pam(dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[i+1], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); } /* Xen supports additional interrupt routes from the PCI devices to * the IOAPIC: the four pins of each PCI device on the bus are also * connected to the IOAPIC directly. * These additional routes can be discovered through ACPI. */ if (xen_enabled()) { PCIDevice *pci_dev = pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"); piix3 = PIIX3_PCI_DEVICE(pci_dev); pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq, piix3, XEN_PIIX_NUM_PIRQS); } else { PCIDevice *pci_dev = pci_create_simple_multifunction(b, -1, true, "PIIX3"); piix3 = PIIX3_PCI_DEVICE(pci_dev); pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, PIIX_NUM_PIRQS); pci_bus_set_route_irq_fn(b, piix3_route_intx_pin_to_irq); } piix3->pic = pic; *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0")); *piix3_devfn = piix3->dev.devfn; ram_size = ram_size / 8 / 1024 / 1024; if (ram_size > 255) { ram_size = 255; } d->config[I440FX_COREBOOT_RAM_SIZE] = ram_size; i440fx_update_memory_mappings(f); return b; }


void qio_channel_socket_connect_async(QIOChannelSocket *ioc, SocketAddressLegacy *addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); SocketAddressLegacy *addrCopy; addrCopy = QAPI_CLONE(SocketAddressLegacy, addr); /* socket_connect() does a non-blocking connect(), but it * still blocks in DNS lookups, so we must use a thread */ trace_qio_channel_socket_connect_async(ioc, addr); qio_task_run_in_thread(task, qio_channel_socket_connect_worker, addrCopy, (GDestroyNotify)qapi_free_SocketAddressLegacy); }


static av_cold int targa_encode_close(AVCodecContext *avctx) { av_frame_free(&avctx->coded_frame); return 0; }


static int vnc_set_x509_credential_dir(VncDisplay *vs, const char *certdir) { if (vnc_set_x509_credential(vs, certdir, X509_CA_CERT_FILE, &vs->x509cacert, 0) < 0) goto cleanup; if (vnc_set_x509_credential(vs, certdir, X509_CA_CRL_FILE, &vs->x509cacrl, 1) < 0) goto cleanup; if (vnc_set_x509_credential(vs, certdir, X509_SERVER_CERT_FILE, &vs->x509cert, 0) < 0) goto cleanup; if (vnc_set_x509_credential(vs, certdir, X509_SERVER_KEY_FILE, &vs->x509key, 0) < 0) goto cleanup; return 0; cleanup: qemu_free(vs->x509cacert); qemu_free(vs->x509cacrl); qemu_free(vs->x509cert); qemu_free(vs->x509key); vs->x509cacert = vs->x509cacrl = vs->x509cert = vs->x509key = NULL; return -1; }


static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) { return shared_page->vcpu_iodata[i].vp_eport; }


int bdrv_flush_all(void) { BlockDriverState *bs = NULL; int result = 0; while ((bs = bdrv_next(bs))) { AioContext *aio_context = bdrv_get_aio_context(bs); int ret; aio_context_acquire(aio_context); ret = bdrv_flush(bs); if (ret < 0 && !result) { result = ret; } aio_context_release(aio_context); } return result; }


static inline void gen_movcf_s (int fs, int fd, int cc, int tf) { uint32_t ccbit; int cond; TCGv r_tmp1 = tcg_temp_local_new(TCG_TYPE_I32); TCGv fp0 = tcg_temp_local_new(TCG_TYPE_I32); TCGv fp1 = tcg_temp_local_new(TCG_TYPE_I32); int l1 = gen_new_label(); if (cc) ccbit = 1 << (24 + cc); else ccbit = 1 << 23; if (tf) cond = TCG_COND_EQ; else cond = TCG_COND_NE; gen_load_fpr32(fp0, fs); gen_load_fpr32(fp1, fd); tcg_gen_andi_i32(r_tmp1, fpu_fcr31, ccbit); tcg_gen_brcondi_i32(cond, r_tmp1, 0, l1); tcg_gen_mov_i32(fp1, fp0); tcg_temp_free(fp0); gen_set_label(l1); tcg_temp_free(r_tmp1); gen_store_fpr32(fp1, fd); tcg_temp_free(fp1); }


static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr, uint32_t val) { int dirty_flags; dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS]; if (!(dirty_flags & CODE_DIRTY_FLAG)) { #if !defined(CONFIG_USER_ONLY) tb_invalidate_phys_page_fast(ram_addr, 4); dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS]; #endif } stl_p(qemu_get_ram_ptr(ram_addr), val); dirty_flags |= (0xff & ~CODE_DIRTY_FLAG); phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags; /* we remove the notdirty callback only if the code has been flushed */ if (dirty_flags == 0xff) tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr); }


static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp) { BDRVQcow2State *s = bs->opaque; int flags = s->flags; QCryptoCipher *cipher = NULL; QDict *options; Error *local_err = NULL; int ret; /* * Backing files are read-only which makes all of their metadata immutable, * that means we don't have to worry about reopening them here. */ cipher = s->cipher; s->cipher = NULL; qcow2_close(bs); bdrv_invalidate_cache(bs->file->bs, &local_err); if (local_err) { error_propagate(errp, local_err); bs->drv = NULL; return; } memset(s, 0, sizeof(BDRVQcow2State)); options = qdict_clone_shallow(bs->options); flags &= ~BDRV_O_INACTIVE; ret = qcow2_open(bs, options, flags, &local_err); QDECREF(options); if (local_err) { error_propagate(errp, local_err); error_prepend(errp, "Could not reopen qcow2 layer: "); bs->drv = NULL; return; } else if (ret < 0) { error_setg_errno(errp, -ret, "Could not reopen qcow2 layer"); bs->drv = NULL; return; } s->cipher = cipher; }


static inline void gen_evmwumiaa(DisasContext *ctx) { TCGv_i64 acc; TCGv_i64 tmp; if (unlikely(!ctx->spe_enabled)) { gen_exception(ctx, POWERPC_EXCP_APU); return; } gen_evmwumi(ctx); /* rD := rA * rB */ acc = tcg_temp_new_i64(); tmp = tcg_temp_new_i64(); /* tmp := rD */ gen_load_gpr64(tmp, rD(ctx->opcode)); /* Load acc */ tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc)); /* acc := tmp + acc */ tcg_gen_add_i64(acc, acc, tmp); /* Store acc */ tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc)); /* rD := acc */ gen_store_gpr64(rD(ctx->opcode), acc); tcg_temp_free_i64(acc); tcg_temp_free_i64(tmp); }


void qemu_system_reset(void) { QEMUResetEntry *re, *nre; /* reset all devices */ TAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { re->func(re->opaque); } }


static int cpu_can_run(CPUState *env) { if (env->stop) return 0; if (env->stopped) return 0; if (!vm_running) return 0; return 1; }


static void cpu_common_parse_features(const char *typename, char *features, Error **errp) { char *featurestr; /* Single "key=value" string being parsed */ char *val; static bool cpu_globals_initialized; /* TODO: all callers of ->parse_features() need to be changed to * call it only once, so we can remove this check (or change it * to assert(!cpu_globals_initialized). * Current callers of ->parse_features() are: * - cpu_generic_init() * - cpu_x86_create() */ if (cpu_globals_initialized) { return; } cpu_globals_initialized = true; featurestr = features ? strtok(features, ",") : NULL; while (featurestr) { val = strchr(featurestr, '='); if (val) { GlobalProperty *prop = g_new0(typeof(*prop), 1); *val = 0; val++; prop->driver = typename; prop->property = g_strdup(featurestr); prop->value = g_strdup(val); prop->errp = &error_fatal; qdev_prop_register_global(prop); } else { error_setg(errp, "Expected key=value format, found %s.", featurestr); return; } featurestr = strtok(NULL, ","); } }


static void ich9_lpc_update_apic(ICH9LPCState *lpc, int gsi) { int level = 0; assert(gsi >= ICH9_LPC_PIC_NUM_PINS); level |= pci_bus_get_irq_level(lpc->d.bus, ich9_gsi_to_pirq(gsi)); if (gsi == lpc->sci_gsi) { level |= lpc->sci_level; } qemu_set_irq(lpc->gsi[gsi], level); }


static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) { SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev); uint64_t nb_sectors; uint8_t *outbuf; int buflen; switch (req->cmd.buf[0]) { case INQUIRY: case MODE_SENSE: case MODE_SENSE_10: case RESERVE: case RESERVE_10: case RELEASE: case RELEASE_10: case START_STOP: case ALLOW_MEDIUM_REMOVAL: case GET_CONFIGURATION: case GET_EVENT_STATUS_NOTIFICATION: case MECHANISM_STATUS: case REQUEST_SENSE: break; default: if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) { scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); return 0; } break; } if (!r->iov.iov_base) { /* * FIXME: we shouldn't return anything bigger than 4k, but the code * requires the buffer to be as big as req->cmd.xfer in several * places. So, do not allow CDBs with a very large ALLOCATION * LENGTH. The real fix would be to modify scsi_read_data and * dma_buf_read, so that they return data beyond the buflen * as all zeros. */ if (req->cmd.xfer > 65536) { goto illegal_request; } r->buflen = MAX(4096, req->cmd.xfer); r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen); } buflen = req->cmd.xfer; outbuf = r->iov.iov_base; switch (req->cmd.buf[0]) { case TEST_UNIT_READY: assert(!s->tray_open && bdrv_is_inserted(s->qdev.conf.bs)); break; case INQUIRY: buflen = scsi_disk_emulate_inquiry(req, outbuf); if (buflen < 0) { goto illegal_request; } break; case MODE_SENSE: case MODE_SENSE_10: buflen = scsi_disk_emulate_mode_sense(r, outbuf); if (buflen < 0) { goto illegal_request; } break; case READ_TOC: buflen = scsi_disk_emulate_read_toc(req, outbuf); if (buflen < 0) { goto illegal_request; } break; case RESERVE: if (req->cmd.buf[1] & 1) { goto illegal_request; } break; case RESERVE_10: if (req->cmd.buf[1] & 3) { goto illegal_request; } break; case RELEASE: if (req->cmd.buf[1] & 1) { goto illegal_request; } break; case RELEASE_10: if (req->cmd.buf[1] & 3) { goto illegal_request; } break; case START_STOP: if (scsi_disk_emulate_start_stop(r) < 0) { return 0; } break; case ALLOW_MEDIUM_REMOVAL: s->tray_locked = req->cmd.buf[4] & 1; bdrv_lock_medium(s->qdev.conf.bs, req->cmd.buf[4] & 1); break; case READ_CAPACITY_10: /* The normal LEN field for this command is zero. */ memset(outbuf, 0, 8); bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); if (!nb_sectors) { scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY)); return -1; } if ((req->cmd.buf[8] & 1) == 0 && req->cmd.lba) { goto illegal_request; } nb_sectors /= s->qdev.blocksize / 512; /* Returned value is the address of the last sector. */ nb_sectors--; /* Remember the new size for read/write sanity checking. */ s->qdev.max_lba = nb_sectors; /* Clip to 2TB, instead of returning capacity modulo 2TB. */ if (nb_sectors > UINT32_MAX) { nb_sectors = UINT32_MAX; } outbuf[0] = (nb_sectors >> 24) & 0xff; outbuf[1] = (nb_sectors >> 16) & 0xff; outbuf[2] = (nb_sectors >> 8) & 0xff; outbuf[3] = nb_sectors & 0xff; outbuf[4] = 0; outbuf[5] = 0; outbuf[6] = s->qdev.blocksize >> 8; outbuf[7] = 0; buflen = 8; break; case REQUEST_SENSE: /* Just return "NO SENSE". */ buflen = scsi_build_sense(NULL, 0, outbuf, r->buflen, (req->cmd.buf[1] & 1) == 0); break; case MECHANISM_STATUS: buflen = scsi_emulate_mechanism_status(s, outbuf); if (buflen < 0) { goto illegal_request; } break; case GET_CONFIGURATION: buflen = scsi_get_configuration(s, outbuf); if (buflen < 0) { goto illegal_request; } break; case GET_EVENT_STATUS_NOTIFICATION: buflen = scsi_get_event_status_notification(s, r, outbuf); if (buflen < 0) { goto illegal_request; } break; case READ_DISC_INFORMATION: buflen = scsi_read_disc_information(s, r, outbuf); if (buflen < 0) { goto illegal_request; } break; case READ_DVD_STRUCTURE: buflen = scsi_read_dvd_structure(s, r, outbuf); if (buflen < 0) { goto illegal_request; } break; case SERVICE_ACTION_IN_16: /* Service Action In subcommands. */ if ((req->cmd.buf[1] & 31) == SAI_READ_CAPACITY_16) { DPRINTF("SAI READ CAPACITY(16)\n"); memset(outbuf, 0, req->cmd.xfer); bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); if (!nb_sectors) { scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY)); return -1; } if ((req->cmd.buf[14] & 1) == 0 && req->cmd.lba) { goto illegal_request; } nb_sectors /= s->qdev.blocksize / 512; /* Returned value is the address of the last sector. */ nb_sectors--; /* Remember the new size for read/write sanity checking. */ s->qdev.max_lba = nb_sectors; outbuf[0] = (nb_sectors >> 56) & 0xff; outbuf[1] = (nb_sectors >> 48) & 0xff; outbuf[2] = (nb_sectors >> 40) & 0xff; outbuf[3] = (nb_sectors >> 32) & 0xff; outbuf[4] = (nb_sectors >> 24) & 0xff; outbuf[5] = (nb_sectors >> 16) & 0xff; outbuf[6] = (nb_sectors >> 8) & 0xff; outbuf[7] = nb_sectors & 0xff; outbuf[8] = 0; outbuf[9] = 0; outbuf[10] = s->qdev.blocksize >> 8; outbuf[11] = 0; outbuf[12] = 0; outbuf[13] = get_physical_block_exp(&s->qdev.conf); /* set TPE bit if the format supports discard */ if (s->qdev.conf.discard_granularity) { outbuf[14] = 0x80; } /* Protection, exponent and lowest lba field left blank. */ buflen = req->cmd.xfer; break; } DPRINTF("Unsupported Service Action In\n"); goto illegal_request; case SYNCHRONIZE_CACHE: /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); bdrv_acct_start(s->qdev.conf.bs, &r->acct, 0, BDRV_ACCT_FLUSH); r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r); return 0; case SEEK_10: DPRINTF("Seek(10) (sector %" PRId64 ")\n", r->req.cmd.lba); if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } break; case MODE_SELECT: DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer); /* We don't support mode parameter changes. Allow the mode parameter header + block descriptors only. */ if (r->req.cmd.xfer > 12) { goto illegal_request; } break; case MODE_SELECT_10: DPRINTF("Mode Select(10) (len %lu)\n", (long)r->req.cmd.xfer); /* We don't support mode parameter changes. Allow the mode parameter header + block descriptors only. */ if (r->req.cmd.xfer > 16) { goto illegal_request; } break; case WRITE_SAME_10: nb_sectors = lduw_be_p(&req->cmd.buf[7]); goto write_same; case WRITE_SAME_16: nb_sectors = ldl_be_p(&req->cmd.buf[10]) & 0xffffffffULL; write_same: if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } /* * We only support WRITE SAME with the unmap bit set for now. */ if (!(req->cmd.buf[1] & 0x8)) { goto illegal_request; } /* The request is used as the AIO opaque value, so add a ref. */ scsi_req_ref(&r->req); r->req.aiocb = bdrv_aio_discard(s->qdev.conf.bs, r->req.cmd.lba * (s->qdev.blocksize / 512), nb_sectors * (s->qdev.blocksize / 512), scsi_aio_complete, r); return 0; default: DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]); scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE)); return 0; } assert(!r->req.aiocb); r->iov.iov_len = MIN(buflen, req->cmd.xfer); if (r->iov.iov_len == 0) { scsi_req_complete(&r->req, GOOD); } if (r->req.cmd.mode == SCSI_XFER_TO_DEV) { assert(r->iov.iov_len == req->cmd.xfer); return -r->iov.iov_len; } else { return r->iov.iov_len; } illegal_request: if (r->req.status == -1) { scsi_check_condition(r, SENSE_CODE(INVALID_FIELD)); } return 0; illegal_lba: scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE)); return 0; }


static void qmp_input_start_list(Visitor *v, const char *name, GenericList **list, size_t size, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true, errp); const QListEntry *entry; if (!qobj) { return; } if (qobject_type(qobj) != QTYPE_QLIST) { if (list) { *list = NULL; } error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "list"); return; } entry = qmp_input_push(qiv, qobj, list, errp); if (list) { if (entry) { *list = g_malloc0(size); } else { *list = NULL; } } }


static int pci_e1000_init(PCIDevice *pci_dev) { E1000State *d = DO_UPCAST(E1000State, dev, pci_dev); uint8_t *pci_conf; uint16_t checksum = 0; int i; uint8_t *macaddr; pci_conf = d->dev.config; pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); pci_config_set_device_id(pci_conf, E1000_DEVID); *(uint16_t *)(pci_conf+0x04) = cpu_to_le16(0x0407); *(uint16_t *)(pci_conf+0x06) = cpu_to_le16(0x0010); pci_conf[0x08] = 0x03; pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET); pci_conf[0x0c] = 0x10; pci_conf[0x3d] = 1; // interrupt pin 0 d->mmio_index = cpu_register_io_memory(e1000_mmio_read, e1000_mmio_write, d); pci_register_bar((PCIDevice *)d, 0, PNPMMIO_SIZE, PCI_ADDRESS_SPACE_MEM, e1000_mmio_map); pci_register_bar((PCIDevice *)d, 1, IOPORT_SIZE, PCI_ADDRESS_SPACE_IO, ioport_map); memmove(d->eeprom_data, e1000_eeprom_template, sizeof e1000_eeprom_template); qemu_macaddr_default_if_unset(&d->conf.macaddr); macaddr = d->conf.macaddr.a; for (i = 0; i < 3; i++) d->eeprom_data[i] = (macaddr[2*i+1]<<8) | macaddr[2*i]; for (i = 0; i < EEPROM_CHECKSUM_REG; i++) checksum += d->eeprom_data[i]; checksum = (uint16_t) EEPROM_SUM - checksum; d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum; d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, d->conf.vlan, d->conf.peer, d->dev.qdev.info->name, d->dev.qdev.id, e1000_can_receive, e1000_receive, NULL, NULL, e1000_cleanup, d); d->vc->link_status_changed = e1000_set_link_status; qemu_format_nic_info_str(d->vc, macaddr); vmstate_register(-1, &vmstate_e1000, d); e1000_reset(d); #if 0 /* rom bev support is broken -> can't load unconditionally */ if (!pci_dev->qdev.hotplugged) { static int loaded = 0; if (!loaded) { rom_add_option("pxe-e1000.bin"); loaded = 1; } } #endif return 0; }


void qemu_clock_notify(QEMUClockType type) { QEMUTimerList *timer_list; QEMUClock *clock = qemu_clock_ptr(type); QLIST_FOREACH(timer_list, &clock->timerlists, list) { timerlist_notify(timer_list); } }


static void backward_filter(RA288Context *ractx) { float temp1[37]; // RTMP in the spec float temp2[11]; // GPTPMP in the spec do_hybrid_window(36, 40, 35, ractx->sp_block, temp1, ractx->sp_hist, ractx->sp_rec, syn_window); if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36)) colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36); do_hybrid_window(10, 8, 20, ractx->gain_block, temp2, ractx->gain_hist, ractx->gain_rec, gain_window); if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10)) colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10); }


int target_mprotect(abi_ulong start, abi_ulong len, int prot) { abi_ulong end, host_start, host_end, addr; int prot1, ret; #ifdef DEBUG_MMAP printf("mprotect: start=0x" TARGET_FMT_lx "len=0x" TARGET_FMT_lx " prot=%c%c%c\n", start, len, prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); #endif if ((start & ~TARGET_PAGE_MASK) != 0) return -EINVAL; len = TARGET_PAGE_ALIGN(len); end = start + len; if (end < start) return -EINVAL; if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) return -EINVAL; if (len == 0) return 0; host_start = start & qemu_host_page_mask; host_end = HOST_PAGE_ALIGN(end); if (start > host_start) { /* handle host page containing start */ prot1 = prot; for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } if (host_end == host_start + qemu_host_page_size) { for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } end = host_end; } ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS); if (ret != 0) return ret; host_start += qemu_host_page_size; } if (end < host_end) { prot1 = prot; for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size, prot1 & PAGE_BITS); if (ret != 0) return ret; host_end -= qemu_host_page_size; } /* handle the pages in the middle */ if (host_start < host_end) { ret = mprotect(g2h(host_start), host_end - host_start, prot); if (ret != 0) return ret; } page_set_flags(start, start + len, prot | PAGE_VALID); return 0; }


static int local_open(FsContext *ctx, V9fsPath *fs_path, int flags, V9fsFidOpenState *fs) { char buffer[PATH_MAX]; char *path = fs_path->data; fs->fd = open(rpath(ctx, path, buffer), flags | O_NOFOLLOW); return fs->fd; }


void qmp_block_commit(const char *device, bool has_base, const char *base, bool has_top, const char *top, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, Error **errp) { BlockDriverState *bs; BlockDriverState *base_bs, *top_bs; Error *local_err = NULL; /* This will be part of the QMP command, if/when the * BlockdevOnError change for blkmirror makes it in */ BlockdevOnError on_error = BLOCKDEV_ON_ERROR_REPORT; if (!has_speed) { speed = 0; } /* drain all i/o before commits */ bdrv_drain_all(); /* Important Note: * libvirt relies on the DeviceNotFound error class in order to probe for * live commit feature versions; for this to work, we must make sure to * perform the device lookup before any generic errors that may occur in a * scenario in which all optional arguments are omitted. */ bs = bdrv_find(device); if (!bs) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, errp)) { return; } /* default top_bs is the active layer */ top_bs = bs; if (has_top && top) { if (strcmp(bs->filename, top) != 0) { top_bs = bdrv_find_backing_image(bs, top); } } if (top_bs == NULL) { error_setg(errp, "Top image file %s not found", top ? top : "NULL"); return; } if (has_base && base) { base_bs = bdrv_find_backing_image(top_bs, base); } else { base_bs = bdrv_find_base(top_bs); } if (base_bs == NULL) { error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL"); return; } /* Do not allow attempts to commit an image into itself */ if (top_bs == base_bs) { error_setg(errp, "cannot commit an image into itself"); return; } if (top_bs == bs) { if (has_backing_file) { error_setg(errp, "'backing-file' specified," " but 'top' is the active layer"); return; } commit_active_start(bs, base_bs, speed, on_error, block_job_cb, bs, &local_err); } else { commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs, has_backing_file ? backing_file : NULL, &local_err); } if (local_err != NULL) { error_propagate(errp, local_err); return; } }


void do_commit(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); BlockDriverState *bs; if (!strcmp(device, "all")) { bdrv_commit_all(); } else { bs = bdrv_find(device); if (!bs) { qerror_report(QERR_DEVICE_NOT_FOUND, device); return; } bdrv_commit(bs); } }


static QmpOutputVisitor *to_qov(Visitor *v) { return container_of(v, QmpOutputVisitor, visitor); }


static void avc_loopfilter_luma_intra_edge_ver_msa(uint8_t *data, uint8_t alpha_in, uint8_t beta_in, uint32_t img_width) { uint8_t *src; v16u8 alpha, beta, p0_asub_q0; v16u8 is_less_than_alpha, is_less_than; v16u8 is_less_than_beta, negate_is_less_than_beta; v8i16 p2_r = { 0 }; v8i16 p1_r = { 0 }; v8i16 p0_r = { 0 }; v8i16 q0_r = { 0 }; v8i16 q1_r = { 0 }; v8i16 q2_r = { 0 }; v8i16 p2_l = { 0 }; v8i16 p1_l = { 0 }; v8i16 p0_l = { 0 }; v8i16 q0_l = { 0 }; v8i16 q1_l = { 0 }; v8i16 q2_l = { 0 }; v16u8 p3_org, p2_org, p1_org, p0_org, q0_org, q1_org, q2_org, q3_org; v8i16 p1_org_r, p0_org_r, q0_org_r, q1_org_r; v8i16 p1_org_l, p0_org_l, q0_org_l, q1_org_l; v16i8 zero = { 0 }; v16u8 tmp_flag; src = data - 4; { v16u8 row0, row1, row2, row3, row4, row5, row6, row7; v16u8 row8, row9, row10, row11, row12, row13, row14, row15; LOAD_8VECS_UB(src, img_width, row0, row1, row2, row3, row4, row5, row6, row7); LOAD_8VECS_UB(src + (8 * img_width), img_width, row8, row9, row10, row11, row12, row13, row14, row15); TRANSPOSE16x8_B_UB(row0, row1, row2, row3, row4, row5, row6, row7, row8, row9, row10, row11, row12, row13, row14, row15, p3_org, p2_org, p1_org, p0_org, q0_org, q1_org, q2_org, q3_org); } p1_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p1_org); p0_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p0_org); q0_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q0_org); q1_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q1_org); p1_org_l = (v8i16) __msa_ilvl_b(zero, (v16i8) p1_org); p0_org_l = (v8i16) __msa_ilvl_b(zero, (v16i8) p0_org); q0_org_l = (v8i16) __msa_ilvl_b(zero, (v16i8) q0_org); q1_org_l = (v8i16) __msa_ilvl_b(zero, (v16i8) q1_org); /* if ( ((unsigned)ABS(p0-q0) < thresholds->alpha_in) && ((unsigned)ABS(p1-p0) < thresholds->beta_in) && ((unsigned)ABS(q1-q0) < thresholds->beta_in) ) */ { v16u8 p1_asub_p0, q1_asub_q0; p0_asub_q0 = __msa_asub_u_b(p0_org, q0_org); p1_asub_p0 = __msa_asub_u_b(p1_org, p0_org); q1_asub_q0 = __msa_asub_u_b(q1_org, q0_org); alpha = (v16u8) __msa_fill_b(alpha_in); beta = (v16u8) __msa_fill_b(beta_in); is_less_than_alpha = (p0_asub_q0 < alpha); is_less_than_beta = (p1_asub_p0 < beta); is_less_than = is_less_than_beta & is_less_than_alpha; is_less_than_beta = (q1_asub_q0 < beta); is_less_than = is_less_than_beta & is_less_than; } if (!__msa_test_bz_v(is_less_than)) { tmp_flag = alpha >> 2; tmp_flag = tmp_flag + 2; tmp_flag = (p0_asub_q0 < tmp_flag); { v16u8 p2_asub_p0; p2_asub_p0 = __msa_asub_u_b(p2_org, p0_org); is_less_than_beta = (p2_asub_p0 < beta); } is_less_than_beta = tmp_flag & is_less_than_beta; negate_is_less_than_beta = __msa_xori_b(is_less_than_beta, 0xff); is_less_than_beta = is_less_than_beta & is_less_than; negate_is_less_than_beta = negate_is_less_than_beta & is_less_than; /* right */ { v16u8 is_less_than_beta_r; is_less_than_beta_r = (v16u8) __msa_sldi_b((v16i8) is_less_than_beta, zero, 8); if (!__msa_test_bz_v(is_less_than_beta_r)) { v8i16 p3_org_r; p3_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p3_org); p2_r = (v8i16) __msa_ilvr_b(zero, (v16i8) p2_org); AVC_LOOP_FILTER_P0P1P2_OR_Q0Q1Q2(p3_org_r, p0_org_r, q0_org_r, p1_org_r, p2_r, q1_org_r, p0_r, p1_r, p2_r); } } /* left */ { v16u8 is_less_than_beta_l; is_less_than_beta_l = (v16u8) __msa_sldi_b(zero, (v16i8) is_less_than_beta, 8); if (!__msa_test_bz_v(is_less_than_beta_l)) { v8i16 p3_org_l; p3_org_l = (v8i16) __msa_ilvl_b(zero, (v16i8) p3_org); p2_l = (v8i16) __msa_ilvl_b(zero, (v16i8) p2_org); AVC_LOOP_FILTER_P0P1P2_OR_Q0Q1Q2(p3_org_l, p0_org_l, q0_org_l, p1_org_l, p2_l, q1_org_l, p0_l, p1_l, p2_l); } } /* combine and store */ if (!__msa_test_bz_v(is_less_than_beta)) { v16u8 p0, p2, p1; p0 = (v16u8) __msa_pckev_b((v16i8) p0_l, (v16i8) p0_r); p1 = (v16u8) __msa_pckev_b((v16i8) p1_l, (v16i8) p1_r); p2 = (v16u8) __msa_pckev_b((v16i8) p2_l, (v16i8) p2_r); p0_org = __msa_bmnz_v(p0_org, p0, is_less_than_beta); p1_org = __msa_bmnz_v(p1_org, p1, is_less_than_beta); p2_org = __msa_bmnz_v(p2_org, p2, is_less_than_beta); } /* right */ { v16u8 negate_is_less_than_beta_r; negate_is_less_than_beta_r = (v16u8) __msa_sldi_b((v16i8) negate_is_less_than_beta, zero, 8); if (!__msa_test_bz_v(negate_is_less_than_beta_r)) { AVC_LOOP_FILTER_P0_OR_Q0(p0_org_r, q1_org_r, p1_org_r, p0_r); } } /* left */ { v16u8 negate_is_less_than_beta_l; negate_is_less_than_beta_l = (v16u8) __msa_sldi_b(zero, (v16i8) negate_is_less_than_beta, 8); if (!__msa_test_bz_v(negate_is_less_than_beta_l)) { AVC_LOOP_FILTER_P0_OR_Q0(p0_org_l, q1_org_l, p1_org_l, p0_l); } } if (!__msa_test_bz_v(negate_is_less_than_beta)) { v16u8 p0; p0 = (v16u8) __msa_pckev_b((v16i8) p0_l, (v16i8) p0_r); p0_org = __msa_bmnz_v(p0_org, p0, negate_is_less_than_beta); } { v16u8 q2_asub_q0; q2_asub_q0 = __msa_asub_u_b(q2_org, q0_org); is_less_than_beta = (q2_asub_q0 < beta); } is_less_than_beta = is_less_than_beta & tmp_flag; negate_is_less_than_beta = __msa_xori_b(is_less_than_beta, 0xff); is_less_than_beta = is_less_than_beta & is_less_than; negate_is_less_than_beta = negate_is_less_than_beta & is_less_than; /* right */ { v16u8 is_less_than_beta_r; is_less_than_beta_r = (v16u8) __msa_sldi_b((v16i8) is_less_than_beta, zero, 8); if (!__msa_test_bz_v(is_less_than_beta_r)) { v8i16 q3_org_r; q3_org_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q3_org); q2_r = (v8i16) __msa_ilvr_b(zero, (v16i8) q2_org); AVC_LOOP_FILTER_P0P1P2_OR_Q0Q1Q2(q3_org_r, q0_org_r, p0_org_r, q1_org_r, q2_r, p1_org_r, q0_r, q1_r, q2_r); } } /* left */ { v16u8 is_less_than_beta_l; is_less_than_beta_l = (v16u8) __msa_sldi_b(zero, (v16i8) is_less_than_beta, 8); if (!__msa_test_bz_v(is_less_than_beta_l)) { v8i16 q3_org_l; q3_org_l = (v8i16) __msa_ilvl_b(zero, (v16i8) q3_org); q2_l = (v8i16) __msa_ilvl_b(zero, (v16i8) q2_org); AVC_LOOP_FILTER_P0P1P2_OR_Q0Q1Q2(q3_org_l, q0_org_l, p0_org_l, q1_org_l, q2_l, p1_org_l, q0_l, q1_l, q2_l); } } /* combine and store */ if (!__msa_test_bz_v(is_less_than_beta)) { v16u8 q0, q1, q2; q0 = (v16u8) __msa_pckev_b((v16i8) q0_l, (v16i8) q0_r); q1 = (v16u8) __msa_pckev_b((v16i8) q1_l, (v16i8) q1_r); q2 = (v16u8) __msa_pckev_b((v16i8) q2_l, (v16i8) q2_r); q0_org = __msa_bmnz_v(q0_org, q0, is_less_than_beta); q1_org = __msa_bmnz_v(q1_org, q1, is_less_than_beta); q2_org = __msa_bmnz_v(q2_org, q2, is_less_than_beta); } /* right */ { v16u8 negate_is_less_than_beta_r; negate_is_less_than_beta_r = (v16u8) __msa_sldi_b((v16i8) negate_is_less_than_beta, zero, 8); if (!__msa_test_bz_v(negate_is_less_than_beta_r)) { AVC_LOOP_FILTER_P0_OR_Q0(q0_org_r, p1_org_r, q1_org_r, q0_r); } } /* left */ { v16u8 negate_is_less_than_beta_l; negate_is_less_than_beta_l = (v16u8) __msa_sldi_b(zero, (v16i8) negate_is_less_than_beta, 8); if (!__msa_test_bz_v(negate_is_less_than_beta_l)) { AVC_LOOP_FILTER_P0_OR_Q0(q0_org_l, p1_org_l, q1_org_l, q0_l); } } if (!__msa_test_bz_v(negate_is_less_than_beta)) { v16u8 q0; q0 = (v16u8) __msa_pckev_b((v16i8) q0_l, (v16i8) q0_r); q0_org = __msa_bmnz_v(q0_org, q0, negate_is_less_than_beta); } } { v16u8 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; uint32_t out0, out2; uint16_t out1, out3; tmp0 = (v16u8) __msa_ilvr_b((v16i8) p1_org, (v16i8) p2_org); tmp1 = (v16u8) __msa_ilvr_b((v16i8) q0_org, (v16i8) p0_org); tmp2 = (v16u8) __msa_ilvr_b((v16i8) q2_org, (v16i8) q1_org); tmp3 = (v16u8) __msa_ilvr_h((v8i16) tmp1, (v8i16) tmp0); tmp4 = (v16u8) __msa_ilvl_h((v8i16) tmp1, (v8i16) tmp0); tmp0 = (v16u8) __msa_ilvl_b((v16i8) p1_org, (v16i8) p2_org); tmp1 = (v16u8) __msa_ilvl_b((v16i8) q0_org, (v16i8) p0_org); tmp5 = (v16u8) __msa_ilvl_b((v16i8) q2_org, (v16i8) q1_org); tmp6 = (v16u8) __msa_ilvr_h((v8i16) tmp1, (v8i16) tmp0); tmp7 = (v16u8) __msa_ilvl_h((v8i16) tmp1, (v8i16) tmp0); src = data - 3; out0 = __msa_copy_u_w((v4i32) tmp3, 0); out1 = __msa_copy_u_h((v8i16) tmp2, 0); out2 = __msa_copy_u_w((v4i32) tmp3, 1); out3 = __msa_copy_u_h((v8i16) tmp2, 1); STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp3, 2); out1 = __msa_copy_u_h((v8i16) tmp2, 2); out2 = __msa_copy_u_w((v4i32) tmp3, 3); out3 = __msa_copy_u_h((v8i16) tmp2, 3); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp4, 0); out1 = __msa_copy_u_h((v8i16) tmp2, 4); out2 = __msa_copy_u_w((v4i32) tmp4, 1); out3 = __msa_copy_u_h((v8i16) tmp2, 5); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp4, 2); out1 = __msa_copy_u_h((v8i16) tmp2, 6); out2 = __msa_copy_u_w((v4i32) tmp4, 3); out3 = __msa_copy_u_h((v8i16) tmp2, 7); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp6, 0); out1 = __msa_copy_u_h((v8i16) tmp5, 0); out2 = __msa_copy_u_w((v4i32) tmp6, 1); out3 = __msa_copy_u_h((v8i16) tmp5, 1); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp6, 2); out1 = __msa_copy_u_h((v8i16) tmp5, 2); out2 = __msa_copy_u_w((v4i32) tmp6, 3); out3 = __msa_copy_u_h((v8i16) tmp5, 3); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp7, 0); out1 = __msa_copy_u_h((v8i16) tmp5, 4); out2 = __msa_copy_u_w((v4i32) tmp7, 1); out3 = __msa_copy_u_h((v8i16) tmp5, 5); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); out0 = __msa_copy_u_w((v4i32) tmp7, 2); out1 = __msa_copy_u_h((v8i16) tmp5, 6); out2 = __msa_copy_u_w((v4i32) tmp7, 3); out3 = __msa_copy_u_h((v8i16) tmp5, 7); src += img_width; STORE_WORD(src, out0); STORE_HWORD((src + 4), out1); src += img_width; STORE_WORD(src, out2); STORE_HWORD((src + 4), out3); } }


static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) { struct dshow_ctx *ctx = s->priv_data; AVPacketList *pktl = NULL; while (!pktl) { WaitForSingleObject(ctx->mutex, INFINITE); pktl = ctx->pktl; if (pktl) { *pkt = pktl->pkt; ctx->pktl = ctx->pktl->next; av_free(pktl); ctx->curbufsize -= pkt->size; } ResetEvent(ctx->event); ReleaseMutex(ctx->mutex); if (!pktl) { if (s->flags & AVFMT_FLAG_NONBLOCK) { return AVERROR(EAGAIN); } else { WaitForSingleObject(ctx->event, INFINITE); } } } return pkt->size; }


static void blend_image(AVFilterContext *ctx, AVFilterBufferRef *dst, AVFilterBufferRef *src, int x, int y) { OverlayContext *over = ctx->priv; int i, j, k; int width = src->video->w; int height = src->video->h; if (over->main_is_packed_rgb) { uint8_t *dp = dst->data[0] + x * over->main_pix_step[0] + y * dst->linesize[0]; uint8_t *sp = src->data[0]; uint8_t alpha; ///< the amount of overlay to blend on to main const int dr = over->main_rgba_map[R]; const int dg = over->main_rgba_map[G]; const int db = over->main_rgba_map[B]; const int da = over->main_rgba_map[A]; const int dstep = over->main_pix_step[0]; const int sr = over->overlay_rgba_map[R]; const int sg = over->overlay_rgba_map[G]; const int sb = over->overlay_rgba_map[B]; const int sa = over->overlay_rgba_map[A]; const int sstep = over->overlay_pix_step[0]; const int main_has_alpha = over->main_has_alpha; for (i = 0; i < height; i++) { uint8_t *d = dp, *s = sp; for (j = 0; j < width; j++) { alpha = s[sa]; // if the main channel has an alpha channel, alpha has to be calculated // to create an un-premultiplied (straight) alpha value if (main_has_alpha && alpha != 0 && alpha != 255) { uint8_t alpha_d = d[da]; alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d); } switch (alpha) { case 0: break; case 255: d[dr] = s[sr]; d[dg] = s[sg]; d[db] = s[sb]; break; default: // main_value = main_value * (1 - alpha) + overlay_value * alpha // since alpha is in the range 0-255, the result must divided by 255 d[dr] = FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha); d[dg] = FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha); d[db] = FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha); } if (main_has_alpha) { switch (alpha) { case 0: break; case 255: d[da] = s[sa]; break; default: // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha d[da] += FAST_DIV255((255 - d[da]) * s[sa]); } } d += dstep; s += sstep; } dp += dst->linesize[0]; sp += src->linesize[0]; } } else { const int main_has_alpha = over->main_has_alpha; if (main_has_alpha) { uint8_t *da = dst->data[3] + x * over->main_pix_step[3] + y * dst->linesize[3]; uint8_t *sa = src->data[3]; uint8_t alpha; ///< the amount of overlay to blend on to main for (i = 0; i < height; i++) { uint8_t *d = da, *s = sa; for (j = 0; j < width; j++) { alpha = *s; if (alpha != 0 && alpha != 255) { uint8_t alpha_d = *d; alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d); } switch (alpha) { case 0: break; case 255: *d = *s; break; default: // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha *d += FAST_DIV255((255 - *d) * *s); } d += 1; s += 1; } da += dst->linesize[3]; sa += src->linesize[3]; } } for (i = 0; i < 3; i++) { int hsub = i ? over->hsub : 0; int vsub = i ? over->vsub : 0; uint8_t *dp = dst->data[i] + (x >> hsub) + (y >> vsub) * dst->linesize[i]; uint8_t *sp = src->data[i]; uint8_t *ap = src->data[3]; int wp = FFALIGN(width, 1<<hsub) >> hsub; int hp = FFALIGN(height, 1<<vsub) >> vsub; for (j = 0; j < hp; j++) { uint8_t *d = dp, *s = sp, *a = ap; for (k = 0; k < wp; k++) { // average alpha for color components, improve quality int alpha_v, alpha_h, alpha; if (hsub && vsub && j+1 < hp && k+1 < wp) { alpha = (a[0] + a[src->linesize[3]] + a[1] + a[src->linesize[3]+1]) >> 2; } else if (hsub || vsub) { alpha_h = hsub && k+1 < wp ? (a[0] + a[1]) >> 1 : a[0]; alpha_v = vsub && j+1 < hp ? (a[0] + a[src->linesize[3]]) >> 1 : a[0]; alpha = (alpha_v + alpha_h) >> 1; } else alpha = a[0]; // if the main channel has an alpha channel, alpha has to be calculated // to create an un-premultiplied (straight) alpha value if (main_has_alpha && alpha != 0 && alpha != 255) { // average alpha for color components, improve quality uint8_t alpha_d; if (hsub && vsub && j+1 < hp && k+1 < wp) { alpha_d = (d[0] + d[src->linesize[3]] + d[1] + d[src->linesize[3]+1]) >> 2; } else if (hsub || vsub) { alpha_h = hsub && k+1 < wp ? (d[0] + d[1]) >> 1 : d[0]; alpha_v = vsub && j+1 < hp ? (d[0] + d[src->linesize[3]]) >> 1 : d[0]; alpha_d = (alpha_v + alpha_h) >> 1; } else alpha_d = d[0]; alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d); } *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha); s++; d++; a += 1 << hsub; } dp += dst->linesize[i]; sp += src->linesize[i]; ap += (1 << vsub) * src->linesize[3]; } } } }


static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, int64_t pts) { MBContext *mb = ctx->priv; int x,y,i, in_cidx=0, next_cidx=0, tmp_cidx; double scale= mb->start_scale*pow(mb->end_scale/mb->start_scale, pts/mb->end_pts); int use_zyklus=0; fill_from_cache(ctx, NULL, &in_cidx, NULL, mb->start_y+scale*(-mb->h/2-0.5), scale); for(y=0; y<mb->h; y++){ const double ci=mb->start_y+scale*(y-mb->h/2); memset(color+linesize*y, 0, sizeof(*color)*mb->w); fill_from_cache(ctx, color+linesize*y, &in_cidx, &next_cidx, ci, scale); tmp_cidx= in_cidx; fill_from_cache(ctx, color+linesize*y, &tmp_cidx, NULL, ci + scale/2, scale); for(x=0; x<mb->w; x++){ const double cr=mb->start_x+scale*(x-mb->w/2); double zr=cr; double zi=ci; uint32_t c=0; double dv= mb->dither / (double)(1LL<<32); mb->dither= mb->dither*1664525+1013904223; if(color[x + y*linesize] & 0xFF000000) continue; use_zyklus= (x==0 || mb->inner!=BLACK ||color[x-1 + y*linesize] == 0xFF000000); #define Z_Z2_C(outr,outi,inr,ini)\ outr= inr*inr - ini*ini + cr;\ outi= 2*inr*ini + ci; #define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\ Z_Z2_C(outr,outi,inr,ini)\ if(use_zyklus){\ if(Z && mb->zyklus[i>>1][0]==outr && mb->zyklus[i>>1][1]==outi)\ break;\ mb->zyklus[i][0]= outr;\ mb->zyklus[i][1]= outi;\ } for(i=0; i<mb->maxiter-8; i++){ double t; Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) i++; Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) i++; Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) i++; Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) i++; Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) i++; Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) i++; Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) i++; Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) if(zr*zr + zi*zi > mb->bailout){ i-= FFMIN(7, i); for(; i<mb->maxiter; i++){ zr= mb->zyklus[i][0]; zi= mb->zyklus[i][1]; if(zr*zr + zi*zi > mb->bailout){ switch(mb->outer){ case ITERATION_COUNT: zr = i; break; case NORMALIZED_ITERATION_COUNT: zr= i + log2(log(mb->bailout) / log(zr*zr + zi*zi)); break; } c= lrintf((sin(zr)+1)*127) + lrintf((sin(zr/1.234)+1)*127)*256*256 + lrintf((sin(zr/100)+1)*127)*256; break; } } break; } } if(!c){ if(mb->inner==PERIOD){ int j; for(j=i-1; j; j--) if(SQR(mb->zyklus[j][0]-zr) + SQR(mb->zyklus[j][1]-zi) < 0.0000000000000001) break; if(j){ c= i-j; c= ((c<<5)&0xE0) + ((c<<16)&0xE000) + ((c<<27)&0xE00000); } }else if(mb->inner==CONVTIME){ c= floor(i*255.0/mb->maxiter+dv)*0x010101; } else if(mb->inner==MINCOL){ int j; double closest=9999; int closest_index=0; for(j=i-1; j>=0; j--) if(SQR(mb->zyklus[j][0]) + SQR(mb->zyklus[j][1]) < closest){ closest= SQR(mb->zyklus[j][0]) + SQR(mb->zyklus[j][1]); closest_index= j; } closest = sqrt(closest); c= lrintf((mb->zyklus[closest_index][0]/closest+1)*127+dv) + lrintf((mb->zyklus[closest_index][1]/closest+1)*127+dv)*256; } } c |= 0xFF000000; color[x + y*linesize]= c; if(next_cidx < mb->cache_allocated){ mb->next_cache[next_cidx ].p[0]= cr; mb->next_cache[next_cidx ].p[1]= ci; mb->next_cache[next_cidx++].val = c; } } fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci + scale/2, scale); } FFSWAP(void*, mb->next_cache, mb->point_cache); mb->cache_used = next_cidx; if(mb->cache_used == mb->cache_allocated) av_log(0, AV_LOG_INFO, "Mandelbrot cache is too small!\n"); }


static void opt_mb_qmax(const char *arg) { video_mb_qmax = atoi(arg); if (video_mb_qmax < 0 || video_mb_qmax > 31) { fprintf(stderr, "qmax must be >= 1 and <= 31\n"); exit(1); } }


static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque) { BDRVRawState *s = bs->opaque; RawAIOCB *acb; if (fd_open(bs) < 0) return NULL; acb = qemu_aio_get(bs, cb, opaque); if (!acb) return NULL; acb->fd = raw_fd_pool_get(s); acb->aiocb.aio_fildes = acb->fd; acb->aiocb.aio_sigevent.sigev_signo = SIGUSR2; acb->aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL; acb->aiocb.aio_buf = buf; if (nb_sectors < 0) acb->aiocb.aio_nbytes = -nb_sectors; else acb->aiocb.aio_nbytes = nb_sectors * 512; acb->aiocb.aio_offset = sector_num * 512; acb->next = posix_aio_state->first_aio; posix_aio_state->first_aio = acb; return acb; }


static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty) { TPMTISEmuState *tis = &s->s.tis; uint32_t ret = TPM_TIS_NO_DATA_BYTE; uint16_t len; if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { len = tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); ret = tis->loc[locty].r_buffer.buffer[tis->loc[locty].r_offset++]; if (tis->loc[locty].r_offset >= len) { /* got last byte */ tis->loc[locty].sts = TPM_TIS_STS_VALID; #ifdef RAISE_STS_IRQ tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); #endif } DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", ret, tis->loc[locty].r_offset-1); } return ret; }


cpu_x86_dump_seg_cache(CPUState *env, FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...), const char *name, struct SegmentCache *sc) { #ifdef TARGET_X86_64 if (env->hflags & HF_CS64_MASK) { cpu_fprintf(f, "%-3s=%04x %016" PRIx64 " %08x %08x", name, sc->selector, sc->base, sc->limit, sc->flags); } else #endif { cpu_fprintf(f, "%-3s=%04x %08x %08x %08x", name, sc->selector, (uint32_t)sc->base, sc->limit, sc->flags); } if (!(env->hflags & HF_PE_MASK) || !(sc->flags & DESC_P_MASK)) goto done; cpu_fprintf(f, " DPL=%d ", (sc->flags & DESC_DPL_MASK) >> DESC_DPL_SHIFT); if (sc->flags & DESC_S_MASK) { if (sc->flags & DESC_CS_MASK) { cpu_fprintf(f, (sc->flags & DESC_L_MASK) ? "CS64" : ((sc->flags & DESC_B_MASK) ? "CS32" : "CS16")); cpu_fprintf(f, " [%c%c", (sc->flags & DESC_C_MASK) ? 'C' : '-', (sc->flags & DESC_R_MASK) ? 'R' : '-'); } else { cpu_fprintf(f, (sc->flags & DESC_B_MASK) ? "DS " : "DS16"); cpu_fprintf(f, " [%c%c", (sc->flags & DESC_E_MASK) ? 'E' : '-', (sc->flags & DESC_W_MASK) ? 'W' : '-'); } cpu_fprintf(f, "%c]", (sc->flags & DESC_A_MASK) ? 'A' : '-'); } else { static const char *sys_type_name[2][16] = { { /* 32 bit mode */ "Reserved", "TSS16-avl", "LDT", "TSS16-busy", "CallGate16", "TaskGate", "IntGate16", "TrapGate16", "Reserved", "TSS32-avl", "Reserved", "TSS32-busy", "CallGate32", "Reserved", "IntGate32", "TrapGate32" }, { /* 64 bit mode */ "<hiword>", "Reserved", "LDT", "Reserved", "Reserved", "Reserved", "Reserved", "Reserved", "Reserved", "TSS64-avl", "Reserved", "TSS64-busy", "CallGate64", "Reserved", "IntGate64", "TrapGate64" } }; cpu_fprintf(f, "%s", sys_type_name[(env->hflags & HF_LMA_MASK) ? 1 : 0] [(sc->flags & DESC_TYPE_MASK) >> DESC_TYPE_SHIFT]); } done: cpu_fprintf(f, "\n"); }


static int qemu_gluster_parse_uri(BlockdevOptionsGluster *gconf, const char *filename) { SocketAddress *gsconf; URI *uri; QueryParams *qp = NULL; bool is_unix = false; int ret = 0; uri = uri_parse(filename); if (!uri) { return -EINVAL; } gconf->server = g_new0(SocketAddressList, 1); gconf->server->value = gsconf = g_new0(SocketAddress, 1); /* transport */ if (!uri->scheme || !strcmp(uri->scheme, "gluster")) { gsconf->type = SOCKET_ADDRESS_TYPE_INET; } else if (!strcmp(uri->scheme, "gluster+tcp")) { gsconf->type = SOCKET_ADDRESS_TYPE_INET; } else if (!strcmp(uri->scheme, "gluster+unix")) { gsconf->type = SOCKET_ADDRESS_TYPE_UNIX; is_unix = true; } else if (!strcmp(uri->scheme, "gluster+rdma")) { gsconf->type = SOCKET_ADDRESS_TYPE_INET; error_report("Warning: rdma feature is not supported, falling " "back to tcp"); } else { ret = -EINVAL; goto out; } ret = parse_volume_options(gconf, uri->path); if (ret < 0) { goto out; } qp = query_params_parse(uri->query); if (qp->n > 1 || (is_unix && !qp->n) || (!is_unix && qp->n)) { ret = -EINVAL; goto out; } if (is_unix) { if (uri->server || uri->port) { ret = -EINVAL; goto out; } if (strcmp(qp->p[0].name, "socket")) { ret = -EINVAL; goto out; } gsconf->u.q_unix.path = g_strdup(qp->p[0].value); } else { gsconf->u.inet.host = g_strdup(uri->server ? uri->server : "localhost"); if (uri->port) { gsconf->u.inet.port = g_strdup_printf("%d", uri->port); } else { gsconf->u.inet.port = g_strdup_printf("%d", GLUSTER_DEFAULT_PORT); } } out: if (qp) { query_params_free(qp); } uri_free(uri); return ret; }


static BlockDriverAIOCB *paio_submit(BlockDriverState *bs, HANDLE hfile, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque, int type) { RawWin32AIOData *acb = g_slice_new(RawWin32AIOData); acb->bs = bs; acb->hfile = hfile; acb->aio_type = type; if (qiov) { acb->aio_iov = qiov->iov; acb->aio_niov = qiov->niov; } acb->aio_nbytes = nb_sectors * 512; acb->aio_offset = sector_num * 512; trace_paio_submit(acb, opaque, sector_num, nb_sectors, type); return thread_pool_submit_aio(aio_worker, acb, cb, opaque); }


static void special_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { qemu_log("pci: special write cycle"); }


MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr index) { PhysPageEntry lp = d->phys_map; PhysPageEntry *p; int i; for (i = P_L2_LEVELS - 1; i >= 0 && !lp.is_leaf; i--) { if (lp.ptr == PHYS_MAP_NODE_NIL) { return &phys_sections[phys_section_unassigned]; } p = phys_map_nodes[lp.ptr]; lp = p[(index >> (i * L2_BITS)) & (L2_SIZE - 1)]; } return &phys_sections[lp.ptr]; }


static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset, int64_t size) { return glfs_zerofill(fd, offset, size); }


static void write_cont (void *opaque, uint32_t nport, uint32_t data) { struct dma_cont *d = opaque; int iport, ichan; iport = (nport >> d->dshift) & 0x0f; switch (iport) { case 8: /* command */ if (data && (data | CMD_NOT_SUPPORTED)) { log ("command %#x not supported\n", data); goto error; } d->command = data; break; case 9: ichan = data & 3; if (data & 4) { d->status |= 1 << (ichan + 4); } else { d->status &= ~(1 << (ichan + 4)); } d->status &= ~(1 << ichan); break; case 0xa: /* single mask */ if (data & 4) d->mask |= 1 << (data & 3); else d->mask &= ~(1 << (data & 3)); break; case 0xb: /* mode */ { ichan = data & 3; #ifdef DEBUG_DMA int op; int ai; int dir; int opmode; op = (data >> 2) & 3; ai = (data >> 4) & 1; dir = (data >> 5) & 1; opmode = (data >> 6) & 3; linfo ("ichan %d, op %d, ai %d, dir %d, opmode %d\n", ichan, op, ai, dir, opmode); #endif d->regs[ichan].mode = data; break; } case 0xc: /* clear flip flop */ d->flip_flop = 0; break; case 0xd: /* reset */ d->flip_flop = 0; d->mask = ~0; d->status = 0; d->command = 0; break; case 0xe: /* clear mask for all channels */ d->mask = 0; break; case 0xf: /* write mask for all channels */ d->mask = data; break; default: log ("dma: unknown iport %#x\n", iport); goto error; } #ifdef DEBUG_DMA if (0xc != iport) { linfo ("nport %#06x, ichan % 2d, val %#06x\n", nport, ichan, data); } #endif return; error: abort (); }


static void test_visitor_in_fail_list(TestInputVisitorData *data, const void *unused) { int64_t i64 = -1; Visitor *v; /* Unvisited list tail */ v = visitor_input_test_init(data, "[ 1, 2, 3 ]"); visit_start_list(v, NULL, NULL, 0, &error_abort); visit_type_int(v, NULL, &i64, &error_abort); g_assert_cmpint(i64, ==, 1); visit_type_int(v, NULL, &i64, &error_abort); g_assert_cmpint(i64, ==, 2); visit_end_list(v, NULL); /* BUG: unvisited tail not reported; actually not reportable by design */ }


void qemu_console_copy(QEMUConsole *console, int src_x, int src_y, int dst_x, int dst_y, int w, int h) { if (active_console == console) { if (console->ds->dpy_copy) console->ds->dpy_copy(console->ds, src_x, src_y, dst_x, dst_y, w, h); else { /* TODO */ console->ds->dpy_update(console->ds, dst_x, dst_y, w, h); } } }


static inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op) { if (offset == (offset & 0xfff)) tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) | INSN_IMM13(offset)); else fprintf(stderr, "unimplemented %s with offset %d\n", __func__, offset); }


static int i440fx_initfn(PCIDevice *dev) { PCII440FXState *d = DO_UPCAST(PCII440FXState, dev, dev); pci_config_set_vendor_id(d->dev.config, PCI_VENDOR_ID_INTEL); pci_config_set_device_id(d->dev.config, PCI_DEVICE_ID_INTEL_82441); d->dev.config[0x08] = 0x02; // revision pci_config_set_class(d->dev.config, PCI_CLASS_BRIDGE_HOST); d->dev.config[I440FX_SMRAM] = 0x02; cpu_smm_register(&i440fx_set_smm, d); return 0; }


void cpu_register_physical_memory_log(MemoryRegionSection *section, bool readonly) { MemoryRegionSection now = *section, remain = *section; if ((now.offset_within_address_space & ~TARGET_PAGE_MASK) || (now.size < TARGET_PAGE_SIZE)) { now.size = MIN(TARGET_PAGE_ALIGN(now.offset_within_address_space) - now.offset_within_address_space, now.size); register_subpage(&now); remain.size -= now.size; remain.offset_within_address_space += now.size; remain.offset_within_region += now.size; } while (remain.size >= TARGET_PAGE_SIZE) { now = remain; if (remain.offset_within_region & ~TARGET_PAGE_MASK) { now.size = TARGET_PAGE_SIZE; register_subpage(&now); } else { now.size &= TARGET_PAGE_MASK; register_multipage(&now); } remain.size -= now.size; remain.offset_within_address_space += now.size; remain.offset_within_region += now.size; } now = remain; if (now.size) { register_subpage(&now); } }


static void virtio_blk_handle_flush(BlockRequest *blkreq, int *num_writes, VirtIOBlockReq *req) { BlockDriverAIOCB *acb; /* * Make sure all outstanding writes are posted to the backing device. */ if (*num_writes > 0) { do_multiwrite(req->dev->bs, blkreq, *num_writes); } *num_writes = 0; acb = bdrv_aio_flush(req->dev->bs, virtio_blk_flush_complete, req); if (!acb) { virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); } }


static void gd_update_cursor(VirtualConsole *vc) { GtkDisplayState *s = vc->s; GdkWindow *window; if (vc->type != GD_VC_GFX) { return; } window = gtk_widget_get_window(GTK_WIDGET(vc->gfx.drawing_area)); if (s->full_screen || qemu_input_is_absolute() || gd_is_grab_active(s)) { gdk_window_set_cursor(window, s->null_cursor); } else { gdk_window_set_cursor(window, NULL); } }


static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) { bool page_aligned = false; unsigned int n, begin; const uint16_t block_size = s->blksize & 0x0fff; uint32_t boundary_chk = 1 << (((s->blksize & 0xf000) >> 12) + 12); uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk); /* XXX: Some sd/mmc drivers (for example, u-boot-slp) do not account for * possible stop at page boundary if initial address is not page aligned, * allow them to work properly */ if ((s->sdmasysad % boundary_chk) == 0) { page_aligned = true; } if (s->trnmod & SDHC_TRNS_READ) { s->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT | SDHC_DAT_LINE_ACTIVE; while (s->blkcnt) { if (s->data_count == 0) { for (n = 0; n < block_size; n++) { s->fifo_buffer[n] = sdbus_read_data(&s->sdbus); } } begin = s->data_count; if (((boundary_count + begin) < block_size) && page_aligned) { s->data_count = boundary_count + begin; boundary_count = 0; } else { s->data_count = block_size; boundary_count -= block_size - begin; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { s->blkcnt--; } } dma_memory_write(&address_space_memory, s->sdmasysad, &s->fifo_buffer[begin], s->data_count - begin); s->sdmasysad += s->data_count - begin; if (s->data_count == block_size) { s->data_count = 0; } if (page_aligned && boundary_count == 0) { break; } } } else { s->prnsts |= SDHC_DOING_WRITE | SDHC_DATA_INHIBIT | SDHC_DAT_LINE_ACTIVE; while (s->blkcnt) { begin = s->data_count; if (((boundary_count + begin) < block_size) && page_aligned) { s->data_count = boundary_count + begin; boundary_count = 0; } else { s->data_count = block_size; boundary_count -= block_size - begin; } dma_memory_read(&address_space_memory, s->sdmasysad, &s->fifo_buffer[begin], s->data_count); s->sdmasysad += s->data_count - begin; if (s->data_count == block_size) { for (n = 0; n < block_size; n++) { sdbus_write_data(&s->sdbus, s->fifo_buffer[n]); } s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { s->blkcnt--; } } if (page_aligned && boundary_count == 0) { break; } } } if (s->blkcnt == 0) { sdhci_end_transfer(s); } else { if (s->norintstsen & SDHC_NISEN_DMA) { s->norintsts |= SDHC_NIS_DMA; } sdhci_update_irq(s); } }


static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MLPDecodeContext *m = avctx->priv_data; GetBitContext gb; unsigned int length, substr; unsigned int substream_start; unsigned int header_size = 4; unsigned int substr_header_size = 0; uint8_t substream_parity_present[MAX_SUBSTREAMS]; uint16_t substream_data_len[MAX_SUBSTREAMS]; uint8_t parity_bits; if (buf_size < 4) return 0; length = (AV_RB16(buf) & 0xfff) * 2; if (length > buf_size) return -1; init_get_bits(&gb, (buf + 4), (length - 4) * 8); m->is_major_sync_unit = 0; if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) { if (read_major_sync(m, &gb) < 0) goto error; m->is_major_sync_unit = 1; header_size += 28; } if (!m->params_valid) { av_log(m->avctx, AV_LOG_WARNING, "Stream parameters not seen; skipping frame.\n"); *data_size = 0; return length; } substream_start = 0; for (substr = 0; substr < m->num_substreams; substr++) { int extraword_present, checkdata_present, end, nonrestart_substr; extraword_present = get_bits1(&gb); nonrestart_substr = get_bits1(&gb); checkdata_present = get_bits1(&gb); skip_bits1(&gb); end = get_bits(&gb, 12) * 2; substr_header_size += 2; if (extraword_present) { if (m->avctx->codec_id == CODEC_ID_MLP) { av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n"); goto error; } skip_bits(&gb, 16); substr_header_size += 2; } if (!(nonrestart_substr ^ m->is_major_sync_unit)) { av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n"); goto error; } if (end + header_size + substr_header_size > length) { av_log(m->avctx, AV_LOG_ERROR, "Indicated length of substream %d data goes off end of " "packet.\n", substr); end = length - header_size - substr_header_size; } if (end < substream_start) { av_log(avctx, AV_LOG_ERROR, "Indicated end offset of substream %d data " "is smaller than calculated start offset.\n", substr); goto error; } if (substr > m->max_decoded_substream) continue; substream_parity_present[substr] = checkdata_present; substream_data_len[substr] = end - substream_start; substream_start = end; } parity_bits = ff_mlp_calculate_parity(buf, 4); parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size); if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) { av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n"); goto error; } buf += header_size + substr_header_size; for (substr = 0; substr <= m->max_decoded_substream; substr++) { SubStream *s = &m->substream[substr]; init_get_bits(&gb, buf, substream_data_len[substr] * 8); m->matrix_changed = 0; memset(m->filter_changed, 0, sizeof(m->filter_changed)); s->blockpos = 0; do { unsigned int ch; if (get_bits1(&gb)) { if (get_bits1(&gb)) { /* A restart header should be present. */ if (read_restart_header(m, &gb, buf, substr) < 0) goto next_substr; s->restart_seen = 1; } if (!s->restart_seen) { goto next_substr; } if (read_decoding_params(m, &gb, substr) < 0) goto next_substr; } if (m->matrix_changed > 1) { av_log(m->avctx, AV_LOG_ERROR, "Matrices may change only once per access unit.\n"); goto next_substr; } for (ch = 0; ch < s->max_channel; ch++) if (m->filter_changed[ch][FIR] > 1 || m->filter_changed[ch][IIR] > 1) { av_log(m->avctx, AV_LOG_ERROR, "Filters may change only once per access unit.\n"); goto next_substr; } if (!s->restart_seen) { goto next_substr; } if (read_block_data(m, &gb, substr) < 0) return -1; if (get_bits_count(&gb) >= substream_data_len[substr] * 8) goto substream_length_mismatch; } while (!get_bits1(&gb)); skip_bits(&gb, (-get_bits_count(&gb)) & 15); if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) { int shorten_by; if (get_bits(&gb, 16) != 0xD234) return -1; shorten_by = get_bits(&gb, 16); if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000) s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos); else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234) return -1; if (substr == m->max_decoded_substream) av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n"); } if (substream_parity_present[substr]) { uint8_t parity, checksum; if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16) goto substream_length_mismatch; parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2); checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2); if ((get_bits(&gb, 8) ^ parity) != 0xa9 ) av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr); if ( get_bits(&gb, 8) != checksum) av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n" , substr); } if (substream_data_len[substr] * 8 != get_bits_count(&gb)) { goto substream_length_mismatch; } next_substr: if (!s->restart_seen) { av_log(m->avctx, AV_LOG_ERROR, "No restart header present in substream %d.\n", substr); } buf += substream_data_len[substr]; } rematrix_channels(m, m->max_decoded_substream); if (output_data(m, m->max_decoded_substream, data, data_size) < 0) return -1; return length; substream_length_mismatch: av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr); return -1; error: m->params_valid = 0; return -1; }


static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { uint64_t reqid = request_id++; int ret = bdrv_co_preadv(bs->file->bs, offset, bytes, qiov, flags); block_request_create(reqid, bs, qemu_coroutine_self()); qemu_coroutine_yield(); return ret; }


void s390x_tod_timer(void *opaque) { S390CPU *cpu = opaque; CPUS390XState *env = &cpu->env; env->pending_int |= INTERRUPT_TOD; cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HARD); }


static uint8_t qpci_spapr_io_readb(QPCIBus *bus, void *addr) { QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus); uint64_t port = (uintptr_t)addr; uint8_t v; if (port < s->pio.size) { v = readb(s->pio_cpu_base + port); } else { v = readb(s->mmio_cpu_base + port); } return v; }


static void bench_cb(void *opaque, int ret) { BenchData *b = opaque; BlockAIOCB *acb; if (ret < 0) { error_report("Failed request: %s\n", strerror(-ret)); exit(EXIT_FAILURE); } if (b->in_flush) { /* Just finished a flush with drained queue: Start next requests */ assert(b->in_flight == 0); b->in_flush = false; } else if (b->in_flight > 0) { int remaining = b->n - b->in_flight; b->n--; b->in_flight--; /* Time for flush? Drain queue if requested, then flush */ if (b->flush_interval && remaining % b->flush_interval == 0) { if (!b->in_flight || !b->drain_on_flush) { BlockCompletionFunc *cb; if (b->drain_on_flush) { b->in_flush = true; cb = bench_cb; } else { cb = bench_undrained_flush_cb; } acb = blk_aio_flush(b->blk, cb, b); if (!acb) { error_report("Failed to issue flush request"); exit(EXIT_FAILURE); } } if (b->drain_on_flush) { return; } } } while (b->n > b->in_flight && b->in_flight < b->nrreq) { if (b->write) { acb = blk_aio_pwritev(b->blk, b->offset, b->qiov, 0, bench_cb, b); } else { acb = blk_aio_preadv(b->blk, b->offset, b->qiov, 0, bench_cb, b); } if (!acb) { error_report("Failed to issue request"); exit(EXIT_FAILURE); } b->in_flight++; b->offset += b->step; b->offset %= b->image_size; } }


static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, int64_t offset, int64_t length, uint64_t addend, bool decrease, enum qcow2_discard_type type) { BDRVQcowState *s = bs->opaque; int64_t start, last, cluster_offset; void *refcount_block = NULL; int64_t old_table_index = -1; int ret; #ifdef DEBUG_ALLOC2 fprintf(stderr, "update_refcount: offset=%" PRId64 " size=%" PRId64 " addend=%s%" PRIu64 "\n", offset, length, decrease ? "-" : "", addend); #endif if (length < 0) { return -EINVAL; } else if (length == 0) { return 0; } if (decrease) { qcow2_cache_set_dependency(bs, s->refcount_block_cache, s->l2_table_cache); } start = start_of_cluster(s, offset); last = start_of_cluster(s, offset + length - 1); for(cluster_offset = start; cluster_offset <= last; cluster_offset += s->cluster_size) { int block_index; uint64_t refcount; int64_t cluster_index = cluster_offset >> s->cluster_bits; int64_t table_index = cluster_index >> s->refcount_block_bits; /* Load the refcount block and allocate it if needed */ if (table_index != old_table_index) { if (refcount_block) { ret = qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); if (ret < 0) { goto fail; } } ret = alloc_refcount_block(bs, cluster_index, &refcount_block); if (ret < 0) { goto fail; } } old_table_index = table_index; qcow2_cache_entry_mark_dirty(bs, s->refcount_block_cache, refcount_block); /* we can update the count and save it */ block_index = cluster_index & (s->refcount_block_size - 1); refcount = s->get_refcount(refcount_block, block_index); if (decrease ? (refcount - addend > refcount) : (refcount + addend < refcount || refcount + addend > s->refcount_max)) { ret = -EINVAL; goto fail; } if (decrease) { refcount -= addend; } else { refcount += addend; } if (refcount == 0 && cluster_index < s->free_cluster_index) { s->free_cluster_index = cluster_index; } s->set_refcount(refcount_block, block_index, refcount); if (refcount == 0 && s->discard_passthrough[type]) { update_refcount_discard(bs, cluster_offset, s->cluster_size); } } ret = 0; fail: if (!s->cache_discards) { qcow2_process_discards(bs, ret); } /* Write last changed block to disk */ if (refcount_block) { int wret; wret = qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); if (wret < 0) { return ret < 0 ? ret : wret; } } /* * Try do undo any updates if an error is returned (This may succeed in * some cases like ENOSPC for allocating a new refcount block) */ if (ret < 0) { int dummy; dummy = update_refcount(bs, offset, cluster_offset - offset, addend, !decrease, QCOW2_DISCARD_NEVER); (void)dummy; } return ret; }


static void virtio_scsi_clear_aio(VirtIOSCSI *s) { VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); int i; if (s->ctrl_vring) { aio_set_event_notifier(s->ctx, &s->ctrl_vring->host_notifier, false, NULL); } if (s->event_vring) { aio_set_event_notifier(s->ctx, &s->event_vring->host_notifier, false, NULL); } if (s->cmd_vrings) { for (i = 0; i < vs->conf.num_queues && s->cmd_vrings[i]; i++) { aio_set_event_notifier(s->ctx, &s->cmd_vrings[i]->host_notifier, false, NULL); } } }


create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) { size_t *sizes = g_new0(size_t, nr_iov); size_t count = 0; void *buf = NULL; void *p; int i; for (i = 0; i < nr_iov; i++) { char *arg = argv[i]; int64_t len; len = cvtnum(arg); if (len < 0) { print_cvtnum_err(len, arg); goto fail; } /* should be SIZE_T_MAX, but that doesn't exist */ if (len > INT_MAX) { printf("Argument '%s' exceeds maximum size %d\n", arg, INT_MAX); goto fail; } sizes[i] = len; count += len; } qemu_iovec_init(qiov, nr_iov); buf = p = qemu_io_alloc(blk, count, pattern); for (i = 0; i < nr_iov; i++) { qemu_iovec_add(qiov, p, sizes[i]); p += sizes[i]; } fail: g_free(sizes); return buf; }


static void pflash_update(pflash_t *pfl, int offset, int size) { int offset_end; if (pfl->bs) { offset_end = offset + size; /* round to sectors */ offset = offset >> 9; offset_end = (offset_end + 511) >> 9; bdrv_write(pfl->bs, offset, pfl->storage + (offset << 9), offset_end - offset); } }


static int piix4_initfn(PCIDevice *d) { uint8_t *pci_conf; isa_bus_new(&d->qdev); register_savevm("PIIX4", 0, 2, piix_save, piix_load, d); pci_conf = d->config; pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_0); // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA); pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic piix4_dev = d; piix4_reset(d); qemu_register_reset(piix4_reset, d); return 0; }


void nbd_client_session_detach_aio_context(NbdClientSession *client) { aio_set_fd_handler(bdrv_get_aio_context(client->bs), client->sock, NULL, NULL, NULL); }


static void fd_put_notify(void *opaque) { QEMUFileFD *s = opaque; /* Remove writable callback and do a put notify */ qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); qemu_file_put_notify(s->file); }


int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f) { SaveStateEntry *se; int ret = 1; QTAILQ_FOREACH(se, &savevm_handlers, entry) { if (se->save_live_state == NULL) continue; /* Section type */ qemu_put_byte(f, QEMU_VM_SECTION_PART); qemu_put_be32(f, se->section_id); ret = se->save_live_state(mon, f, QEMU_VM_SECTION_PART, se->opaque); if (!ret) { /* Do not proceed to the next vmstate before this one reported completion of the current stage. This serializes the migration and reduces the probability that a faster changing state is synchronized over and over again. */ break; } } if (ret != 0) { return ret; } ret = qemu_file_get_error(f); if (ret != 0) { qemu_savevm_state_cancel(mon, f); } return ret; }


int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m) { BDRVQcowState *s = bs->opaque; uint64_t start, remaining; uint64_t cluster_offset; uint64_t cur_bytes; int ret; trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset, n_start, n_end); assert(n_start * BDRV_SECTOR_SIZE == offset_into_cluster(s, offset)); offset = start_of_cluster(s, offset); again: start = offset + (n_start << BDRV_SECTOR_BITS); remaining = (n_end - n_start) << BDRV_SECTOR_BITS; cluster_offset = 0; *host_offset = 0; /* * Now start gathering as many contiguous clusters as possible: * * 1. Check for overlaps with in-flight allocations * * a) Overlap not in the first cluster -> shorten this request and let * the caller handle the rest in its next loop iteration. * * b) Real overlaps of two requests. Yield and restart the search for * contiguous clusters (the situation could have changed while we * were sleeping) * * c) TODO: Request starts in the same cluster as the in-flight * allocation ends. Shorten the COW of the in-fight allocation, set * cluster_offset to write to the same cluster and set up the right * synchronisation between the in-flight request and the new one. */ cur_bytes = remaining; ret = handle_dependencies(bs, start, &cur_bytes); if (ret == -EAGAIN) { goto again; } else if (ret < 0) { return ret; } else { /* handle_dependencies() may have decreased cur_bytes (shortened * the allocations below) so that the next dependency is processed * correctly during the next loop iteration. */ } /* * 2. Count contiguous COPIED clusters. */ ret = handle_copied(bs, start, &cluster_offset, &cur_bytes, m); if (ret < 0) { return ret; } else if (ret) { if (!*host_offset) { *host_offset = start_of_cluster(s, cluster_offset); } start += cur_bytes; remaining -= cur_bytes; cluster_offset += cur_bytes; cur_bytes = remaining; } else if (cur_bytes == 0) { goto done; } /* If there is something left to allocate, do that now */ if (remaining == 0) { goto done; } /* * 3. If the request still hasn't completed, allocate new clusters, * considering any cluster_offset of steps 1c or 2. */ ret = handle_alloc(bs, start, &cluster_offset, &cur_bytes, m); if (ret < 0) { return ret; } else if (ret) { if (!*host_offset) { *host_offset = start_of_cluster(s, cluster_offset); } start += cur_bytes; remaining -= cur_bytes; cluster_offset += cur_bytes; } /* Some cleanup work */ done: *num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS); assert(*num > 0); assert(*host_offset != 0); return 0; }


QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head, const GraphicHwOps *hw_ops, void *opaque) { int width = 640; int height = 480; QemuConsole *s; DisplayState *ds; ds = get_alloc_displaystate(); trace_console_gfx_new(); s = new_console(ds, GRAPHIC_CONSOLE, head); s->hw_ops = hw_ops; s->hw = opaque; if (dev) { object_property_set_link(OBJECT(s), OBJECT(dev), "device", &error_abort); } s->surface = qemu_create_displaysurface(width, height); return s; }


static inline void stw_phys_internal(target_phys_addr_t addr, uint32_t val, enum device_endian endian) { uint8_t *ptr; MemoryRegionSection *section; section = phys_page_find(addr >> TARGET_PAGE_BITS); if (!memory_region_is_ram(section->mr) || section->readonly) { addr = memory_region_section_addr(section, addr); if (memory_region_is_ram(section->mr)) { section = &phys_sections[phys_section_rom]; } #if defined(TARGET_WORDS_BIGENDIAN) if (endian == DEVICE_LITTLE_ENDIAN) { val = bswap16(val); } #else if (endian == DEVICE_BIG_ENDIAN) { val = bswap16(val); } #endif io_mem_write(section->mr, addr, val, 2); } else { unsigned long addr1; addr1 = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK) + memory_region_section_addr(section, addr); /* RAM case */ ptr = qemu_get_ram_ptr(addr1); switch (endian) { case DEVICE_LITTLE_ENDIAN: stw_le_p(ptr, val); break; case DEVICE_BIG_ENDIAN: stw_be_p(ptr, val); break; default: stw_p(ptr, val); break; } invalidate_and_set_dirty(addr1, 2); } }


bool virtio_disk_is_eckd(void) { if (guessed_disk_nature) { return (blk_cfg.blk_size == 4096); } return (blk_cfg.geometry.heads == 15) && (blk_cfg.geometry.sectors == 12) && (blk_cfg.blk_size == 4096); }