void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine, uint16_t io_base) { Aml *dev; Aml *crs; Aml *pkg; Aml *field; Aml *method; Aml *if_ctx; Aml *else_ctx; int i, apic_idx; Aml *sb_scope = aml_scope("_SB"); uint8_t madt_tmpl[8] = {0x00, 0x08, 0x00, 0x00, 0x00, 0, 0, 0}; Aml *cpu_id = aml_arg(1); Aml *apic_id = aml_arg(0); Aml *cpu_on = aml_local(0); Aml *madt = aml_local(1); Aml *cpus_map = aml_name(CPU_ON_BITMAP); Aml *zero = aml_int(0); Aml *one = aml_int(1); MachineClass *mc = MACHINE_GET_CLASS(machine); CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(machine); PCMachineState *pcms = PC_MACHINE(machine); /* * _MAT method - creates an madt apic buffer * apic_id = Arg0 = Local APIC ID * cpu_id = Arg1 = Processor ID * cpu_on = Local0 = CPON flag for this cpu * madt = Local1 = Buffer (in madt apic form) to return */ method = aml_method(CPU_MAT_METHOD, 2, AML_NOTSERIALIZED); aml_append(method, aml_store(aml_derefof(aml_index(cpus_map, apic_id)), cpu_on)); aml_append(method, aml_store(aml_buffer(sizeof(madt_tmpl), madt_tmpl), madt)); /* Update the processor id, lapic id, and enable/disable status */ aml_append(method, aml_store(cpu_id, aml_index(madt, aml_int(2)))); aml_append(method, aml_store(apic_id, aml_index(madt, aml_int(3)))); aml_append(method, aml_store(cpu_on, aml_index(madt, aml_int(4)))); aml_append(method, aml_return(madt)); aml_append(sb_scope, method); /* * _STA method - return ON status of cpu * apic_id = Arg0 = Local APIC ID * cpu_on = Local0 = CPON flag for this cpu */ method = aml_method(CPU_STATUS_METHOD, 1, AML_NOTSERIALIZED); aml_append(method, aml_store(aml_derefof(aml_index(cpus_map, apic_id)), cpu_on)); if_ctx = aml_if(cpu_on); { aml_append(if_ctx, aml_return(aml_int(0xF))); } aml_append(method, if_ctx); else_ctx = aml_else(); { aml_append(else_ctx, aml_return(zero)); } aml_append(method, else_ctx); aml_append(sb_scope, method); method = aml_method(CPU_EJECT_METHOD, 2, AML_NOTSERIALIZED); aml_append(method, aml_sleep(200)); aml_append(sb_scope, method); method = aml_method(CPU_SCAN_METHOD, 0, AML_NOTSERIALIZED); { Aml *while_ctx, *if_ctx2, *else_ctx2; Aml *bus_check_evt = aml_int(1); Aml *remove_evt = aml_int(3); Aml *status_map = aml_local(5); /* Local5 = active cpu bitmap */ Aml *byte = aml_local(2); /* Local2 = last read byte from bitmap */ Aml *idx = aml_local(0); /* Processor ID / APIC ID iterator */ Aml *is_cpu_on = aml_local(1); /* Local1 = CPON flag for cpu */ Aml *status = aml_local(3); /* Local3 = active state for cpu */ aml_append(method, aml_store(aml_name(CPU_STATUS_MAP), status_map)); aml_append(method, aml_store(zero, byte)); aml_append(method, aml_store(zero, idx)); /* While (idx < SizeOf(CPON)) */ while_ctx = aml_while(aml_lless(idx, aml_sizeof(cpus_map))); aml_append(while_ctx, aml_store(aml_derefof(aml_index(cpus_map, idx)), is_cpu_on)); if_ctx = aml_if(aml_and(idx, aml_int(0x07), NULL)); { /* Shift down previously read bitmap byte */ aml_append(if_ctx, aml_shiftright(byte, one, byte)); } aml_append(while_ctx, if_ctx); else_ctx = aml_else(); { /* Read next byte from cpu bitmap */ aml_append(else_ctx, aml_store(aml_derefof(aml_index(status_map, aml_shiftright(idx, aml_int(3), NULL))), byte)); } aml_append(while_ctx, else_ctx); aml_append(while_ctx, aml_store(aml_and(byte, one, NULL), status)); if_ctx = aml_if(aml_lnot(aml_equal(is_cpu_on, status))); { /* State change - update CPON with new state */ aml_append(if_ctx, aml_store(status, aml_index(cpus_map, idx))); if_ctx2 = aml_if(aml_equal(status, one)); { aml_append(if_ctx2, aml_call2(AML_NOTIFY_METHOD, idx, bus_check_evt)); } aml_append(if_ctx, if_ctx2); else_ctx2 = aml_else(); { aml_append(else_ctx2, aml_call2(AML_NOTIFY_METHOD, idx, remove_evt)); } } aml_append(if_ctx, else_ctx2); aml_append(while_ctx, if_ctx); aml_append(while_ctx, aml_increment(idx)); /* go to next cpu */ aml_append(method, while_ctx); } aml_append(sb_scope, method); /* The current AML generator can cover the APIC ID range [0..255], * inclusive, for VCPU hotplug. */ QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256); g_assert(pcms->apic_id_limit <= ACPI_CPU_HOTPLUG_ID_LIMIT); /* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ dev = aml_device("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE)); aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A06"))); aml_append(dev, aml_name_decl("_UID", aml_string("CPU Hotplug resources")) ); /* device present, functioning, decoding, not shown in UI */ aml_append(dev, aml_name_decl("_STA", aml_int(0xB))); crs = aml_resource_template(); aml_append(crs, aml_io(AML_DECODE16, io_base, io_base, 1, ACPI_GPE_PROC_LEN) ); aml_append(dev, aml_name_decl("_CRS", crs)); aml_append(sb_scope, dev); /* declare CPU hotplug MMIO region and PRS field to access it */ aml_append(sb_scope, aml_operation_region( "PRST", AML_SYSTEM_IO, aml_int(io_base), ACPI_GPE_PROC_LEN)); field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK, AML_PRESERVE); aml_append(field, aml_named_field("PRS", 256)); aml_append(sb_scope, field); /* build Processor object for each processor */ for (i = 0; i < apic_ids->len; i++) { int apic_id = apic_ids->cpus[i].arch_id; assert(apic_id < ACPI_CPU_HOTPLUG_ID_LIMIT); dev = aml_processor(i, 0, 0, "CP%.02X", apic_id); method = aml_method("_MAT", 0, AML_NOTSERIALIZED); aml_append(method, aml_return(aml_call2(CPU_MAT_METHOD, aml_int(apic_id), aml_int(i)) )); aml_append(dev, method); method = aml_method("_STA", 0, AML_NOTSERIALIZED); aml_append(method, aml_return(aml_call1(CPU_STATUS_METHOD, aml_int(apic_id)))); aml_append(dev, method); method = aml_method("_EJ0", 1, AML_NOTSERIALIZED); aml_append(method, aml_return(aml_call2(CPU_EJECT_METHOD, aml_int(apic_id), aml_arg(0))) ); aml_append(dev, method); aml_append(sb_scope, dev); } /* build this code: * Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...} */ /* Arg0 = APIC ID */ method = aml_method(AML_NOTIFY_METHOD, 2, AML_NOTSERIALIZED); for (i = 0; i < apic_ids->len; i++) { int apic_id = apic_ids->cpus[i].arch_id; if_ctx = aml_if(aml_equal(aml_arg(0), aml_int(apic_id))); aml_append(if_ctx, aml_notify(aml_name("CP%.02X", apic_id), aml_arg(1)) ); aml_append(method, if_ctx); } aml_append(sb_scope, method); /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" * * Note: The ability to create variable-sized packages was first * introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages * ith up to 255 elements. Windows guests up to win2k8 fail when * VarPackageOp is used. */ pkg = pcms->apic_id_limit <= 255 ? aml_package(pcms->apic_id_limit) : aml_varpackage(pcms->apic_id_limit); for (i = 0, apic_idx = 0; i < apic_ids->len; i++) { int apic_id = apic_ids->cpus[i].arch_id; for (; apic_idx < apic_id; apic_idx++) { aml_append(pkg, aml_int(0)); } aml_append(pkg, aml_int(apic_ids->cpus[i].cpu ? 1 : 0)); apic_idx = apic_id + 1; } aml_append(sb_scope, aml_name_decl(CPU_ON_BITMAP, pkg)); g_free(apic_ids); aml_append(ctx, sb_scope); method = aml_method("\\_GPE._E02", 0, AML_NOTSERIALIZED); aml_append(method, aml_call0("\\_SB." CPU_SCAN_METHOD)); aml_append(ctx, method); }


static void test_dispatch_cmd_io(void) { QDict *req = qdict_new(); QDict *args = qdict_new(); QDict *args3 = qdict_new(); QDict *ud1a = qdict_new(); QDict *ud1b = qdict_new(); QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef; QDict *ret_dict_dict2, *ret_dict_dict2_userdef; QInt *ret3; qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42))); qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello"))); qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422))); qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2"))); qdict_put_obj(args, "ud1a", QOBJECT(ud1a)); qdict_put_obj(args, "ud1b", QOBJECT(ud1b)); qdict_put_obj(req, "arguments", QOBJECT(args)); qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2"))); ret = qobject_to_qdict(test_qmp_dispatch(req)); assert(!strcmp(qdict_get_str(ret, "string"), "blah1")); ret_dict = qdict_get_qdict(ret, "dict"); assert(!strcmp(qdict_get_str(ret_dict, "string"), "blah2")); ret_dict_dict = qdict_get_qdict(ret_dict, "dict"); ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef"); assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42); assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello")); assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3")); ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict2"); ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef"); assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422); assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2")); assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4")); QDECREF(ret); qdict_put(args3, "a", qint_from_int(66)); qdict_put(req, "arguments", args3); qdict_put(req, "execute", qstring_from_str("user_def_cmd3")); ret3 = qobject_to_qint(test_qmp_dispatch(req)); assert(qint_get_int(ret3) == 66); QDECREF(ret3); QDECREF(req); }


static void coroutine_fn bdrv_flush_co_entry(void *opaque) { RwCo *rwco = opaque; rwco->ret = bdrv_co_flush(rwco->bs); }


static inline void t_gen_add_flag(TCGv d, int flag) { TCGv c; c = tcg_temp_new(TCG_TYPE_TL); t_gen_mov_TN_preg(c, PR_CCS); /* Propagate carry into d. */ tcg_gen_andi_tl(c, c, 1 << flag); if (flag) tcg_gen_shri_tl(c, c, flag); tcg_gen_add_tl(d, d, c); tcg_temp_free(c); }


void console_select(unsigned int index) { TextConsole *s; if (index >= MAX_CONSOLES) return; s = consoles[index]; if (s) { active_console = s; if (s->g_width && s->g_height && (s->g_width != s->ds->width || s->g_height != s->ds->height)) dpy_resize(s->ds, s->g_width, s->g_height); vga_hw_invalidate(); } }


static void update_max_chunk_size(BDRVDMGState *s, uint32_t chunk, uint32_t *max_compressed_size, uint32_t *max_sectors_per_chunk) { uint32_t compressed_size = 0; uint32_t uncompressed_sectors = 0; switch (s->types[chunk]) { case 0x80000005: /* zlib compressed */ case 0x80000006: /* bzip2 compressed */ compressed_size = s->lengths[chunk]; uncompressed_sectors = s->sectorcounts[chunk]; break; case 1: /* copy */ uncompressed_sectors = (s->lengths[chunk] + 511) / 512; break; case 2: /* zero */ uncompressed_sectors = s->sectorcounts[chunk]; break; } if (compressed_size > *max_compressed_size) { *max_compressed_size = compressed_size; } if (uncompressed_sectors > *max_sectors_per_chunk) { *max_sectors_per_chunk = uncompressed_sectors; } }


static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){ AVFormatContext *s= nut->avf; ByteIOContext *bc = &s->pb; int64_t end, tmp; AVRational time_base; nut->last_syncpoint_pos= url_ftell(bc)-8; end= get_packetheader(nut, bc, 1); end += url_ftell(bc); tmp= get_v(bc); *back_ptr= nut->last_syncpoint_pos - 16*get_v(bc); if(*back_ptr < 0) return -1; ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp); if(skip_reserved(bc, end) || get_checksum(bc)){ av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n"); return -1; } *ts= tmp / s->nb_streams * av_q2d(nut->time_base[tmp % s->nb_streams])*AV_TIME_BASE; add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts); return 0; }


int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) { int i; const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; int max_step [4]; /* max pixel step for each plane */ int max_step_comp[4]; /* the component for each plane which has the max pixel step */ memset(linesizes, 0, 4*sizeof(linesizes[0])); if (desc->flags & PIX_FMT_HWACCEL) return AVERROR(EINVAL); if (desc->flags & PIX_FMT_BITSTREAM) { linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; return 0; } av_image_fill_max_pixsteps(max_step, max_step_comp, desc); for (i = 0; i < 4; i++) { int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0; linesizes[i] = max_step[i] * (((width + (1 << s) - 1)) >> s); } return 0; }


static void qmp_output_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { QmpOutputVisitor *qov = to_qov(v); qmp_output_add(qov, name, qint_from_int(*obj)); }


void qemu_bh_cancel(QEMUBH *bh) { bh->scheduled = 0; }


static int cdrom_probe_device(const char *filename) { int fd, ret; int prio = 0; if (strstart(filename, "/dev/cd", NULL)) prio = 50; fd = open(filename, O_RDONLY | O_NONBLOCK); if (fd < 0) { goto out; } /* Attempt to detect via a CDROM specific ioctl */ ret = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); if (ret >= 0) prio = 100; close(fd); out: return prio; }


static uint64_t megasas_mmio_read(void *opaque, target_phys_addr_t addr, unsigned size) { MegasasState *s = opaque; uint32_t retval = 0; switch (addr) { case MFI_IDB: retval = 0; break; case MFI_OMSG0: case MFI_OSP0: retval = (megasas_use_msix(s) ? MFI_FWSTATE_MSIX_SUPPORTED : 0) | (s->fw_state & MFI_FWSTATE_MASK) | ((s->fw_sge & 0xff) << 16) | (s->fw_cmds & 0xFFFF); break; case MFI_OSTS: if (megasas_intr_enabled(s) && s->doorbell) { retval = MFI_1078_RM | 1; } break; case MFI_OMSK: retval = s->intr_mask; break; case MFI_ODCR0: retval = s->doorbell; break; default: trace_megasas_mmio_invalid_readl(addr); break; } trace_megasas_mmio_readl(addr, retval); return retval; }


static uint64_t pxa2xx_rtc_read(void *opaque, hwaddr addr, unsigned size) { PXA2xxRTCState *s = (PXA2xxRTCState *) opaque; switch (addr) { case RTTR: return s->rttr; case RTSR: return s->rtsr; case RTAR: return s->rtar; case RDAR1: return s->rdar1; case RDAR2: return s->rdar2; case RYAR1: return s->ryar1; case RYAR2: return s->ryar2; case SWAR1: return s->swar1; case SWAR2: return s->swar2; case PIAR: return s->piar; case RCNR: return s->last_rcnr + ((qemu_clock_get_ms(rtc_clock) - s->last_hz) << 15) / (1000 * ((s->rttr & 0xffff) + 1)); case RDCR: return s->last_rdcr + ((qemu_clock_get_ms(rtc_clock) - s->last_hz) << 15) / (1000 * ((s->rttr & 0xffff) + 1)); case RYCR: return s->last_rycr; case SWCR: if (s->rtsr & (1 << 12)) return s->last_swcr + (qemu_clock_get_ms(rtc_clock) - s->last_sw) / 10; else return s->last_swcr; default: printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); break; } return 0; }


static void test_visitor_out_union_flat(TestOutputVisitorData *data, const void *unused) { QObject *arg; QDict *qdict; Error *err = NULL; UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion)); tmp->enum1 = ENUM_ONE_VALUE1; tmp->string = g_strdup("str"); tmp->value1 = g_malloc0(sizeof(UserDefA)); /* TODO when generator bug is fixed: tmp->integer = 41; */ tmp->value1->boolean = true; visit_type_UserDefFlatUnion(data->ov, &tmp, NULL, &err); g_assert(err == NULL); arg = qmp_output_get_qobject(data->qov); g_assert(qobject_type(arg) == QTYPE_QDICT); qdict = qobject_to_qdict(arg); g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1"); g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str"); /* TODO g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41); */ g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true); qapi_free_UserDefFlatUnion(tmp); QDECREF(qdict); }


static SaveStateEntry *find_se(const char *idstr, int instance_id) { SaveStateEntry *se; QTAILQ_FOREACH(se, &savevm_handlers, entry) { if (!strcmp(se->idstr, idstr) && instance_id == se->instance_id) return se; } return NULL; }


av_cold void ff_vorbisdsp_init_x86(VorbisDSPContext *dsp) { #if HAVE_YASM int cpu_flags = av_get_cpu_flags(); #if ARCH_X86_32 if (cpu_flags & AV_CPU_FLAG_3DNOW) dsp->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_3dnow; #endif /* ARCH_X86_32 */ if (cpu_flags & AV_CPU_FLAG_SSE) dsp->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_sse; #endif /* HAVE_YASM */ }


static void output_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) { int ret = 0; /* apply the output bitstream filters, if any */ if (ost->nb_bitstream_filters) { int idx; ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt); if (ret < 0) goto finish; idx = 1; while (idx) { /* get a packet from the previous filter up the chain */ ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt); if (ret == AVERROR(EAGAIN)) { ret = 0; idx--; continue; } else if (ret < 0) goto finish; /* send it to the next filter down the chain or to the muxer */ if (idx < ost->nb_bitstream_filters) { ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt); if (ret < 0) goto finish; idx++; } else write_packet(s, pkt, ost); } } else write_packet(s, pkt, ost); finish: if (ret < 0 && ret != AVERROR_EOF) { av_log(NULL, AV_LOG_FATAL, "Error applying bitstream filters to an output " "packet for stream #%d:%d.\n", ost->file_index, ost->index); exit_program(1); } }


static void pred_temp_direct_motion(const H264Context *const h, H264SliceContext *sl, int *mb_type) { int b8_stride = 2; int b4_stride = h->b_stride; int mb_xy = sl->mb_xy, mb_y = sl->mb_y; int mb_type_col[2]; const int16_t (*l1mv0)[2], (*l1mv1)[2]; const int8_t *l1ref0, *l1ref1; const int is_b8x8 = IS_8X8(*mb_type); unsigned int sub_mb_type; int i8, i4; assert(sl->ref_list[1][0].reference & 3); await_reference_mb_row(h, sl->ref_list[1][0].parent, sl->mb_y + !!IS_INTERLACED(*mb_type)); if (IS_INTERLACED(sl->ref_list[1][0].parent->mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL mb_y = (sl->mb_y & ~1) + sl->col_parity; mb_xy = sl->mb_x + ((sl->mb_y & ~1) + sl->col_parity) * h->mb_stride; b8_stride = 0; } else { mb_y += sl->col_fieldoff; mb_xy += h->mb_stride * sl->col_fieldoff; // non-zero for FL -> FL & differ parity } goto single_col; } else { // AFL/AFR/FR/FL -> AFR/FR if (IS_INTERLACED(*mb_type)) { // AFL /FL -> AFR/FR mb_y = sl->mb_y & ~1; mb_xy = sl->mb_x + (sl->mb_y & ~1) * h->mb_stride; mb_type_col[0] = sl->ref_list[1][0].parent->mb_type[mb_xy]; mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy + h->mb_stride]; b8_stride = 2 + 4 * h->mb_stride; b4_stride *= 6; if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { mb_type_col[0] &= ~MB_TYPE_INTERLACED; mb_type_col[1] &= ~MB_TYPE_INTERLACED; } sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ if ((mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) && !is_b8x8) { *mb_type |= MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_DIRECT2; /* B_16x8 */ } else { *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; } } else { // AFR/FR -> AFR/FR single_col: mb_type_col[0] = mb_type_col[1] = sl->ref_list[1][0].parent->mb_type[mb_xy]; sub_mb_type = MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_DIRECT2; /* B_SUB_8x8 */ if (!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)) { *mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_DIRECT2; /* B_16x16 */ } else if (!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16))) { *mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8 | MB_TYPE_8x16)); } else { if (!h->sps.direct_8x8_inference_flag) { /* FIXME: save sub mb types from previous frames (or derive * from MVs) so we know exactly what block size to use */ sub_mb_type = MB_TYPE_8x8 | MB_TYPE_P0L0 | MB_TYPE_P0L1 | MB_TYPE_DIRECT2; /* B_SUB_4x4 */ } *mb_type |= MB_TYPE_8x8 | MB_TYPE_L0L1; } } } await_reference_mb_row(h, sl->ref_list[1][0].parent, mb_y); l1mv0 = &sl->ref_list[1][0].parent->motion_val[0][h->mb2b_xy[mb_xy]]; l1mv1 = &sl->ref_list[1][0].parent->motion_val[1][h->mb2b_xy[mb_xy]]; l1ref0 = &sl->ref_list[1][0].parent->ref_index[0][4 * mb_xy]; l1ref1 = &sl->ref_list[1][0].parent->ref_index[1][4 * mb_xy]; if (!b8_stride) { if (sl->mb_y & 1) { l1ref0 += 2; l1ref1 += 2; l1mv0 += 2 * b4_stride; l1mv1 += 2 * b4_stride; } } { const int *map_col_to_list0[2] = { sl->map_col_to_list0[0], sl->map_col_to_list0[1] }; const int *dist_scale_factor = sl->dist_scale_factor; int ref_offset; if (FRAME_MBAFF(h) && IS_INTERLACED(*mb_type)) { map_col_to_list0[0] = sl->map_col_to_list0_field[sl->mb_y & 1][0]; map_col_to_list0[1] = sl->map_col_to_list0_field[sl->mb_y & 1][1]; dist_scale_factor = sl->dist_scale_factor_field[sl->mb_y & 1]; } ref_offset = (sl->ref_list[1][0].parent->mbaff << 4) & (mb_type_col[0] >> 3); if (IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])) { int y_shift = 2 * !IS_INTERLACED(*mb_type); assert(h->sps.direct_8x8_inference_flag); for (i8 = 0; i8 < 4; i8++) { const int x8 = i8 & 1; const int y8 = i8 >> 1; int ref0, scale; const int16_t (*l1mv)[2] = l1mv0; if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) continue; sl->sub_mb_type[i8] = sub_mb_type; fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); if (IS_INTRA(mb_type_col[y8])) { fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); continue; } ref0 = l1ref0[x8 + y8 * b8_stride]; if (ref0 >= 0) ref0 = map_col_to_list0[0][ref0 + ref_offset]; else { ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] + ref_offset]; l1mv = l1mv1; } scale = dist_scale_factor[ref0]; fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, ref0, 1); { const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride]; int my_col = (mv_col[1] << y_shift) / 2; int mx = (scale * mv_col[0] + 128) >> 8; int my = (scale * my_col + 128) >> 8; fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, pack16to32(mx, my), 4); fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, pack16to32(mx - mv_col[0], my - my_col), 4); } } return; } /* one-to-one mv scaling */ if (IS_16X16(*mb_type)) { int ref, mv0, mv1; fill_rectangle(&sl->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); if (IS_INTRA(mb_type_col[0])) { ref = mv0 = mv1 = 0; } else { const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset] : map_col_to_list0[1][l1ref1[0] + ref_offset]; const int scale = dist_scale_factor[ref0]; const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0]; int mv_l0[2]; mv_l0[0] = (scale * mv_col[0] + 128) >> 8; mv_l0[1] = (scale * mv_col[1] + 128) >> 8; ref = ref0; mv0 = pack16to32(mv_l0[0], mv_l0[1]); mv1 = pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]); } fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); fill_rectangle(&sl->mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4); fill_rectangle(&sl->mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4); } else { for (i8 = 0; i8 < 4; i8++) { const int x8 = i8 & 1; const int y8 = i8 >> 1; int ref0, scale; const int16_t (*l1mv)[2] = l1mv0; if (is_b8x8 && !IS_DIRECT(sl->sub_mb_type[i8])) continue; sl->sub_mb_type[i8] = sub_mb_type; fill_rectangle(&sl->ref_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 1); if (IS_INTRA(mb_type_col[0])) { fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 1); fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, 0, 4); fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, 0, 4); continue; } assert(b8_stride == 2); ref0 = l1ref0[i8]; if (ref0 >= 0) ref0 = map_col_to_list0[0][ref0 + ref_offset]; else { ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset]; l1mv = l1mv1; } scale = dist_scale_factor[ref0]; fill_rectangle(&sl->ref_cache[0][scan8[i8 * 4]], 2, 2, 8, ref0, 1); if (IS_SUB_8X8(sub_mb_type)) { const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride]; int mx = (scale * mv_col[0] + 128) >> 8; int my = (scale * mv_col[1] + 128) >> 8; fill_rectangle(&sl->mv_cache[0][scan8[i8 * 4]], 2, 2, 8, pack16to32(mx, my), 4); fill_rectangle(&sl->mv_cache[1][scan8[i8 * 4]], 2, 2, 8, pack16to32(mx - mv_col[0], my - mv_col[1]), 4); } else { for (i4 = 0; i4 < 4; i4++) { const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) + (y8 * 2 + (i4 >> 1)) * b4_stride]; int16_t *mv_l0 = sl->mv_cache[0][scan8[i8 * 4 + i4]]; mv_l0[0] = (scale * mv_col[0] + 128) >> 8; mv_l0[1] = (scale * mv_col[1] + 128) >> 8; AV_WN32A(sl->mv_cache[1][scan8[i8 * 4 + i4]], pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1])); } } } } } }


static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size) { const VC1Context *v = avctx->priv_data; const MpegEncContext *s = &v->s; struct vaapi_context * const vactx = avctx->hwaccel_context; VAPictureParameterBufferVC1 *pic_param; vactx->slice_param_size = sizeof(VASliceParameterBufferVC1); /* Fill in VAPictureParameterBufferVC1 */ pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferVC1)); if (!pic_param) return -1; pic_param->forward_reference_picture = VA_INVALID_ID; pic_param->backward_reference_picture = VA_INVALID_ID; pic_param->inloop_decoded_picture = VA_INVALID_ID; pic_param->sequence_fields.value = 0; /* reset all bits */ pic_param->sequence_fields.bits.pulldown = v->broadcast; pic_param->sequence_fields.bits.interlace = v->interlace; pic_param->sequence_fields.bits.tfcntrflag = v->tfcntrflag; pic_param->sequence_fields.bits.finterpflag = v->finterpflag; pic_param->sequence_fields.bits.psf = v->psf; pic_param->sequence_fields.bits.multires = v->multires; pic_param->sequence_fields.bits.overlap = v->overlap; pic_param->sequence_fields.bits.syncmarker = v->resync_marker; pic_param->sequence_fields.bits.rangered = v->rangered; pic_param->sequence_fields.bits.max_b_frames = s->avctx->max_b_frames; #if VA_CHECK_VERSION(0,32,0) pic_param->sequence_fields.bits.profile = v->profile; #endif pic_param->coded_width = s->avctx->coded_width; pic_param->coded_height = s->avctx->coded_height; pic_param->entrypoint_fields.value = 0; /* reset all bits */ pic_param->entrypoint_fields.bits.broken_link = v->broken_link; pic_param->entrypoint_fields.bits.closed_entry = v->closed_entry; pic_param->entrypoint_fields.bits.panscan_flag = v->panscanflag; pic_param->entrypoint_fields.bits.loopfilter = s->loop_filter; pic_param->conditional_overlap_flag = v->condover; pic_param->fast_uvmc_flag = v->fastuvmc; pic_param->range_mapping_fields.value = 0; /* reset all bits */ pic_param->range_mapping_fields.bits.luma_flag = v->range_mapy_flag; pic_param->range_mapping_fields.bits.luma = v->range_mapy; pic_param->range_mapping_fields.bits.chroma_flag = v->range_mapuv_flag; pic_param->range_mapping_fields.bits.chroma = v->range_mapuv; pic_param->b_picture_fraction = v->bfraction_lut_index; pic_param->cbp_table = v->cbpcy_vlc ? v->cbpcy_vlc - ff_vc1_cbpcy_p_vlc : 0; pic_param->mb_mode_table = 0; /* XXX: interlaced frame */ pic_param->range_reduction_frame = v->rangeredfrm; pic_param->rounding_control = v->rnd; pic_param->post_processing = v->postproc; pic_param->picture_resolution_index = v->respic; pic_param->luma_scale = v->lumscale; pic_param->luma_shift = v->lumshift; pic_param->picture_fields.value = 0; /* reset all bits */ pic_param->picture_fields.bits.picture_type = vc1_get_PTYPE(v); pic_param->picture_fields.bits.frame_coding_mode = v->fcm; pic_param->picture_fields.bits.top_field_first = v->tff; pic_param->picture_fields.bits.is_first_field = v->fcm == 0; /* XXX: interlaced frame */ pic_param->picture_fields.bits.intensity_compensation = v->mv_mode == MV_PMODE_INTENSITY_COMP; pic_param->raw_coding.value = 0; /* reset all bits */ pic_param->raw_coding.flags.mv_type_mb = v->mv_type_is_raw; pic_param->raw_coding.flags.direct_mb = v->dmb_is_raw; pic_param->raw_coding.flags.skip_mb = v->skip_is_raw; pic_param->raw_coding.flags.field_tx = 0; /* XXX: interlaced frame */ pic_param->raw_coding.flags.forward_mb = 0; /* XXX: interlaced frame */ pic_param->raw_coding.flags.ac_pred = v->acpred_is_raw; pic_param->raw_coding.flags.overflags = v->overflg_is_raw; pic_param->bitplane_present.value = 0; /* reset all bits */ pic_param->bitplane_present.flags.bp_mv_type_mb = vc1_has_MVTYPEMB_bitplane(v); pic_param->bitplane_present.flags.bp_direct_mb = vc1_has_DIRECTMB_bitplane(v); pic_param->bitplane_present.flags.bp_skip_mb = vc1_has_SKIPMB_bitplane(v); pic_param->bitplane_present.flags.bp_field_tx = 0; /* XXX: interlaced frame */ pic_param->bitplane_present.flags.bp_forward_mb = 0; /* XXX: interlaced frame */ pic_param->bitplane_present.flags.bp_ac_pred = vc1_has_ACPRED_bitplane(v); pic_param->bitplane_present.flags.bp_overflags = vc1_has_OVERFLAGS_bitplane(v); pic_param->reference_fields.value = 0; /* reset all bits */ pic_param->reference_fields.bits.reference_distance_flag = v->refdist_flag; pic_param->reference_fields.bits.reference_distance = 0; /* XXX: interlaced frame */ pic_param->reference_fields.bits.num_reference_pictures = 0; /* XXX: interlaced frame */ pic_param->reference_fields.bits.reference_field_pic_indicator = 0; /* XXX: interlaced frame */ pic_param->mv_fields.value = 0; /* reset all bits */ pic_param->mv_fields.bits.mv_mode = vc1_get_MVMODE(v); pic_param->mv_fields.bits.mv_mode2 = vc1_get_MVMODE2(v); pic_param->mv_fields.bits.mv_table = s->mv_table_index; pic_param->mv_fields.bits.two_mv_block_pattern_table = 0; /* XXX: interlaced frame */ pic_param->mv_fields.bits.four_mv_switch = 0; /* XXX: interlaced frame */ pic_param->mv_fields.bits.four_mv_block_pattern_table = 0; /* XXX: interlaced frame */ pic_param->mv_fields.bits.extended_mv_flag = v->extended_mv; pic_param->mv_fields.bits.extended_mv_range = v->mvrange; pic_param->mv_fields.bits.extended_dmv_flag = v->extended_dmv; pic_param->mv_fields.bits.extended_dmv_range = 0; /* XXX: interlaced frame */ pic_param->pic_quantizer_fields.value = 0; /* reset all bits */ pic_param->pic_quantizer_fields.bits.dquant = v->dquant; pic_param->pic_quantizer_fields.bits.quantizer = v->quantizer_mode; pic_param->pic_quantizer_fields.bits.half_qp = v->halfpq; pic_param->pic_quantizer_fields.bits.pic_quantizer_scale = v->pq; pic_param->pic_quantizer_fields.bits.pic_quantizer_type = v->pquantizer; pic_param->pic_quantizer_fields.bits.dq_frame = v->dquantfrm; pic_param->pic_quantizer_fields.bits.dq_profile = v->dqprofile; pic_param->pic_quantizer_fields.bits.dq_sb_edge = v->dqprofile == DQPROFILE_SINGLE_EDGE ? v->dqsbedge : 0; pic_param->pic_quantizer_fields.bits.dq_db_edge = v->dqprofile == DQPROFILE_DOUBLE_EDGES ? v->dqsbedge : 0; pic_param->pic_quantizer_fields.bits.dq_binary_level = v->dqbilevel; pic_param->pic_quantizer_fields.bits.alt_pic_quantizer = v->altpq; pic_param->transform_fields.value = 0; /* reset all bits */ pic_param->transform_fields.bits.variable_sized_transform_flag = v->vstransform; pic_param->transform_fields.bits.mb_level_transform_type_flag = v->ttmbf; pic_param->transform_fields.bits.frame_level_transform_type = vc1_get_TTFRM(v); pic_param->transform_fields.bits.transform_ac_codingset_idx1 = v->c_ac_table_index; pic_param->transform_fields.bits.transform_ac_codingset_idx2 = v->y_ac_table_index; pic_param->transform_fields.bits.intra_transform_dc_table = v->s.dc_table_index; switch (s->pict_type) { case AV_PICTURE_TYPE_B: pic_param->backward_reference_picture = ff_vaapi_get_surface_id(s->next_picture.f); // fall-through case AV_PICTURE_TYPE_P: pic_param->forward_reference_picture = ff_vaapi_get_surface_id(s->last_picture.f); break; } if (pic_param->bitplane_present.value) { uint8_t *bitplane; const uint8_t *ff_bp[3]; int x, y, n; switch (s->pict_type) { case AV_PICTURE_TYPE_P: ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL; ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb ? s->mbskip_table : NULL; ff_bp[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? v->mv_type_mb_plane : NULL; break; case AV_PICTURE_TYPE_B: if (!v->bi_type) { ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL; ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb ? s->mbskip_table : NULL; ff_bp[2] = NULL; /* XXX: interlaced frame (FORWARD plane) */ break; } /* fall-through (BI-type) */ case AV_PICTURE_TYPE_I: ff_bp[0] = NULL; /* XXX: interlaced frame (FIELDTX plane) */ ff_bp[1] = pic_param->bitplane_present.flags.bp_ac_pred ? v->acpred_plane : NULL; ff_bp[2] = pic_param->bitplane_present.flags.bp_overflags ? v->over_flags_plane : NULL; break; default: ff_bp[0] = NULL; ff_bp[1] = NULL; ff_bp[2] = NULL; break; } bitplane = ff_vaapi_alloc_bitplane(vactx, (s->mb_width * s->mb_height + 1) / 2); if (!bitplane) return -1; n = 0; for (y = 0; y < s->mb_height; y++) for (x = 0; x < s->mb_width; x++, n++) vc1_pack_bitplanes(bitplane, n, ff_bp, x, y, s->mb_stride); if (n & 1) /* move last nibble to the high order */ bitplane[n/2] <<= 4; } return 0; }


static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){ GetBitContext gb; int i; init_get_bits(&gb, src, length); for(i=0; i<3; i++){ read_len_table(s->len[i], &gb); if(generate_bits_table(s->bits[i], s->len[i])<0){ return -1; } #if 0 for(j=0; j<256; j++){ printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j); } #endif init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4); } return 0; }


static void test_source_notify(void) { while (g_main_context_iteration(NULL, false)); aio_notify(ctx); g_assert(g_main_context_iteration(NULL, true)); g_assert(!g_main_context_iteration(NULL, false)); }


static void virtio_crypto_dataq_bh(void *opaque) { VirtIOCryptoQueue *q = opaque; VirtIOCrypto *vcrypto = q->vcrypto; VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); /* This happens when device was stopped but BH wasn't. */ if (!vdev->vm_running) { return; } /* Just in case the driver is not ready on more */ if (unlikely(!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))) { return; } virtio_crypto_handle_dataq(vdev, q->dataq); virtio_queue_set_notification(q->dataq, 1); }


static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, hwaddr addr_limit) { void *fdt = NULL; int size, rc; uint32_t acells, scells; if (binfo->dtb_filename) { char *filename; filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename); if (!filename) { fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename); goto fail; } fdt = load_device_tree(filename, &size); if (!fdt) { fprintf(stderr, "Couldn't open dtb file %s\n", filename); g_free(filename); goto fail; } g_free(filename); } else if (binfo->get_dtb) { fdt = binfo->get_dtb(binfo, &size); if (!fdt) { fprintf(stderr, "Board was unable to create a dtb blob\n"); goto fail; } } if (addr_limit > addr && size > (addr_limit - addr)) { /* Installing the device tree blob at addr would exceed addr_limit. * Whether this constitutes failure is up to the caller to decide, * so just return 0 as size, i.e., no error. */ g_free(fdt); return 0; } acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells"); scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells"); if (acells == 0 || scells == 0) { fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n"); goto fail; } if (scells < 2 && binfo->ram_size >= (1ULL << 32)) { /* This is user error so deserves a friendlier error message * than the failure of setprop_sized_cells would provide */ fprintf(stderr, "qemu: dtb file not compatible with " "RAM size > 4GB\n"); goto fail; } rc = qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg", acells, binfo->loader_start, scells, binfo->ram_size); if (rc < 0) { fprintf(stderr, "couldn't set /memory/reg\n"); goto fail; } if (binfo->kernel_cmdline && *binfo->kernel_cmdline) { rc = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", binfo->kernel_cmdline); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/bootargs\n"); goto fail; } } if (binfo->initrd_size) { rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", binfo->initrd_start); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); goto fail; } rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", binfo->initrd_start + binfo->initrd_size); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); goto fail; } } if (binfo->modify_dtb) { binfo->modify_dtb(binfo, fdt); } qemu_fdt_dumpdtb(fdt, size); /* Put the DTB into the memory map as a ROM image: this will ensure * the DTB is copied again upon reset, even if addr points into RAM. */ rom_add_blob_fixed("dtb", fdt, size, addr); g_free(fdt); return size; fail: g_free(fdt); return -1; }


static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, const char *model, const char *name, int fd, int is_connected) { struct sockaddr_in saddr; int newfd; socklen_t saddr_len = sizeof(saddr); NetClientState *nc; NetSocketState *s; /* fd passed: multicast: "learn" dgram_dst address from bound address and save it * Because this may be "shared" socket from a "master" process, datagrams would be recv() * by ONLY ONE process: we must "clone" this dgram socket --jjo */ if (is_connected) { if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) { /* must be bound */ if (saddr.sin_addr.s_addr == 0) { fprintf(stderr, "qemu: error: init_dgram: fd=%d unbound, " "cannot setup multicast dst addr\n", fd); goto err; } /* clone dgram socket */ newfd = net_socket_mcast_create(&saddr, NULL); if (newfd < 0) { /* error already reported by net_socket_mcast_create() */ goto err; } /* clone newfd to fd, close newfd */ dup2(newfd, fd); close(newfd); } else { fprintf(stderr, "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n", fd, strerror(errno)); goto err; } } nc = qemu_new_net_client(&net_dgram_socket_info, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d (%s mcast=%s:%d)", fd, is_connected ? "cloned" : "", inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); s = DO_UPCAST(NetSocketState, nc, nc); s->fd = fd; s->listen_fd = -1; s->send_fn = net_socket_send_dgram; net_socket_read_poll(s, true); /* mcast: save bound address as dst */ if (is_connected) { s->dgram_dst = saddr; } return s; err: closesocket(fd); return NULL; }


static int wc3_read_packet(AVFormatContext *s, AVPacket *pkt) { Wc3DemuxContext *wc3 = s->priv_data; ByteIOContext *pb = s->pb; unsigned int fourcc_tag; unsigned int size; int packet_read = 0; int ret = 0; unsigned char text[1024]; unsigned int palette_number; int i; unsigned char r, g, b; int base_palette_index; while (!packet_read) { fourcc_tag = get_le32(pb); /* chunk sizes are 16-bit aligned */ size = (get_be32(pb) + 1) & (~1); if (url_feof(pb)) return AVERROR(EIO); switch (fourcc_tag) { case BRCH_TAG: /* no-op */ break; case SHOT_TAG: /* load up new palette */ palette_number = get_le32(pb); if (palette_number >= wc3->palette_count) return AVERROR_INVALIDDATA; base_palette_index = palette_number * PALETTE_COUNT * 3; for (i = 0; i < PALETTE_COUNT; i++) { r = wc3->palettes[base_palette_index + i * 3 + 0]; g = wc3->palettes[base_palette_index + i * 3 + 1]; b = wc3->palettes[base_palette_index + i * 3 + 2]; wc3->palette_control.palette[i] = (r << 16) | (g << 8) | (b); } wc3->palette_control.palette_changed = 1; break; case VGA__TAG: /* send out video chunk */ ret= av_get_packet(pb, pkt, size); pkt->stream_index = wc3->video_stream_index; pkt->pts = wc3->pts; packet_read = 1; break; case TEXT_TAG: /* subtitle chunk */ #if 0 url_fseek(pb, size, SEEK_CUR); #else if ((unsigned)size > sizeof(text) || (ret = get_buffer(pb, text, size)) != size) ret = AVERROR(EIO); else { int i = 0; av_log (s, AV_LOG_DEBUG, "Subtitle time!\n"); av_log (s, AV_LOG_DEBUG, " inglish: %s\n", &text[i + 1]); i += text[i] + 1; av_log (s, AV_LOG_DEBUG, " doytsch: %s\n", &text[i + 1]); i += text[i] + 1; av_log (s, AV_LOG_DEBUG, " fronsay: %s\n", &text[i + 1]); } #endif break; case AUDI_TAG: /* send out audio chunk */ ret= av_get_packet(pb, pkt, size); pkt->stream_index = wc3->audio_stream_index; pkt->pts = wc3->pts; /* time to advance pts */ wc3->pts++; packet_read = 1; break; default: av_log (s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n", (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24), (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24)); ret = AVERROR_INVALIDDATA; packet_read = 1; break; } } return ret; }


void hmp_info_memdev(Monitor *mon, const QDict *qdict) { Error *err = NULL; MemdevList *memdev_list = qmp_query_memdev(&err); MemdevList *m = memdev_list; StringOutputVisitor *ov; char *str; int i = 0; while (m) { ov = string_output_visitor_new(false); visit_type_uint16List(string_output_get_visitor(ov), &m->value->host_nodes, NULL, NULL); monitor_printf(mon, "memory backend: %d\n", i); monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); monitor_printf(mon, " merge: %s\n", m->value->merge ? "true" : "false"); monitor_printf(mon, " dump: %s\n", m->value->dump ? "true" : "false"); monitor_printf(mon, " prealloc: %s\n", m->value->prealloc ? "true" : "false"); monitor_printf(mon, " policy: %s\n", HostMemPolicy_lookup[m->value->policy]); str = string_output_get_string(ov); monitor_printf(mon, " host nodes: %s\n", str); g_free(str); string_output_visitor_cleanup(ov); m = m->next; i++; } monitor_printf(mon, "\n"); }


static void guest_suspend(const char *pmutils_bin, const char *sysfile_str, Error **err) { pid_t pid; char *pmutils_path; pmutils_path = g_find_program_in_path(pmutils_bin); pid = fork(); if (pid == 0) { /* child */ int fd; setsid(); reopen_fd_to_null(0); reopen_fd_to_null(1); reopen_fd_to_null(2); if (pmutils_path) { execle(pmutils_path, pmutils_bin, NULL, environ); } /* * If we get here either pm-utils is not installed or execle() has * failed. Let's try the manual method if the caller wants it. */ if (!sysfile_str) { _exit(EXIT_FAILURE); } fd = open(LINUX_SYS_STATE_FILE, O_WRONLY); if (fd < 0) { _exit(EXIT_FAILURE); } if (write(fd, sysfile_str, strlen(sysfile_str)) < 0) { _exit(EXIT_FAILURE); } _exit(EXIT_SUCCESS); } g_free(pmutils_path); if (pid < 0) { error_set(err, QERR_UNDEFINED_ERROR); return; } }


static void test_qemu_strtoull_max(void) { const char *str = g_strdup_printf("%llu", ULLONG_MAX); char f = 'X'; const char *endptr = &f; uint64_t res = 999; int err; err = qemu_strtoull(str, &endptr, 0, &res); g_assert_cmpint(err, ==, 0); g_assert_cmpint(res, ==, ULLONG_MAX); g_assert(endptr == str + strlen(str)); }


static int rate_control(AVCodecContext *avctx, void *arg) { SliceArgs *slice_dat = arg; VC2EncContext *s = slice_dat->ctx; const int sx = slice_dat->x; const int sy = slice_dat->y; int quant_buf[2], bits_buf[2], quant = s->q_start, range = s->q_start/3; const int64_t top = slice_dat->bits_ceil; const double percent = s->tolerance; const double bottom = top - top*(percent/100.0f); int bits = count_hq_slice(s, sx, sy, quant); range -= range & 1; /* Make it an even number */ while ((bits > top) || (bits < bottom)) { range *= bits > top ? +1 : -1; quant = av_clip(quant + range, 0, s->q_ceil); bits = count_hq_slice(s, sx, sy, quant); range = av_clip(range/2, 1, s->q_ceil); if (quant_buf[1] == quant) { quant = bits_buf[0] < bits ? quant_buf[0] : quant; bits = bits_buf[0] < bits ? bits_buf[0] : bits; break; } quant_buf[1] = quant_buf[0]; quant_buf[0] = quant; bits_buf[1] = bits_buf[0]; bits_buf[0] = bits; } slice_dat->quant_idx = av_clip(quant, 0, s->q_ceil); slice_dat->bytes = FFALIGN((bits >> 3), s->size_scaler) + 4 + s->prefix_bytes; return 0; }


static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds, uint64_t info_begin, uint64_t info_length) { BDRVDMGState *s = bs->opaque; int ret; uint32_t count, rsrc_data_offset; uint8_t *buffer = NULL; uint64_t info_end; uint64_t offset; /* read offset from begin of resource fork (info_begin) to resource data */ ret = read_uint32(bs, info_begin, &rsrc_data_offset); if (ret < 0) { goto fail; } else if (rsrc_data_offset > info_length) { ret = -EINVAL; goto fail; } /* read length of resource data */ ret = read_uint32(bs, info_begin + 8, &count); if (ret < 0) { goto fail; } else if (count == 0 || rsrc_data_offset + count > info_length) { ret = -EINVAL; goto fail; } /* begin of resource data (consisting of one or more resources) */ offset = info_begin + rsrc_data_offset; /* end of resource data (there is possibly a following resource map * which will be ignored). */ info_end = offset + count; /* read offsets (mish blocks) from one or more resources in resource data */ while (offset < info_end) { /* size of following resource */ ret = read_uint32(bs, offset, &count); if (ret < 0) { goto fail; } else if (count == 0) { ret = -EINVAL; goto fail; } offset += 4; buffer = g_realloc(buffer, count); ret = bdrv_pread(bs->file, offset, buffer, count); if (ret < 0) { goto fail; } ret = dmg_read_mish_block(s, ds, buffer, count); if (ret < 0) { goto fail; } /* advance offset by size of resource */ offset += count; } ret = 0; fail: g_free(buffer); return ret; }


static int ogg_read_page(AVFormatContext *s, int *str) { AVIOContext *bc = s->pb; struct ogg *ogg = s->priv_data; struct ogg_stream *os; int ret, i = 0; int flags, nsegs; uint64_t gp; uint32_t serial; int size, idx; uint8_t sync[4]; int sp = 0; ret = avio_read(bc, sync, 4); if (ret < 4) return ret < 0 ? ret : AVERROR_EOF; do{ int c; if (sync[sp & 3] == 'O' && sync[(sp + 1) & 3] == 'g' && sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S') break; c = avio_r8(bc); if (bc->eof_reached) return AVERROR_EOF; sync[sp++ & 3] = c; }while (i++ < MAX_PAGE_SIZE); if (i >= MAX_PAGE_SIZE){ av_log (s, AV_LOG_INFO, "ogg, can't find sync word\n"); return AVERROR_INVALIDDATA; } if (avio_r8(bc) != 0) /* version */ return AVERROR_INVALIDDATA; flags = avio_r8(bc); gp = avio_rl64 (bc); serial = avio_rl32 (bc); avio_skip(bc, 8); /* seq, crc */ nsegs = avio_r8(bc); idx = ogg_find_stream (ogg, serial); if (idx < 0){ if (ogg->headers) { int n; for (n = 0; n < ogg->nstreams; n++) { av_freep(&ogg->streams[n].buf); if (!ogg->state || ogg->state->streams[n].private != ogg->streams[n].private) av_freep(&ogg->streams[n].private); } ogg->curidx = -1; ogg->nstreams = 0; idx = ogg_new_stream(s, serial, 0); } else { idx = ogg_new_stream(s, serial, 1); } if (idx < 0) return idx; } os = ogg->streams + idx; os->page_pos = avio_tell(bc) - 27; if(os->psize > 0) ogg_new_buf(ogg, idx); ret = avio_read(bc, os->segments, nsegs); if (ret < nsegs) return ret < 0 ? ret : AVERROR_EOF; os->nsegs = nsegs; os->segp = 0; size = 0; for (i = 0; i < nsegs; i++) size += os->segments[i]; if (flags & OGG_FLAG_CONT || os->incomplete){ if (!os->psize){ while (os->segp < os->nsegs){ int seg = os->segments[os->segp++]; os->pstart += seg; if (seg < 255) break; } os->sync_pos = os->page_pos; } }else{ os->psize = 0; os->sync_pos = os->page_pos; } if (os->bufsize - os->bufpos < size){ uint8_t *nb = av_malloc (os->bufsize *= 2); memcpy (nb, os->buf, os->bufpos); av_free (os->buf); os->buf = nb; } ret = avio_read(bc, os->buf + os->bufpos, size); if (ret < size) return ret < 0 ? ret : AVERROR_EOF; os->bufpos += size; os->granule = gp; os->flags = flags; if (str) *str = idx; return 0; }


static int qdev_add_one_global(QemuOpts *opts, void *opaque) { GlobalProperty *g; ObjectClass *oc; g = g_malloc0(sizeof(*g)); g->driver = qemu_opt_get(opts, "driver"); g->property = qemu_opt_get(opts, "property"); g->value = qemu_opt_get(opts, "value"); oc = object_class_by_name(g->driver); if (oc) { DeviceClass *dc = DEVICE_CLASS(oc); if (dc->hotpluggable) { /* If hotpluggable then skip not_used checking. */ g->not_used = false; } else { /* Maybe a typo. */ g->not_used = true; } } else { /* Maybe a typo. */ g->not_used = true; } qdev_prop_register_global(g); return 0; }


void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, const ptrdiff_t dst_pitch) { int x, y, indx; int32_t p0, p1, p2, p3, tmp0, tmp1, tmp2; int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6; int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9; ptrdiff_t pitch, back_pitch; const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; const int num_bands = 4; /* all bands should have the same pitch */ pitch = plane->bands[0].pitch; /* pixels at the position "y-1" will be set to pixels at the "y" for the 1st iteration */ back_pitch = 0; /* get pointers to the wavelet bands */ b0_ptr = plane->bands[0].buf; b1_ptr = plane->bands[1].buf; b2_ptr = plane->bands[2].buf; b3_ptr = plane->bands[3].buf; for (y = 0; y < plane->height; y += 2) { if (y+2 >= plane->height) pitch= 0; /* load storage variables with values */ if (num_bands > 0) { b0_1 = b0_ptr[0]; b0_2 = b0_ptr[pitch]; } if (num_bands > 1) { b1_1 = b1_ptr[back_pitch]; b1_2 = b1_ptr[0]; b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch]; } if (num_bands > 2) { b2_2 = b2_ptr[0]; // b2[x, y ] b2_3 = b2_2; // b2[x+1,y ] = b2[x,y] b2_5 = b2_ptr[pitch]; // b2[x ,y+1] b2_6 = b2_5; // b2[x+1,y+1] = b2[x,y+1] } if (num_bands > 3) { b3_2 = b3_ptr[back_pitch]; // b3[x ,y-1] b3_3 = b3_2; // b3[x+1,y-1] = b3[x ,y-1] b3_5 = b3_ptr[0]; // b3[x ,y ] b3_6 = b3_5; // b3[x+1,y ] = b3[x ,y ] b3_8 = b3_2 - b3_5*6 + b3_ptr[pitch]; b3_9 = b3_8; } for (x = 0, indx = 0; x < plane->width; x+=2, indx++) { if (x+2 >= plane->width) { b0_ptr --; b1_ptr --; b2_ptr --; b3_ptr --; } /* some values calculated in the previous iterations can */ /* be reused in the next ones, so do appropriate copying */ b2_1 = b2_2; // b2[x-1,y ] = b2[x, y ] b2_2 = b2_3; // b2[x ,y ] = b2[x+1,y ] b2_4 = b2_5; // b2[x-1,y+1] = b2[x ,y+1] b2_5 = b2_6; // b2[x ,y+1] = b2[x+1,y+1] b3_1 = b3_2; // b3[x-1,y-1] = b3[x ,y-1] b3_2 = b3_3; // b3[x ,y-1] = b3[x+1,y-1] b3_4 = b3_5; // b3[x-1,y ] = b3[x ,y ] b3_5 = b3_6; // b3[x ,y ] = b3[x+1,y ] b3_7 = b3_8; // vert_HPF(x-1) b3_8 = b3_9; // vert_HPF(x ) p0 = p1 = p2 = p3 = 0; /* process the LL-band by applying LPF both vertically and horizontally */ if (num_bands > 0) { tmp0 = b0_1; tmp2 = b0_2; b0_1 = b0_ptr[indx+1]; b0_2 = b0_ptr[pitch+indx+1]; tmp1 = tmp0 + b0_1; p0 = tmp0 << 4; p1 = tmp1 << 3; p2 = (tmp0 + tmp2) << 3; p3 = (tmp1 + tmp2 + b0_2) << 2; } /* process the HL-band by applying HPF vertically and LPF horizontally */ if (num_bands > 1) { tmp0 = b1_2; tmp1 = b1_1; b1_2 = b1_ptr[indx+1]; b1_1 = b1_ptr[back_pitch+indx+1]; tmp2 = tmp1 - tmp0*6 + b1_3; b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch+indx+1]; p0 += (tmp0 + tmp1) << 3; p1 += (tmp0 + tmp1 + b1_1 + b1_2) << 2; p2 += tmp2 << 2; p3 += (tmp2 + b1_3) << 1; } /* process the LH-band by applying LPF vertically and HPF horizontally */ if (num_bands > 2) { b2_3 = b2_ptr[indx+1]; b2_6 = b2_ptr[pitch+indx+1]; tmp0 = b2_1 + b2_2; tmp1 = b2_1 - b2_2*6 + b2_3; p0 += tmp0 << 3; p1 += tmp1 << 2; p2 += (tmp0 + b2_4 + b2_5) << 2; p3 += (tmp1 + b2_4 - b2_5*6 + b2_6) << 1; } /* process the HH-band by applying HPF both vertically and horizontally */ if (num_bands > 3) { b3_6 = b3_ptr[indx+1]; // b3[x+1,y ] b3_3 = b3_ptr[back_pitch+indx+1]; // b3[x+1,y-1] tmp0 = b3_1 + b3_4; tmp1 = b3_2 + b3_5; tmp2 = b3_3 + b3_6; b3_9 = b3_3 - b3_6*6 + b3_ptr[pitch+indx+1]; p0 += (tmp0 + tmp1) << 2; p1 += (tmp0 - tmp1*6 + tmp2) << 1; p2 += (b3_7 + b3_8) << 1; p3 += b3_7 - b3_8*6 + b3_9; } /* output four pixels */ dst[x] = av_clip_uint8((p0 >> 6) + 128); dst[x+1] = av_clip_uint8((p1 >> 6) + 128); dst[dst_pitch+x] = av_clip_uint8((p2 >> 6) + 128); dst[dst_pitch+x+1] = av_clip_uint8((p3 >> 6) + 128); }// for x dst += dst_pitch << 1; back_pitch = -pitch; b0_ptr += pitch + 1; b1_ptr += pitch + 1; b2_ptr += pitch + 1; b3_ptr += pitch + 1; } }


void virtio_scsi_common_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev); int i; virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI, sizeof(VirtIOSCSIConfig)); s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *)); s->sense_size = VIRTIO_SCSI_SENSE_SIZE; s->cdb_size = VIRTIO_SCSI_CDB_SIZE; s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, virtio_scsi_handle_ctrl); s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, virtio_scsi_handle_event); for (i = 0; i < s->conf.num_queues; i++) { s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, virtio_scsi_handle_cmd); } }


static CharDriverState *qemu_chr_open_udp_fd(int fd) { CharDriverState *chr = NULL; NetCharDriver *s = NULL; chr = qemu_chr_alloc(); s = g_malloc0(sizeof(NetCharDriver)); s->fd = fd; s->chan = io_channel_from_socket(s->fd); s->bufcnt = 0; s->bufptr = 0; chr->opaque = s; chr->chr_write = udp_chr_write; chr->chr_update_read_handler = udp_chr_update_read_handler; chr->chr_close = udp_chr_close; /* be isn't opened until we get a connection */ chr->explicit_be_open = true; return chr; }


static int genh_read_packet(AVFormatContext *s, AVPacket *pkt) { AVCodecContext *codec = s->streams[0]->codec; GENHDemuxContext *c = s->priv_data; int ret; if (c->dsp_int_type == 1 && codec->codec_id == AV_CODEC_ID_ADPCM_THP && codec->channels > 1) { int i, ch; if (avio_feof(s->pb)) return AVERROR_EOF; av_new_packet(pkt, 8 * codec->channels); for (i = 0; i < 8 / c->interleave_size; i++) { for (ch = 0; ch < codec->channels; ch++) { pkt->data[ch * 8 + i*c->interleave_size+0] = avio_r8(s->pb); pkt->data[ch * 8 + i*c->interleave_size+1] = avio_r8(s->pb); } } ret = 0; } else { ret = av_get_packet(s->pb, pkt, codec->block_align ? codec->block_align : 1024 * codec->channels); } pkt->stream_index = 0; return ret; }


static void balloon_page(void *addr, int deflate) { #if defined(__linux__) if (!kvm_enabled() || kvm_has_sync_mmu()) madvise(addr, TARGET_PAGE_SIZE, deflate ? MADV_WILLNEED : MADV_DONTNEED); #endif }


static void test_self(void) { Coroutine *coroutine; coroutine = qemu_coroutine_create(verify_self); qemu_coroutine_enter(coroutine, &coroutine); }


static void gen_wrteei(DisasContext *ctx) { #if defined(CONFIG_USER_ONLY) gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); #else if (unlikely(ctx->pr)) { gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; } if (ctx->opcode & 0x00008000) { tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); /* Stop translation to have a chance to raise an exception */ gen_stop_exception(ctx); } else { tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); } #endif }


void qemu_put_be16(QEMUFile *f, unsigned int v) { qemu_put_byte(f, v >> 8); qemu_put_byte(f, v); }


static void test_cancel(void) { WorkerTestData data[100]; int num_canceled; int i; /* Start more work items than there will be threads, to ensure * the pool is full. */ test_submit_many(); /* Start long running jobs, to ensure we can cancel some. */ for (i = 0; i < 100; i++) { data[i].n = 0; data[i].ret = -EINPROGRESS; data[i].aiocb = thread_pool_submit_aio(pool, long_cb, &data[i], done_cb, &data[i]); } /* Starting the threads may be left to a bottom half. Let it * run, but do not waste too much time... */ active = 100; aio_notify(ctx); aio_poll(ctx, false); /* Wait some time for the threads to start, with some sanity * testing on the behavior of the scheduler... */ g_assert_cmpint(active, ==, 100); g_usleep(1000000); g_assert_cmpint(active, >, 50); /* Cancel the jobs that haven't been started yet. */ num_canceled = 0; for (i = 0; i < 100; i++) { if (atomic_cmpxchg(&data[i].n, 0, 3) == 0) { data[i].ret = -ECANCELED; bdrv_aio_cancel(data[i].aiocb); active--; num_canceled++; } } g_assert_cmpint(active, >, 0); g_assert_cmpint(num_canceled, <, 100); /* Canceling the others will be a blocking operation. */ for (i = 0; i < 100; i++) { if (data[i].n != 3) { bdrv_aio_cancel(data[i].aiocb); } } /* Finish execution and execute any remaining callbacks. */ qemu_aio_wait_all(); g_assert_cmpint(active, ==, 0); for (i = 0; i < 100; i++) { if (data[i].n == 3) { g_assert_cmpint(data[i].ret, ==, -ECANCELED); g_assert(data[i].aiocb != NULL); } else { g_assert_cmpint(data[i].n, ==, 2); g_assert_cmpint(data[i].ret, ==, 0); g_assert(data[i].aiocb == NULL); } } }


static void spr_write_tbl(DisasContext *ctx, int sprn, int gprn) { if (ctx->tb->cflags & CF_USE_ICOUNT) { gen_io_start(); } gen_helper_store_tbl(cpu_env, cpu_gpr[gprn]); if (ctx->tb->cflags & CF_USE_ICOUNT) { gen_io_end(); gen_stop_exception(ctx); } }


static void coroutine_fn commit_run(void *opaque) { CommitBlockJob *s = opaque; BlockDriverState *active = s->active; BlockDriverState *top = s->top; BlockDriverState *base = s->base; BlockDriverState *overlay_bs = NULL; int64_t sector_num, end; int ret = 0; int n = 0; void *buf; int bytes_written = 0; int64_t base_len; ret = s->common.len = bdrv_getlength(top); if (s->common.len < 0) { goto exit_restore_reopen; } ret = base_len = bdrv_getlength(base); if (base_len < 0) { goto exit_restore_reopen; } if (base_len < s->common.len) { ret = bdrv_truncate(base, s->common.len); if (ret) { goto exit_restore_reopen; } } overlay_bs = bdrv_find_overlay(active, top); end = s->common.len >> BDRV_SECTOR_BITS; buf = qemu_blockalign(top, COMMIT_BUFFER_SIZE); for (sector_num = 0; sector_num < end; sector_num += n) { uint64_t delay_ns = 0; bool copy; wait: /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ block_job_sleep_ns(&s->common, rt_clock, delay_ns); if (block_job_is_cancelled(&s->common)) { break; } /* Copy if allocated above the base */ ret = bdrv_co_is_allocated_above(top, base, sector_num, COMMIT_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); copy = (ret == 1); trace_commit_one_iteration(s, sector_num, n, ret); if (copy) { if (s->common.speed) { delay_ns = ratelimit_calculate_delay(&s->limit, n); if (delay_ns > 0) { goto wait; } } ret = commit_populate(top, base, sector_num, n, buf); bytes_written += n * BDRV_SECTOR_SIZE; } if (ret < 0) { if (s->on_error == BLOCKDEV_ON_ERROR_STOP || s->on_error == BLOCKDEV_ON_ERROR_REPORT|| (s->on_error == BLOCKDEV_ON_ERROR_ENOSPC && ret == -ENOSPC)) { goto exit_free_buf; } else { n = 0; continue; } } /* Publish progress */ s->common.offset += n * BDRV_SECTOR_SIZE; } ret = 0; if (!block_job_is_cancelled(&s->common) && sector_num == end) { /* success */ ret = bdrv_drop_intermediate(active, top, base); } exit_free_buf: qemu_vfree(buf); exit_restore_reopen: /* restore base open flags here if appropriate (e.g., change the base back * to r/o). These reopens do not need to be atomic, since we won't abort * even on failure here */ if (s->base_flags != bdrv_get_flags(base)) { bdrv_reopen(base, s->base_flags, NULL); } if (s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) { bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL); } block_job_completed(&s->common, ret); }


static inline long double compute_read_bwidth(void) { assert(block_mig_state.total_time != 0); return (block_mig_state.reads * BLOCK_SIZE)/ block_mig_state.total_time; }


size_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset, int bswap, const char *fmt, ...) { int i; va_list ap; size_t old_offset = offset; va_start(ap, fmt); for (i = 0; fmt[i]; i++) { switch (fmt[i]) { case 'b': { uint8_t *valp = va_arg(ap, uint8_t *); offset += v9fs_unpack(valp, out_sg, out_num, offset, sizeof(*valp)); break; } case 'w': { uint16_t val, *valp; valp = va_arg(ap, uint16_t *); offset += v9fs_unpack(&val, out_sg, out_num, offset, sizeof(val)); if (bswap) { *valp = le16_to_cpu(val); } else { *valp = val; } break; } case 'd': { uint32_t val, *valp; valp = va_arg(ap, uint32_t *); offset += v9fs_unpack(&val, out_sg, out_num, offset, sizeof(val)); if (bswap) { *valp = le32_to_cpu(val); } else { *valp = val; } break; } case 'q': { uint64_t val, *valp; valp = va_arg(ap, uint64_t *); offset += v9fs_unpack(&val, out_sg, out_num, offset, sizeof(val)); if (bswap) { *valp = le64_to_cpu(val); } else { *valp = val; } break; } case 's': { V9fsString *str = va_arg(ap, V9fsString *); offset += v9fs_unmarshal(out_sg, out_num, offset, bswap, "w", &str->size); /* FIXME: sanity check str->size */ str->data = g_malloc(str->size + 1); offset += v9fs_unpack(str->data, out_sg, out_num, offset, str->size); str->data[str->size] = 0; break; } case 'Q': { V9fsQID *qidp = va_arg(ap, V9fsQID *); offset += v9fs_unmarshal(out_sg, out_num, offset, bswap, "bdq", &qidp->type, &qidp->version, &qidp->path); break; } case 'S': { V9fsStat *statp = va_arg(ap, V9fsStat *); offset += v9fs_unmarshal(out_sg, out_num, offset, bswap, "wwdQdddqsssssddd", &statp->size, &statp->type, &statp->dev, &statp->qid, &statp->mode, &statp->atime, &statp->mtime, &statp->length, &statp->name, &statp->uid, &statp->gid, &statp->muid, &statp->extension, &statp->n_uid, &statp->n_gid, &statp->n_muid); break; } case 'I': { V9fsIattr *iattr = va_arg(ap, V9fsIattr *); offset += v9fs_unmarshal(out_sg, out_num, offset, bswap, "ddddqqqqq", &iattr->valid, &iattr->mode, &iattr->uid, &iattr->gid, &iattr->size, &iattr->atime_sec, &iattr->atime_nsec, &iattr->mtime_sec, &iattr->mtime_nsec); break; } default: break; } } va_end(ap); return offset - old_offset; }


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


int qcrypto_init(Error **errp G_GNUC_UNUSED) { return 0; }


static av_cold int MPA_encode_init(AVCodecContext *avctx) { MpegAudioContext *s = avctx->priv_data; int freq = avctx->sample_rate; int bitrate = avctx->bit_rate; int channels = avctx->channels; int i, v, table; float a; if (channels <= 0 || channels > 2){ av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels); return AVERROR(EINVAL); } bitrate = bitrate / 1000; s->nb_channels = channels; avctx->frame_size = MPA_FRAME_SIZE; avctx->delay = 512 - 32 + 1; /* encoding freq */ s->lsf = 0; for(i=0;i<3;i++) { if (avpriv_mpa_freq_tab[i] == freq) break; if ((avpriv_mpa_freq_tab[i] / 2) == freq) { s->lsf = 1; break; } } if (i == 3){ av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq); return AVERROR(EINVAL); } s->freq_index = i; /* encoding bitrate & frequency */ for(i=0;i<15;i++) { if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate) break; } if (i == 15){ av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate); return AVERROR(EINVAL); } s->bitrate_index = i; /* compute total header size & pad bit */ a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0); s->frame_size = ((int)a) * 8; /* frame fractional size to compute padding */ s->frame_frac = 0; s->frame_frac_incr = (int)((a - floor(a)) * 65536.0); /* select the right allocation table */ table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf); /* number of used subbands */ s->sblimit = ff_mpa_sblimit_table[table]; s->alloc_table = ff_mpa_alloc_tables[table]; av_dlog(avctx, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n", bitrate, freq, s->frame_size, table, s->frame_frac_incr); for(i=0;i<s->nb_channels;i++) s->samples_offset[i] = 0; for(i=0;i<257;i++) { int v; v = ff_mpa_enwindow[i]; #if WFRAC_BITS != 16 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); #endif s->filter_bank[i] = v; if ((i & 63) != 0) v = -v; if (i != 0) s->filter_bank[512 - i] = v; } for(i=0;i<64;i++) { v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20)); if (v <= 0) v = 1; s->scale_factor_table[i] = v; s->scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20); } for(i=0;i<128;i++) { v = i - 64; if (v <= -3) v = 0; else if (v < 0) v = 1; else if (v == 0) v = 2; else if (v < 3) v = 3; else v = 4; s->scale_diff_table[i] = v; } for(i=0;i<17;i++) { v = ff_mpa_quant_bits[i]; if (v < 0) v = -v; else v = v * 3; s->total_quant_bits[i] = 12 * v; } return 0; }


BlockDriverState *check_to_replace_node(const char *node_name, Error **errp) { BlockDriverState *to_replace_bs = bdrv_find_node(node_name); AioContext *aio_context; if (!to_replace_bs) { error_setg(errp, "Node name '%s' not found", node_name); return NULL; } aio_context = bdrv_get_aio_context(to_replace_bs); aio_context_acquire(aio_context); if (bdrv_op_is_blocked(to_replace_bs, BLOCK_OP_TYPE_REPLACE, errp)) { to_replace_bs = NULL; goto out; } /* We don't want arbitrary node of the BDS chain to be replaced only the top * most non filter in order to prevent data corruption. * Another benefit is that this tests exclude backing files which are * blocked by the backing blockers. */ if (!bdrv_is_first_non_filter(to_replace_bs)) { error_setg(errp, "Only top most non filter can be replaced"); to_replace_bs = NULL; goto out; } out: aio_context_release(aio_context); return to_replace_bs; }


static uint32_t ecc_mem_readb(void *opaque, target_phys_addr_t addr) { printf("ECC: Unsupported read 0x" TARGET_FMT_plx " 00\n", addr); return 0; }


static inline void gen_op_mov_reg_v(int ot, int reg, TCGv t0) { switch(ot) { case OT_BYTE: if (reg < 4 X86_64_DEF( || reg >= 8 || x86_64_hregs)) { tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], t0, 0, 8); } else { tcg_gen_deposit_tl(cpu_regs[reg - 4], cpu_regs[reg - 4], t0, 8, 8); } break; case OT_WORD: tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], t0, 0, 16); break; default: /* XXX this shouldn't be reached; abort? */ case OT_LONG: /* For x86_64, this sets the higher half of register to zero. For i386, this is equivalent to a mov. */ tcg_gen_ext32u_tl(cpu_regs[reg], t0); break; #ifdef TARGET_X86_64 case OT_QUAD: tcg_gen_mov_tl(cpu_regs[reg], t0); break; #endif } }


static int local_symlink(FsContext *fs_ctx, const char *oldpath, V9fsPath *dir_path, const char *name, FsCred *credp) { int err = -1; int serrno = 0; char *newpath; V9fsString fullname; char buffer[PATH_MAX]; v9fs_string_init(&fullname); v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); newpath = fullname.data; /* Determine the security model */ if (fs_ctx->fs_sm == SM_MAPPED) { int fd; ssize_t oldpath_size, write_size; fd = open(rpath(fs_ctx, newpath, buffer), O_CREAT|O_EXCL|O_RDWR, SM_LOCAL_MODE_BITS); if (fd == -1) { err = fd; goto out; } /* Write the oldpath (target) to the file. */ oldpath_size = strlen(oldpath); do { write_size = write(fd, (void *)oldpath, oldpath_size); } while (write_size == -1 && errno == EINTR); if (write_size != oldpath_size) { serrno = errno; close(fd); err = -1; goto err_end; } close(fd); /* Set cleint credentials in symlink's xattr */ credp->fc_mode = credp->fc_mode|S_IFLNK; err = local_set_xattr(rpath(fs_ctx, newpath, buffer), credp); if (err == -1) { serrno = errno; goto err_end; } } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) || (fs_ctx->fs_sm == SM_NONE)) { err = symlink(oldpath, rpath(fs_ctx, newpath, buffer)); if (err) { goto out; } err = lchown(rpath(fs_ctx, newpath, buffer), credp->fc_uid, credp->fc_gid); if (err == -1) { /* * If we fail to change ownership and if we are * using security model none. Ignore the error */ if (fs_ctx->fs_sm != SM_NONE) { serrno = errno; goto err_end; } else err = 0; } } goto out; err_end: remove(rpath(fs_ctx, newpath, buffer)); errno = serrno; out: v9fs_string_free(&fullname); return err; }


int socket_listen(SocketAddress *addr, Error **errp) { QemuOpts *opts; int fd; opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); switch (addr->kind) { case SOCKET_ADDRESS_KIND_INET: inet_addr_to_opts(opts, addr->inet); fd = inet_listen_opts(opts, 0, errp); break; case SOCKET_ADDRESS_KIND_UNIX: qemu_opt_set(opts, "path", addr->q_unix->path, &error_abort); fd = unix_listen_opts(opts, errp); break; case SOCKET_ADDRESS_KIND_FD: fd = monitor_get_fd(cur_mon, addr->fd->str, errp); break; default: abort(); } qemu_opts_del(opts); return fd; }


static int qcow_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVQcowState *s = bs->opaque; unsigned int len, i, shift; int ret; QCowHeader header; Error *local_err = NULL; bs->file = bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); if (!bs->file) { return -EINVAL; } ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { goto fail; } be32_to_cpus(&header.magic); be32_to_cpus(&header.version); be64_to_cpus(&header.backing_file_offset); be32_to_cpus(&header.backing_file_size); be32_to_cpus(&header.mtime); be64_to_cpus(&header.size); be32_to_cpus(&header.crypt_method); be64_to_cpus(&header.l1_table_offset); if (header.magic != QCOW_MAGIC) { error_setg(errp, "Image not in qcow format"); ret = -EINVAL; goto fail; } if (header.version != QCOW_VERSION) { error_setg(errp, "Unsupported qcow version %" PRIu32, header.version); ret = -ENOTSUP; goto fail; } if (header.size <= 1) { error_setg(errp, "Image size is too small (must be at least 2 bytes)"); ret = -EINVAL; goto fail; } if (header.cluster_bits < 9 || header.cluster_bits > 16) { error_setg(errp, "Cluster size must be between 512 and 64k"); ret = -EINVAL; goto fail; } /* l2_bits specifies number of entries; storing a uint64_t in each entry, * so bytes = num_entries << 3. */ if (header.l2_bits < 9 - 3 || header.l2_bits > 16 - 3) { error_setg(errp, "L2 table size must be between 512 and 64k"); ret = -EINVAL; goto fail; } if (header.crypt_method > QCOW_CRYPT_AES) { error_setg(errp, "invalid encryption method in qcow header"); ret = -EINVAL; goto fail; } if (!qcrypto_cipher_supports(QCRYPTO_CIPHER_ALG_AES_128, QCRYPTO_CIPHER_MODE_CBC)) { error_setg(errp, "AES cipher not available"); ret = -EINVAL; goto fail; } s->crypt_method_header = header.crypt_method; if (s->crypt_method_header) { if (bdrv_uses_whitelist() && s->crypt_method_header == QCOW_CRYPT_AES) { error_setg(errp, "Use of AES-CBC encrypted qcow images is no longer " "supported in system emulators"); error_append_hint(errp, "You can use 'qemu-img convert' to convert your " "image to an alternative supported format, such " "as unencrypted qcow, or raw with the LUKS " "format instead.\n"); ret = -ENOSYS; goto fail; } bs->encrypted = true; } s->cluster_bits = header.cluster_bits; s->cluster_size = 1 << s->cluster_bits; s->cluster_sectors = 1 << (s->cluster_bits - 9); s->l2_bits = header.l2_bits; s->l2_size = 1 << s->l2_bits; bs->total_sectors = header.size / 512; s->cluster_offset_mask = (1LL << (63 - s->cluster_bits)) - 1; /* read the level 1 table */ shift = s->cluster_bits + s->l2_bits; if (header.size > UINT64_MAX - (1LL << shift)) { error_setg(errp, "Image too large"); ret = -EINVAL; goto fail; } else { uint64_t l1_size = (header.size + (1LL << shift) - 1) >> shift; if (l1_size > INT_MAX / sizeof(uint64_t)) { error_setg(errp, "Image too large"); ret = -EINVAL; goto fail; } s->l1_size = l1_size; } s->l1_table_offset = header.l1_table_offset; s->l1_table = g_try_new(uint64_t, s->l1_size); if (s->l1_table == NULL) { error_setg(errp, "Could not allocate memory for L1 table"); ret = -ENOMEM; goto fail; } ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)); if (ret < 0) { goto fail; } for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } /* alloc L2 cache (max. 64k * 16 * 8 = 8 MB) */ s->l2_cache = qemu_try_blockalign(bs->file->bs, s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); if (s->l2_cache == NULL) { error_setg(errp, "Could not allocate L2 table cache"); ret = -ENOMEM; goto fail; } s->cluster_cache = g_malloc(s->cluster_size); s->cluster_data = g_malloc(s->cluster_size); s->cluster_cache_offset = -1; /* read the backing file name */ if (header.backing_file_offset != 0) { len = header.backing_file_size; if (len > 1023 || len >= sizeof(bs->backing_file)) { error_setg(errp, "Backing file name too long"); ret = -EINVAL; goto fail; } ret = bdrv_pread(bs->file, header.backing_file_offset, bs->backing_file, len); if (ret < 0) { goto fail; } bs->backing_file[len] = '\0'; } /* Disable migration when qcow images are used */ error_setg(&s->migration_blocker, "The qcow format used by node '%s' " "does not support live migration", bdrv_get_device_or_node_name(bs)); ret = migrate_add_blocker(s->migration_blocker, &local_err); if (local_err) { error_propagate(errp, local_err); error_free(s->migration_blocker); goto fail; } qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->l1_table); qemu_vfree(s->l2_cache); g_free(s->cluster_cache); g_free(s->cluster_data); return ret; }


static void sigp_restart(CPUState *cs, run_on_cpu_data arg) { S390CPU *cpu = S390_CPU(cs); SigpInfo *si = arg.host_ptr; struct kvm_s390_irq irq = { .type = KVM_S390_RESTART, }; switch (s390_cpu_get_state(cpu)) { case CPU_STATE_STOPPED: /* the restart irq has to be delivered prior to any other pending irq */ cpu_synchronize_state(cs); do_restart_interrupt(&cpu->env); s390_cpu_set_state(CPU_STATE_OPERATING, cpu); break; case CPU_STATE_OPERATING: kvm_s390_vcpu_interrupt(cpu, &irq); break; } si->cc = SIGP_CC_ORDER_CODE_ACCEPTED; }


void qemu_purge_queued_packets(VLANClientState *vc) { VLANPacket *packet, *next; TAILQ_FOREACH_SAFE(packet, &vc->vlan->send_queue, entry, next) { if (packet->sender == vc) { TAILQ_REMOVE(&vc->vlan->send_queue, packet, entry); qemu_free(packet); } } }


static void mips_tlb_flush_extra (CPUState *env, int first) { /* Discard entries from env->tlb[first] onwards. */ while (env->tlb_in_use > first) { invalidate_tlb(--env->tlb_in_use, 0); } }


void ff_avg_h264_qpel8_mc32_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_midh_qrt_and_aver_dst_8w_msa(src - (2 * stride) - 2, stride, dst, stride, 8, 1); }


DeviceState *exynos4210_uart_create(target_phys_addr_t addr, int fifo_size, int channel, CharDriverState *chr, qemu_irq irq) { DeviceState *dev; SysBusDevice *bus; const char chr_name[] = "serial"; char label[ARRAY_SIZE(chr_name) + 1]; dev = qdev_create(NULL, "exynos4210.uart"); if (!chr) { if (channel >= MAX_SERIAL_PORTS) { hw_error("Only %d serial ports are supported by QEMU.\n", MAX_SERIAL_PORTS); } chr = serial_hds[channel]; if (!chr) { snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, channel); chr = qemu_chr_new(label, "null", NULL); if (!(chr)) { hw_error("Can't assign serial port to UART%d.\n", channel); } } } qdev_prop_set_chr(dev, "chardev", chr); qdev_prop_set_uint32(dev, "channel", channel); qdev_prop_set_uint32(dev, "rx-size", fifo_size); qdev_prop_set_uint32(dev, "tx-size", fifo_size); bus = sysbus_from_qdev(dev); qdev_init_nofail(dev); if (addr != (target_phys_addr_t)-1) { sysbus_mmio_map(bus, 0, addr); } sysbus_connect_irq(bus, 0, irq); return dev; }


static VncClientInfo *qmp_query_vnc_client(const VncState *client) { struct sockaddr_storage sa; socklen_t salen = sizeof(sa); char host[NI_MAXHOST]; char serv[NI_MAXSERV]; VncClientInfo *info; if (getpeername(client->csock, (struct sockaddr *)&sa, &salen) < 0) { return NULL; } if (getnameinfo((struct sockaddr *)&sa, salen, host, sizeof(host), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV) < 0) { return NULL; } info = g_malloc0(sizeof(*info)); info->base = g_malloc0(sizeof(*info->base)); info->base->host = g_strdup(host); info->base->service = g_strdup(serv); info->base->family = inet_netfamily(sa.ss_family); info->base->websocket = client->websocket; if (client->tls) { info->x509_dname = qcrypto_tls_session_get_peer_name(client->tls); info->has_x509_dname = info->x509_dname != NULL; } #ifdef CONFIG_VNC_SASL if (client->sasl.conn && client->sasl.username) { info->has_sasl_username = true; info->sasl_username = g_strdup(client->sasl.username); } #endif return info; }


static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) { uint8_t *src; int x, y, x_end, y_end, chroma; int c_tc[2], beta[2], tc[2]; uint8_t no_p[2] = { 0 }; uint8_t no_q[2] = { 0 }; int log2_ctb_size = s->sps->log2_ctb_size; int ctb_size = 1 << log2_ctb_size; int ctb = (x0 >> log2_ctb_size) + (y0 >> log2_ctb_size) * s->sps->ctb_width; int cur_tc_offset = s->deblock[ctb].tc_offset; int cur_beta_offset = s->deblock[ctb].beta_offset; int tc_offset, left_tc_offset, beta_offset, left_beta_offset; int pcmf = (s->sps->pcm_enabled_flag && s->sps->pcm.loop_filter_disable_flag) || s->pps->transquant_bypass_enable_flag; if (x0) { left_tc_offset = s->deblock[ctb - 1].tc_offset; left_beta_offset = s->deblock[ctb - 1].beta_offset; } x_end = x0 + ctb_size; if (x_end > s->sps->width) x_end = s->sps->width; y_end = y0 + ctb_size; if (y_end > s->sps->height) y_end = s->sps->height; tc_offset = cur_tc_offset; beta_offset = cur_beta_offset; // vertical filtering luma for (y = y0; y < y_end; y += 8) { for (x = x0 ? x0 : 8; x < x_end; x += 8) { const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width]; const int bs1 = s->vertical_bs[(x >> 3) + ((y + 4) >> 2) * s->bs_width]; if (bs0 || bs1) { const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; const int qp1 = (get_qPy(s, x - 1, y + 4) + get_qPy(s, x, y + 4) + 1) >> 1; beta[0] = betatable[av_clip(qp0 + beta_offset, 0, MAX_QP)]; beta[1] = betatable[av_clip(qp1 + beta_offset, 0, MAX_QP)]; tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0; tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0; src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x - 1, y); no_p[1] = get_pcm(s, x - 1, y + 4); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x, y + 4); s->hevcdsp.hevc_v_loop_filter_luma_c(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); } else s->hevcdsp.hevc_v_loop_filter_luma(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); } } } // vertical filtering chroma for (chroma = 1; chroma <= 2; chroma++) { for (y = y0; y < y_end; y += 16) { for (x = x0 ? x0 : 16; x < x_end; x += 16) { const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width]; const int bs1 = s->vertical_bs[(x >> 3) + ((y + 8) >> 2) * s->bs_width]; if ((bs0 == 2) || (bs1 == 2)) { const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; const int qp1 = (get_qPy(s, x - 1, y + 8) + get_qPy(s, x, y + 8) + 1) >> 1; c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0; src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x - 1, y); no_p[1] = get_pcm(s, x - 1, y + 8); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x, y + 8); s->hevcdsp.hevc_v_loop_filter_chroma_c(src, s->frame->linesize[chroma], c_tc, no_p, no_q); } else s->hevcdsp.hevc_v_loop_filter_chroma(src, s->frame->linesize[chroma], c_tc, no_p, no_q); } } } } // horizontal filtering luma if (x_end != s->sps->width) x_end -= 8; for (y = y0 ? y0 : 8; y < y_end; y += 8) { for (x = x0 ? x0 - 8 : 0; x < x_end; x += 8) { const int bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; const int bs1 = s->horizontal_bs[(x + 4 + y * s->bs_width) >> 2]; if (bs0 || bs1) { const int qp0 = (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1; const int qp1 = (get_qPy(s, x + 4, y - 1) + get_qPy(s, x + 4, y) + 1) >> 1; tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset; beta[0] = betatable[av_clip(qp0 + beta_offset, 0, MAX_QP)]; beta[1] = betatable[av_clip(qp1 + beta_offset, 0, MAX_QP)]; tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0; tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0; src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x, y - 1); no_p[1] = get_pcm(s, x + 4, y - 1); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x + 4, y); s->hevcdsp.hevc_h_loop_filter_luma_c(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); } else s->hevcdsp.hevc_h_loop_filter_luma(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q); } } } // horizontal filtering chroma for (chroma = 1; chroma <= 2; chroma++) { for (y = y0 ? y0 : 16; y < y_end; y += 16) { for (x = x0 - 8; x < x_end; x += 16) { int bs0, bs1; // to make sure no memory access over boundary when x = -8 // TODO: simplify with row based deblocking if (x < 0) { bs0 = 0; bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2]; } else if (x >= x_end - 8) { bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; bs1 = 0; } else { bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2]; } if ((bs0 == 2) || (bs1 == 2)) { const int qp0 = bs0 == 2 ? (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1 : 0; const int qp1 = bs1 == 2 ? (get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1 : 0; tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; c_tc[0] = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[1] = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0; src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; if (pcmf) { no_p[0] = get_pcm(s, x, y - 1); no_p[1] = get_pcm(s, x + 8, y - 1); no_q[0] = get_pcm(s, x, y); no_q[1] = get_pcm(s, x + 8, y); s->hevcdsp.hevc_h_loop_filter_chroma_c(src, s->frame->linesize[chroma], c_tc, no_p, no_q); } else s->hevcdsp.hevc_h_loop_filter_chroma(src, s->frame->linesize[chroma], c_tc, no_p, no_q); } } } } }


static inline void mix_2f_2r_to_dolby(AC3DecodeContext *ctx) { int i; float (*output)[256] = ctx->audio_block.block_output; for (i = 0; i < 256; i++) { output[1][i] -= output[3][i]; output[2][i] += output[4][i]; } memset(output[3], 0, sizeof(output[3])); memset(output[4], 0, sizeof(output[4])); }


int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) { QSVFrame *cur; MFXVideoENCODE_Close(q->session); if (q->internal_session) MFXClose(q->internal_session); q->session = NULL; q->internal_session = NULL; cur = q->work_frames; while (cur) { q->work_frames = cur->next; av_frame_free(&cur->frame); av_freep(&cur); cur = q->work_frames; } while (q->async_fifo && av_fifo_size(q->async_fifo)) { AVPacket pkt; mfxSyncPoint sync; mfxBitstream *bs; av_fifo_generic_read(q->async_fifo, &pkt, sizeof(pkt), NULL); av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL); av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL); av_freep(&bs); av_packet_unref(&pkt); } av_fifo_free(q->async_fifo); q->async_fifo = NULL; av_frame_free(&avctx->coded_frame); return 0; }


static av_cold int raw_encode_init(AVCodecContext *avctx) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); avctx->coded_frame = av_frame_alloc(); if (!avctx->coded_frame) return AVERROR(ENOMEM); avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; avctx->coded_frame->key_frame = 1; avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc); if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; }


int ff_audio_mix(AudioMix *am, AudioData *src) { int use_generic = 1; int len = src->nb_samples; int i, j; /* determine whether to use the optimized function based on pointer and samples alignment in both the input and output */ if (am->has_optimized_func) { int aligned_len = FFALIGN(len, am->samples_align); if (!(src->ptr_align % am->ptr_align) && src->samples_align >= aligned_len) { len = aligned_len; use_generic = 0; } } av_dlog(am->avr, "audio_mix: %d samples - %d to %d channels (%s)\n", src->nb_samples, am->in_channels, am->out_channels, use_generic ? am->func_descr_generic : am->func_descr); if (am->in_matrix_channels && am->out_matrix_channels) { uint8_t **data; uint8_t *data0[AVRESAMPLE_MAX_CHANNELS]; if (am->out_matrix_channels < am->out_channels || am->in_matrix_channels < am->in_channels) { for (i = 0, j = 0; i < FFMAX(am->in_channels, am->out_channels); i++) { if (am->input_skip[i] || am->output_skip[i] || am->output_zero[i]) continue; data0[j++] = src->data[i]; } data = data0; } else { data = src->data; } if (use_generic) am->mix_generic(data, am->matrix, len, am->out_matrix_channels, am->in_matrix_channels); else am->mix(data, am->matrix, len, am->out_matrix_channels, am->in_matrix_channels); } if (am->out_matrix_channels < am->out_channels) { for (i = 0; i < am->out_channels; i++) if (am->output_zero[i]) av_samples_set_silence(&src->data[i], 0, len, 1, am->fmt); } ff_audio_data_set_channels(src, am->out_channels); return 0; }


static int ahci_dma_set_inactive(IDEDMA *dma) { AHCIDevice *ad = DO_UPCAST(AHCIDevice, dma, dma); DPRINTF(ad->port_no, "dma done\n"); /* update d2h status */ ahci_write_fis_d2h(ad, NULL); ad->dma_cb = NULL; /* maybe we still have something to process, check later */ ad->check_bh = qemu_bh_new(ahci_check_cmd_bh, ad); qemu_bh_schedule(ad->check_bh); return 0; }


DriveInfo *drive_init(QemuOpts *opts, void *opaque, int *fatal_error) { const char *buf; const char *file = NULL; char devname[128]; const char *serial; const char *mediastr = ""; BlockInterfaceType type; enum { MEDIA_DISK, MEDIA_CDROM } media; int bus_id, unit_id; int cyls, heads, secs, translation; BlockDriver *drv = NULL; QEMUMachine *machine = opaque; int max_devs; int index; int ro = 0; int bdrv_flags = 0; int on_read_error, on_write_error; const char *devaddr; DriveInfo *dinfo; int snapshot = 0; *fatal_error = 1; translation = BIOS_ATA_TRANSLATION_AUTO; if (machine && machine->use_scsi) { type = IF_SCSI; max_devs = MAX_SCSI_DEVS; pstrcpy(devname, sizeof(devname), "scsi"); } else { type = IF_IDE; max_devs = MAX_IDE_DEVS; pstrcpy(devname, sizeof(devname), "ide"); } media = MEDIA_DISK; /* extract parameters */ bus_id = qemu_opt_get_number(opts, "bus", 0); unit_id = qemu_opt_get_number(opts, "unit", -1); index = qemu_opt_get_number(opts, "index", -1); cyls = qemu_opt_get_number(opts, "cyls", 0); heads = qemu_opt_get_number(opts, "heads", 0); secs = qemu_opt_get_number(opts, "secs", 0); snapshot = qemu_opt_get_bool(opts, "snapshot", 0); ro = qemu_opt_get_bool(opts, "readonly", 0); file = qemu_opt_get(opts, "file"); serial = qemu_opt_get(opts, "serial"); if ((buf = qemu_opt_get(opts, "if")) != NULL) { pstrcpy(devname, sizeof(devname), buf); if (!strcmp(buf, "ide")) { type = IF_IDE; max_devs = MAX_IDE_DEVS; } else if (!strcmp(buf, "scsi")) { type = IF_SCSI; max_devs = MAX_SCSI_DEVS; } else if (!strcmp(buf, "floppy")) { type = IF_FLOPPY; max_devs = 0; } else if (!strcmp(buf, "pflash")) { type = IF_PFLASH; max_devs = 0; } else if (!strcmp(buf, "mtd")) { type = IF_MTD; max_devs = 0; } else if (!strcmp(buf, "sd")) { type = IF_SD; max_devs = 0; } else if (!strcmp(buf, "virtio")) { type = IF_VIRTIO; max_devs = 0; } else if (!strcmp(buf, "xen")) { type = IF_XEN; max_devs = 0; } else if (!strcmp(buf, "none")) { type = IF_NONE; max_devs = 0; } else { fprintf(stderr, "qemu: unsupported bus type '%s'\n", buf); return NULL; } } if (cyls || heads || secs) { if (cyls < 1 || (type == IF_IDE && cyls > 16383)) { fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", buf); return NULL; } if (heads < 1 || (type == IF_IDE && heads > 16)) { fprintf(stderr, "qemu: '%s' invalid physical heads number\n", buf); return NULL; } if (secs < 1 || (type == IF_IDE && secs > 63)) { fprintf(stderr, "qemu: '%s' invalid physical secs number\n", buf); return NULL; } } if ((buf = qemu_opt_get(opts, "trans")) != NULL) { if (!cyls) { fprintf(stderr, "qemu: '%s' trans must be used with cyls,heads and secs\n", buf); return NULL; } if (!strcmp(buf, "none")) translation = BIOS_ATA_TRANSLATION_NONE; else if (!strcmp(buf, "lba")) translation = BIOS_ATA_TRANSLATION_LBA; else if (!strcmp(buf, "auto")) translation = BIOS_ATA_TRANSLATION_AUTO; else { fprintf(stderr, "qemu: '%s' invalid translation type\n", buf); return NULL; } } if ((buf = qemu_opt_get(opts, "media")) != NULL) { if (!strcmp(buf, "disk")) { media = MEDIA_DISK; } else if (!strcmp(buf, "cdrom")) { if (cyls || secs || heads) { fprintf(stderr, "qemu: '%s' invalid physical CHS format\n", buf); return NULL; } media = MEDIA_CDROM; } else { fprintf(stderr, "qemu: '%s' invalid media\n", buf); return NULL; } } if ((buf = qemu_opt_get(opts, "cache")) != NULL) { if (!strcmp(buf, "off") || !strcmp(buf, "none")) { bdrv_flags |= BDRV_O_NOCACHE; } else if (!strcmp(buf, "writeback")) { } else if (!strcmp(buf, "writethrough")) { /* this is the default */ } else { fprintf(stderr, "qemu: invalid cache option\n"); return NULL; } } #ifdef CONFIG_LINUX_AIO if ((buf = qemu_opt_get(opts, "aio")) != NULL) { if (!strcmp(buf, "native")) { bdrv_flags |= BDRV_O_NATIVE_AIO; } else if (!strcmp(buf, "threads")) { /* this is the default */ } else { fprintf(stderr, "qemu: invalid aio option\n"); return NULL; } } #endif if ((buf = qemu_opt_get(opts, "format")) != NULL) { if (strcmp(buf, "?") == 0) { fprintf(stderr, "qemu: Supported formats:"); bdrv_iterate_format(bdrv_format_print, NULL); fprintf(stderr, "\n"); return NULL; } drv = bdrv_find_whitelisted_format(buf); if (!drv) { fprintf(stderr, "qemu: '%s' invalid format\n", buf); return NULL; } } on_write_error = BLOCK_ERR_STOP_ENOSPC; if ((buf = qemu_opt_get(opts, "werror")) != NULL) { if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { fprintf(stderr, "werror is no supported by this format\n"); return NULL; } on_write_error = parse_block_error_action(buf, 0); if (on_write_error < 0) { return NULL; } } on_read_error = BLOCK_ERR_REPORT; if ((buf = qemu_opt_get(opts, "rerror")) != NULL) { if (type != IF_IDE && type != IF_VIRTIO) { fprintf(stderr, "rerror is no supported by this format\n"); return NULL; } on_read_error = parse_block_error_action(buf, 1); if (on_read_error < 0) { return NULL; } } if ((devaddr = qemu_opt_get(opts, "addr")) != NULL) { if (type != IF_VIRTIO) { fprintf(stderr, "addr is not supported\n"); return NULL; } } /* compute bus and unit according index */ if (index != -1) { if (bus_id != 0 || unit_id != -1) { fprintf(stderr, "qemu: index cannot be used with bus and unit\n"); return NULL; } if (max_devs == 0) { unit_id = index; bus_id = 0; } else { unit_id = index % max_devs; bus_id = index / max_devs; } } /* if user doesn't specify a unit_id, * try to find the first free */ if (unit_id == -1) { unit_id = 0; while (drive_get(type, bus_id, unit_id) != NULL) { unit_id++; if (max_devs && unit_id >= max_devs) { unit_id -= max_devs; bus_id++; } } } /* check unit id */ if (max_devs && unit_id >= max_devs) { fprintf(stderr, "qemu: unit %d too big (max is %d)\n", unit_id, max_devs - 1); return NULL; } /* * ignore multiple definitions */ if (drive_get(type, bus_id, unit_id) != NULL) { *fatal_error = 0; return NULL; } /* init */ dinfo = qemu_mallocz(sizeof(*dinfo)); if ((buf = qemu_opts_id(opts)) != NULL) { dinfo->id = qemu_strdup(buf); } else { /* no id supplied -> create one */ dinfo->id = qemu_mallocz(32); if (type == IF_IDE || type == IF_SCSI) mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; if (max_devs) snprintf(dinfo->id, 32, "%s%i%s%i", devname, bus_id, mediastr, unit_id); else snprintf(dinfo->id, 32, "%s%s%i", devname, mediastr, unit_id); } dinfo->bdrv = bdrv_new(dinfo->id); dinfo->devaddr = devaddr; dinfo->type = type; dinfo->bus = bus_id; dinfo->unit = unit_id; dinfo->on_read_error = on_read_error; dinfo->on_write_error = on_write_error; dinfo->opts = opts; if (serial) strncpy(dinfo->serial, serial, sizeof(serial)); QTAILQ_INSERT_TAIL(&drives, dinfo, next); switch(type) { case IF_IDE: case IF_SCSI: case IF_XEN: case IF_NONE: switch(media) { case MEDIA_DISK: if (cyls != 0) { bdrv_set_geometry_hint(dinfo->bdrv, cyls, heads, secs); bdrv_set_translation_hint(dinfo->bdrv, translation); } break; case MEDIA_CDROM: bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_CDROM); break; } break; case IF_SD: /* FIXME: This isn't really a floppy, but it's a reasonable approximation. */ case IF_FLOPPY: bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_FLOPPY); break; case IF_PFLASH: case IF_MTD: break; case IF_VIRTIO: /* add virtio block device */ opts = qemu_opts_create(&qemu_device_opts, NULL, 0); qemu_opt_set(opts, "driver", "virtio-blk-pci"); qemu_opt_set(opts, "drive", dinfo->id); if (devaddr) qemu_opt_set(opts, "addr", devaddr); break; case IF_COUNT: abort(); } if (!file) { *fatal_error = 0; return NULL; } if (snapshot) { /* always use write-back with snapshot */ bdrv_flags &= ~BDRV_O_CACHE_MASK; bdrv_flags |= (BDRV_O_SNAPSHOT|BDRV_O_CACHE_WB); } if (media == MEDIA_CDROM) { /* CDROM is fine for any interface, don't check. */ ro = 1; } else if (ro == 1) { if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY) { fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n"); return NULL; } } bdrv_flags |= ro ? 0 : BDRV_O_RDWR; if (bdrv_open(dinfo->bdrv, file, bdrv_flags, drv) < 0) { fprintf(stderr, "qemu: could not open disk image %s: %s\n", file, strerror(errno)); return NULL; } if (bdrv_key_required(dinfo->bdrv)) autostart = 0; *fatal_error = 0; return dinfo; }


static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) { int i, x, y; i=0; x=0; y=0; while(i<buf_size) { int run_length, color; if (buf[i] & 0x80) { run_length = 1; color = buf[i]; i++; }else{ run_length = (buf[i] & 0x7f) + 2; color = buf[i+1]; i+=2; } if (half_horiz) run_length *=2; if (color) { memset(s->frame.data[0] + y*s->frame.linesize[0] + x, color, run_length); if (half_vert) memset(s->frame.data[0] + (y+1)*s->frame.linesize[0] + x, color, run_length); } x+= run_length; if (x >= s->avctx->width) { x=0; y += half_vert ? 2 : 1; } } }


milkymist_init(QEMUMachineInitArgs *args) { const char *cpu_model = args->cpu_model; const char *kernel_filename = args->kernel_filename; const char *kernel_cmdline = args->kernel_cmdline; const char *initrd_filename = args->initrd_filename; LM32CPU *cpu; CPULM32State *env; int kernel_size; DriveInfo *dinfo; MemoryRegion *address_space_mem = get_system_memory(); MemoryRegion *phys_sdram = g_new(MemoryRegion, 1); qemu_irq irq[32], *cpu_irq; int i; char *bios_filename; ResetInfo *reset_info; /* memory map */ hwaddr flash_base = 0x00000000; size_t flash_sector_size = 128 * 1024; size_t flash_size = 32 * 1024 * 1024; hwaddr sdram_base = 0x40000000; size_t sdram_size = 128 * 1024 * 1024; hwaddr initrd_base = sdram_base + 0x1002000; hwaddr cmdline_base = sdram_base + 0x1000000; size_t initrd_max = sdram_size - 0x1002000; reset_info = g_malloc0(sizeof(ResetInfo)); if (cpu_model == NULL) { cpu_model = "lm32-full"; cpu = cpu_lm32_init(cpu_model); env = &cpu->env; reset_info->cpu = cpu; cpu_lm32_set_phys_msb_ignore(env, 1); memory_region_init_ram(phys_sdram, NULL, "milkymist.sdram", sdram_size); vmstate_register_ram_global(phys_sdram); memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram); dinfo = drive_get(IF_PFLASH, 0, 0); /* Numonyx JS28F256J3F105 */ pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size, dinfo ? dinfo->bdrv : NULL, flash_sector_size, flash_size / flash_sector_size, 2, 0x00, 0x89, 0x00, 0x1d, 1); /* create irq lines */ cpu_irq = qemu_allocate_irqs(cpu_irq_handler, cpu, 1); env->pic_state = lm32_pic_init(*cpu_irq); for (i = 0; i < 32; i++) { irq[i] = qdev_get_gpio_in(env->pic_state, i); /* load bios rom */ if (bios_name == NULL) { bios_name = BIOS_FILENAME; bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); if (bios_filename) { load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE); reset_info->bootstrap_pc = BIOS_OFFSET; /* if no kernel is given no valid bios rom is a fatal error */ if (!kernel_filename && !dinfo && !bios_filename && !qtest_enabled()) { fprintf(stderr, "qemu: could not load Milkymist One bios '%s'\n", bios_name); milkymist_uart_create(0x60000000, irq[0]); milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3], 80000000, 0x10014d31, 0x0000041f, 0x00000001); milkymist_hpdmc_create(0x60002000); milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff); milkymist_memcard_create(0x60004000); milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]); milkymist_pfpu_create(0x60006000, irq[8]); milkymist_tmu2_create(0x60007000, irq[9]); milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]); milkymist_softusb_create(0x6000f000, irq[15], 0x20000000, 0x1000, 0x20020000, 0x2000); /* make sure juart isn't the first chardev */ env->juart_state = lm32_juart_init(); if (kernel_filename) { uint64_t entry; /* Boots a kernel elf binary. */ kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL, 1, ELF_MACHINE, 0); reset_info->bootstrap_pc = entry; if (kernel_size < 0) { kernel_size = load_image_targphys(kernel_filename, sdram_base, sdram_size); reset_info->bootstrap_pc = sdram_base; if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename); if (kernel_cmdline && strlen(kernel_cmdline)) { pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline); reset_info->cmdline_base = (uint32_t)cmdline_base; if (initrd_filename) { size_t initrd_size; initrd_size = load_image_targphys(initrd_filename, initrd_base, initrd_max); reset_info->initrd_base = (uint32_t)initrd_base; reset_info->initrd_size = (uint32_t)initrd_size; qemu_register_reset(main_cpu_reset, reset_info);


void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix=1; static int count; static char line[1024], prev[1024]; static int is_atty; AVClass* avc= ptr ? *(AVClass**)ptr : NULL; if(level>av_log_level) return; line[0]=0; #undef fprintf if(print_prefix && avc) { if (avc->parent_log_context_offset) { AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset); if(parent && *parent){ snprintf(line, sizeof(line), "[%s @ %p] ", (*parent)->item_name(parent), parent); } } snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr); } vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); print_prefix= line[strlen(line)-1] == '\n'; #if HAVE_ISATTY if(!is_atty) is_atty= isatty(2) ? 1 : -1; #endif if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ count++; if(is_atty==1) fprintf(stderr, " Last message repeated %d times\r", count); return; } if(count>0){ fprintf(stderr, " Last message repeated %d times\n", count); count=0; } colored_fputs(av_clip(level>>3, 0, 6), line); strcpy(prev, line); }


static int bt_hci_name_req(struct bt_hci_s *hci, bdaddr_t *bdaddr) { struct bt_device_s *slave; evt_remote_name_req_complete params; int len; for (slave = hci->device.net->slave; slave; slave = slave->next) if (slave->page_scan && !bacmp(&slave->bd_addr, bdaddr)) break; if (!slave) return -ENODEV; bt_hci_event_status(hci, HCI_SUCCESS); params.status = HCI_SUCCESS; bacpy(&params.bdaddr, &slave->bd_addr); len = snprintf(params.name, sizeof(params.name), "%s", slave->lmp_name ?: ""); memset(params.name + len, 0, sizeof(params.name) - len); bt_hci_event(hci, EVT_REMOTE_NAME_REQ_COMPLETE, &params, EVT_REMOTE_NAME_REQ_COMPLETE_SIZE); return 0; }