bool cResponsePacket::initStream(uint32_t opCode, uint32_t streamID, uint32_t duration, int64_t pts, int64_t dts) { initBuffers(); uint32_t ul; uint64_t ull; ul = htonl(VNSI_CHANNEL_STREAM); // stream channel memcpy(&buffer[0], &ul, sizeof(uint32_t)); ul = htonl(opCode); // Stream packet operation code memcpy(&buffer[4], &ul, sizeof(uint32_t)); ul = htonl(streamID); // Stream ID memcpy(&buffer[8], &ul, sizeof(uint32_t)); ul = htonl(duration); // Duration memcpy(&buffer[12], &ul, sizeof(uint32_t)); ull = __cpu_to_be64(pts); // PTS memcpy(&buffer[16], &ull, sizeof(uint64_t)); ull = __cpu_to_be64(dts); // DTS memcpy(&buffer[24], &ull, sizeof(uint64_t)); ul = 0; memcpy(&buffer[userDataLenPosStream], &ul, sizeof(uint32_t)); bufUsed = headerLengthStream; return true; }
int blkin_pack_trace_info(const struct blkin_trace_info *info, struct blkin_trace_info_packed *pinfo) { if (!info || !pinfo) { return -EINVAL; } pinfo->trace_id = __cpu_to_be64(info->trace_id); pinfo->span_id = __cpu_to_be64(info->span_id); pinfo->parent_span_id = __cpu_to_be64(info->parent_span_id); return 0; }
bool cResponsePacket::add_U64(uint64_t ull) { if (!checkExtend(sizeof(uint64_t))) return false; uint64_t tmp = __cpu_to_be64(ull); memcpy(&buffer[bufUsed], &tmp, sizeof(uint64_t)); bufUsed += sizeof(uint64_t); return true; }
bool cResponsePacket::add_double(double d) { if (!checkExtend(sizeof(double))) return false; uint64_t ull; memcpy(&ull, &d, sizeof(double)); ull = __cpu_to_be64(ull); memcpy(&buffer[bufUsed], &ull, sizeof(uint64_t)); bufUsed += sizeof(uint64_t); return true; }
int spc_report_luns(int host_no, struct scsi_cmd *cmd) { struct tgt_device *dev; struct list_head *dev_list = &cmd->c_target->device_list; uint64_t lun, *data; int idx, alen, oalen, nr_luns, rbuflen = 4096, overflow; unsigned char key = ILLEGAL_REQUEST, asc = 0x24; alen = __be32_to_cpu(*(uint32_t *)&cmd->scb[6]); if (alen < 16) goto sense; data = valloc(pagesize); if (!data) { key = HARDWARE_ERROR; asc = 0; goto sense; } memset(data, 0, pagesize); alen &= ~(8 - 1); oalen = alen; alen -= 8; rbuflen -= 8; /* FIXME */ idx = 1; nr_luns = 0; overflow = 0; list_for_each_entry(dev, dev_list, device_siblings) { nr_luns++; if (overflow) continue; lun = dev->lun; lun = ((lun > 0xff) ? (0x1 << 30) : 0) | ((0x3ff & lun) << 16); data[idx++] = __cpu_to_be64(lun << 32); if (!(alen -= 8)) overflow = 1; if (!(rbuflen -= 8)) { fprintf(stderr, "FIXME: too many luns\n"); exit(-1); } }
static void handle_card(struct sstate *ss) { unsigned char buf[2048]; int rd; struct rx_info *ri = (struct rx_info*) buf; struct client *c; rd = card_read(ss, ri + 1, sizeof(buf) - sizeof(*ri), ri); if (rd >= 0) rd += sizeof(*ri); #ifdef __MACH__ ri->ri_mactime = OSSwapHostToBigInt64(ri->ri_mactime); ri->ri_power = OSSwapHostToBigInt32(ri->ri_power); ri->ri_noise = OSSwapHostToBigInt32(ri->ri_noise); ri->ri_channel = OSSwapHostToBigInt32(ri->ri_channel); ri->ri_rate = OSSwapHostToBigInt32(ri->ri_rate); ri->ri_antenna = OSSwapHostToBigInt32(ri->ri_antenna); #elif defined(__FreeBSD__) #if BYTE_ORDER == BIG_ENDIAN # define __be32_to_cpu(x) (x) # define __be64_to_cpu(x) (x) #elif BYTE_ORDER == LITTLE_ENDIAN # define __be32_to_cpu(x) __bswap32(x) # define __be64_to_cpu(x) __bswap64(x) #endif #else ri->ri_mactime = __cpu_to_be64(ri->ri_mactime); ri->ri_power = __cpu_to_be32(ri->ri_power); ri->ri_noise = __cpu_to_be32(ri->ri_noise); ri->ri_channel = __cpu_to_be32(ri->ri_channel); ri->ri_rate = __cpu_to_be32(ri->ri_rate); ri->ri_antenna = __cpu_to_be32(ri->ri_antenna); #endif /* __MACH__ */ c = ss->ss_clients.c_next; while (c != &ss->ss_clients) { client_send_packet(ss, c, buf, rd); c = c->c_next; } }
int as_particle_get_int(as_particle *p, void *data, uint32_t *sz) { // attempt to get size if (!data) { *sz = 8; return(0); } if (*sz < 8) { *sz = 8; return(-1); } as_particle_int *pi = (as_particle_int *)p; *(uint64_t *) data = __cpu_to_be64(pi->i); cf_detail(AS_PARTICLE, "READING value %"PRIx64"", pi->i); *sz = 8; return(0); }
static int ibmvio_report_luns(int host_no, struct scsi_cmd *cmd) { struct scsi_lu *lu; struct list_head *dev_list = &cmd->c_target->device_list; uint64_t lun, *data; int idx, alen, oalen, nr_luns, rbuflen = 4096; uint8_t *lun_buf = cmd->lun; unsigned char key = ILLEGAL_REQUEST; uint16_t asc = ASC_INVALID_FIELD_IN_CDB; alen = __be32_to_cpu(*(uint32_t *)&cmd->scb[6]); if (alen < 16) goto sense; data = scsi_get_in_buffer(cmd); alen &= ~(8 - 1); oalen = alen; if ((*((uint64_t *) lun_buf))) { nr_luns = 1; goto done; } alen -= 8; rbuflen -= 8; /* FIXME */ idx = 2; nr_luns = 1; list_for_each_entry(lu, dev_list, device_siblings) { lun = lu->lun; lun = make_lun(0, lun & 0x003f, 0); data[idx++] = __cpu_to_be64(lun); if (!(alen -= 8)) break; if (!(rbuflen -= 8)) { fprintf(stderr, "FIXME: too many luns\n"); exit(-1); } nr_luns++; }
static int nx_sha512_init(struct shash_desc *desc) { struct sha512_state *sctx = shash_desc_ctx(desc); struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); int len; int rc; nx_ctx_init(nx_ctx, HCOP_FC_SHA); memset(sctx, 0, sizeof *sctx); nx_ctx->ap = &nx_ctx->props[NX_PROPS_SHA512]; NX_CPB_SET_DIGEST_SIZE(nx_ctx->csbcpb, NX_DS_SHA512); len = SHA512_DIGEST_SIZE; rc = nx_sha_build_sg_list(nx_ctx, nx_ctx->out_sg, &nx_ctx->op.outlen, &len, (u8 *)sctx->state, NX_DS_SHA512); if (rc || len != SHA512_DIGEST_SIZE) goto out; sctx->state[0] = __cpu_to_be64(SHA512_H0); sctx->state[1] = __cpu_to_be64(SHA512_H1); sctx->state[2] = __cpu_to_be64(SHA512_H2); sctx->state[3] = __cpu_to_be64(SHA512_H3); sctx->state[4] = __cpu_to_be64(SHA512_H4); sctx->state[5] = __cpu_to_be64(SHA512_H5); sctx->state[6] = __cpu_to_be64(SHA512_H6); sctx->state[7] = __cpu_to_be64(SHA512_H7); sctx->count[0] = 0; out: return 0; }
static int __report_luns(struct list_head *dev_list, uint8_t *lun_buf, uint8_t *scb, uint8_t *p, int *len) { struct tgt_device *dev; uint64_t lun, *data = (uint64_t *) p; int idx, alen, oalen, nr_luns, rbuflen = 4096; int result = SAM_STAT_GOOD; memset(data, 0, rbuflen); alen = __be32_to_cpu(*(uint32_t *)&scb[6]); if (alen < 16) { *len = sense_data_build(p, 0x70, ILLEGAL_REQUEST, 0x24, 0); return SAM_STAT_CHECK_CONDITION; } alen &= ~(8 - 1); oalen = alen; alen -= 8; rbuflen -= 8; /* FIXME */ idx = 1; nr_luns = 0; list_for_each_entry(dev, dev_list, d_list) { lun = dev->lun; lun = ((lun > 0xff) ? (0x1 << 30) : 0) | ((0x3ff & lun) << 16); data[idx++] = __cpu_to_be64(lun << 32); if (!(alen -= 8)) break; if (!(rbuflen -= 8)) { fprintf(stderr, "FIXME: too many luns\n"); exit(-1); } nr_luns++; }
static int pohmelfs_trans_iter(struct netfs_trans *t, struct pohmelfs_crypto_engine *e, int (*iterator) (struct pohmelfs_crypto_engine *e, struct scatterlist *dst, struct scatterlist *src)) { void *data = t->iovec.iov_base + sizeof(struct netfs_cmd) + t->psb->crypto_attached_size; unsigned int size = t->iovec.iov_len - sizeof(struct netfs_cmd) - t->psb->crypto_attached_size; struct netfs_cmd *cmd = data; unsigned int sz, pages = t->attached_pages, i, csize, cmd_cmd, dpage_idx; struct scatterlist sg_src, sg_dst; int err; while (size) { cmd = data; cmd_cmd = __be16_to_cpu(cmd->cmd); csize = __be32_to_cpu(cmd->size); cmd->iv = __cpu_to_be64(e->iv); if (cmd_cmd == NETFS_READ_PAGES || cmd_cmd == NETFS_READ_PAGE) csize = __be16_to_cpu(cmd->ext); sz = csize + __be16_to_cpu(cmd->cpad) + sizeof(struct netfs_cmd); dprintk("%s: size: %u, sz: %u, cmd_size: %u, cmd_cpad: %u.\n", __func__, size, sz, __be32_to_cpu(cmd->size), __be16_to_cpu(cmd->cpad)); data += sz; size -= sz; sg_init_one(&sg_src, cmd->data, sz - sizeof(struct netfs_cmd)); sg_init_one(&sg_dst, cmd->data, sz - sizeof(struct netfs_cmd)); err = iterator(e, &sg_dst, &sg_src); if (err) return err; } if (!pages) return 0; dpage_idx = 0; for (i = 0; i < t->page_num; ++i) { struct page *page = t->pages[i]; struct page *dpage = e->pages[dpage_idx]; if (!page) continue; sg_init_table(&sg_src, 1); sg_init_table(&sg_dst, 1); sg_set_page(&sg_src, page, page_private(page), 0); sg_set_page(&sg_dst, dpage, page_private(page), 0); err = iterator(e, &sg_dst, &sg_src); if (err) return err; pages--; if (!pages) break; dpage_idx++; } return 0; }
/* returns 1 if this was a spectral frame, even if not handled. */ int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr, struct ath_rx_status *rs, u64 tsf) { struct ath_hw *ah = sc->sc_ah; u8 num_bins, *bins, *vdata = (u8 *)hdr; struct fft_sample_ht20 fft_sample_20; struct fft_sample_ht20_40 fft_sample_40; struct fft_sample_tlv *tlv; struct ath_radar_info *radar_info; int len = rs->rs_datalen; int dc_pos; u16 fft_len, length, freq = ah->curchan->chan->center_freq; enum nl80211_channel_type chan_type; /* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer * via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT * yet, but this is supposed to be possible as well. */ if (rs->rs_phyerr != ATH9K_PHYERR_RADAR && rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT && rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL) return 0; /* check if spectral scan bit is set. This does not have to be checked * if received through a SPECTRAL phy error, but shouldn't hurt. */ radar_info = ((struct ath_radar_info *)&vdata[len]) - 1; if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK)) return 0; chan_type = cfg80211_get_chandef_type(&sc->hw->conf.chandef); if ((chan_type == NL80211_CHAN_HT40MINUS) || (chan_type == NL80211_CHAN_HT40PLUS)) { fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN; num_bins = SPECTRAL_HT20_40_NUM_BINS; bins = (u8 *)fft_sample_40.data; } else { fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN; num_bins = SPECTRAL_HT20_NUM_BINS; bins = (u8 *)fft_sample_20.data; } /* Variation in the data length is possible and will be fixed later */ if ((len > fft_len + 2) || (len < fft_len - 1)) return 1; switch (len - fft_len) { case 0: /* length correct, nothing to do. */ memcpy(bins, vdata, num_bins); break; case -1: /* first byte missing, duplicate it. */ memcpy(&bins[1], vdata, num_bins - 1); bins[0] = vdata[0]; break; case 2: /* MAC added 2 extra bytes at bin 30 and 32, remove them. */ memcpy(bins, vdata, 30); bins[30] = vdata[31]; memcpy(&bins[31], &vdata[33], num_bins - 31); break; case 1: /* MAC added 2 extra bytes AND first byte is missing. */ bins[0] = vdata[0]; memcpy(&bins[1], vdata, 30); bins[31] = vdata[31]; memcpy(&bins[32], &vdata[33], num_bins - 32); break; default: return 1; } /* DC value (value in the middle) is the blind spot of the spectral * sample and invalid, interpolate it. */ dc_pos = num_bins / 2; bins[dc_pos] = (bins[dc_pos + 1] + bins[dc_pos - 1]) / 2; if ((chan_type == NL80211_CHAN_HT40MINUS) || (chan_type == NL80211_CHAN_HT40PLUS)) { s8 lower_rssi, upper_rssi; s16 ext_nf; u8 lower_max_index, upper_max_index; u8 lower_bitmap_w, upper_bitmap_w; u16 lower_mag, upper_mag; struct ath9k_hw_cal_data *caldata = ah->caldata; struct ath_ht20_40_mag_info *mag_info; if (caldata) ext_nf = ath9k_hw_getchan_noise(ah, ah->curchan, caldata->nfCalHist[3].privNF); else ext_nf = ATH_DEFAULT_NOISE_FLOOR; length = sizeof(fft_sample_40) - sizeof(struct fft_sample_tlv); fft_sample_40.tlv.type = ATH_FFT_SAMPLE_HT20_40; fft_sample_40.tlv.length = __cpu_to_be16(length); fft_sample_40.freq = __cpu_to_be16(freq); fft_sample_40.channel_type = chan_type; if (chan_type == NL80211_CHAN_HT40PLUS) { lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]); fft_sample_40.lower_noise = ah->noise; fft_sample_40.upper_noise = ext_nf; } else { lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]); upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); fft_sample_40.lower_noise = ext_nf; fft_sample_40.upper_noise = ah->noise; } fft_sample_40.lower_rssi = lower_rssi; fft_sample_40.upper_rssi = upper_rssi; mag_info = ((struct ath_ht20_40_mag_info *)radar_info) - 1; lower_mag = spectral_max_magnitude(mag_info->lower_bins); upper_mag = spectral_max_magnitude(mag_info->upper_bins); fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag); fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag); lower_max_index = spectral_max_index(mag_info->lower_bins); upper_max_index = spectral_max_index(mag_info->upper_bins); fft_sample_40.lower_max_index = lower_max_index; fft_sample_40.upper_max_index = upper_max_index; lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins); upper_bitmap_w = spectral_bitmap_weight(mag_info->upper_bins); fft_sample_40.lower_bitmap_weight = lower_bitmap_w; fft_sample_40.upper_bitmap_weight = upper_bitmap_w; fft_sample_40.max_exp = mag_info->max_exp & 0xf; fft_sample_40.tsf = __cpu_to_be64(tsf); tlv = (struct fft_sample_tlv *)&fft_sample_40; } else { u8 max_index, bitmap_w; u16 magnitude; struct ath_ht20_mag_info *mag_info; length = sizeof(fft_sample_20) - sizeof(struct fft_sample_tlv); fft_sample_20.tlv.type = ATH_FFT_SAMPLE_HT20; fft_sample_20.tlv.length = __cpu_to_be16(length); fft_sample_20.freq = __cpu_to_be16(freq); fft_sample_20.rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); fft_sample_20.noise = ah->noise; mag_info = ((struct ath_ht20_mag_info *)radar_info) - 1; magnitude = spectral_max_magnitude(mag_info->all_bins); fft_sample_20.max_magnitude = __cpu_to_be16(magnitude); max_index = spectral_max_index(mag_info->all_bins); fft_sample_20.max_index = max_index; bitmap_w = spectral_bitmap_weight(mag_info->all_bins); fft_sample_20.bitmap_weight = bitmap_w; fft_sample_20.max_exp = mag_info->max_exp & 0xf; fft_sample_20.tsf = __cpu_to_be64(tsf); tlv = (struct fft_sample_tlv *)&fft_sample_20; } ath_debug_send_fft_sample(sc, tlv); return 1; }
uint8_t * as_msg_write_fields(uint8_t *buf, const char *ns, int ns_len, const char *set, int set_len, const cf_digest *d, cf_digest *d_ret, uint64_t trid, as_msg_field *scan_param_field, void * c) { udf_call * call = (udf_call*) c; // printf("write_fields\n"); // lay out the fields as_msg_field *mf = (as_msg_field *) buf; as_msg_field *mf_tmp = mf; if (ns) { mf->type = AS_MSG_FIELD_TYPE_NAMESPACE; mf->field_sz = ns_len + 1; // printf("write_fields: ns: write_fields: %d\n", mf->field_sz); memcpy(mf->data, ns, ns_len); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; } if (set) { mf->type = AS_MSG_FIELD_TYPE_SET; mf->field_sz = set_len + 1; //printf("write_fields: set: write_fields: %d\n", mf->field_sz); memcpy(mf->data, set, set_len); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; } if (trid) { mf->type = AS_MSG_FIELD_TYPE_TRID; //Convert the transaction-id to network byte order (big-endian) uint64_t trid_nbo = __cpu_to_be64(trid); //swaps in place mf->field_sz = sizeof(trid_nbo) + 1; //printf("write_fields: trid: write_fields: %d\n", mf->field_sz); memcpy(mf->data, &trid_nbo, sizeof(trid_nbo)); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; } if (scan_param_field) { mf->type = AS_MSG_FIELD_TYPE_SCAN_OPTIONS; mf->field_sz = sizeof(as_msg_field) + 1; //printf("write_fields: scan: write_fields: %d\n", mf->field_sz); memcpy(mf->data, scan_param_field, sizeof(as_msg_field)); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; } /** * UDF */ if ( call ) { int len = 0; // Append filename to message fields len = strlen(call->filename) * sizeof(char); mf->type = AS_MSG_FIELD_TYPE_UDF_FILENAME; mf->field_sz = len + 1; memcpy(mf->data, call->filename, len); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; // Append function name to message fields len = strlen(call->function) * sizeof(char); mf->type = AS_MSG_FIELD_TYPE_UDF_FUNCTION; mf->field_sz = len + 1; memcpy(mf->data, call->function, len); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; // Append arglist to message fields if (call->arglist) { len = call->arglist->field_sz * sizeof(char); mf->type = AS_MSG_FIELD_TYPE_UDF_ARGLIST; mf->field_sz = len + 1; memcpy(mf->data, call->arglist->data, len); mf_tmp = as_msg_field_get_next(mf); mf = mf_tmp; } } if (d) { mf->type = AS_MSG_FIELD_TYPE_DIGEST_RIPE; mf->field_sz = sizeof(cf_digest) + 1; memcpy(mf->data, d, sizeof(cf_digest)); mf_tmp = as_msg_field_get_next(mf); if (d_ret) memcpy(d_ret, d, sizeof(cf_digest)); mf = mf_tmp; } return ( (uint8_t *) mf_tmp ); }
cl_msg * as_msg_make_response_msg( uint32_t result_code, uint32_t generation, uint32_t void_time, as_msg_op **ops, as_bin **bins, uint16_t bin_count, as_namespace *ns, cl_msg *msgp_in, size_t *msg_sz_in, uint64_t trid, const char *setname) { int setname_len = 0; // figure out the size of the entire buffer int msg_sz = sizeof(cl_msg); msg_sz += sizeof(as_msg_op) * bin_count; // the bin headers for (uint16_t i = 0; i < bin_count; i++) { if (bins[i]) { msg_sz += ns->single_bin ? 0 : strlen(as_bin_get_name_from_id(ns, bins[i]->id)); uint32_t psz; if (as_bin_is_hidden(bins[i])) { psz = 0; } else { bool tojson = (as_bin_get_particle_type(bins[i]) == AS_PARTICLE_TYPE_LUA_BLOB); _as_particle_tobuf(bins[i], 0, &psz, tojson); // get size } msg_sz += psz; } else if (ops[i]) // no bin, only op, no particle size msg_sz += ops[i]->name_sz; else cf_warning(AS_PROTO, "internal error!"); } //If a transaction-id is sent by the client, we should send it back in a field if (trid != 0) { msg_sz += (sizeof(as_msg_field) + sizeof(trid)); } // If setname is present, we will send it as a field. Account for its space overhead. if (setname != 0) { setname_len = strlen(setname); msg_sz += (sizeof(as_msg_field) + setname_len); } // most cases are small messages - try to stack alloc if we can byte *b; if ((0 == msgp_in) || (*msg_sz_in < msg_sz)) { b = cf_malloc(msg_sz); if (!b) return(0); } else { b = (byte *) msgp_in; } *msg_sz_in = msg_sz; // set up the header byte *buf = b; // current buffer pointer cl_msg *msgp = (cl_msg *) buf; msgp->proto.version = PROTO_VERSION; msgp->proto.type = PROTO_TYPE_AS_MSG; msgp->proto.sz = msg_sz - sizeof(as_proto); as_proto_swap(&msgp->proto); as_msg *m = &msgp->msg; m->header_sz = sizeof(as_msg); m->info1 = 0; m->info2 = 0; m->info3 = 0; m->unused = 0; m->result_code = result_code; m->generation = generation; m->record_ttl = void_time; m->transaction_ttl = 0; m->n_ops = bin_count; m->n_fields = 0; // Count the number of fields that we are going to send back if (trid != 0) { m->n_fields++; } if (setname != NULL) { m->n_fields++; } as_msg_swap_header(m); buf += sizeof(cl_msg); //If we have to send back the transaction-id, we have fields to send back if (trid != 0) { as_msg_field *trfield = (as_msg_field *) buf; //Allow space for the message field header buf += sizeof(as_msg_field); //Fill the field header trfield->type = AS_MSG_FIELD_TYPE_TRID; //Copy the transaction-id as field data in network byte order (big-endian) uint64_t trid_nbo = __cpu_to_be64(trid); trfield->field_sz = sizeof(trid_nbo); memcpy(trfield->data, &trid_nbo, sizeof(trid_nbo)); as_msg_swap_field(trfield); //Allow space for the message field data buf += sizeof(trid_nbo); } // If we have to send back the setname, we have fields to send back if (setname != NULL) { as_msg_field *trfield = (as_msg_field *) buf; // Allow space for the message field header buf += sizeof(as_msg_field); // Fill the field header trfield->type = AS_MSG_FIELD_TYPE_SET; trfield->field_sz = setname_len + 1; memcpy(trfield->data, setname, setname_len); as_msg_swap_field(trfield); // Allow space for the message field data buf += setname_len; } // over all bins, copy into the buffer for (uint16_t i = 0; i < bin_count; i++) { as_msg_op *op = (as_msg_op *)buf; buf += sizeof(as_msg_op); op->op = AS_MSG_OP_READ; if (bins[i]) { op->version = as_bin_get_version(bins[i], ns->single_bin); op->name_sz = as_bin_memcpy_name(ns, op->name, bins[i]); } else { op->version = 0; memcpy(op->name, ops[i]->name, ops[i]->name_sz); op->name_sz = ops[i]->name_sz; } buf += op->name_sz; // cf_detail(AS_PROTO, "make response: bin %d %s : version %d",i,bins[i]->name,op->version); // Since there are two variable bits, the size is everything after the // data bytes - and this is only the head, we're patching up the rest // in a minute. op->op_sz = 4 + op->name_sz; if (bins[i] && as_bin_inuse(bins[i])) { op->particle_type = as_particle_type_convert(as_bin_get_particle_type(bins[i])); uint32_t psz = msg_sz - (buf - b); // size remaining in buffer, for safety if (as_bin_is_hidden(bins[i])) { op->particle_type = AS_PARTICLE_TYPE_NULL; psz = 0; // packet of size NULL } else { bool tojson = (as_bin_get_particle_type(bins[i]) == AS_PARTICLE_TYPE_LUA_BLOB); if (0 != _as_particle_tobuf(bins[i], buf, &psz, tojson)) { cf_warning(AS_PROTO, "particle to buf: could not copy data!"); } } buf += psz; op->op_sz += psz; } else { op->particle_type = AS_PARTICLE_TYPE_NULL; } as_msg_swap_op(op); } return((cl_msg *) b); }
void ft_board_setup_ex(void *blob, bd_t *bd) { int lpae; u64 size; char *env; u64 *reserve_start; int unitrd_fixup = 0; env = env_get("mem_lpae"); lpae = env && simple_strtol(env, NULL, 0); env = env_get("uinitrd_fixup"); unitrd_fixup = env && simple_strtol(env, NULL, 0); /* Fix up the initrd */ if (lpae && unitrd_fixup) { int nodeoffset; int err; u64 *prop1, *prop2; u64 initrd_start, initrd_end; nodeoffset = fdt_path_offset(blob, "/chosen"); if (nodeoffset >= 0) { prop1 = (u64 *)fdt_getprop(blob, nodeoffset, "linux,initrd-start", NULL); prop2 = (u64 *)fdt_getprop(blob, nodeoffset, "linux,initrd-end", NULL); if (prop1 && prop2) { initrd_start = __be64_to_cpu(*prop1); initrd_start -= CONFIG_SYS_SDRAM_BASE; initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE; initrd_start = __cpu_to_be64(initrd_start); initrd_end = __be64_to_cpu(*prop2); initrd_end -= CONFIG_SYS_SDRAM_BASE; initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE; initrd_end = __cpu_to_be64(initrd_end); err = fdt_delprop(blob, nodeoffset, "linux,initrd-start"); if (err < 0) puts("error deleting initrd-start\n"); err = fdt_delprop(blob, nodeoffset, "linux,initrd-end"); if (err < 0) puts("error deleting initrd-end\n"); err = fdt_setprop(blob, nodeoffset, "linux,initrd-start", &initrd_start, sizeof(initrd_start)); if (err < 0) puts("error adding initrd-start\n"); err = fdt_setprop(blob, nodeoffset, "linux,initrd-end", &initrd_end, sizeof(initrd_end)); if (err < 0) puts("error adding linux,initrd-end\n"); } } } if (lpae) { /* * the initrd and other reserved memory areas are * embedded in in the DTB itslef. fix up these addresses * to 36 bit format */ reserve_start = (u64 *)((char *)blob + fdt_off_mem_rsvmap(blob)); while (1) { *reserve_start = __cpu_to_be64(*reserve_start); size = __cpu_to_be64(*(reserve_start + 1)); if (size) { *reserve_start -= CONFIG_SYS_SDRAM_BASE; *reserve_start += CONFIG_SYS_LPAE_SDRAM_BASE; *reserve_start = __cpu_to_be64(*reserve_start); } else { break; } reserve_start += 2; } } ddr3_check_ecc_int(KS2_DDR3A_EMIF_CTRL_BASE); }