int
send_and_recv_header(const char *ip, mode_t mode, char **header, char *txt)
{
	char *hdr = malloc(2000 * sizeof(char));

	if ( hdr == NULL ) {
		return -1;
	}

	socket_client_t *client = malloc(sizeof(socket_client_t));


	if ( client == NULL ) {
		fprintf(stderr, "malloc failed\n");
		free(hdr);
		return -1;
	}


	if ( socket_client_new(client, ip) == -1 ) {
		free(hdr);
		socket_client_free(client);
		return -1;
	}


	if ( socket_client_connect(client) == -1 ) {
		free(hdr);
		socket_client_free(client);
		return -1;
	}


	if ( mode )
		hdr = build_header(mode, txt);
	else
		hdr = build_header(mode, "None");


	if ( socket_client_send(client->socket_cli, hdr) == -1 ) {
		free(hdr);
		socket_client_free(client);
		return -1;
	}


	if ( socket_client_recv(client->socket_cli, &hdr) == -1 ) {
		free(hdr);
		socket_client_free(client);
		return -1;
	}


	*header = strdup(hdr);


	socket_client_free(client);
	free(hdr);
	return 0;
}
Beispiel #2
0
bool mail_attach::save_to(mime_code* coder, string& out)
{
	if (coder)
		build_header(coder->get_encoding_type(), out);
	else
		build_header(NULL, out);

	string buf;
	if (ifstream::load(filepath_.c_str(), &buf) == false)
	{
		logger_error("load %s error %s",
			filepath_.c_str(), last_serror());
		return false;
	}

	if (coder)
	{
		coder->reset();
		coder->encode_update(buf.c_str(), (int) buf.size(), &out);
		coder->encode_finish(&out);
	}
	else
		out.append(buf);

	return true;
}
/* FADT */
static void
build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
           unsigned facs, unsigned dsdt)
{
    AcpiFadtDescriptorRev1 *fadt = acpi_data_push(table_data, sizeof(*fadt));

    fadt->firmware_ctrl = cpu_to_le32(facs);
    /* FACS address to be filled by Guest linker */
    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
                                   ACPI_BUILD_TABLE_FILE,
                                   table_data, &fadt->firmware_ctrl,
                                   sizeof fadt->firmware_ctrl);

    fadt->dsdt = cpu_to_le32(dsdt);
    /* DSDT address to be filled by Guest linker */
    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
                                   ACPI_BUILD_TABLE_FILE,
                                   table_data, &fadt->dsdt,
                                   sizeof fadt->dsdt);

    fadt_setup(fadt, pm);

    build_header(linker, table_data,
                 (void *)fadt, ACPI_FACP_SIGNATURE, sizeof(*fadt), 1);
}
Beispiel #4
0
/* size and flags are useful only for setxattr. for getxattr they can
 * be just set to 0 */
unsigned int build_xattr(corefs_packet * packet, unsigned int type, const char * name, const char *path, int size, int flags){

	unsigned int pathlen;
  unsigned int namelen;

  build_header(packet, COREFS_REQUEST);
  packet->payload.request.type = COREFS_REQUEST_XATTR;

  corefs_xattr * xattr =  (corefs_xattr*)&(packet->payload.request.op.xattr);
  xattr->type = type;
  xattr->flags = flags;
  pathlen = size;

  xattr->sizeofvalue = pathlen;
  pathlen = strlen(path);
  xattr->pathlen = pathlen;
  if(name)
    namelen = strlen(name);
  else namelen = 0;
  
  xattr->namelen = namelen;
  
  strcpy((char*)xattr->params,path);
  if(name)
    strcpy((char*)xattr->params+pathlen+1,name); // format: path || attribute name
  
  packet->header.payload_size =  REQUEST_BASE_SIZE(packet->payload.request) + SIZEOF_XATTR((*xattr));

  dprintf(stderr, "build_xattr payload_size %u pathlen %u , namelen%u\n", packet->header.payload_size, pathlen, namelen);
  dprintf(stderr, "build_xattr header_size %u\n", header_size);
  
  return   packet->header.payload_size + SIZEOF_HEADER(packet->header);
}
Beispiel #5
0
/* Build rsdt table */
void
build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
           const char *oem_id, const char *oem_table_id)
{
    int i;
    unsigned rsdt_entries_offset;
    AcpiRsdtDescriptorRev1 *rsdt;
    const unsigned table_data_len = (sizeof(uint32_t) * table_offsets->len);
    const unsigned rsdt_entry_size = sizeof(rsdt->table_offset_entry[0]);
    const size_t rsdt_len = sizeof(*rsdt) + table_data_len;

    rsdt = acpi_data_push(table_data, rsdt_len);
    rsdt_entries_offset = (char *)rsdt->table_offset_entry - table_data->data;
    for (i = 0; i < table_offsets->len; ++i) {
        uint32_t ref_tbl_offset = g_array_index(table_offsets, uint32_t, i);
        uint32_t rsdt_entry_offset = rsdt_entries_offset + rsdt_entry_size * i;

        /* rsdt->table_offset_entry to be filled by Guest linker */
        bios_linker_loader_add_pointer(linker,
            ACPI_BUILD_TABLE_FILE, rsdt_entry_offset, rsdt_entry_size,
            ACPI_BUILD_TABLE_FILE, ref_tbl_offset);
    }
    build_header(linker, table_data,
                 (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id);
}
Beispiel #6
0
bool Th105DataArchiveExtractor::write_header(std::vector<FileInfo> &file_list, FILE *fp) {
	if(fp == NULL) {
		return false;
	}

	const unsigned short file_count = file_list.size();
	unsigned int header_size;
	if(!calc_header_size(header_size, file_list)) {
		return false;
	}
	fseek(fp, 0, SEEK_SET);
	if(fwrite(&file_count, 2, 1, fp) != 1) {
		return false;
	}
	if(fwrite(&header_size, 4, 1, fp) != 1) {
		return false;
	}
	if(file_list.empty()) {
		return true;
	}
	std::vector<unsigned char> header(header_size);
	if(!build_header(header, file_list)) {
		return false;
	}
	if(!header_encrypt(header, 6 + header_size, 0xC5, 0x83, 0x53)) {
		return false;
	}
	if(fwrite(&header.front(), 1, header_size, fp) != header_size) {
		return false;
	}
	return true;
}
Beispiel #7
0
/*
 * Send an Amanda dump header to the output file and set file->blocksize
 */
static ssize_t
write_header(
    XferDestHolding *self,
    int fd)
{
    char *buffer;
    size_t written;

    self->chunk_header->blocksize = HEADER_BLOCK_BYTES;
    if (debug_chunker > 1)
        dump_dumpfile_t((dumpfile_t *)self->chunk_header);
    buffer = build_header((dumpfile_t *)self->chunk_header, NULL, HEADER_BLOCK_BYTES);
    if (!buffer) /* this shouldn't happen */
        error(_("header does not fit in %zd bytes"), (size_t)HEADER_BLOCK_BYTES);

    written = db_full_write(fd, buffer, HEADER_BLOCK_BYTES);
    g_free(buffer);
    if(written == HEADER_BLOCK_BYTES) return HEADER_BLOCK_BYTES;

    /* fake ENOSPC when we get a short write without errno set */
    if(errno == 0)
        errno = ENOSPC;

    return (ssize_t)-1;
}
Beispiel #8
0
/*
 * Send an Amanda dump header to the output file and set file->blocksize
 */
static ssize_t
write_tapeheader(
    int		outfd,
    dumpfile_t *file)
{
    char *buffer;
    size_t written;

    file->blocksize = DISK_BLOCK_BYTES;
    if (debug_chunker > 1)
        dump_dumpfile_t(file);
    buffer = build_header(file, NULL, DISK_BLOCK_BYTES);
    if (!buffer) /* this shouldn't happen */
        error(_("header does not fit in %zd bytes"), (size_t)DISK_BLOCK_BYTES);

    written = full_write(outfd, buffer, DISK_BLOCK_BYTES);
    amfree(buffer);
    if(written == DISK_BLOCK_BYTES) return 0;

    /* fake ENOSPC when we get a short write without errno set */
    if(errno == 0)
        errno = ENOSPC;

    return (ssize_t)-1;
}
Beispiel #9
0
static void
build_spcr(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
{
    AcpiSerialPortConsoleRedirection *spcr;
    const MemMapEntry *uart_memmap = &guest_info->memmap[VIRT_UART];
    int irq = guest_info->irqmap[VIRT_UART] + ARM_SPI_BASE;

    spcr = acpi_data_push(table_data, sizeof(*spcr));

    spcr->interface_type = 0x3;    /* ARM PL011 UART */

    spcr->base_address.space_id = AML_SYSTEM_MEMORY;
    spcr->base_address.bit_width = 8;
    spcr->base_address.bit_offset = 0;
    spcr->base_address.access_width = 1;
    spcr->base_address.address = cpu_to_le64(uart_memmap->base);

    spcr->interrupt_types = (1 << 3); /* Bit[3] ARMH GIC interrupt */
    spcr->gsi = cpu_to_le32(irq);  /* Global System Interrupt */

    spcr->baud = 3;                /* Baud Rate: 3 = 9600 */
    spcr->parity = 0;              /* No Parity */
    spcr->stopbits = 1;            /* 1 Stop bit */
    spcr->flowctrl = (1 << 1);     /* Bit[1] = RTS/CTS hardware flow control */
    spcr->term_type = 0;           /* Terminal Type: 0 = VT100 */

    spcr->pci_device_id = 0xffff;  /* PCI Device ID: not a PCI device */
    spcr->pci_vendor_id = 0xffff;  /* PCI Vendor ID: not a PCI device */

    build_header(linker, table_data, (void *)spcr, "SPCR", sizeof(*spcr), 2,
                 NULL, NULL);
}
static void
build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
{
    AcpiTableMcfg *mcfg;
    uint32_t sig;
    int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]);

    mcfg = acpi_data_push(table_data, len);
    mcfg->allocation[0].address = cpu_to_le64(info->mcfg_base);
    /* Only a single allocation so no need to play with segments */
    mcfg->allocation[0].pci_segment = cpu_to_le16(0);
    mcfg->allocation[0].start_bus_number = 0;
    mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->mcfg_size - 1);

    /* MCFG is used for ECAM which can be enabled or disabled by guest.
     * To avoid table size changes (which create migration issues),
     * always create the table even if there are no allocations,
     * but set the signature to a reserved value in this case.
     * ACPI spec requires OSPMs to ignore such tables.
     */
    if (info->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) {
        sig = ACPI_RSRV_SIGNATURE;
    } else {
        sig = ACPI_MCFG_SIGNATURE;
    }
    build_header(linker, table_data, (void *)mcfg, sig, len, 1);
}
Beispiel #11
0
unsigned int build_status(corefs_packet* packet, unsigned int status, unsigned int type)
{
	build_header(packet, COREFS_RESPONSE);
	packet->header.payload_size=SIZEOF_STATUS(packet->payload.response.rop.status) + RESPONSE_BASE_SIZE(packet->payload.response);
  packet->payload.response.type = type;
	packet->payload.response.rop.status.bits=status;
	return header_size + SIZEOF_STATUS(packet->payload.response.rop.status) + RESPONSE_BASE_SIZE(packet->payload.response);
}
Beispiel #12
0
// returns total packet size
unsigned int build_request_data(corefs_packet* packet, const char* data, size_t size)
{
	build_header(packet, COREFS_REQUEST);
	packet->header.payload_size = size + REQUEST_BASE_SIZE(packet->payload.request);
  packet->payload.request.type = COREFS_REQUEST_DATA;
	memmove(packet->payload.request.op.raw, data, size);
	return SIZEOF_HEADER(packet->header) + packet->header.payload_size;
}
Beispiel #13
0
char * add_header(char * header_type, char * header_content, char * content){
	char * header = build_header(header_type, header_content);
	char * new_str = (char * ) malloc((int)strlen(header) + (int)strlen(content) + 1);
	sprintf(new_str, "%s%s", header, content);

	free(header);
	return new_str;
}
Beispiel #14
0
char * add_header(const char * header_type, const char * header_content, char * content){
	char * header = build_header(header_type, header_content);
	char * new_str =  malloc(strlen(header) + strlen(content) + 4);
	sprintf(new_str, "%s%s", header, content);
	//printf("Size of header: %d, sizeof content, %d, sizeof new_str: %d\n", (int)strlen(header),(int)strlen(content),(int)strlen(new_str));
	free(header);
	return new_str;
}
Beispiel #15
0
unsigned int build_response_with_moredata(corefs_packet* packet, const char* data, size_t size, unsigned int offset)
{
	build_header(packet, COREFS_RESPONSE);
	packet->header.payload_size = size + RESPONSE_BASE_SIZE(packet->payload.response);
  packet->payload.response.type = COREFS_RESPONSE_MOREDATA;
  packet->payload.response.more_offset = offset;
	memcpy(packet->payload.response.rop.raw, data, size);
	return SIZEOF_HEADER(packet->header) + packet->header.payload_size;
}
Beispiel #16
0
/* MADT */
static void
build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
{
    int madt_start = table_data->len;
    const MemMapEntry *memmap = guest_info->memmap;
    const int *irqmap = guest_info->irqmap;
    AcpiMultipleApicTable *madt;
    AcpiMadtGenericDistributor *gicd;
    AcpiMadtGenericMsiFrame *gic_msi;
    int i;

    madt = acpi_data_push(table_data, sizeof *madt);

    gicd = acpi_data_push(table_data, sizeof *gicd);
    gicd->type = ACPI_APIC_GENERIC_DISTRIBUTOR;
    gicd->length = sizeof(*gicd);
    gicd->base_address = memmap[VIRT_GIC_DIST].base;

    for (i = 0; i < guest_info->smp_cpus; i++) {
        AcpiMadtGenericInterrupt *gicc = acpi_data_push(table_data,
                                                     sizeof *gicc);
        ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(i));

        gicc->type = ACPI_APIC_GENERIC_INTERRUPT;
        gicc->length = sizeof(*gicc);
        if (guest_info->gic_version == 2) {
            gicc->base_address = memmap[VIRT_GIC_CPU].base;
        }
        gicc->cpu_interface_number = i;
        gicc->arm_mpidr = armcpu->mp_affinity;
        gicc->uid = i;
        gicc->flags = cpu_to_le32(ACPI_GICC_ENABLED);
    }

    if (guest_info->gic_version == 3) {
        AcpiMadtGenericRedistributor *gicr = acpi_data_push(table_data,
                                                         sizeof *gicr);

        gicr->type = ACPI_APIC_GENERIC_REDISTRIBUTOR;
        gicr->length = sizeof(*gicr);
        gicr->base_address = cpu_to_le64(memmap[VIRT_GIC_REDIST].base);
        gicr->range_length = cpu_to_le32(memmap[VIRT_GIC_REDIST].size);
    } else {
        gic_msi = acpi_data_push(table_data, sizeof *gic_msi);
        gic_msi->type = ACPI_APIC_GENERIC_MSI_FRAME;
        gic_msi->length = sizeof(*gic_msi);
        gic_msi->gic_msi_frame_id = 0;
        gic_msi->base_address = cpu_to_le64(memmap[VIRT_GIC_V2M].base);
        gic_msi->flags = cpu_to_le32(1);
        gic_msi->spi_count = cpu_to_le16(NUM_GICV2M_SPIS);
        gic_msi->spi_base = cpu_to_le16(irqmap[VIRT_GIC_V2M] + ARM_SPI_BASE);
    }

    build_header(linker, table_data,
                 (void *)(table_data->data + madt_start), "APIC",
                 table_data->len - madt_start, 3, NULL, NULL);
}
clientWindowSeg* createWindowSeg() {

	clientWindowSeg*  currentSegment = (clientWindowSeg*)malloc(sizeof(clientWindowSeg));
	currentSegment->isReceived=0;
	currentSegment->header=build_header(0,0,0,0,0,0);
	memset(currentSegment->data,0,488);
	currentSegment->serverSeqNo=0;
	currentSegment->next=NULL;
	return currentSegment;
}
hdr populateClientBuffer(int previousAckNo,int slidingWindowSize,char *Message,hdr recvHeader, sharedBuf *buffer, int *isDone){

	hdr replyHeader;
	int diff,i,currentWindowSize,currentServerSeqNo,ack;
	currentServerSeqNo = ntohs(recvHeader.seq);
	//printf("\nThe current Server sequence number is %d\n",ntohs(recvHeader.seq));
	pthread_mutex_lock(&buffer->mutex);
	if(buffer->head == NULL) {
		buffer->head  =createWindowSeg();
		buffer->tail = buffer->head ;
		buffer->head ->serverSeqNo = previousAckNo;
	}
	if(buffer->head->serverSeqNo > currentServerSeqNo) {
		currentWindowSize = findWindowSize(slidingWindowSize, buffer);
		replyHeader = build_header(0,buffer->head->serverSeqNo,0,0,currentWindowSize,0);
		pthread_mutex_unlock(&buffer->mutex);
		return replyHeader;
	}
	diff = currentServerSeqNo-buffer->head ->serverSeqNo;
	if(diff > slidingWindowSize) {
		printf("diff and SlidingWindowSizes are %d %d \n",diff, slidingWindowSize);
		printf("Sever is Malfunctioning, sent packets more than the window size \n");
		exit(3);
	}
	currentWindowSize = buffer->tail->serverSeqNo - buffer->head ->serverSeqNo;
	if(diff<currentWindowSize ) {
		fillInTheMiddle(recvHeader, Message, diff, buffer);
	}
	else {
		extendWindow(recvHeader, Message, buffer);
	}

	currentWindowSize = findWindowSize(slidingWindowSize, buffer);
	ack = findACK(slidingWindowSize, buffer);
	replyHeader = build_header(0,ack,0,0,currentWindowSize,0);
	buffer->currentSize = slidingWindowSize-currentWindowSize;
	(*isDone) = isFinSetForLastPacket(buffer);
	printCurrentBuffer(buffer);
	pthread_mutex_unlock(&buffer->mutex);

	return replyHeader;
}
Beispiel #19
0
void handler_page(const ByteString_t & _path_info) {
		ByteString_t name(_path_info.array() + 1, _path_info.length() - 1);
		name.append('\0');
		ByteString_t wiki;

		wiki_storage->get(name.array(), &wiki);

		build_header(_path_info);
		build_wiki(wiki);
		build_footer();
}
static void
build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
{
    AcpiTableHeader *dsdt;

    assert(misc->dsdt_code && misc->dsdt_size);

    dsdt = acpi_data_push(table_data, misc->dsdt_size);
    memcpy(dsdt, misc->dsdt_code, misc->dsdt_size);

    memset(dsdt, 0, sizeof *dsdt);
    build_header(linker, table_data, dsdt, ACPI_DSDT_SIGNATURE,
                 misc->dsdt_size, 1);
}
static void
build_hpet(GArray *table_data, GArray *linker)
{
    Acpi20Hpet *hpet;

    hpet = acpi_data_push(table_data, sizeof(*hpet));
    /* Note timer_block_id value must be kept in sync with value advertised by
     * emulated hpet
     */
    hpet->timer_block_id = cpu_to_le32(0x8086a201);
    hpet->addr.address = cpu_to_le64(HPET_BASE);
    build_header(linker, table_data,
                 (void *)hpet, ACPI_HPET_SIGNATURE, sizeof(*hpet), 1);
}
Beispiel #22
0
static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
		       const struct iphdr *tnl_params,
		       __be16 proto)
{
	struct ip_tunnel *tunnel = netdev_priv(dev);

	if (tunnel->parms.o_flags & TUNNEL_SEQ)
		tunnel->o_seqno++;

	/* Push GRE header. */
	build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
		     proto, tunnel->parms.o_key, htonl(tunnel->o_seqno));

	skb_set_inner_protocol(skb, proto);
	ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
}
Beispiel #23
0
BONFIRE_MAIN()
{
    //uart_puts("Node 2 started.\n")
    int test = 0;

    BONFIRE_LOOP()
    {
        bonfire_send(build_header(0,3));
        test++;
        bonfire_send(test);
        test++;
        bonfire_send(test);
    }

    BONFIRE_RET();
}
Beispiel #24
0
/**
 * Allocate message and store data there
 */
RTPMessage *rtp_new_message ( RTPSession *session, const uint8_t *data, uint32_t length )
{
    if ( !session ) {
        LOGGER_WARNING("No session!");
        return NULL;
    }

    uint8_t *from_pos;
    RTPMessage *retu = calloc(1, sizeof (RTPMessage));

    if ( !retu ) {
        LOGGER_WARNING("Alloc failed! Program might misbehave!");
        return NULL;
    }

    /* Sets header values and copies the extension header in retu */
    retu->header = build_header ( session ); /* It allocates memory and all */
    retu->ext_header = session->ext_header;


    uint32_t total_length = length + retu->header->length + 1;

    retu->data[0] = session->prefix;

    if ( retu->ext_header ) {
        total_length += ( 4 /* Minimum ext header len */ + retu->ext_header->length * size_32 );

        from_pos = add_header ( retu->header, retu->data + 1 );
        from_pos = add_ext_header ( retu->ext_header, from_pos + 1 );
    } else {
        from_pos = add_header ( retu->header, retu->data + 1 );
    }

    /*
     * Parses the extension header into the message
     * Of course if any
     */

    /* Appends data on to retu->data */
    memcpy ( from_pos, data, length );

    retu->length = total_length;

    retu->next = NULL;

    return retu;
}
Beispiel #25
0
int main(int argc, char const *argv[]) {

    unsigned destination = 0;
    unsigned flit_number = 0;
    unsigned flit;
    unsigned packet_counter = 0;

    setup_uart(CPU_SPEED, UART_BAUDRATE);
    uart_puts("UART TEST: If you can read this, then UART output works!\n");

    while(1){
        if ((ni_read_flags() & NI_READ_MASK) == 0)
        {
            flit = ni_read();
        }else if((ni_read_flags() & NI_WRITE_MASK) == 0 && packet_counter < 100)
        {
            flit_number ++;
            if (flit_number == 1){
                ni_write(build_header(destination, 3));
                destination ++;
                if (destination == MY_ADDR){
                    destination ++;
                }
                if (destination == 4){
                    destination = 0;
                }
            }else if (flit_number == 3){
                ni_write(0);
                flit_number = 0;
                packet_counter ++;
            }else{
                ni_write(0b1111111111111111111111111111);
            }
        }
        if (packet_counter >= 100){
            while ((ni_read_flags() & NI_READ_MASK) == 0){
                flit = ni_read();
            }
            uart_puts("finished sending packets!\n");
            break;
        }
    }

    /* Run CPU test */
    test_plasma_funcitons();
    return 0;
}
Beispiel #26
0
static void nvdimm_build_nfit(GSList *device_list, GArray *table_offsets,
                              GArray *table_data, GArray *linker)
{
    GArray *structures = nvdimm_build_device_structure(device_list);
    void *header;

    acpi_add_table(table_offsets, table_data);

    /* NFIT header. */
    header = acpi_data_push(table_data, sizeof(NvdimmNfitHeader));
    /* NVDIMM device structures. */
    g_array_append_vals(table_data, structures->data, structures->len);

    build_header(linker, table_data, header, "NFIT",
                 sizeof(NvdimmNfitHeader) + structures->len, 1, NULL);
    g_array_free(structures, true);
}
Beispiel #27
0
static void
build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
{
    AcpiTableMcfg *mcfg;
    const MemMapEntry *memmap = guest_info->memmap;
    int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);

    mcfg = acpi_data_push(table_data, len);
    mcfg->allocation[0].address = cpu_to_le64(memmap[VIRT_PCIE_ECAM].base);

    /* Only a single allocation so no need to play with segments */
    mcfg->allocation[0].pci_segment = cpu_to_le16(0);
    mcfg->allocation[0].start_bus_number = 0;
    mcfg->allocation[0].end_bus_number = (memmap[VIRT_PCIE_ECAM].size
                                          / PCIE_MMCFG_SIZE_MIN) - 1;

    build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
}
Beispiel #28
0
static void nvdimm_build_nfit(AcpiNVDIMMState *state, GArray *table_offsets,
                              GArray *table_data, BIOSLinker *linker)
{
    NvdimmFitBuffer *fit_buf = &state->fit_buf;
    unsigned int header;

    acpi_add_table(table_offsets, table_data);

    /* NFIT header. */
    header = table_data->len;
    acpi_data_push(table_data, sizeof(NvdimmNfitHeader));
    /* NVDIMM device structures. */
    g_array_append_vals(table_data, fit_buf->fit->data, fit_buf->fit->len);

    build_header(linker, table_data,
                 (void *)(table_data->data + header), "NFIT",
                 sizeof(NvdimmNfitHeader) + fit_buf->fit->len, 1, NULL, NULL);
}
Beispiel #29
0
/* Assumes that the user info is already intialized before calling
 * this function. Returns total packet size. */
unsigned int build_fileop(corefs_packet* packet, unsigned int type, unsigned int offset, unsigned int size, 
	const char* path)
{
	unsigned int pathlen;

  build_header(packet,COREFS_REQUEST);
  packet->payload.request.type = COREFS_REQUEST_FILEOP;
  packet->payload.request.op.fileop.type = type;
	packet->payload.request.op.fileop.offset=offset;
	packet->payload.request.op.fileop.size=size;
	pathlen=strlen(path);
	packet->payload.request.op.fileop.pathlen = pathlen;
	strcpy((char*)packet->payload.request.op.fileop.path, path);

  packet->header.payload_size = REQUEST_BASE_SIZE(packet->payload.request) + SIZEOF_FILEOP_NOPATH(packet->payload.request.op.fileop) + pathlen;
    
	return 	packet->header.payload_size +  SIZEOF_HEADER(packet->header);
  
}
Beispiel #30
0
static void
build_srat(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info)
{
    AcpiSystemResourceAffinityTable *srat;
    AcpiSratProcessorGiccAffinity *core;
    AcpiSratMemoryAffinity *numamem;
    int i, j, srat_start;
    uint64_t mem_base;
    uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof(uint32_t));

    for (i = 0; i < guest_info->smp_cpus; i++) {
        j = numa_get_node_for_cpu(i);
        if (j < nb_numa_nodes) {
                cpu_node[i] = j;
        }
    }

    srat_start = table_data->len;
    srat = acpi_data_push(table_data, sizeof(*srat));
    srat->reserved1 = cpu_to_le32(1);

    for (i = 0; i < guest_info->smp_cpus; ++i) {
        core = acpi_data_push(table_data, sizeof(*core));
        core->type = ACPI_SRAT_PROCESSOR_GICC;
        core->length = sizeof(*core);
        core->proximity = cpu_to_le32(cpu_node[i]);
        core->acpi_processor_uid = cpu_to_le32(i);
        core->flags = cpu_to_le32(1);
    }
    g_free(cpu_node);

    mem_base = guest_info->memmap[VIRT_MEM].base;
    for (i = 0; i < nb_numa_nodes; ++i) {
        numamem = acpi_data_push(table_data, sizeof(*numamem));
        build_srat_memory(numamem, mem_base, numa_info[i].node_mem, i,
                          MEM_AFFINITY_ENABLED);
        mem_base += numa_info[i].node_mem;
    }

    build_header(linker, table_data, (void *)srat, "SRAT",
                 table_data->len - srat_start, 3, NULL, NULL);
}