int xics_alloc_block(XICSState *icp, int src, int num, bool lsi, bool align) { int i, first = -1; ICSState *ics = &icp->ics[src]; assert(src == 0); /* * MSIMesage::data is used for storing VIRQ so * it has to be aligned to num to support multiple * MSI vectors. MSI-X is not affected by this. * The hint is used for the first IRQ, the rest should * be allocated continuously. */ if (align) { assert((num == 1) || (num == 2) || (num == 4) || (num == 8) || (num == 16) || (num == 32)); first = ics_find_free_block(ics, num, num); } else { first = ics_find_free_block(ics, num, 1); } if (first >= 0) { for (i = first; i < first + num; ++i) { ics_set_irq_type(ics, i, lsi); } } first += ics->offset; trace_xics_alloc_block(src, first, num, lsi, align); return first; }


void object_property_get_uint16List(Object *obj, const char *name, uint16List **list, Error **errp) { StringOutputVisitor *ov; StringInputVisitor *iv; ov = string_output_visitor_new(false); object_property_get(obj, string_output_get_visitor(ov), name, errp); iv = string_input_visitor_new(string_output_get_string(ov)); visit_type_uint16List(string_input_get_visitor(iv), list, NULL, errp); string_output_visitor_cleanup(ov); string_input_visitor_cleanup(iv); }


static int raw_create(const char *filename, QEMUOptionParameter *options) { int fd; int64_t total_size = 0; /* Read out options */ while (options && options->name) { if (!strcmp(options->name, BLOCK_OPT_SIZE)) { total_size = options->value.n / 512; } options++; } fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd < 0) return -EIO; ftruncate(fd, total_size * 512); close(fd); return 0; }


static inline void RENAME(rgb24ToUV_half)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { int i; assert(src1==src2); for (i=0; i<width; i++) { int r= src1[6*i + 0] + src1[6*i + 3]; int g= src1[6*i + 1] + src1[6*i + 4]; int b= src1[6*i + 2] + src1[6*i + 5]; dstU[i]= (RU*r + GU*g + BU*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1); dstV[i]= (RV*r + GV*g + BV*b + (257<<RGB2YUV_SHIFT))>>(RGB2YUV_SHIFT+1); } }


uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, int n_start, int n_end, int *num, QCowL2Meta *m) { BDRVQcowState *s = bs->opaque; int l2_index, ret; uint64_t l2_offset, *l2_table, cluster_offset; int nb_clusters, i = 0; QCowL2Meta *old_alloc; ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index); if (ret == 0) return 0; nb_clusters = size_to_clusters(s, n_end << 9); nb_clusters = MIN(nb_clusters, s->l2_size - l2_index); cluster_offset = be64_to_cpu(l2_table[l2_index]); /* We keep all QCOW_OFLAG_COPIED clusters */ if (cluster_offset & QCOW_OFLAG_COPIED) { nb_clusters = count_contiguous_clusters(nb_clusters, s->cluster_size, &l2_table[l2_index], 0, 0); cluster_offset &= ~QCOW_OFLAG_COPIED; m->nb_clusters = 0; goto out; } /* for the moment, multiple compressed clusters are not managed */ if (cluster_offset & QCOW_OFLAG_COMPRESSED) nb_clusters = 1; /* how many available clusters ? */ while (i < nb_clusters) { i += count_contiguous_clusters(nb_clusters - i, s->cluster_size, &l2_table[l2_index], i, 0); if(be64_to_cpu(l2_table[l2_index + i])) break; i += count_contiguous_free_clusters(nb_clusters - i, &l2_table[l2_index + i]); cluster_offset = be64_to_cpu(l2_table[l2_index + i]); if ((cluster_offset & QCOW_OFLAG_COPIED) || (cluster_offset & QCOW_OFLAG_COMPRESSED)) break; } nb_clusters = i; /* * Check if there already is an AIO write request in flight which allocates * the same cluster. In this case we need to wait until the previous * request has completed and updated the L2 table accordingly. */ QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) { uint64_t end_offset = offset + nb_clusters * s->cluster_size; uint64_t old_offset = old_alloc->offset; uint64_t old_end_offset = old_alloc->offset + old_alloc->nb_clusters * s->cluster_size; if (end_offset < old_offset || offset > old_end_offset) { /* No intersection */ } else { if (offset < old_offset) { /* Stop at the start of a running allocation */ nb_clusters = (old_offset - offset) >> s->cluster_bits; } else { nb_clusters = 0; } if (nb_clusters == 0) { /* Set dependency and wait for a callback */ m->depends_on = old_alloc; m->nb_clusters = 0; *num = 0; return 0; } } } if (!nb_clusters) { abort(); } QLIST_INSERT_HEAD(&s->cluster_allocs, m, next_in_flight); /* allocate a new cluster */ cluster_offset = qcow2_alloc_clusters(bs, nb_clusters * s->cluster_size); /* save info needed for meta data update */ m->offset = offset; m->n_start = n_start; m->nb_clusters = nb_clusters; out: m->nb_available = MIN(nb_clusters << (s->cluster_bits - 9), n_end); *num = m->nb_available - n_start; return cluster_offset; }


void ff_xvmc_init_block(MpegEncContext *s) { struct xvmc_render_state *render = (struct xvmc_render_state*)s->current_picture.data[2]; assert(render); if (!render || render->magic != AV_XVMC_RENDER_MAGIC) { assert(0); return; // make sure that this is a render packet } s->block = (DCTELEM *)(render->data_blocks + render->next_free_data_block_num * 64); }


void do_adde (void) { T2 = T0; T0 += T1 + xer_ca; if (likely(!(T0 < T2 || (xer_ca == 1 && T0 == T2)))) { xer_ca = 0; } else { xer_ca = 1; } }


static uint32_t ecc_mem_readl(void *opaque, target_phys_addr_t addr) { ECCState *s = opaque; uint32_t ret = 0; switch (addr & ECC_ADDR_MASK) { case ECC_MER: ret = s->regs[0]; DPRINTF("Read memory enable %08x\n", ret); break; case ECC_MDR: ret = s->regs[1]; DPRINTF("Read memory delay %08x\n", ret); break; case ECC_MFSR: ret = s->regs[2]; DPRINTF("Read memory fault status %08x\n", ret); break; case ECC_VCR: ret = s->regs[3]; DPRINTF("Read slot configuration %08x\n", ret); break; case ECC_MFAR0: ret = s->regs[4]; DPRINTF("Read memory fault address 0 %08x\n", ret); break; case ECC_MFAR1: ret = s->regs[5]; DPRINTF("Read memory fault address 1 %08x\n", ret); break; case ECC_DR: ret = s->regs[6]; DPRINTF("Read diagnostic %08x\n", ret); break; case ECC_ECR0: ret = s->regs[7]; DPRINTF("Read event count 1 %08x\n", ret); break; case ECC_ECR1: ret = s->regs[7]; DPRINTF("Read event count 2 %08x\n", ret); break; } return ret; }


int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { int i, ret = 0; if (!avpkt->data && avpkt->size) { av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n"); return AVERROR(EINVAL); if (!avctx->codec) return AVERROR(EINVAL); if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) { av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n"); return AVERROR(EINVAL); *got_sub_ptr = 0; avcodec_get_subtitle_defaults(sub); if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) { AVPacket pkt_recoded; AVPacket tmp = *avpkt; int did_split = av_packet_split_side_data(&tmp); //apply_param_change(avctx, &tmp); pkt_recoded = tmp; ret = recode_subtitle(avctx, &pkt_recoded, &tmp); if (ret < 0) { *got_sub_ptr = 0; } else { avctx->internal->pkt = &pkt_recoded; if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q); ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded); av_assert1((ret >= 0) >= !!*got_sub_ptr && !!*got_sub_ptr >= !!sub->num_rects); if (sub->num_rects && !sub->end_display_time && avpkt->duration && avctx->pkt_timebase.num) { AVRational ms = { 1, 1000 }; sub->end_display_time = av_rescale_q(avpkt->duration, avctx->pkt_timebase, ms); for (i = 0; i < sub->num_rects; i++) { if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) { av_log(avctx, AV_LOG_ERROR, "Invalid UTF-8 in decoded subtitles text; " "maybe missing -sub_charenc option\n"); avsubtitle_free(sub); return AVERROR_INVALIDDATA; if (tmp.data != pkt_recoded.data) { // did we recode? /* prevent from destroying side data from original packet */ pkt_recoded.side_data = NULL; pkt_recoded.side_data_elems = 0; av_free_packet(&pkt_recoded); if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) sub->format = 0; else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) sub->format = 1; avctx->internal->pkt = NULL; av_packet_free_side_data(&tmp); if(ret == tmp.size) ret = avpkt->size; if (*got_sub_ptr) avctx->frame_number++; return ret;


static int mp_decode_frame(MPADecodeContext *s, short *samples) { int i, nb_frames, ch; short *samples_ptr; init_get_bits(&s->gb, s->inbuf + HEADER_SIZE, s->inbuf_ptr - s->inbuf - HEADER_SIZE); /* skip error protection field */ if (s->error_protection) get_bits(&s->gb, 16); dprintf("frame %d:\n", s->frame_count); switch(s->layer) { case 1: nb_frames = mp_decode_layer1(s); break; case 2: nb_frames = mp_decode_layer2(s); break; case 3: default: nb_frames = mp_decode_layer3(s); break; } #if defined(DEBUG) for(i=0;i<nb_frames;i++) { for(ch=0;ch<s->nb_channels;ch++) { int j; printf("%d-%d:", i, ch); for(j=0;j<SBLIMIT;j++) printf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE); printf("\n"); } } #endif /* apply the synthesis filter */ for(ch=0;ch<s->nb_channels;ch++) { samples_ptr = samples + ch; for(i=0;i<nb_frames;i++) { synth_filter(s, ch, samples_ptr, s->nb_channels, s->sb_samples[ch][i]); samples_ptr += 32 * s->nb_channels; } } #ifdef DEBUG s->frame_count++; #endif return nb_frames * 32 * sizeof(short) * s->nb_channels; }


static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { PCMDecode *s = avctx->priv_data; int sample_size, c, n; short *samples; const uint8_t *src, *src8, *src2[MAX_CHANNELS]; uint8_t *dstu8; int16_t *dst_int16_t; int32_t *dst_int32_t; int64_t *dst_int64_t; uint16_t *dst_uint16_t; uint32_t *dst_uint32_t; samples = data; src = buf; if (avctx->sample_fmt!=avctx->codec->sample_fmts[0]) { av_log(avctx, AV_LOG_ERROR, "invalid sample_fmt\n"); return -1; } if(avctx->channels <= 0 || avctx->channels > MAX_CHANNELS){ av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n"); return -1; } sample_size = av_get_bits_per_sample(avctx->codec_id)/8; /* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */ if (CODEC_ID_PCM_DVD == avctx->codec_id) /* 2 samples are interleaved per block in PCM_DVD */ sample_size = avctx->bits_per_coded_sample * 2 / 8; n = avctx->channels * sample_size; if(n && buf_size % n){ av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n"); return -1; } buf_size= FFMIN(buf_size, *data_size/2); *data_size=0; n = buf_size/sample_size; switch(avctx->codec->id) { case CODEC_ID_PCM_U32LE: DECODE(uint32_t, le32, src, samples, n, 0, 0x80000000) break; case CODEC_ID_PCM_U32BE: DECODE(uint32_t, be32, src, samples, n, 0, 0x80000000) break; case CODEC_ID_PCM_S24LE: DECODE(int32_t, le24, src, samples, n, 8, 0) break; case CODEC_ID_PCM_S24BE: DECODE(int32_t, be24, src, samples, n, 8, 0) break; case CODEC_ID_PCM_U24LE: DECODE(uint32_t, le24, src, samples, n, 8, 0x800000) break; case CODEC_ID_PCM_U24BE: DECODE(uint32_t, be24, src, samples, n, 8, 0x800000) break; case CODEC_ID_PCM_S24DAUD: for(;n>0;n--) { uint32_t v = bytestream_get_be24(&src); v >>= 4; // sync flags are here *samples++ = ff_reverse[(v >> 8) & 0xff] + (ff_reverse[v & 0xff] << 8); } break; case CODEC_ID_PCM_S16LE_PLANAR: n /= avctx->channels; for(c=0;c<avctx->channels;c++) src2[c] = &src[c*n*2]; for(;n>0;n--) for(c=0;c<avctx->channels;c++) *samples++ = bytestream_get_le16(&src2[c]); src = src2[avctx->channels-1]; break; case CODEC_ID_PCM_U16LE: DECODE(uint16_t, le16, src, samples, n, 0, 0x8000) break; case CODEC_ID_PCM_U16BE: DECODE(uint16_t, be16, src, samples, n, 0, 0x8000) break; case CODEC_ID_PCM_S8: dstu8= (uint8_t*)samples; for(;n>0;n--) { *dstu8++ = *src++ + 128; } samples= (short*)dstu8; break; #if WORDS_BIGENDIAN case CODEC_ID_PCM_F64LE: DECODE(int64_t, le64, src, samples, n, 0, 0) break; case CODEC_ID_PCM_S32LE: case CODEC_ID_PCM_F32LE: DECODE(int32_t, le32, src, samples, n, 0, 0) break; case CODEC_ID_PCM_S16LE: DECODE(int16_t, le16, src, samples, n, 0, 0) break; case CODEC_ID_PCM_F64BE: case CODEC_ID_PCM_F32BE: case CODEC_ID_PCM_S32BE: case CODEC_ID_PCM_S16BE: #else case CODEC_ID_PCM_F64BE: DECODE(int64_t, be64, src, samples, n, 0, 0) break; case CODEC_ID_PCM_F32BE: case CODEC_ID_PCM_S32BE: DECODE(int32_t, be32, src, samples, n, 0, 0) break; case CODEC_ID_PCM_S16BE: DECODE(int16_t, be16, src, samples, n, 0, 0) break; case CODEC_ID_PCM_F64LE: case CODEC_ID_PCM_F32LE: case CODEC_ID_PCM_S32LE: case CODEC_ID_PCM_S16LE: #endif /* WORDS_BIGENDIAN */ case CODEC_ID_PCM_U8: memcpy(samples, src, n*sample_size); src += n*sample_size; samples = (short*)((uint8_t*)data + n*sample_size); break; case CODEC_ID_PCM_ZORK: for(;n>0;n--) { int x= *src++; if(x&128) x-= 128; else x = -x; *samples++ = x << 8; } break; case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: for(;n>0;n--) { *samples++ = s->table[*src++]; } break; case CODEC_ID_PCM_DVD: dst_int32_t = data; n /= avctx->channels; switch (avctx->bits_per_coded_sample) { case 20: while (n--) { c = avctx->channels; src8 = src + 4*c; while (c--) { *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 &0xf0) << 8); *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ &0x0f) << 12); } src = src8; } break; case 24: while (n--) { c = avctx->channels; src8 = src + 4*c; while (c--) { *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8); *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8); } src = src8; } break; default: av_log(avctx, AV_LOG_ERROR, "PCM DVD unsupported sample depth\n"); return -1; break; } samples = (short *) dst_int32_t; break; default: return -1; } *data_size = (uint8_t *)samples - (uint8_t *)data; return src - buf; }


static int write_trailer(AVFormatContext *s) { WVMuxContext *wc = s->priv_data; AVIOContext *pb = s->pb; ff_ape_write(s); if (pb->seekable) { avio_seek(pb, 12, SEEK_SET); avio_wl32(pb, wc->duration); avio_flush(pb); } return 0; }


void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) { BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); /* virtio-1 compliant devices cannot change the alignment */ if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { error_report("tried to modify queue alignment for virtio-1 device"); return; } /* Check that the transport told us it was going to do this * (so a buggy transport will immediately assert rather than * silently failing to migrate this state) */ assert(k->has_variable_vring_alignment); vdev->vq[n].vring.align = align; virtio_queue_update_rings(vdev, n); }


static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, long width, long height, long lumStride, long chromStride, long dstStride, long vertLumPerChroma) { long y; const x86_reg chromWidth= width>>1; for (y=0; y<height; y++) { #if COMPILE_TEMPLATE_MMX //FIXME handle 2 lines at once (fewer prefetches, reuse some chroma, but very likely memory-limited anyway) __asm__ volatile( "xor %%"REG_a", %%"REG_a" \n\t" ".p2align 4 \n\t" "1: \n\t" PREFETCH" 32(%1, %%"REG_a", 2) \n\t" PREFETCH" 32(%2, %%"REG_a") \n\t" PREFETCH" 32(%3, %%"REG_a") \n\t" "movq (%2, %%"REG_a"), %%mm0 \n\t" // U(0) "movq %%mm0, %%mm2 \n\t" // U(0) "movq (%3, %%"REG_a"), %%mm1 \n\t" // V(0) "punpcklbw %%mm1, %%mm0 \n\t" // UVUV UVUV(0) "punpckhbw %%mm1, %%mm2 \n\t" // UVUV UVUV(8) "movq (%1, %%"REG_a",2), %%mm3 \n\t" // Y(0) "movq 8(%1, %%"REG_a",2), %%mm5 \n\t" // Y(8) "movq %%mm0, %%mm4 \n\t" // Y(0) "movq %%mm2, %%mm6 \n\t" // Y(8) "punpcklbw %%mm3, %%mm0 \n\t" // YUYV YUYV(0) "punpckhbw %%mm3, %%mm4 \n\t" // YUYV YUYV(4) "punpcklbw %%mm5, %%mm2 \n\t" // YUYV YUYV(8) "punpckhbw %%mm5, %%mm6 \n\t" // YUYV YUYV(12) MOVNTQ" %%mm0, (%0, %%"REG_a", 4) \n\t" MOVNTQ" %%mm4, 8(%0, %%"REG_a", 4) \n\t" MOVNTQ" %%mm2, 16(%0, %%"REG_a", 4) \n\t" MOVNTQ" %%mm6, 24(%0, %%"REG_a", 4) \n\t" "add $8, %%"REG_a" \n\t" "cmp %4, %%"REG_a" \n\t" " jb 1b \n\t" ::"r"(dst), "r"(ysrc), "r"(usrc), "r"(vsrc), "g" (chromWidth) : "%"REG_a ); #else //FIXME adapt the Alpha ASM code from yv12->yuy2 #if HAVE_FAST_64BIT int i; uint64_t *ldst = (uint64_t *) dst; const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; for (i = 0; i < chromWidth; i += 2) { uint64_t k, l; k = uc[0] + (yc[0] << 8) + (vc[0] << 16) + (yc[1] << 24); l = uc[1] + (yc[2] << 8) + (vc[1] << 16) + (yc[3] << 24); *ldst++ = k + (l << 32); yc += 4; uc += 2; vc += 2; } #else int i, *idst = (int32_t *) dst; const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; for (i = 0; i < chromWidth; i++) { #if HAVE_BIGENDIAN *idst++ = (uc[0] << 24)+ (yc[0] << 16) + (vc[0] << 8) + (yc[1] << 0); #else *idst++ = uc[0] + (yc[0] << 8) + (vc[0] << 16) + (yc[1] << 24); #endif yc += 2; uc++; vc++; } #endif #endif if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { usrc += chromStride; vsrc += chromStride; } ysrc += lumStride; dst += dstStride; } #if COMPILE_TEMPLATE_MMX __asm__(EMMS" \n\t" SFENCE" \n\t" :::"memory"); #endif }


int qcrypto_init(Error **errp) { int ret; ret = gnutls_global_init(); if (ret < 0) { error_setg(errp, "Unable to initialize GNUTLS library: %s", gnutls_strerror(ret)); return -1; } #ifdef DEBUG_GNUTLS gnutls_global_set_log_level(10); gnutls_global_set_log_function(qcrypto_gnutls_log); #endif #ifdef CONFIG_GNUTLS_GCRYPT if (!gcry_check_version(GCRYPT_VERSION)) { error_setg(errp, "Unable to initialize gcrypt"); return -1; } #ifdef QCRYPTO_INIT_GCRYPT_THREADS gcry_control(GCRYCTL_SET_THREAD_CBS, &qcrypto_gcrypt_thread_impl); #endif /* QCRYPTO_INIT_GCRYPT_THREADS */ gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); #endif return 0; }


static void read_vec_element_i32(DisasContext *s, TCGv_i32 tcg_dest, int srcidx, int element, TCGMemOp memop) { int vect_off = vec_reg_offset(srcidx, element, memop & MO_SIZE); switch (memop) { case MO_8: tcg_gen_ld8u_i32(tcg_dest, cpu_env, vect_off); break; case MO_16: tcg_gen_ld16u_i32(tcg_dest, cpu_env, vect_off); break; case MO_8|MO_SIGN: tcg_gen_ld8s_i32(tcg_dest, cpu_env, vect_off); break; case MO_16|MO_SIGN: tcg_gen_ld16s_i32(tcg_dest, cpu_env, vect_off); break; case MO_32: case MO_32|MO_SIGN: tcg_gen_ld_i32(tcg_dest, cpu_env, vect_off); break; default: g_assert_not_reached(); } }


static void vring_desc_read(VirtIODevice *vdev, VRingDesc *desc, hwaddr desc_pa, int i) { address_space_read(&address_space_memory, desc_pa + i * sizeof(VRingDesc), MEMTXATTRS_UNSPECIFIED, (void *)desc, sizeof(VRingDesc)); virtio_tswap64s(vdev, &desc->addr); virtio_tswap32s(vdev, &desc->len); virtio_tswap16s(vdev, &desc->flags); virtio_tswap16s(vdev, &desc->next); }


static AddressSpace *q35_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) { IntelIOMMUState *s = opaque; VTDAddressSpace **pvtd_as; int bus_num = pci_bus_num(bus); assert(0 <= bus_num && bus_num <= VTD_PCI_BUS_MAX); assert(0 <= devfn && devfn <= VTD_PCI_DEVFN_MAX); pvtd_as = s->address_spaces[bus_num]; if (!pvtd_as) { /* No corresponding free() */ pvtd_as = g_malloc0(sizeof(VTDAddressSpace *) * VTD_PCI_DEVFN_MAX); s->address_spaces[bus_num] = pvtd_as; } if (!pvtd_as[devfn]) { pvtd_as[devfn] = g_malloc0(sizeof(VTDAddressSpace)); pvtd_as[devfn]->bus_num = (uint8_t)bus_num; pvtd_as[devfn]->devfn = (uint8_t)devfn; pvtd_as[devfn]->iommu_state = s; pvtd_as[devfn]->context_cache_entry.context_cache_gen = 0; memory_region_init_iommu(&pvtd_as[devfn]->iommu, OBJECT(s), &s->iommu_ops, "intel_iommu", UINT64_MAX); address_space_init(&pvtd_as[devfn]->as, &pvtd_as[devfn]->iommu, "intel_iommu"); } return &pvtd_as[devfn]->as; }


static inline uint64_t vmdk_find_offset_in_cluster(VmdkExtent *extent, int64_t offset) { uint64_t offset_in_cluster, extent_begin_offset, extent_relative_offset; uint64_t cluster_size = extent->cluster_sectors * BDRV_SECTOR_SIZE; extent_begin_offset = (extent->end_sector - extent->sectors) * BDRV_SECTOR_SIZE; extent_relative_offset = offset - extent_begin_offset; offset_in_cluster = extent_relative_offset % cluster_size; return offset_in_cluster; }


static unsigned int dec_move_pr(DisasContext *dc) { TCGv t0; DIS(fprintf (logfile, "move $p%u, $r%u\n", dc->op1, dc->op2)); cris_cc_mask(dc, 0); if (dc->op2 == PR_CCS) cris_evaluate_flags(dc); t0 = tcg_temp_new(TCG_TYPE_TL); t_gen_mov_TN_preg(t0, dc->op2); cris_alu(dc, CC_OP_MOVE, cpu_R[dc->op1], cpu_R[dc->op1], t0, preg_sizes[dc->op2]); tcg_temp_free(t0); return 2; }


static void virtio_balloon_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->init = virtio_balloon_init_pci; k->exit = virtio_balloon_exit_pci; k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON; k->revision = VIRTIO_PCI_ABI_VERSION; k->class_id = PCI_CLASS_MEMORY_RAM; dc->alias = "virtio-balloon"; dc->reset = virtio_pci_reset; dc->props = virtio_balloon_properties; }


static int fetch_active_ports_list(QEMUFile *f, VirtIOSerial *s, uint32_t nr_active_ports) { uint32_t i; s->post_load = g_malloc0(sizeof(*s->post_load)); s->post_load->nr_active_ports = nr_active_ports; s->post_load->connected = g_malloc0(sizeof(*s->post_load->connected) * nr_active_ports); s->post_load->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, virtio_serial_post_load_timer_cb, s); /* Items in struct VirtIOSerialPort */ for (i = 0; i < nr_active_ports; i++) { VirtIOSerialPort *port; uint32_t elem_popped; uint32_t id; id = qemu_get_be32(f); port = find_port_by_id(s, id); if (!port) { return -EINVAL; } port->guest_connected = qemu_get_byte(f); s->post_load->connected[i].port = port; s->post_load->connected[i].host_connected = qemu_get_byte(f); qemu_get_be32s(f, &elem_popped); if (elem_popped) { qemu_get_be32s(f, &port->iov_idx); qemu_get_be64s(f, &port->iov_offset); port->elem = qemu_get_virtqueue_element(f, sizeof(VirtQueueElement)); /* * Port was throttled on source machine. Let's * unthrottle it here so data starts flowing again. */ virtio_serial_throttle_port(port, false); } } timer_mod(s->post_load->timer, 1); return 0; }


void HELPER(ucf64_cmps)(float32 a, float32 b, uint32_t c, CPUUniCore32State *env) { int flag; flag = float32_compare_quiet(a, b, &env->ucf64.fp_status); env->CF = 0; switch (c & 0x7) { case 0: /* F */ break; case 1: /* UN */ if (flag == 2) { env->CF = 1; } break; case 2: /* EQ */ if (flag == 0) { env->CF = 1; } break; case 3: /* UEQ */ if ((flag == 0) || (flag == 2)) { env->CF = 1; } break; case 4: /* OLT */ if (flag == -1) { env->CF = 1; } break; case 5: /* ULT */ if ((flag == -1) || (flag == 2)) { env->CF = 1; } break; case 6: /* OLE */ if ((flag == -1) || (flag == 0)) { env->CF = 1; } break; case 7: /* ULE */ if (flag != 1) { env->CF = 1; } break; } env->ucf64.xregs[UC32_UCF64_FPSCR] = (env->CF << 29) | (env->ucf64.xregs[UC32_UCF64_FPSCR] & 0x0fffffff); }


static void RENAME(yuv2yuyv422_2)(SwsContext *c, const uint16_t *buf0, const uint16_t *buf1, const uint16_t *ubuf0, const uint16_t *ubuf1, const uint16_t *vbuf0, const uint16_t *vbuf1, const uint16_t *abuf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2PACKED(%%REGBP, %5) WRITEYUY2(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), "a" (&c->redDither) ); }


static int scsi_disk_emulate_start_stop(SCSIDiskReq *r) { SCSIRequest *req = &r->req; SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev); bool start = req->cmd.buf[4] & 1; bool loej = req->cmd.buf[4] & 2; /* load on start, eject on !start */ if (s->qdev.type == TYPE_ROM && loej) { if (!start && !s->tray_open && s->tray_locked) { scsi_check_condition(r, bdrv_is_inserted(s->qdev.conf.bs) ? SENSE_CODE(ILLEGAL_REQ_REMOVAL_PREVENTED) : SENSE_CODE(NOT_READY_REMOVAL_PREVENTED)); return -1; } if (s->tray_open != !start) { bdrv_eject(s->qdev.conf.bs, !start); s->tray_open = !start; } } return 0; }


static void ecc_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val) { printf("ECC: Unsupported write 0x" TARGET_FMT_plx " %04x\n", addr, val & 0xffff); }


int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info) { int handle = 0; int n; if (arch_info->exception == 1) { if (arch_info->dr6 & (1 << 14)) { if (cpu_single_env->singlestep_enabled) handle = 1; } else { for (n = 0; n < 4; n++) if (arch_info->dr6 & (1 << n)) switch ((arch_info->dr7 >> (16 + n*4)) & 0x3) { case 0x0: handle = 1; break; case 0x1: handle = 1; cpu_single_env->watchpoint_hit = &hw_watchpoint; hw_watchpoint.vaddr = hw_breakpoint[n].addr; hw_watchpoint.flags = BP_MEM_WRITE; break; case 0x3: handle = 1; cpu_single_env->watchpoint_hit = &hw_watchpoint; hw_watchpoint.vaddr = hw_breakpoint[n].addr; hw_watchpoint.flags = BP_MEM_ACCESS; break; } } } else if (kvm_find_sw_breakpoint(cpu_single_env, arch_info->pc)) handle = 1; if (!handle) { cpu_synchronize_state(cpu_single_env); assert(cpu_single_env->exception_injected == -1); cpu_single_env->exception_injected = arch_info->exception; cpu_single_env->has_error_code = 0; } return handle; }


static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend, Error **errp) { ChardevStdio *stdio; stdio = backend->u.stdio = g_new0(ChardevStdio, 1); qemu_chr_parse_common(opts, qapi_ChardevStdio_base(stdio)); stdio->has_signal = true; stdio->signal = qemu_opt_get_bool(opts, "signal", true); }


static void mirror_complete(BlockJob *job, Error **errp) { MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); Error *local_err = NULL; int ret; ret = bdrv_open_backing_file(s->target, NULL, &local_err); if (ret < 0) { error_propagate(errp, local_err); return; } if (!s->synced) { error_setg(errp, QERR_BLOCK_JOB_NOT_READY, bdrv_get_device_name(job->bs)); return; } /* check the target bs is not blocked and block all operations on it */ if (s->replaces) { AioContext *replace_aio_context; s->to_replace = check_to_replace_node(s->replaces, &local_err); if (!s->to_replace) { error_propagate(errp, local_err); return; } replace_aio_context = bdrv_get_aio_context(s->to_replace); aio_context_acquire(replace_aio_context); error_setg(&s->replace_blocker, "block device is in use by block-job-complete"); bdrv_op_block_all(s->to_replace, s->replace_blocker); bdrv_ref(s->to_replace); aio_context_release(replace_aio_context); } s->should_complete = true; block_job_enter(&s->common); }


static bool scsi_target_emulate_inquiry(SCSITargetReq *r) { assert(r->req.dev->lun != r->req.lun); scsi_target_alloc_buf(&r->req, SCSI_INQUIRY_LEN); if (r->req.cmd.buf[1] & 0x2) { /* Command support data - optional, not implemented */ return false; } if (r->req.cmd.buf[1] & 0x1) { /* Vital product data */ uint8_t page_code = r->req.cmd.buf[2]; r->buf[r->len++] = page_code ; /* this page */ r->buf[r->len++] = 0x00; switch (page_code) { case 0x00: /* Supported page codes, mandatory */ { int pages; pages = r->len++; r->buf[r->len++] = 0x00; /* list of supported pages (this page) */ r->buf[pages] = r->len - pages - 1; /* number of pages */ break; } default: return false; } /* done with EVPD */ assert(r->len < r->buf_len); r->len = MIN(r->req.cmd.xfer, r->len); return true; } /* Standard INQUIRY data */ if (r->req.cmd.buf[2] != 0) { return false; } /* PAGE CODE == 0 */ r->len = MIN(r->req.cmd.xfer, SCSI_INQUIRY_LEN); memset(r->buf, 0, r->len); if (r->req.lun != 0) { r->buf[0] = TYPE_NO_LUN; } else { r->buf[0] = TYPE_NOT_PRESENT | TYPE_INACTIVE; r->buf[2] = 5; /* Version */ r->buf[3] = 2 | 0x10; /* HiSup, response data format */ r->buf[4] = r->len - 5; /* Additional Length = (Len - 1) - 4 */ r->buf[7] = 0x10 | (r->req.bus->info->tcq ? 0x02 : 0); /* Sync, TCQ. */ memcpy(&r->buf[8], "QEMU ", 8); memcpy(&r->buf[16], "QEMU TARGET ", 16); pstrcpy((char *) &r->buf[32], 4, qemu_get_version()); } return true; }


void OPPROTO op_movl_npc_T0(void) { env->npc = T0; }


void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce) { TemporalNoiseShaping *tns = &sce->tns; int w, g, order, sfb_start, sfb_len, coef_start, shift[MAX_LPC_ORDER], count = 0; const int is8 = sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE; const int tns_max_order = is8 ? 7 : s->profile == FF_PROFILE_AAC_LOW ? 12 : TNS_MAX_ORDER; const float freq_mult = mpeg4audio_sample_rates[s->samplerate_index]/(1024.0f/sce->ics.num_windows)/2.0f; float max_coef = 0.0f; sce->tns.present = 0; return; for (coef_start = 0; coef_start < 1024; coef_start++) max_coef = FFMAX(max_coef, sce->pcoeffs[coef_start]); for (w = 0; w < sce->ics.num_windows; w++) { int filters = 1, start = 0, coef_len = 0; int32_t conv_coeff[1024] = {0}; int32_t coefs_t[MAX_LPC_ORDER][MAX_LPC_ORDER] = {{0}}; /* Determine start sfb + coef - excludes anything below threshold */ for (g = 0; g < sce->ics.num_swb; g++) { if (start*freq_mult > TNS_LOW_LIMIT) { sfb_start = w*16+g; sfb_len = (w+1)*16 + g - sfb_start; coef_start = sce->ics.swb_offset[sfb_start]; coef_len = sce->ics.swb_offset[sfb_start + sfb_len] - coef_start; break; } start += sce->ics.swb_sizes[g]; } if (coef_len <= 0) continue; conv_to_int32(conv_coeff, &sce->pcoeffs[coef_start], coef_len, max_coef); /* LPC */ order = ff_lpc_calc_coefs(&s->lpc, conv_coeff, coef_len, TNS_MIN_PRED_ORDER, tns_max_order, 32, coefs_t, shift, FF_LPC_TYPE_LEVINSON, 10, ORDER_METHOD_EST, MAX_LPC_SHIFT, 0) - 1; /* Works surprisingly well, remember to tweak MAX_LPC_SHIFT if you want to play around with this */ if (shift[order] > 3) { int direction = 0; float tns_coefs_raw[TNS_MAX_ORDER]; tns->n_filt[w] = filters++; conv_to_float(tns_coefs_raw, coefs_t[order], order); for (g = 0; g < tns->n_filt[w]; g++) { process_tns_coeffs(tns, tns_coefs_raw, order, w, g); apply_tns_filter(&sce->coeffs[coef_start], sce->pcoeffs, order, direction, tns->coef[w][g], sce->ics.ltp.present, w, g, coef_start, coef_len); tns->order[w][g] = order; tns->length[w][g] = sfb_len; tns->direction[w][g] = direction; } count++; } } sce->tns.present = !!count; }


int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec) { _Bool exp = 0; if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init) return 0; if (lockmgr_cb) { if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN)) return -1; } if (atomic_fetch_add(&entangled_thread_counter, 1)) { av_log(log_ctx, AV_LOG_ERROR, "Insufficient thread locking. At least %d threads are " "calling avcodec_open2() at the same time right now.\n", atomic_load(&entangled_thread_counter)); if (!lockmgr_cb) av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n"); atomic_store(&ff_avcodec_locked, 1); ff_unlock_avcodec(codec); return AVERROR(EINVAL); } av_assert0(atomic_compare_exchange_strong(&ff_avcodec_locked, &exp, 1)); return 0; }


void FUNCC(ff_h264_idct_add)(uint8_t *_dst, int16_t *_block, int stride) { int i; pixel *dst = (pixel*)_dst; dctcoef *block = (dctcoef*)_block; stride >>= sizeof(pixel)-1; block[0] += 1 << 5; for(i=0; i<4; i++){ const int z0= block[i + 4*0] + block[i + 4*2]; const int z1= block[i + 4*0] - block[i + 4*2]; const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; const int z3= block[i + 4*1] + (block[i + 4*3]>>1); block[i + 4*0]= z0 + z3; block[i + 4*1]= z1 + z2; block[i + 4*2]= z1 - z2; block[i + 4*3]= z0 - z3; } for(i=0; i<4; i++){ const int z0= block[0 + 4*i] + block[2 + 4*i]; const int z1= block[0 + 4*i] - block[2 + 4*i]; const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); dst[i + 0*stride]= av_clip_pixel(dst[i + 0*stride] + ((z0 + z3) >> 6)); dst[i + 1*stride]= av_clip_pixel(dst[i + 1*stride] + ((z1 + z2) >> 6)); dst[i + 2*stride]= av_clip_pixel(dst[i + 2*stride] + ((z1 - z2) >> 6)); dst[i + 3*stride]= av_clip_pixel(dst[i + 3*stride] + ((z0 - z3) >> 6)); } memset(block, 0, 16 * sizeof(dctcoef)); }


static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque, uint64_t flags) { RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult), .type = RDMA_CONTROL_REGISTER_RESULT, .repeat = 0, }; RDMAControlHeader unreg_resp = { .len = 0, .type = RDMA_CONTROL_UNREGISTER_FINISHED, .repeat = 0, }; RDMAControlHeader blocks = { .type = RDMA_CONTROL_RAM_BLOCKS_RESULT, .repeat = 1 }; QEMUFileRDMA *rfile = opaque; RDMAContext *rdma = rfile->rdma; RDMALocalBlocks *local = &rdma->local_ram_blocks; RDMAControlHeader head; RDMARegister *reg, *registers; RDMACompress *comp; RDMARegisterResult *reg_result; static RDMARegisterResult results[RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE]; RDMALocalBlock *block; void *host_addr; int ret = 0; int idx = 0; int count = 0; int i = 0; CHECK_ERROR_STATE(); do { DDDPRINTF("Waiting for next request %" PRIu64 "...\n", flags); ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_NONE); if (ret < 0) { break; } if (head.repeat > RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE) { fprintf(stderr, "rdma: Too many requests in this message (%d)." "Bailing.\n", head.repeat); ret = -EIO; break; } switch (head.type) { case RDMA_CONTROL_COMPRESS: comp = (RDMACompress *) rdma->wr_data[idx].control_curr; network_to_compress(comp); DDPRINTF("Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64 "\n", comp->length, comp->block_idx, comp->offset); block = &(rdma->local_ram_blocks.block[comp->block_idx]); host_addr = block->local_host_addr + (comp->offset - block->offset); ram_handle_compressed(host_addr, comp->value, comp->length); break; case RDMA_CONTROL_REGISTER_FINISHED: DDDPRINTF("Current registrations complete.\n"); goto out; case RDMA_CONTROL_RAM_BLOCKS_REQUEST: DPRINTF("Initial setup info requested.\n"); if (rdma->pin_all) { ret = qemu_rdma_reg_whole_ram_blocks(rdma); if (ret) { fprintf(stderr, "rdma migration: error dest " "registering ram blocks!\n"); goto out; } } /* * Dest uses this to prepare to transmit the RAMBlock descriptions * to the source VM after connection setup. * Both sides use the "remote" structure to communicate and update * their "local" descriptions with what was sent. */ for (i = 0; i < local->nb_blocks; i++) { rdma->block[i].remote_host_addr = (uint64_t)(local->block[i].local_host_addr); if (rdma->pin_all) { rdma->block[i].remote_rkey = local->block[i].mr->rkey; } rdma->block[i].offset = local->block[i].offset; rdma->block[i].length = local->block[i].length; remote_block_to_network(&rdma->block[i]); } blocks.len = rdma->local_ram_blocks.nb_blocks * sizeof(RDMARemoteBlock); ret = qemu_rdma_post_send_control(rdma, (uint8_t *) rdma->block, &blocks); if (ret < 0) { fprintf(stderr, "rdma migration: error sending remote info!\n"); goto out; } break; case RDMA_CONTROL_REGISTER_REQUEST: DDPRINTF("There are %d registration requests\n", head.repeat); reg_resp.repeat = head.repeat; registers = (RDMARegister *) rdma->wr_data[idx].control_curr; for (count = 0; count < head.repeat; count++) { uint64_t chunk; uint8_t *chunk_start, *chunk_end; reg = &registers[count]; network_to_register(reg); reg_result = &results[count]; DDPRINTF("Registration request (%d): index %d, current_addr %" PRIu64 " chunks: %" PRIu64 "\n", count, reg->current_index, reg->key.current_addr, reg->chunks); block = &(rdma->local_ram_blocks.block[reg->current_index]); if (block->is_ram_block) { host_addr = (block->local_host_addr + (reg->key.current_addr - block->offset)); chunk = ram_chunk_index(block->local_host_addr, (uint8_t *) host_addr); } else { chunk = reg->key.chunk; host_addr = block->local_host_addr + (reg->key.chunk * (1UL << RDMA_REG_CHUNK_SHIFT)); } chunk_start = ram_chunk_start(block, chunk); chunk_end = ram_chunk_end(block, chunk + reg->chunks); if (qemu_rdma_register_and_get_keys(rdma, block, (uint8_t *)host_addr, NULL, &reg_result->rkey, chunk, chunk_start, chunk_end)) { fprintf(stderr, "cannot get rkey!\n"); ret = -EINVAL; goto out; } reg_result->host_addr = (uint64_t) block->local_host_addr; DDPRINTF("Registered rkey for this request: %x\n", reg_result->rkey); result_to_network(reg_result); } ret = qemu_rdma_post_send_control(rdma, (uint8_t *) results, &reg_resp); if (ret < 0) { fprintf(stderr, "Failed to send control buffer!\n"); goto out; } break; case RDMA_CONTROL_UNREGISTER_REQUEST: DDPRINTF("There are %d unregistration requests\n", head.repeat); unreg_resp.repeat = head.repeat; registers = (RDMARegister *) rdma->wr_data[idx].control_curr; for (count = 0; count < head.repeat; count++) { reg = &registers[count]; network_to_register(reg); DDPRINTF("Unregistration request (%d): " " index %d, chunk %" PRIu64 "\n", count, reg->current_index, reg->key.chunk); block = &(rdma->local_ram_blocks.block[reg->current_index]); ret = ibv_dereg_mr(block->pmr[reg->key.chunk]); block->pmr[reg->key.chunk] = NULL; if (ret != 0) { perror("rdma unregistration chunk failed"); ret = -ret; goto out; } rdma->total_registrations--; DDPRINTF("Unregistered chunk %" PRIu64 " successfully.\n", reg->key.chunk); } ret = qemu_rdma_post_send_control(rdma, NULL, &unreg_resp); if (ret < 0) { fprintf(stderr, "Failed to send control buffer!\n"); goto out; } break; case RDMA_CONTROL_REGISTER_RESULT: fprintf(stderr, "Invalid RESULT message at dest.\n"); ret = -EIO; goto out; default: fprintf(stderr, "Unknown control message %s\n", control_desc[head.type]); ret = -EIO; goto out; } } while (1); out: if (ret < 0) { rdma->error_state = ret; } return ret; }


static int read_data(void *opaque, uint8_t *buf, int buf_size) { struct playlist *v = opaque; HLSContext *c = v->parent->priv_data; int ret, i; int just_opened = 0; restart: if (!v->needed) return AVERROR_EOF; if (!v->input) { int64_t reload_interval; struct segment *seg; /* Check that the playlist is still needed before opening a new * segment. */ if (v->ctx && v->ctx->nb_streams) { v->needed = 0; for (i = 0; i < v->n_main_streams; i++) { if (v->main_streams[i]->discard < AVDISCARD_ALL) { v->needed = 1; break; } } } if (!v->needed) { av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n", v->index); return AVERROR_EOF; } /* If this is a live stream and the reload interval has elapsed since * the last playlist reload, reload the playlists now. */ reload_interval = default_reload_interval(v); reload: reload_count++; if (reload_count > c->max_reload) return AVERROR_EOF; if (!v->finished && av_gettime_relative() - v->last_load_time >= reload_interval) { if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) { av_log(v->parent, AV_LOG_WARNING, "Failed to reload playlist %d\n", v->index); return ret; } /* If we need to reload the playlist again below (if * there's still no more segments), switch to a reload * interval of half the target duration. */ reload_interval = v->target_duration / 2; } if (v->cur_seq_no < v->start_seq_no) { av_log(NULL, AV_LOG_WARNING, "skipping %d segments ahead, expired from playlists\n", v->start_seq_no - v->cur_seq_no); v->cur_seq_no = v->start_seq_no; } if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { if (v->finished) return AVERROR_EOF; while (av_gettime_relative() - v->last_load_time < reload_interval) { if (ff_check_interrupt(c->interrupt_callback)) return AVERROR_EXIT; av_usleep(100*1000); } /* Enough time has elapsed since the last reload */ goto reload; } seg = current_segment(v); /* load/update Media Initialization Section, if any */ ret = update_init_section(v, seg); if (ret) return ret; ret = open_input(c, v, seg); if (ret < 0) { if (ff_check_interrupt(c->interrupt_callback)) return AVERROR_EXIT; av_log(v->parent, AV_LOG_WARNING, "Failed to open segment of playlist %d\n", v->index); v->cur_seq_no += 1; goto reload; } just_opened = 1; } if (v->init_sec_buf_read_offset < v->init_sec_data_len) { /* Push init section out first before first actual segment */ int copy_size = FFMIN(v->init_sec_data_len - v->init_sec_buf_read_offset, buf_size); memcpy(buf, v->init_sec_buf, copy_size); v->init_sec_buf_read_offset += copy_size; return copy_size; } ret = read_from_url(v, current_segment(v), buf, buf_size, READ_NORMAL); if (ret > 0) { if (just_opened && v->is_id3_timestamped != 0) { /* Intercept ID3 tags here, elementary audio streams are required * to convey timestamps using them in the beginning of each segment. */ intercept_id3(v, buf, buf_size, &ret); } return ret; } ff_format_io_close(v->parent, &v->input); v->cur_seq_no++; c->cur_seq_no = v->cur_seq_no; goto restart; }


static void put_swf_matrix(ByteIOContext *pb, int a, int b, int c, int d, int tx, int ty) { PutBitContext p; uint8_t buf[256]; init_put_bits(&p, buf, sizeof(buf)); put_bits(&p, 1, 1); /* a, d present */ put_bits(&p, 5, 20); /* nb bits */ put_bits(&p, 20, a); put_bits(&p, 20, d); put_bits(&p, 1, 1); /* b, c present */ put_bits(&p, 5, 20); /* nb bits */ put_bits(&p, 20, c); put_bits(&p, 20, b); put_bits(&p, 5, 20); /* nb bits */ put_bits(&p, 20, tx); put_bits(&p, 20, ty); flush_put_bits(&p); put_buffer(pb, buf, pbBufPtr(&p) - p.buf); }


int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame) { NVDECContext *ctx = avctx->internal->hwaccel_priv_data; FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data; NVDECFrame *cf = NULL; int ret; ctx->bitstream_len = 0; ctx->nb_slices = 0; if (fdd->hwaccel_priv) return 0; cf = av_mallocz(sizeof(*cf)); if (!cf) return AVERROR(ENOMEM); cf->decoder_ref = av_buffer_ref(ctx->decoder_ref); if (!cf->decoder_ref) goto fail; cf->idx_ref = av_buffer_pool_get(ctx->decoder_pool); if (!cf->idx_ref) { av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n"); ret = AVERROR(ENOMEM); goto fail; } cf->idx = *(unsigned int*)cf->idx_ref->data; fdd->hwaccel_priv = cf; fdd->hwaccel_priv_free = nvdec_fdd_priv_free; fdd->post_process = nvdec_retrieve_data; return 0; fail: nvdec_fdd_priv_free(cf); return ret; }


static int mov_read_trun(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { MOVFragment *frag = &c->fragment; AVStream *st = c->fc->streams[frag->track_id-1]; MOVStreamContext *sc = st->priv_data; uint64_t offset; int64_t dts; int data_offset = 0; unsigned entries, first_sample_flags = frag->flags; int flags, distance, i; if (sc->pseudo_stream_id+1 != frag->stsd_id) return 0; if (!st->nb_index_entries) return -1; get_byte(pb); /* version */ flags = get_be24(pb); entries = get_be32(pb); dprintf(c->fc, "flags 0x%x entries %d\n", flags, entries); if (flags & 0x001) data_offset = get_be32(pb); if (flags & 0x004) first_sample_flags = get_be32(pb); if (flags & 0x800) { if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data)) return -1; sc->ctts_data = av_realloc(sc->ctts_data, (entries+sc->ctts_count)*sizeof(*sc->ctts_data)); if (!sc->ctts_data) return AVERROR(ENOMEM); } dts = st->duration; offset = frag->base_data_offset + data_offset; distance = 0; dprintf(c->fc, "first sample flags 0x%x\n", first_sample_flags); for (i = 0; i < entries; i++) { unsigned sample_size = frag->size; int sample_flags = i ? frag->flags : first_sample_flags; unsigned sample_duration = frag->duration; int keyframe; if (flags & 0x100) sample_duration = get_be32(pb); if (flags & 0x200) sample_size = get_be32(pb); if (flags & 0x400) sample_flags = get_be32(pb); if (flags & 0x800) { sc->ctts_data[sc->ctts_count].count = 1; sc->ctts_data[sc->ctts_count].duration = get_be32(pb); sc->ctts_count++; } if ((keyframe = st->codec->codec_type == CODEC_TYPE_AUDIO || (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000)) distance = 0; av_add_index_entry(st, offset, dts, sample_size, distance, keyframe ? AVINDEX_KEYFRAME : 0); dprintf(c->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " "size %d, distance %d, keyframe %d\n", st->index, sc->sample_count+i, offset, dts, sample_size, distance, keyframe); distance++; assert(sample_duration % sc->time_rate == 0); dts += sample_duration / sc->time_rate; offset += sample_size; } frag->moof_offset = offset; sc->sample_count = st->nb_index_entries; st->duration = dts; return 0; }


void mpv_decode_mb_internal(MpegEncContext *s, int16_t block[12][64], int is_mpeg12) { const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; #if FF_API_XVMC FF_DISABLE_DEPRECATION_WARNINGS if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration){ ff_xvmc_decode_mb(s);//xvmc uses pblocks return; } FF_ENABLE_DEPRECATION_WARNINGS #endif /* FF_API_XVMC */ if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { /* print DCT coefficients */ int i,j; av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y); for(i=0; i<6; i++){ for(j=0; j<64; j++){ av_log(s->avctx, AV_LOG_DEBUG, "%5d", block[i][s->idsp.idct_permutation[j]]); } av_log(s->avctx, AV_LOG_DEBUG, "\n"); } } s->current_picture.qscale_table[mb_xy] = s->qscale; /* update DC predictors for P macroblocks */ if (!s->mb_intra) { if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) { if(s->mbintra_table[mb_xy]) ff_clean_intra_table_entries(s); } else { s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->intra_dc_precision; } } else if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) s->mbintra_table[mb_xy]=1; if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc uint8_t *dest_y, *dest_cb, *dest_cr; int dct_linesize, dct_offset; op_pixels_func (*op_pix)[4]; qpel_mc_func (*op_qpix)[16]; const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics const int uvlinesize = s->current_picture.f->linesize[1]; const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band; const int block_size = 8; /* avoid copy if macroblock skipped in last frame too */ /* skip only during decoding as we might trash the buffers during encoding a bit */ if(!s->encoding){ uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; if (s->mb_skipped) { s->mb_skipped= 0; assert(s->pict_type!=AV_PICTURE_TYPE_I); *mbskip_ptr = 1; } else if(!s->current_picture.reference) { *mbskip_ptr = 1; } else{ *mbskip_ptr = 0; /* not skipped */ } } dct_linesize = linesize << s->interlaced_dct; dct_offset = s->interlaced_dct ? linesize : linesize * block_size; if(readable){ dest_y= s->dest[0]; dest_cb= s->dest[1]; dest_cr= s->dest[2]; }else{ dest_y = s->sc.b_scratchpad; dest_cb= s->sc.b_scratchpad+16*linesize; dest_cr= s->sc.b_scratchpad+32*linesize; } if (!s->mb_intra) { /* motion handling */ /* decoding or more than one mb_type (MC was already done otherwise) */ if(!s->encoding){ if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) { if (s->mv_dir & MV_DIR_FORWARD) { ff_thread_await_progress(&s->last_picture_ptr->tf, lowest_referenced_row(s, 0), 0); } if (s->mv_dir & MV_DIR_BACKWARD) { ff_thread_await_progress(&s->next_picture_ptr->tf, lowest_referenced_row(s, 1), 0); } } op_qpix= s->me.qpel_put; if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ op_pix = s->hdsp.put_pixels_tab; }else{ op_pix = s->hdsp.put_no_rnd_pixels_tab; } if (s->mv_dir & MV_DIR_FORWARD) { ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f->data, op_pix, op_qpix); op_pix = s->hdsp.avg_pixels_tab; op_qpix= s->me.qpel_avg; } if (s->mv_dir & MV_DIR_BACKWARD) { ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f->data, op_pix, op_qpix); } } /* skip dequant / idct if we are really late ;) */ if(s->avctx->skip_idct){ if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) || s->avctx->skip_idct >= AVDISCARD_ALL) goto skip_idct; } /* add dct residue */ if(s->encoding || !( s->msmpeg4_version || s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO || (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){ add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { if (s->chroma_y_shift){ add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); }else{ dct_linesize >>= 1; dct_offset >>=1; add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale); add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale); add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale); add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale); } } } else if(is_mpeg12 || (s->codec_id != AV_CODEC_ID_WMV2)){ add_dct(s, block[0], 0, dest_y , dct_linesize); add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { if(s->chroma_y_shift){//Chroma420 add_dct(s, block[4], 4, dest_cb, uvlinesize); add_dct(s, block[5], 5, dest_cr, uvlinesize); }else{ //chroma422 dct_linesize = uvlinesize << s->interlaced_dct; dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize * 8; add_dct(s, block[4], 4, dest_cb, dct_linesize); add_dct(s, block[5], 5, dest_cr, dct_linesize); add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize); add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize); if(!s->chroma_x_shift){//Chroma444 add_dct(s, block[8], 8, dest_cb+8, dct_linesize); add_dct(s, block[9], 9, dest_cr+8, dct_linesize); add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize); add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize); } } }//fi gray } else if (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) { ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); } } else { /* dct only in intra block */ if(s->encoding || !(s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO)){ put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { if(s->chroma_y_shift){ put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); }else{ dct_offset >>=1; dct_linesize >>=1; put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale); put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale); put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale); put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale); } } }else{ s->idsp.idct_put(dest_y, dct_linesize, block[0]); s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]); s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]); s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]); if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { if(s->chroma_y_shift){ s->idsp.idct_put(dest_cb, uvlinesize, block[4]); s->idsp.idct_put(dest_cr, uvlinesize, block[5]); }else{ dct_linesize = uvlinesize << s->interlaced_dct; dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize * 8; s->idsp.idct_put(dest_cb, dct_linesize, block[4]); s->idsp.idct_put(dest_cr, dct_linesize, block[5]); s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]); s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]); if(!s->chroma_x_shift){//Chroma444 s->idsp.idct_put(dest_cb + 8, dct_linesize, block[8]); s->idsp.idct_put(dest_cr + 8, dct_linesize, block[9]); s->idsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]); s->idsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]); } } }//gray } } skip_idct: if(!readable){ s->hdsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16); s->hdsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize,16 >> s->chroma_y_shift); s->hdsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shift); } } }


static void device_finalize(Object *obj) { NamedGPIOList *ngl, *next; DeviceState *dev = DEVICE(obj); qemu_opts_del(dev->opts); QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) { QLIST_REMOVE(ngl, node); qemu_free_irqs(ngl->in, ngl->num_in); g_free(ngl->name); g_free(ngl); /* ngl->out irqs are owned by the other end and should not be freed * here */ } }


static int vdi_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVVdiState *s = bs->opaque; VdiHeader header; size_t bmap_size; int ret; logout("\n"); ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1); if (ret < 0) { goto fail; } vdi_header_to_cpu(&header); #if defined(CONFIG_VDI_DEBUG) vdi_header_print(&header); #endif if (header.disk_size % SECTOR_SIZE != 0) { /* 'VBoxManage convertfromraw' can create images with odd disk sizes. We accept them but round the disk size to the next multiple of SECTOR_SIZE. */ logout("odd disk size %" PRIu64 " B, round up\n", header.disk_size); header.disk_size += SECTOR_SIZE - 1; header.disk_size &= ~(SECTOR_SIZE - 1); } if (header.signature != VDI_SIGNATURE) { error_setg(errp, "Image not in VDI format (bad signature %08x)", header.signature); ret = -EINVAL; goto fail; } else if (header.version != VDI_VERSION_1_1) { error_setg(errp, "unsupported VDI image (version %u.%u)", header.version >> 16, header.version & 0xffff); ret = -ENOTSUP; goto fail; } else if (header.offset_bmap % SECTOR_SIZE != 0) { /* We only support block maps which start on a sector boundary. */ error_setg(errp, "unsupported VDI image (unaligned block map offset " "0x%x)", header.offset_bmap); ret = -ENOTSUP; goto fail; } else if (header.offset_data % SECTOR_SIZE != 0) { /* We only support data blocks which start on a sector boundary. */ error_setg(errp, "unsupported VDI image (unaligned data offset 0x%x)", header.offset_data); ret = -ENOTSUP; goto fail; } else if (header.sector_size != SECTOR_SIZE) { error_setg(errp, "unsupported VDI image (sector size %u is not %u)", header.sector_size, SECTOR_SIZE); ret = -ENOTSUP; goto fail; } else if (header.block_size != 1 * MiB) { error_setg(errp, "unsupported VDI image (sector size %u is not %u)", header.block_size, 1 * MiB); ret = -ENOTSUP; goto fail; } else if (header.disk_size > (uint64_t)header.blocks_in_image * header.block_size) { error_setg(errp, "unsupported VDI image (disk size %" PRIu64 ", " "image bitmap has room for %" PRIu64 ")", header.disk_size, (uint64_t)header.blocks_in_image * header.block_size); ret = -ENOTSUP; goto fail; } else if (!uuid_is_null(header.uuid_link)) { error_setg(errp, "unsupported VDI image (non-NULL link UUID)"); ret = -ENOTSUP; goto fail; } else if (!uuid_is_null(header.uuid_parent)) { error_setg(errp, "unsupported VDI image (non-NULL parent UUID)"); ret = -ENOTSUP; goto fail; } bs->total_sectors = header.disk_size / SECTOR_SIZE; s->block_size = header.block_size; s->block_sectors = header.block_size / SECTOR_SIZE; s->bmap_sector = header.offset_bmap / SECTOR_SIZE; s->header = header; bmap_size = header.blocks_in_image * sizeof(uint32_t); bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE; s->bmap = g_malloc(bmap_size * SECTOR_SIZE); ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size); if (ret < 0) { goto fail_free_bmap; } /* Disable migration when vdi images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "vdi", bs->device_name, "live migration"); migrate_add_blocker(s->migration_blocker); return 0; fail_free_bmap: g_free(s->bmap); fail: return ret; }


static void i440fx_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->no_hotplug = 1; k->init = i440fx_initfn; k->config_write = i440fx_write_config; k->vendor_id = PCI_VENDOR_ID_INTEL; k->device_id = PCI_DEVICE_ID_INTEL_82441; k->revision = 0x02; k->class_id = PCI_CLASS_BRIDGE_HOST; dc->desc = "Host bridge"; dc->no_user = 1; dc->vmsd = &vmstate_i440fx; }


int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) { const int isRgb = isBGR(c->dstFormat); const int bpp = fmt_depth(c->dstFormat); int i; uint8_t table_Y[1024]; uint32_t *table_32 = 0; uint16_t *table_16 = 0; uint8_t *table_8 = 0; uint8_t *table_332 = 0; uint8_t *table_121 = 0; uint8_t *table_1 = 0; int entry_size = 0; void *table_r = 0, *table_g = 0, *table_b = 0; void *table_start; int64_t crv = inv_table[0]; int64_t cbu = inv_table[1]; int64_t cgu = -inv_table[2]; int64_t cgv = -inv_table[3]; int64_t cy = 1<<16; int64_t oy = 0; //printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv); if(!fullRange){ cy= (cy*255) / 219; oy= 16<<16; }else{ crv= (crv*224) / 255; cbu= (cbu*224) / 255; cgu= (cgu*224) / 255; cgv= (cgv*224) / 255; } cy = (cy *contrast )>>16; crv= (crv*contrast * saturation)>>32; cbu= (cbu*contrast * saturation)>>32; cgu= (cgu*contrast * saturation)>>32; cgv= (cgv*contrast * saturation)>>32; //printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv); oy -= 256*brightness; for (i = 0; i < 1024; i++) { int j; j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32; j = (j < 0) ? 0 : ((j > 255) ? 255 : j); table_Y[i] = j; } switch (bpp) { case 32: table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); entry_size = sizeof (uint32_t); table_r = table_32 + 197; table_b = table_32 + 197 + 685; table_g = table_32 + 197 + 2*682; for (i = -197; i < 256+197; i++) ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0); for (i = -132; i < 256+132; i++) ((uint32_t *)table_g)[i] = table_Y[i+384] << 8; for (i = -232; i < 256+232; i++) ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16); break; case 24: table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t)); entry_size = sizeof (uint8_t); table_r = table_g = table_b = table_8 + 232; for (i = -232; i < 256+232; i++) ((uint8_t * )table_b)[i] = table_Y[i+384]; break; case 15: case 16: table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); entry_size = sizeof (uint16_t); table_r = table_16 + 197; table_b = table_16 + 197 + 685; table_g = table_16 + 197 + 2*682; for (i = -197; i < 256+197; i++) { int j = table_Y[i+384] >> 3; if (isRgb) j <<= ((bpp==16) ? 11 : 10); ((uint16_t *)table_r)[i] = j; } for (i = -132; i < 256+132; i++) { int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3); ((uint16_t *)table_g)[i] = j << 5; } for (i = -232; i < 256+232; i++) { int j = table_Y[i+384] >> 3; if (!isRgb) j <<= ((bpp==16) ? 11 : 10); ((uint16_t *)table_b)[i] = j; } break; case 8: table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); entry_size = sizeof (uint8_t); table_r = table_332 + 197; table_b = table_332 + 197 + 685; table_g = table_332 + 197 + 2*682; for (i = -197; i < 256+197; i++) { int j = (table_Y[i+384 - 16] + 18)/36; if (isRgb) j <<= 5; ((uint8_t *)table_r)[i] = j; } for (i = -132; i < 256+132; i++) { int j = (table_Y[i+384 - 16] + 18)/36; if (!isRgb) j <<= 1; ((uint8_t *)table_g)[i] = j << 2; } for (i = -232; i < 256+232; i++) { int j = (table_Y[i+384 - 37] + 43)/85; if (!isRgb) j <<= 6; ((uint8_t *)table_b)[i] = j; } break; case 4: case 4|128: table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); entry_size = sizeof (uint8_t); table_r = table_121 + 197; table_b = table_121 + 197 + 685; table_g = table_121 + 197 + 2*682; for (i = -197; i < 256+197; i++) { int j = table_Y[i+384 - 110] >> 7; if (isRgb) j <<= 3; ((uint8_t *)table_r)[i] = j; } for (i = -132; i < 256+132; i++) { int j = (table_Y[i+384 - 37]+ 43)/85; ((uint8_t *)table_g)[i] = j << 1; } for (i = -232; i < 256+232; i++) { int j =table_Y[i+384 - 110] >> 7; if (!isRgb) j <<= 3; ((uint8_t *)table_b)[i] = j; } break; case 1: table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t)); entry_size = sizeof (uint8_t); table_g = table_1; table_r = table_b = NULL; for (i = 0; i < 256+256; i++) { int j = table_Y[i + 384 - 110]>>7; ((uint8_t *)table_g)[i] = j; } break; default: table_start= NULL; av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); //free mem? return -1; } for (i = 0; i < 256; i++) { c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309); c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309); c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309); } av_free(c->yuvTable); c->yuvTable= table_start; return 0; }


target_ulong helper_udiv(target_ulong a, target_ulong b) { uint64_t x0; uint32_t x1; x0 = (a & 0xffffffff) | ((int64_t) (env->y) << 32); x1 = (b & 0xffffffff); if (x1 == 0) { raise_exception(TT_DIV_ZERO); } x0 = x0 / x1; if (x0 > 0xffffffff) { env->cc_src2 = 1; return 0xffffffff; } else { env->cc_src2 = 0; return x0; } }


static direntry_t *create_short_filename(BDRVVVFATState *s, const char *filename, unsigned int directory_start) { int i, j = 0; direntry_t *entry = array_get_next(&(s->directory)); const gchar *p, *last_dot = NULL; gunichar c; bool lossy_conversion = false; char tail[11]; if (!entry) { return NULL; } memset(entry->name, 0x20, sizeof(entry->name)); /* copy filename and search last dot */ for (p = filename; ; p = g_utf8_next_char(p)) { c = g_utf8_get_char(p); if (c == '\0') { break; } else if (c == '.') { if (j == 0) { /* '.' at start of filename */ lossy_conversion = true; } else { if (last_dot) { lossy_conversion = true; } last_dot = p; } } else if (!last_dot) { /* first part of the name; copy it */ uint8_t v = to_valid_short_char(c); if (j < 8 && v) { entry->name[j++] = v; } else { lossy_conversion = true; } } } /* copy extension (if any) */ if (last_dot) { j = 0; for (p = g_utf8_next_char(last_dot); ; p = g_utf8_next_char(p)) { c = g_utf8_get_char(p); if (c == '\0') { break; } else { /* extension; copy it */ uint8_t v = to_valid_short_char(c); if (j < 3 && v) { entry->name[8 + (j++)] = v; } else { lossy_conversion = true; } } } } if (entry->name[0] == DIR_KANJI) { entry->name[0] = DIR_KANJI_FAKE; } /* numeric-tail generation */ for (j = 0; j < 8; j++) { if (entry->name[j] == ' ') { break; } } for (i = lossy_conversion ? 1 : 0; i < 999999; i++) { direntry_t *entry1; if (i > 0) { int len = sprintf(tail, "~%d", i); memcpy(entry->name + MIN(j, 8 - len), tail, len); } for (entry1 = array_get(&(s->directory), directory_start); entry1 < entry; entry1++) { if (!is_long_name(entry1) && !memcmp(entry1->name, entry->name, 11)) { break; /* found dupe */ } } if (entry1 == entry) { /* no dupe found */ return entry; } } return NULL; }


void ff_print_debug_info(MpegEncContext *s, Picture *p) { AVFrame *pict; if (s->avctx->hwaccel || !p || !p->mb_type) return; pict = &p->f; if (s->avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) { int x,y; av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: "); switch (pict->pict_type) { case AV_PICTURE_TYPE_I: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break; case AV_PICTURE_TYPE_P: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break; case AV_PICTURE_TYPE_B: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break; case AV_PICTURE_TYPE_S: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break; case AV_PICTURE_TYPE_SI: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break; case AV_PICTURE_TYPE_SP: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break; } for (y = 0; y < s->mb_height; y++) { for (x = 0; x < s->mb_width; x++) { if (s->avctx->debug & FF_DEBUG_SKIP) { int count = s->mbskip_table[x + y * s->mb_stride]; if (count > 9) count = 9; av_log(s->avctx, AV_LOG_DEBUG, "%1d", count); } if (s->avctx->debug & FF_DEBUG_QP) { av_log(s->avctx, AV_LOG_DEBUG, "%2d", p->qscale_table[x + y * s->mb_stride]); } if (s->avctx->debug & FF_DEBUG_MB_TYPE) { int mb_type = p->mb_type[x + y * s->mb_stride]; // Type & MV direction if (IS_PCM(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "P"); else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "A"); else if (IS_INTRA4x4(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "i"); else if (IS_INTRA16x16(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "I"); else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "d"); else if (IS_DIRECT(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "D"); else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "g"); else if (IS_GMC(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "G"); else if (IS_SKIP(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "S"); else if (!USES_LIST(mb_type, 1)) av_log(s->avctx, AV_LOG_DEBUG, ">"); else if (!USES_LIST(mb_type, 0)) av_log(s->avctx, AV_LOG_DEBUG, "<"); else { assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); av_log(s->avctx, AV_LOG_DEBUG, "X"); } // segmentation if (IS_8X8(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "+"); else if (IS_16X8(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "-"); else if (IS_8X16(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "|"); else if (IS_INTRA(mb_type) || IS_16X16(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, " "); else av_log(s->avctx, AV_LOG_DEBUG, "?"); if (IS_INTERLACED(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "="); else av_log(s->avctx, AV_LOG_DEBUG, " "); } } av_log(s->avctx, AV_LOG_DEBUG, "\n"); } } }


static int xan_huffman_decode(unsigned char *dest, const unsigned char *src, int dest_len) { unsigned char byte = *src++; unsigned char ival = byte + 0x16; const unsigned char * ptr = src + byte*2; unsigned char val = ival; unsigned char *dest_end = dest + dest_len; GetBitContext gb; init_get_bits(&gb, ptr, 0); // FIXME: no src size available while ( val != 0x16 ) { val = src[val - 0x17 + get_bits1(&gb) * byte]; if ( val < 0x16 ) { if (dest + 1 > dest_end) return 0; *dest++ = val; val = ival; } } return 0; }


static int kvm_log_stop(CPUPhysMemoryClient *client, target_phys_addr_t phys_addr, ram_addr_t size) { return kvm_dirty_pages_log_change(phys_addr, size, false); }


void MPV_common_end(MpegEncContext *s) { int i; if (s->motion_val) free(s->motion_val); if (s->h263_pred) { free(s->dc_val[0]); free(s->ac_val[0]); free(s->coded_block); free(s->mbintra_table); } if (s->mbskip_table) free(s->mbskip_table); for(i=0;i<3;i++) { free(s->last_picture_base[i]); free(s->next_picture_base[i]); if (s->has_b_frames) free(s->aux_picture_base[i]); } s->context_initialized = 0; }


static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) { BDRVBlkdebugState *s = bs->opaque; QDict *opts; const QDictEntry *e; bool force_json = false; for (e = qdict_first(options); e; e = qdict_next(options, e)) { if (strcmp(qdict_entry_key(e), "config") && strcmp(qdict_entry_key(e), "x-image")) { force_json = true; break; } } if (force_json && !bs->file->bs->full_open_options) { /* The config file cannot be recreated, so creating a plain filename * is impossible */ return; } if (!force_json && bs->file->bs->exact_filename[0]) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), "blkdebug:%s:%s", s->config_file ?: "", bs->file->bs->exact_filename); } opts = qdict_new(); qdict_put_str(opts, "driver", "blkdebug"); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "image", bs->file->bs->full_open_options); for (e = qdict_first(options); e; e = qdict_next(options, e)) { if (strcmp(qdict_entry_key(e), "x-image")) { qobject_incref(qdict_entry_value(e)); qdict_put_obj(opts, qdict_entry_key(e), qdict_entry_value(e)); } } bs->full_open_options = opts; }


static inline int usb_bt_fifo_dequeue(struct usb_hci_in_fifo_s *fifo, USBPacket *p) { int len; if (likely(!fifo->len)) return USB_RET_STALL; len = MIN(p->len, fifo->fifo[fifo->start].len); memcpy(p->data, fifo->fifo[fifo->start].data, len); if (len == p->len) { fifo->fifo[fifo->start].len -= len; fifo->fifo[fifo->start].data += len; } else { fifo->start ++; fifo->start &= CFIFO_LEN_MASK; fifo->len --; } fifo->dstart += len; fifo->dlen -= len; if (fifo->dstart >= fifo->dsize) { fifo->dstart = 0; fifo->dsize = DFIFO_LEN_MASK + 1; } return len; }


static int block_load(QEMUFile *f, void *opaque, int version_id) { static int banner_printed; int len, flags; char device_name[256]; int64_t addr; BlockDriverState *bs; uint8_t *buf; do { addr = qemu_get_be64(f); flags = addr & ~BDRV_SECTOR_MASK; addr >>= BDRV_SECTOR_BITS; if (flags & BLK_MIG_FLAG_DEVICE_BLOCK) { int ret; /* get device name */ len = qemu_get_byte(f); qemu_get_buffer(f, (uint8_t *)device_name, len); device_name[len] = '\0'; bs = bdrv_find(device_name); if (!bs) { fprintf(stderr, "Error unknown block device %s\n", device_name); return -EINVAL; } buf = qemu_malloc(BLOCK_SIZE); qemu_get_buffer(f, buf, BLOCK_SIZE); ret = bdrv_write(bs, addr, buf, BDRV_SECTORS_PER_DIRTY_CHUNK); qemu_free(buf); if (ret < 0) { return ret; } } else if (flags & BLK_MIG_FLAG_PROGRESS) { if (!banner_printed) { printf("Receiving block device images\n"); banner_printed = 1; } printf("Completed %d %%%c", (int)addr, (addr == 100) ? '\n' : '\r'); fflush(stdout); } else if (!(flags & BLK_MIG_FLAG_EOS)) { fprintf(stderr, "Unknown flags\n"); return -EINVAL; } if (qemu_file_has_error(f)) { return -EIO; } } while (!(flags & BLK_MIG_FLAG_EOS)); return 0; }


static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as) { ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; struct alsa_params_req req; struct alsa_params_obt obt; snd_pcm_t *handle; struct audsettings obt_as; req.fmt = aud_to_alsafmt (as->fmt, as->endianness); req.freq = as->freq; req.nchannels = as->nchannels; req.period_size = conf.period_size_in; req.buffer_size = conf.buffer_size_in; req.size_in_usec = conf.size_in_usec_in; req.override_mask = (conf.period_size_in_overridden ? 1 : 0) | (conf.buffer_size_in_overridden ? 2 : 0); if (alsa_open (1, &req, &obt, &handle)) { return -1; } obt_as.freq = obt.freq; obt_as.nchannels = obt.nchannels; obt_as.fmt = obt.fmt; obt_as.endianness = obt.endianness; audio_pcm_init_info (&hw->info, &obt_as); hw->samples = obt.samples; alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); if (!alsa->pcm_buf) { dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n", hw->samples, 1 << hw->info.shift); alsa_anal_close1 (&handle); return -1; } alsa->handle = handle; return 0; }


static uint32_t m5206_mbar_readb(void *opaque, target_phys_addr_t offset) { m5206_mbar_state *s = (m5206_mbar_state *)opaque; offset &= 0x3ff; if (offset > 0x200) { hw_error("Bad MBAR read offset 0x%x", (int)offset); } if (m5206_mbar_width[offset >> 2] > 1) { uint16_t val; val = m5206_mbar_readw(opaque, offset & ~1); if ((offset & 1) == 0) { val >>= 8; } return val & 0xff; } return m5206_mbar_read(s, offset, 1); }


static int vnc_zlib_stop(VncState *vs, int stream_id) { z_streamp zstream = &vs->zlib_stream[stream_id]; int previous_out; // switch back to normal output/zlib buffers vs->zlib = vs->output; vs->output = vs->zlib_tmp; // compress the zlib buffer // initialize the stream // XXX need one stream per session if (zstream->opaque != vs) { int err; VNC_DEBUG("VNC: initializing zlib stream %d\n", stream_id); VNC_DEBUG("VNC: opaque = %p | vs = %p\n", zstream->opaque, vs); zstream->zalloc = Z_NULL; zstream->zfree = Z_NULL; err = deflateInit2(zstream, vs->tight_compression, Z_DEFLATED, MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (err != Z_OK) { fprintf(stderr, "VNC: error initializing zlib\n"); return -1; } zstream->opaque = vs; } // XXX what to do if tight_compression changed in between? // reserve memory in output buffer buffer_reserve(&vs->output, vs->zlib.offset + 64); // set pointers zstream->next_in = vs->zlib.buffer; zstream->avail_in = vs->zlib.offset; zstream->next_out = vs->output.buffer + vs->output.offset; zstream->avail_out = vs->output.capacity - vs->output.offset; zstream->data_type = Z_BINARY; previous_out = zstream->total_out; // start encoding if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) { fprintf(stderr, "VNC: error during zlib compression\n"); return -1; } vs->output.offset = vs->output.capacity - zstream->avail_out; return zstream->total_out - previous_out; }


static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { FLACParseContext *fpc = s->priv_data; FLACHeaderMarker *curr; int nb_headers; const uint8_t *read_end = buf; const uint8_t *read_start = buf; if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { FLACFrameInfo fi; if (frame_header_is_valid(avctx, buf, &fi)) { s->duration = fi.blocksize; if (!avctx->sample_rate) avctx->sample_rate = fi.samplerate; if (fpc->pc->flags & PARSER_FLAG_USE_CODEC_TS){ fpc->pc->pts = fi.frame_or_sample_num; if (!fi.is_var_size) fpc->pc->pts *= fi.blocksize; } } *poutbuf = buf; *poutbuf_size = buf_size; return buf_size; } fpc->avctx = avctx; if (fpc->best_header_valid) return get_best_header(fpc, poutbuf, poutbuf_size); /* If a best_header was found last call remove it with the buffer data. */ if (fpc->best_header && fpc->best_header->best_child) { FLACHeaderMarker *temp; FLACHeaderMarker *best_child = fpc->best_header->best_child; /* Remove headers in list until the end of the best_header. */ for (curr = fpc->headers; curr != best_child; curr = temp) { if (curr != fpc->best_header) { av_log(avctx, AV_LOG_DEBUG, "dropping low score %i frame header from offset %i to %i\n", curr->max_score, curr->offset, curr->next->offset); } temp = curr->next; av_freep(&curr->link_penalty); av_free(curr); } /* Release returned data from ring buffer. */ av_fifo_drain(fpc->fifo_buf, best_child->offset); /* Fix the offset for the headers remaining to match the new buffer. */ for (curr = best_child->next; curr; curr = curr->next) curr->offset -= best_child->offset; best_child->offset = 0; fpc->headers = best_child; if (fpc->nb_headers_buffered >= FLAC_MIN_HEADERS) { fpc->best_header = best_child; return get_best_header(fpc, poutbuf, poutbuf_size); } fpc->best_header = NULL; } else if (fpc->best_header) { /* No end frame no need to delete the buffer; probably eof */ FLACHeaderMarker *temp; for (curr = fpc->headers; curr != fpc->best_header; curr = temp) { temp = curr->next; av_freep(&curr->link_penalty); av_free(curr); } fpc->headers = fpc->best_header->next; av_freep(&fpc->best_header->link_penalty); av_freep(&fpc->best_header); } /* Find and score new headers. */ /* buf_size is to zero when padding, so check for this since we do */ /* not want to try to read more input once we have found the end. */ /* Note that as (non-modified) parameters, buf can be non-NULL, */ /* while buf_size is 0. */ while ((buf && buf_size && read_end < buf + buf_size && fpc->nb_headers_buffered < FLAC_MIN_HEADERS) || ((!buf || !buf_size) && !fpc->end_padded)) { int start_offset; /* Pad the end once if EOF, to check the final region for headers. */ if (!buf || !buf_size) { fpc->end_padded = 1; buf_size = MAX_FRAME_HEADER_SIZE; read_end = read_start + MAX_FRAME_HEADER_SIZE; } else { /* The maximum read size is the upper-bound of what the parser needs to have the required number of frames buffered */ int nb_desired = FLAC_MIN_HEADERS - fpc->nb_headers_buffered + 1; read_end = read_end + FFMIN(buf + buf_size - read_end, nb_desired * FLAC_AVG_FRAME_SIZE); } if (!av_fifo_space(fpc->fifo_buf) && av_fifo_size(fpc->fifo_buf) / FLAC_AVG_FRAME_SIZE > fpc->nb_headers_buffered * 20) { /* There is less than one valid flac header buffered for 20 headers * buffered. Therefore the fifo is most likely filled with invalid * data and the input is not a flac file. */ goto handle_error; } /* Fill the buffer. */ if ( av_fifo_space(fpc->fifo_buf) < read_end - read_start && av_fifo_realloc2(fpc->fifo_buf, (read_end - read_start) + 2*av_fifo_size(fpc->fifo_buf)) < 0) { av_log(avctx, AV_LOG_ERROR, "couldn't reallocate buffer of size %"PTRDIFF_SPECIFIER"\n", (read_end - read_start) + av_fifo_size(fpc->fifo_buf)); goto handle_error; } if (buf && buf_size) { av_fifo_generic_write(fpc->fifo_buf, (void*) read_start, read_end - read_start, NULL); } else { int8_t pad[MAX_FRAME_HEADER_SIZE] = { 0 }; av_fifo_generic_write(fpc->fifo_buf, (void*) pad, sizeof(pad), NULL); } /* Tag headers and update sequences. */ start_offset = av_fifo_size(fpc->fifo_buf) - ((read_end - read_start) + (MAX_FRAME_HEADER_SIZE - 1)); start_offset = FFMAX(0, start_offset); nb_headers = find_new_headers(fpc, start_offset); if (nb_headers < 0) { av_log(avctx, AV_LOG_ERROR, "find_new_headers couldn't allocate FLAC header\n"); goto handle_error; } fpc->nb_headers_buffered = nb_headers; /* Wait till FLAC_MIN_HEADERS to output a valid frame. */ if (!fpc->end_padded && fpc->nb_headers_buffered < FLAC_MIN_HEADERS) { if (buf && read_end < buf + buf_size) { read_start = read_end; continue; } else { goto handle_error; } } /* If headers found, update the scores since we have longer chains. */ if (fpc->end_padded || fpc->nb_headers_found) score_sequences(fpc); /* restore the state pre-padding */ if (fpc->end_padded) { int warp = fpc->fifo_buf->wptr - fpc->fifo_buf->buffer < MAX_FRAME_HEADER_SIZE; /* HACK: drain the tail of the fifo */ fpc->fifo_buf->wptr -= MAX_FRAME_HEADER_SIZE; fpc->fifo_buf->wndx -= MAX_FRAME_HEADER_SIZE; if (warp) { fpc->fifo_buf->wptr += fpc->fifo_buf->end - fpc->fifo_buf->buffer; } buf_size = 0; read_start = read_end = NULL; } } for (curr = fpc->headers; curr; curr = curr->next) { if (curr->max_score > 0 && (!fpc->best_header || curr->max_score > fpc->best_header->max_score)) { fpc->best_header = curr; } } if (fpc->best_header) { fpc->best_header_valid = 1; if (fpc->best_header->offset > 0) { /* Output a junk frame. */ av_log(avctx, AV_LOG_DEBUG, "Junk frame till offset %i\n", fpc->best_header->offset); /* Set duration to 0. It is unknown or invalid in a junk frame. */ s->duration = 0; *poutbuf_size = fpc->best_header->offset; *poutbuf = flac_fifo_read_wrap(fpc, 0, *poutbuf_size, &fpc->wrap_buf, &fpc->wrap_buf_allocated_size); return buf_size ? (read_end - buf) : (fpc->best_header->offset - av_fifo_size(fpc->fifo_buf)); } if (!buf_size) return get_best_header(fpc, poutbuf, poutbuf_size); } handle_error: *poutbuf = NULL; *poutbuf_size = 0; return buf_size ? read_end - buf : 0; }


int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags) { VLCcode *buf; int i, j, ret; vlc->bits = nb_bits; if(flags & INIT_VLC_USE_NEW_STATIC){ VLC dyn_vlc = *vlc; if (vlc->table_size) return 0; ret = ff_init_vlc_sparse(&dyn_vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, symbols, symbols_wrap, symbols_size, flags & ~INIT_VLC_USE_NEW_STATIC); av_assert0(ret >= 0); av_assert0(dyn_vlc.table_size <= vlc->table_allocated); if(dyn_vlc.table_size < vlc->table_allocated) av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", dyn_vlc.table_size, vlc->table_allocated); memcpy(vlc->table, dyn_vlc.table, dyn_vlc.table_size * sizeof(*vlc->table)); vlc->table_size = dyn_vlc.table_size; ff_free_vlc(&dyn_vlc); return 0; }else { vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; } av_dlog(NULL, "build table nb_codes=%d\n", nb_codes); buf = av_malloc((nb_codes+1)*sizeof(VLCcode)); av_assert0(symbols_size <= 2 || !symbols); j = 0; #define COPY(condition)\ for (i = 0; i < nb_codes; i++) {\ GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\ if (!(condition))\ continue;\ if (buf[j].bits > 3*nb_bits || buf[j].bits>32) {\ av_log(NULL, AV_LOG_ERROR, "Too long VLC in init_vlc\n");\ return -1;\ }\ GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\ if (buf[j].code >= (1LL<<buf[j].bits)) {\ av_log(NULL, AV_LOG_ERROR, "Invalid code in init_vlc\n");\ return -1;\ }\ if (flags & INIT_VLC_LE)\ buf[j].code = bitswap_32(buf[j].code);\ else\ buf[j].code <<= 32 - buf[j].bits;\ if (symbols)\ GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\ else\ buf[j].symbol = i;\ j++;\ } COPY(buf[j].bits > nb_bits); // qsort is the slowest part of init_vlc, and could probably be improved or avoided qsort(buf, j, sizeof(VLCcode), compare_vlcspec); COPY(buf[j].bits && buf[j].bits <= nb_bits); nb_codes = j; ret = build_table(vlc, nb_bits, nb_codes, buf, flags); av_free(buf); if (ret < 0) { av_freep(&vlc->table); return -1; } return 0; }


static void idr(H264Context *h){ int i; ff_h264_remove_all_refs(h); h->prev_frame_num= 0; h->prev_frame_num_offset= 0; h->prev_poc_msb= h->prev_poc_lsb= 0; for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) h->last_pocs[i] = INT_MIN; }


static void cg3_initfn(Object *obj) { SysBusDevice *sbd = SYS_BUS_DEVICE(obj); CG3State *s = CG3(obj); memory_region_init_ram(&s->rom, NULL, "cg3.prom", FCODE_MAX_ROM_SIZE, &error_abort); memory_region_set_readonly(&s->rom, true); sysbus_init_mmio(sbd, &s->rom); memory_region_init_io(&s->reg, NULL, &cg3_reg_ops, s, "cg3.reg", CG3_REG_SIZE); sysbus_init_mmio(sbd, &s->reg); }


int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) { int id, sr, ch, ba, tag, bps; id = avctx->codec_id; sr = avctx->sample_rate; ch = avctx->channels; ba = avctx->block_align; tag = avctx->codec_tag; bps = av_get_exact_bits_per_sample(avctx->codec_id); /* codecs with an exact constant bits per sample */ if (bps > 0 && ch > 0 && frame_bytes > 0) return (frame_bytes * 8) / (bps * ch); bps = avctx->bits_per_coded_sample; /* codecs with a fixed packet duration */ switch (id) { case CODEC_ID_ADPCM_ADX: return 32; case CODEC_ID_ADPCM_IMA_QT: return 64; case CODEC_ID_ADPCM_EA_XAS: return 128; case CODEC_ID_AMR_NB: case CODEC_ID_GSM: case CODEC_ID_QCELP: case CODEC_ID_RA_144: case CODEC_ID_RA_288: return 160; case CODEC_ID_IMC: return 256; case CODEC_ID_AMR_WB: case CODEC_ID_GSM_MS: return 320; case CODEC_ID_MP1: return 384; case CODEC_ID_ATRAC1: return 512; case CODEC_ID_ATRAC3: return 1024; case CODEC_ID_MP2: case CODEC_ID_MUSEPACK7: return 1152; case CODEC_ID_AC3: return 1536; } if (sr > 0) { /* calc from sample rate */ if (id == CODEC_ID_TTA) return 256 * sr / 245; if (ch > 0) { /* calc from sample rate and channels */ if (id == CODEC_ID_BINKAUDIO_DCT) return (480 << (sr / 22050)) / ch; } } if (ba > 0) { /* calc from block_align */ if (id == CODEC_ID_SIPR) { switch (ba) { case 20: return 160; case 19: return 144; case 29: return 288; case 37: return 480; } } } if (frame_bytes > 0) { /* calc from frame_bytes only */ if (id == CODEC_ID_TRUESPEECH) return 240 * (frame_bytes / 32); if (id == CODEC_ID_NELLYMOSER) return 256 * (frame_bytes / 64); if (bps > 0) { /* calc from frame_bytes and bits_per_coded_sample */ if (id == CODEC_ID_ADPCM_G726) return frame_bytes * 8 / bps; } if (ch > 0) { /* calc from frame_bytes and channels */ switch (id) { case CODEC_ID_ADPCM_4XM: case CODEC_ID_ADPCM_IMA_ISS: return (frame_bytes - 4 * ch) * 2 / ch; case CODEC_ID_ADPCM_IMA_SMJPEG: return (frame_bytes - 4) * 2 / ch; case CODEC_ID_ADPCM_IMA_AMV: return (frame_bytes - 8) * 2 / ch; case CODEC_ID_ADPCM_XA: return (frame_bytes / 128) * 224 / ch; case CODEC_ID_INTERPLAY_DPCM: return (frame_bytes - 6 - ch) / ch; case CODEC_ID_ROQ_DPCM: return (frame_bytes - 8) / ch; case CODEC_ID_XAN_DPCM: return (frame_bytes - 2 * ch) / ch; case CODEC_ID_MACE3: return 3 * frame_bytes / ch; case CODEC_ID_MACE6: return 6 * frame_bytes / ch; case CODEC_ID_PCM_LXF: return 2 * (frame_bytes / (5 * ch)); } if (tag) { /* calc from frame_bytes, channels, and codec_tag */ if (id == CODEC_ID_SOL_DPCM) { if (tag == 3) return frame_bytes / ch; else return frame_bytes * 2 / ch; } } if (ba > 0) { /* calc from frame_bytes, channels, and block_align */ int blocks = frame_bytes / ba; switch (avctx->codec_id) { case CODEC_ID_ADPCM_IMA_WAV: return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8); case CODEC_ID_ADPCM_IMA_DK3: return blocks * (((ba - 16) * 2 / 3 * 4) / ch); case CODEC_ID_ADPCM_IMA_DK4: return blocks * (1 + (ba - 4 * ch) * 2 / ch); case CODEC_ID_ADPCM_MS: return blocks * (2 + (ba - 7 * ch) * 2 / ch); } } if (bps > 0) { /* calc from frame_bytes, channels, and bits_per_coded_sample */ switch (avctx->codec_id) { case CODEC_ID_PCM_DVD: return 2 * (frame_bytes / ((bps * 2 / 8) * ch)); case CODEC_ID_PCM_BLURAY: return frame_bytes / ((FFALIGN(ch, 2) * bps) / 8); case CODEC_ID_S302M: return 2 * (frame_bytes / ((bps + 4) / 4)) / ch; } } } } return 0; }


static void parse_context_init(SchroParseUnitContext *parse_ctx, const uint8_t *buf, int buf_size) { parse_ctx->buf = buf; parse_ctx->buf_size = buf_size; }


static int update_size(AVCodecContext *ctx, int w, int h) { VP9Context *s = ctx->priv_data; uint8_t *p; if (s->above_partition_ctx && w == ctx->width && h == ctx->height) return 0; ctx->width = w; ctx->height = h; s->sb_cols = (w + 63) >> 6; s->sb_rows = (h + 63) >> 6; s->cols = (w + 7) >> 3; s->rows = (h + 7) >> 3; #define assign(var, type, n) var = (type) p; p += s->sb_cols * n * sizeof(*var) av_free(s->above_partition_ctx); p = av_malloc(s->sb_cols * (240 + sizeof(*s->lflvl) + 16 * sizeof(*s->above_mv_ctx) + 64 * s->sb_rows * (1 + sizeof(*s->mv[0]) * 2))); if (!p) return AVERROR(ENOMEM); assign(s->above_partition_ctx, uint8_t *, 8); assign(s->above_skip_ctx, uint8_t *, 8); assign(s->above_txfm_ctx, uint8_t *, 8); assign(s->above_mode_ctx, uint8_t *, 16); assign(s->above_y_nnz_ctx, uint8_t *, 16); assign(s->above_uv_nnz_ctx[0], uint8_t *, 8); assign(s->above_uv_nnz_ctx[1], uint8_t *, 8); assign(s->intra_pred_data[0], uint8_t *, 64); assign(s->intra_pred_data[1], uint8_t *, 32); assign(s->intra_pred_data[2], uint8_t *, 32); assign(s->above_segpred_ctx, uint8_t *, 8); assign(s->above_intra_ctx, uint8_t *, 8); assign(s->above_comp_ctx, uint8_t *, 8); assign(s->above_ref_ctx, uint8_t *, 8); assign(s->above_filter_ctx, uint8_t *, 8); assign(s->lflvl, struct VP9Filter *, 1); assign(s->above_mv_ctx, VP56mv(*)[2], 16); assign(s->segmentation_map, uint8_t *, 64 * s->sb_rows); assign(s->mv[0], struct VP9mvrefPair *, 64 * s->sb_rows); assign(s->mv[1], struct VP9mvrefPair *, 64 * s->sb_rows); #undef assign return 0; }


static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) { SmackerContext *smk = s->priv_data; int flags; int ret; int i; int frame_size = 0; int palchange = 0; if (s->pb->eof_reached || smk->cur_frame >= smk->frames) return AVERROR_EOF; /* if we demuxed all streams, pass another frame */ if(smk->curstream < 0) { avio_seek(s->pb, smk->nextpos, 0); frame_size = smk->frm_size[smk->cur_frame] & (~3); flags = smk->frm_flags[smk->cur_frame]; /* handle palette change event */ if(flags & SMACKER_PAL){ int size, sz, t, off, j, pos; uint8_t *pal = smk->pal; uint8_t oldpal[768]; memcpy(oldpal, pal, 768); size = avio_r8(s->pb); size = size * 4 - 1; frame_size -= size; frame_size--; sz = 0; pos = avio_tell(s->pb) + size; while(sz < 256){ t = avio_r8(s->pb); if(t & 0x80){ /* skip palette entries */ sz += (t & 0x7F) + 1; pal += ((t & 0x7F) + 1) * 3; } else if(t & 0x40){ /* copy with offset */ off = avio_r8(s->pb); j = (t & 0x3F) + 1; if (off + j > 0x100) { av_log(s, AV_LOG_ERROR, "Invalid palette update, offset=%d length=%d extends beyond palette size\n", off, j); return AVERROR_INVALIDDATA; } off *= 3; while(j-- && sz < 256) { *pal++ = oldpal[off + 0]; *pal++ = oldpal[off + 1]; *pal++ = oldpal[off + 2]; sz++; off += 3; } } else { /* new entries */ *pal++ = smk_pal[t]; *pal++ = smk_pal[avio_r8(s->pb) & 0x3F]; *pal++ = smk_pal[avio_r8(s->pb) & 0x3F]; sz++; } } avio_seek(s->pb, pos, 0); palchange |= 1; } flags >>= 1; smk->curstream = -1; /* if audio chunks are present, put them to stack and retrieve later */ for(i = 0; i < 7; i++) { if(flags & 1) { uint32_t size; uint8_t *tmpbuf; size = avio_rl32(s->pb) - 4; if (!size || size > frame_size) { av_log(s, AV_LOG_ERROR, "Invalid audio part size\n"); return AVERROR_INVALIDDATA; } frame_size -= size; frame_size -= 4; smk->curstream++; tmpbuf = av_realloc(smk->bufs[smk->curstream], size); if (!tmpbuf) return AVERROR(ENOMEM); smk->bufs[smk->curstream] = tmpbuf; smk->buf_sizes[smk->curstream] = size; ret = avio_read(s->pb, smk->bufs[smk->curstream], size); if(ret != size) return AVERROR(EIO); smk->stream_id[smk->curstream] = smk->indexes[i]; } flags >>= 1; } if (frame_size < 0) return AVERROR_INVALIDDATA; if (av_new_packet(pkt, frame_size + 769)) return AVERROR(ENOMEM); if(smk->frm_size[smk->cur_frame] & 1) palchange |= 2; pkt->data[0] = palchange; memcpy(pkt->data + 1, smk->pal, 768); ret = avio_read(s->pb, pkt->data + 769, frame_size); if(ret != frame_size) return AVERROR(EIO); pkt->stream_index = smk->videoindex; pkt->pts = smk->cur_frame; pkt->size = ret + 769; smk->cur_frame++; smk->nextpos = avio_tell(s->pb); } else { if (smk->stream_id[smk->curstream] < 0) return AVERROR_INVALIDDATA; if (av_new_packet(pkt, smk->buf_sizes[smk->curstream])) return AVERROR(ENOMEM); memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]); pkt->size = smk->buf_sizes[smk->curstream]; pkt->stream_index = smk->stream_id[smk->curstream]; pkt->pts = smk->aud_pts[smk->curstream]; smk->aud_pts[smk->curstream] += AV_RL32(pkt->data); smk->curstream--; } return 0; }


static void wm8750_audio_out_cb(void *opaque, int free_b) { struct wm8750_s *s = (struct wm8750_s *) opaque; wm8750_out_flush(s); s->req_out = free_b; s->data_req(s->opaque, free_b >> 2, s->req_in >> 2); }


static void unix_process_msgfd(CharDriverState *chr, struct msghdr *msg) { TCPCharDriver *s = chr->opaque; struct cmsghdr *cmsg; for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { int fd; if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) continue; fd = *((int *)CMSG_DATA(cmsg)); if (fd < 0) continue; #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); #endif if (s->msgfd != -1) close(s->msgfd); s->msgfd = fd; } }


void ga_channel_free(GAChannel *c) { if (c->method == GA_CHANNEL_UNIX_LISTEN && c->listen_channel) { ga_channel_listen_close(c); } if (c->client_channel) { ga_channel_client_close(c); } g_free(c); }


ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp) { RAMBlock *new_block; ram_addr_t addr; Error *local_err = NULL; size = TARGET_PAGE_ALIGN(size); new_block = g_malloc0(sizeof(*new_block)); new_block->mr = mr; new_block->used_length = size; new_block->max_length = max_size; new_block->fd = -1; new_block->host = host; if (host) { new_block->flags |= RAM_PREALLOC; } addr = ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); error_propagate(errp, local_err); return -1; } return addr; }


void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, uint16_t subchannel_nr, uint32_t io_int_parm, uint32_t io_int_word) { uint32_t type; if (io_int_word & IO_INT_WORD_AI) { type = KVM_S390_INT_IO(1, 0, 0, 0); } else { type = ((subchannel_id & 0xff00) << 24) | ((subchannel_id & 0x00060) << 22) | (subchannel_nr << 16); } kvm_s390_interrupt_internal(cpu, type, ((uint32_t)subchannel_id << 16) | subchannel_nr, ((uint64_t)io_int_parm << 32) | io_int_word, 1); }


static void elcr_ioport_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { PICCommonState *s = opaque; s->elcr = val & s->elcr_mask; }


void nonono(const char* file, int line, const char* msg) { fprintf(stderr, "Nonono! %s:%d %s\n", file, line, msg); exit(-5); }


static void spitz_i2c_setup(PXA2xxState *cpu) { /* Attach the CPU on one end of our I2C bus. */ i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]); #ifdef HAS_AUDIO DeviceState *wm; /* Attach a WM8750 to the bus */ wm = i2c_create_slave(bus, "wm8750", 0); spitz_wm8750_addr(wm, 0, 0); pxa2xx_gpio_out_set(cpu->gpio, SPITZ_GPIO_WM, qemu_allocate_irqs(spitz_wm8750_addr, wm, 1)[0]); /* .. and to the sound interface. */ cpu->i2s->opaque = wm; cpu->i2s->codec_out = wm8750_dac_dat; cpu->i2s->codec_in = wm8750_adc_dat; wm8750_data_req_set(wm, cpu->i2s->data_req, cpu->i2s); #endif }


static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out) { OutputStream *ost = ofilter->ost; AVCodecContext *codec = ost->st->codec; AVFilterContext *last_filter = out->filter_ctx; int pad_idx = out->pad_idx; char *sample_fmts, *sample_rates, *channel_layouts; char name[255]; int ret; snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index); ret = avfilter_graph_create_filter(&ofilter->filter, avfilter_get_by_name("ffabuffersink"), name, NULL, NULL, fg->graph); if (ret < 0) return ret; #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \ AVFilterContext *filt_ctx; \ \ av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \ "similarly to -af " filter_name "=%s.\n", arg); \ \ ret = avfilter_graph_create_filter(&filt_ctx, \ avfilter_get_by_name(filter_name), \ filter_name, arg, NULL, fg->graph); \ if (ret < 0) \ return ret; \ \ ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \ if (ret < 0) \ return ret; \ \ last_filter = filt_ctx; \ pad_idx = 0; \ } while (0) if (ost->audio_channels_mapped) { int i; AVBPrint pan_buf; av_bprint_init(&pan_buf, 256, 8192); av_bprintf(&pan_buf, "0x%"PRIx64, av_get_default_channel_layout(ost->audio_channels_mapped)); for (i = 0; i < ost->audio_channels_mapped; i++) if (ost->audio_channels_map[i] != -1) av_bprintf(&pan_buf, ":c%d=c%d", i, ost->audio_channels_map[i]); AUTO_INSERT_FILTER("-map_channel", "pan", pan_buf.str); av_bprint_finalize(&pan_buf, NULL); } if (codec->channels && !codec->channel_layout) codec->channel_layout = av_get_default_channel_layout(codec->channels); sample_fmts = choose_sample_fmts(ost); sample_rates = choose_sample_rates(ost); channel_layouts = choose_channel_layouts(ost); if (sample_fmts || sample_rates || channel_layouts) { AVFilterContext *format; char args[256]; int len = 0; if (sample_fmts) len += snprintf(args + len, sizeof(args) - len, "sample_fmts=%s:", sample_fmts); if (sample_rates) len += snprintf(args + len, sizeof(args) - len, "sample_rates=%s:", sample_rates); if (channel_layouts) len += snprintf(args + len, sizeof(args) - len, "channel_layouts=%s:", channel_layouts); args[len - 1] = 0; av_freep(&sample_fmts); av_freep(&sample_rates); av_freep(&channel_layouts); snprintf(name, sizeof(name), "audio format for output stream %d:%d", ost->file_index, ost->index); ret = avfilter_graph_create_filter(&format, avfilter_get_by_name("aformat"), name, args, NULL, fg->graph); if (ret < 0) return ret; ret = avfilter_link(last_filter, pad_idx, format, 0); if (ret < 0) return ret; last_filter = format; pad_idx = 0; } if (audio_volume != 256 && 0) { char args[256]; snprintf(args, sizeof(args), "%f", audio_volume / 256.); AUTO_INSERT_FILTER("-vol", "volume", args); } if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0) return ret; return 0; }


void restore_boot_order(void *opaque) { char *normal_boot_order = opaque; static int first = 1; /* Restore boot order and remove ourselves after the first boot */ if (first) { first = 0; return; } qemu_boot_set(normal_boot_order); qemu_unregister_reset(restore_boot_order, normal_boot_order); g_free(normal_boot_order); }


static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base) { VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev); VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev, base); VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus); int ret, max_nr_ports; bool plugging_port0; port->vser = bus->vser; port->bh = qemu_bh_new(flush_queued_data_bh, port); /* * Is the first console port we're seeing? If so, put it up at * location 0. This is done for backward compatibility (old * kernel, new qemu). */ plugging_port0 = port->is_console && !find_port_by_id(port->vser, 0); if (find_port_by_id(port->vser, port->id)) { error_report("virtio-serial-bus: A port already exists at id %u\n", port->id); return -1; } if (port->id == VIRTIO_CONSOLE_BAD_ID) { if (plugging_port0) { port->id = 0; } else { port->id = find_free_port_id(port->vser); if (port->id == VIRTIO_CONSOLE_BAD_ID) { error_report("virtio-serial-bus: Maximum port limit for this device reached\n"); return -1; } } } max_nr_ports = tswap32(port->vser->config.max_nr_ports); if (port->id >= max_nr_ports) { error_report("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u\n", max_nr_ports - 1); return -1; } port->info = info; ret = info->init(port); if (ret) { return ret; } if (!use_multiport(port->vser)) { /* * Allow writes to guest in this case; we have no way of * knowing if a guest port is connected. */ port->guest_connected = true; } port->elem.out_num = 0; QTAILQ_INSERT_TAIL(&port->vser->ports, port, next); port->ivq = port->vser->ivqs[port->id]; port->ovq = port->vser->ovqs[port->id]; add_port(port->vser, port->id); /* Send an update to the guest about this new port added */ virtio_notify_config(&port->vser->vdev); return ret; }


void block_job_pause(BlockJob *job) { job->paused = true; }


static void prop_get_fdt(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); Error *err = NULL; int fdt_offset_next, fdt_offset, fdt_depth; void *fdt; if (!drc->fdt) { visit_type_null(v, NULL, errp); return; } fdt = drc->fdt; fdt_offset = drc->fdt_start_offset; fdt_depth = 0; do { const char *name = NULL; const struct fdt_property *prop = NULL; int prop_len = 0, name_len = 0; uint32_t tag; tag = fdt_next_tag(fdt, fdt_offset, &fdt_offset_next); switch (tag) { case FDT_BEGIN_NODE: fdt_depth++; name = fdt_get_name(fdt, fdt_offset, &name_len); visit_start_struct(v, name, NULL, 0, &err); if (err) { error_propagate(errp, err); return; } break; case FDT_END_NODE: /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */ g_assert(fdt_depth > 0); visit_check_struct(v, &err); visit_end_struct(v); if (err) { error_propagate(errp, err); return; } fdt_depth--; break; case FDT_PROP: { int i; prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len); name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); visit_start_list(v, name, &err); if (err) { error_propagate(errp, err); return; } for (i = 0; i < prop_len; i++) { visit_type_uint8(v, NULL, (uint8_t *)&prop->data[i], &err); if (err) { error_propagate(errp, err); return; } } visit_end_list(v); break; } default: error_setg(&error_abort, "device FDT in unexpected state: %d", tag); } fdt_offset = fdt_offset_next; } while (fdt_depth != 0); }


int bdrv_pwrite(BlockDriverState *bs, int64_t offset, const void *buf, int bytes) { QEMUIOVector qiov; struct iovec iov = { .iov_base = (void *) buf, .iov_len = bytes, }; if (bytes < 0) { return -EINVAL; } qemu_iovec_init_external(&qiov, &iov, 1); return bdrv_pwritev(bs, offset, &qiov); }


static int ppc_fixup_cpu(PowerPCCPU *cpu) { CPUPPCState *env = &cpu->env; /* TCG doesn't (yet) emulate some groups of instructions that * are implemented on some otherwise supported CPUs (e.g. VSX * and decimal floating point instructions on POWER7). We * remove unsupported instruction groups from the cpu state's * instruction masks and hope the guest can cope. For at * least the pseries machine, the unavailability of these * instructions can be advertised to the guest via the device * tree. */ if ((env->insns_flags & ~PPC_TCG_INSNS) || (env->insns_flags2 & ~PPC_TCG_INSNS2)) { fprintf(stderr, "Warning: Disabling some instructions which are not " "emulated by TCG (0x%" PRIx64 ", 0x%" PRIx64 ")\n", env->insns_flags & ~PPC_TCG_INSNS, env->insns_flags2 & ~PPC_TCG_INSNS2); } env->insns_flags &= PPC_TCG_INSNS; env->insns_flags2 &= PPC_TCG_INSNS2; return 0; }