Hypervisor Display架构

Hypervisor Display架构部分

1,所有LA侧的APP与显示相关的调用最终都会交由SurfaceFlinger处理

2,SurfaceFlinger会最终调用android.hardware.graphics.composer@2.4-service服务

3,android.hardware.graphics.composer@2.4-service服务会调用GPU&DRM&Qcom的一些列库文件(很遗憾这些库相当一大部分源码是不开源的)

4,libdrm库调用open/ioctl等函数会经过lib_drm_fe库的转接,当然lib_drm_fe会做很多其他适配的工作

5,lib_drm_fe会调用内核HGSL驱动中的hab通信接口与QNX侧的wfd_be服务进行通信

6,wfd_be服务会解析接收到的LA侧的数据包

7,根据数据包中的命令类型调用不同的openwfd接口,需要注意的是,这里的接口是做了一层转换的,举个例子wfdEnumerateDevices_Host,这个接口会进行转换之后真正调用wfdEnumerateDevices函数

8,所有的操作都执行完成之后,如果有必要会唤醒wfd_be的commit&vsync现场,通知openwfd刷新画面

lib_drm_fe会调用内核HGSL驱动中的hab通信接口与QNX侧的wfd_be服务进行通信

 sa8295 dtsi配置

direwolf-vm.dtsi
msm_gpu_hyp: qcom,hgsl@0x3d00000 {compatible = "qcom,hgsl";reg = <0x3d00000 0x8>, <0x3d8f000 0x4>;reg-names = "hgsl_reg_hwinf", "hgsl_reg_gmucx";qcom,glb-db-senders = <&hgsl_tcsr_sender0&hgsl_tcsr_sender1>;qcom,glb-db-receivers = <&hgsl_tcsr_receiver0&hgsl_tcsr_receiver1>;};

kernel/msm-5.4/drivers/soc/qcom/hgsl/hgsl 设备树匹配

static const struct of_device_id qcom_hgsl_of_match[] = {{ .compatible = "qcom,hgsl" },{}
};
MODULE_DEVICE_TABLE(of, qcom_hgsl_of_match);static struct platform_driver qcom_hgsl_driver = {.probe = qcom_hgsl_probe,.remove = qcom_hgsl_remove,.driver  = {.name  = "qcom-hgsl",.of_match_table = qcom_hgsl_of_match,},
};
module_platform_driver(qcom_hgsl_driver);

lagvm/LINUX/android/kernel/msm-5.4/drivers/soc/qcom/hgsl/hgsl.c

static int qcom_hgsl_probe(struct platform_device *pdev)
{struct qcom_hgsl *hgsl_dev;int ret;int i;hgsl_dev = devm_kzalloc(&pdev->dev, sizeof(*hgsl_dev), GFP_KERNEL);if (!hgsl_dev)return -ENOMEM;hgsl_dev->dev = &pdev->dev;ret = qcom_hgsl_register(pdev, hgsl_dev);if (ret < 0) {dev_err(&pdev->dev, "qcom_hgsl_register failed, ret %d\n",ret);return ret;}ret = hgsl_init_context(hgsl_dev);if (ret < 0) {dev_err(&pdev->dev, "hgsl_init_context failed, ret %d\n",ret);goto exit_dereg;}//创建hgsl-release-wq workqueueret = hgsl_init_release_wq(hgsl_dev);if (ret < 0) {dev_err(&pdev->dev, "hgsl_init_release_wq failed, ret %d\n",ret);goto exit_dereg;}hgsl_dev->db_off = hgsl_is_db_off(pdev);idr_init(&hgsl_dev->isync_timeline_idr);spin_lock_init(&hgsl_dev->isync_timeline_lock);for (i = 0; i < MAX_DB_QUEUE; i++) {mutex_init(&hgsl_dev->dbq[i].lock);hgsl_dev->dbq[i].state = DB_STATE_Q_UNINIT;}if (!hgsl_dev->db_off)hgsl_init_global_hyp_channel(hgsl_dev);platform_set_drvdata(pdev, hgsl_dev);return 0;exit_dereg:qcom_hgsl_deregister(pdev);return ret;
}

 

static int qcom_hgsl_register(struct platform_device *pdev,struct qcom_hgsl *hgsl_dev)
{int ret;ret = alloc_chrdev_region(&hgsl_dev->device_no, 0,HGSL_DEV_NUM,HGSL_DEVICE_NAME);if (ret < 0) {dev_err(&pdev->dev, "alloc_chrdev_region failed %d\n", ret);return ret;}//创建一个hgsl class节点hgsl_dev->driver_class = class_create(THIS_MODULE, HGSL_DEVICE_NAME);if (IS_ERR(hgsl_dev->driver_class)) {ret = -ENOMEM;dev_err(&pdev->dev, "class_create failed %d\n", ret);goto exit_unreg_chrdev_region;}//创建一个hgsl 设备hgsl_dev->class_dev = device_create(hgsl_dev->driver_class,NULL,hgsl_dev->device_no,hgsl_dev, HGSL_DEVICE_NAME);if (IS_ERR(hgsl_dev->class_dev)) {dev_err(&pdev->dev, "class_device_create failed %d\n", ret);ret = -ENOMEM;goto exit_destroy_class;}//注册hgsl 设备操作接口cdev_init(&hgsl_dev->cdev, &hgsl_fops);hgsl_dev->cdev.owner = THIS_MODULE;//注册hgsl设备ret = cdev_add(&hgsl_dev->cdev,MKDEV(MAJOR(hgsl_dev->device_no), 0),1);if (ret < 0) {dev_err(&pdev->dev, "cdev_add failed %d\n", ret);goto exit_destroy_device;}ret = dma_coerce_mask_and_coherent(hgsl_dev->dev, DMA_BIT_MASK(64));if (ret)LOGW("Failed to set dma mask to 64 bits, ret = %d", ret);return 0;exit_destroy_device:device_destroy(hgsl_dev->driver_class, hgsl_dev->device_no);
exit_destroy_class:class_destroy(hgsl_dev->driver_class);
exit_unreg_chrdev_region:unregister_chrdev_region(hgsl_dev->device_no, 1);return ret;
}

 

设备注册的操作接口hgsl_fops

static const struct file_operations hgsl_fops = {.owner = THIS_MODULE,.open = hgsl_open,.release = hgsl_release,.read = hgsl_read,.unlocked_ioctl = hgsl_ioctl,.compat_ioctl = hgsl_compat_ioctl
};

 

static int hgsl_open(struct inode *inodep, struct file *filep)
{struct hgsl_priv *priv = hgsl_zalloc(sizeof(*priv));struct qcom_hgsl  *hgsl = container_of(inodep->i_cdev,struct qcom_hgsl, cdev);//获取当前进程的pid 和task_structstruct pid *pid = task_tgid(current);struct task_struct *task = pid_task(pid, PIDTYPE_PID);int ret = 0;if (!priv)return -ENOMEM;if (!task) {ret = -EINVAL;goto out;}INIT_LIST_HEAD(&priv->mem_mapped);INIT_LIST_HEAD(&priv->mem_allocated);mutex_init(&priv->lock);priv->pid = task_pid_nr(task);ret = hgsl_hyp_init(&priv->hyp_priv, hgsl->dev,priv->pid, task->comm);if (ret != 0)goto out;priv->dev = hgsl;filep->private_data = priv;out:if (ret != 0)kfree(priv);return ret;
}

 

int hgsl_hyp_init(struct hgsl_hyp_priv_t *priv, struct device *dev,int client_pid, const char * const client_name)
{priv->dev = dev;return hgsl_hyp_channel_pool_init(priv, client_pid, client_name);
}
//将task_struct 信息与hgsl_hyp_priv_t 绑定
static int hgsl_hyp_channel_pool_init(struct hgsl_hyp_priv_t *priv,int client_pid, const char * const client_name)
{INIT_LIST_HEAD(&priv->free_channels);INIT_LIST_HEAD(&priv->busy_channels);mutex_init(&priv->lock);priv->conn_id = 0;strlcpy(priv->client_name, client_name, sizeof(priv->client_name));priv->client_pid = client_pid;idr_init(&priv->channel_idr);LOGD("pid %d, task name %s", (int) priv->client_pid, priv->client_name);return 0;
}

Libgsl 会使与驱动hgsl交互

static long hgsl_compat_ioctl(struct file *filep, unsigned int cmd,unsigned long arg)
{return hgsl_ioctl(filep, cmd, arg);
}

static long hgsl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{int ret;switch (cmd) {case HGSL_IOCTL_ISSUE_IB:ret = hgsl_ioctl_issueib(filep, arg);break;case HGSL_IOCTL_CTXT_CREATE:ret = hgsl_ioctl_ctxt_create(filep, arg);break;case HGSL_IOCTL_CTXT_DESTROY:ret = hgsl_ioctl_ctxt_destroy(filep, arg);break;case HGSL_IOCTL_WAIT_TIMESTAMP:ret = hgsl_ioctl_wait_timestamp(filep, arg);break;case HGSL_IOCTL_READ_TIMESTAMP:ret = hgsl_ioctl_read_timestamp(filep, arg);break;case HGSL_IOCTL_CHECK_TIMESTAMP:ret = hgsl_ioctl_check_timestamp(filep, arg);break;case HGSL_IOCTL_HYP_GENERIC_TRANSACTION:ret = hgsl_ioctl_hyp_generic_transaction(filep, arg);break;case HGSL_IOCTL_GET_SHADOWTS_MEM:ret = hgsl_ioctl_get_shadowts_mem(filep, arg);break;case HGSL_IOCTL_PUT_SHADOWTS_MEM:ret = hgsl_ioctl_put_shadowts_mem(filep, arg);break;case HGSL_IOCTL_MEM_ALLOC:ret = hgsl_ioctl_mem_alloc(filep, arg);break;case HGSL_IOCTL_MEM_FREE:ret = hgsl_ioctl_mem_free(filep, arg);break;case HGSL_IOCTL_MEM_MAP_SMMU:ret = hgsl_ioctl_mem_map_smmu(filep, arg);break;case HGSL_IOCTL_MEM_UNMAP_SMMU:ret = hgsl_ioctl_mem_unmap_smmu(filep, arg);break;case HGSL_IOCTL_MEM_CACHE_OPERATION:ret = hgsl_ioctl_mem_cache_operation(filep, arg);break;case HGSL_IOCTL_ISSUIB_WITH_ALLOC_LIST:ret = hgsl_ioctl_issueib_with_alloc_list(filep, arg);break;case HGSL_IOCTL_GET_SYSTEM_TIME:ret = hgsl_ioctl_get_system_time(filep, arg);break;case HGSL_IOCTL_SYNCOBJ_WAIT_MULTIPLE:ret = hgsl_ioctl_syncobj_wait_multiple(filep, arg);break;case HGSL_IOCTL_PERFCOUNTER_SELECT:ret = hgsl_ioctl_perfcounter_select(filep, arg);break;case HGSL_IOCTL_PERFCOUNTER_DESELECT:ret = hgsl_ioctl_perfcounter_deselect(filep, arg);break;case HGSL_IOCTL_PERFCOUNTER_QUERY_SELECTION:ret = hgsl_ioctl_perfcounter_query_selection(filep, arg);break;case HGSL_IOCTL_PERFCOUNTER_READ:ret = hgsl_ioctl_perfcounter_read(filep, arg);break;case HGSL_IOCTL_SET_METAINFO:ret = hgsl_ioctl_set_metainfo(filep, arg);break;case HGSL_IOCTL_HSYNC_FENCE_CREATE:ret = hgsl_ioctl_hsync_fence_create(filep, arg);break;case HGSL_IOCTL_ISYNC_TIMELINE_CREATE:ret = hgsl_ioctl_isync_timeline_create(filep, arg);break;case HGSL_IOCTL_ISYNC_TIMELINE_DESTROY:ret = hgsl_ioctl_isync_timeline_destroy(filep, arg);break;case HGSL_IOCTL_ISYNC_FENCE_CREATE:ret = hgsl_ioctl_isync_fence_create(filep, arg);break;case HGSL_IOCTL_ISYNC_FENCE_SIGNAL:ret = hgsl_ioctl_isync_fence_signal(filep, arg);break;case HGSL_IOCTL_ISYNC_FORWARD:ret = hgsl_ioctl_isync_forward(filep, arg);break;case HGSL_IOCTL_TIMELINE_CREATE:ret = hgsl_ioctl_timeline_create(filep, arg);break;case HGSL_IOCTL_TIMELINE_SIGNAL:ret = hgsl_ioctl_timeline_signal(filep, arg);break;case HGSL_IOCTL_TIMELINE_QUERY:ret = hgsl_ioctl_timeline_query(filep, arg);break;case HGSL_IOCTL_TIMELINE_WAIT:ret = hgsl_ioctl_timeline_wait(filep, arg);break;default:ret = -ENOIOCTLCMD;}return ret;
}
static int hgsl_ioctl_ctxt_create(struct file *filep, unsigned long arg)
{struct hgsl_priv *priv = filep->private_data;struct qcom_hgsl *hgsl = priv->dev;struct hgsl_ioctl_ctxt_create_params params;struct hgsl_context *ctxt = NULL;int ret = 0;struct hgsl_hab_channel_t *hab_channel = NULL;bool ctxt_created = false;if (copy_from_user(&params, USRPTR(arg), sizeof(params))) {LOGE("failed to copy params from user");ret = -EFAULT;return ret;}//建立hab socketret = hgsl_hyp_channel_pool_get(&priv->hyp_priv, 0, &hab_channel);if (ret) {LOGE("Failed to get hab channel %d", ret);goto out;}ctxt = hgsl_zalloc(sizeof(*ctxt));if (ctxt == NULL) {ret = -ENOMEM;return ret;}if (params.flags & GSL_CONTEXT_FLAG_CLIENT_GENERATED_TS)params.flags |= GSL_CONTEXT_FLAG_USER_GENERATED_TS;if (params.flags & GSL_CONTEXT_FLAG_BIND) {params.flags &= ~GSL_CONTEXT_FLAG_CLIENT_GENERATED_TS;params.flags |= GSL_CONTEXT_FLAG_USER_GENERATED_TS;}//使用hab socket发送数据ret = hgsl_hyp_ctxt_create(hab_channel, &params);if (ret)goto out;if (params.ctxthandle >= HGSL_CONTEXT_NUM) {LOGE("invalid ctxt id %d", params.ctxthandle);ret = -EINVAL;goto out;}ctxt->context_id = params.ctxthandle;ctxt->devhandle = params.devhandle;ctxt->pid = priv->pid;ctxt->priv = priv;ctxt->flags = params.flags;hgsl_get_shadowts_mem(hab_channel, ctxt);if (hgsl->global_hyp_inited && !hgsl->db_off)hgsl_ctxt_create_dbq(priv, hab_channel, ctxt);kref_init(&ctxt->kref);init_waitqueue_head(&ctxt->wait_q);write_lock(&hgsl->ctxt_lock);if (hgsl->contexts[ctxt->context_id] != NULL) {LOGE("context id %d already created",ctxt->context_id);ret = -EBUSY;write_unlock(&hgsl->ctxt_lock);goto out;}hgsl->contexts[ctxt->context_id] = ctxt;write_unlock(&hgsl->ctxt_lock);ctxt_created = true;if (hgsl_ctxt_use_global_dbq(ctxt)) {ret = hgsl_hsync_timeline_create(ctxt);if (ret < 0)LOGE("hsync timeline failed for context %d", params.ctxthandle);}if (ctxt->timeline)params.sync_type = HGSL_SYNC_TYPE_HSYNC;elseparams.sync_type = HGSL_SYNC_TYPE_ISYNC;if (copy_to_user(USRPTR(arg), &params, sizeof(params))) {ret = -EFAULT;goto out;}out:LOGD("%d", params.ctxthandle);if (ret) {if (ctxt_created)hgsl_ctxt_destroy(priv, hab_channel, params.ctxthandle, NULL, false);else if (ctxt && (params.ctxthandle < HGSL_CONTEXT_NUM)) {_unmap_shadow(ctxt);hgsl_hyp_put_shadowts_mem(hab_channel, &ctxt->shadow_ts_node);hgsl_hyp_ctxt_destroy(hab_channel, ctxt->devhandle, ctxt->context_id, NULL);kfree(ctxt);}LOGE("failed to create context");}hgsl_hyp_channel_pool_put(hab_channel);return ret;
}
int hgsl_hyp_channel_pool_get(struct hgsl_hyp_priv_t *priv, int id, struct hgsl_hab_channel_t **channel)
{struct hgsl_hab_channel_t *hab_channel = NULL;int ret = 0;if (!channel)return -EINVAL;mutex_lock(&priv->lock);if (id) {ret = hgsl_hyp_channel_pool_get_by_id(priv, id, &hab_channel);if (ret)LOGE("Failed to find channel %d, ret %d", id, ret);} else {if (list_empty(&priv->free_channels)) {//创建一个channel ret = hgsl_rpc_create_channel(priv, &hab_channel);LOGD("hgsl_rpc_create_channel returned, ret %d hab_channel %p",ret, hab_channel);} else {hab_channel = container_of(priv->free_channels.next,struct hgsl_hab_channel_t, node);if (hab_channel != NULL) {list_del(&hab_channel->node);LOGD("get %p from free pool", hab_channel);} else {ret = -EINVAL;LOGE("invalid hab_channel in the list");}}if (!ret)list_add_tail(&hab_channel->node, &priv->busy_channels);}if (!ret) {*channel = hab_channel;hab_channel->busy = true;}mutex_unlock(&priv->lock);if ((!ret) && (!id)) {ret = hgsl_rpc_parcel_reset(hab_channel);if (ret) {LOGE("hgsl_rpc_parcel_reset failed %d", ret);hgsl_hyp_channel_pool_put(hab_channel);hab_channel = NULL;}}return ret;
}

创建hab_channel

static int hgsl_rpc_create_channel(struct hgsl_hyp_priv_t *priv,struct hgsl_hab_channel_t **channel)
{int socket = HAB_INVALID_HANDLE;int ret = -ENOMEM;struct hgsl_hab_channel_t *hab_channel= (struct hgsl_hab_channel_t *)hgsl_zalloc(sizeof(struct hgsl_hab_channel_t));if (hab_channel == NULL) {LOGE("Failed to allocate hab_channel");goto out;}hab_channel->socket = HAB_INVALID_HANDLE;hab_channel->priv = priv;hab_channel->busy = false;hab_channel->wait_retry = false;hab_channel->id = idr_alloc(&priv->channel_idr, hab_channel,1, 0, GFP_NOWAIT);if (hab_channel->id < 0) {LOGE("Failed to allocate id for hab channel");ret = hab_channel->id;goto out;}//初始化hab_channelret = hgsl_rpc_parcel_init(hab_channel);if (ret) {LOGE("Failed to init parcel");goto out;}//创建hab socketif (priv->conn_id == 0) {ret = hgsl_rpc_connect(priv, &socket);if (ret) {LOGE("Failed to open socket %d", ret);goto out;}hab_channel->socket = socket;//进行数据通讯ret = rpc_handshake(priv, hab_channel);if (ret)LOGE("rpc_handshake failed %d", ret);gsl_hab_close(socket);hab_channel->socket = HAB_INVALID_HANDLE;}ret = hgsl_rpc_connect(priv, &socket);if (ret) {LOGE("Failed to open socket %d", ret);goto out;}hab_channel->socket = socket;ret = rpc_sub_handshake(priv, hab_channel);if (ret) {LOGE("sub handshake failed %d", ret);gsl_hab_close(socket);hab_channel->socket = HAB_INVALID_HANDLE;}out:if (ret) {LOGE("Failed to create channel %d exiting", ret);if (hab_channel != NULL) {hgsl_hyp_close_channel(hab_channel);hab_channel = NULL;}} else {*channel = hab_channel;}return ret;
}
static int hgsl_rpc_connect(struct hgsl_hyp_priv_t *priv, int *socket)
{int err = 0;int tmp_socket = priv->conn_id;LOGI("connecting using conn_id %d", tmp_socket);err = gsl_hab_open(&tmp_socket);LOGI("socket_open err %d, socket %d", err, tmp_socket);*socket = tmp_socket;return err;
}
int gsl_hab_open(int *habfd)
{int ret = 0;ret = habmm_socket_open(habfd, HAB_MMID_CREATE(MM_GFX, (int)*habfd), HAB_OPEN_WAIT_TIMEOUT_MS, HABMM_SOCKET_OPEN_FLAGS_SINGLE_BE_SINGLE_FE);LOGD("habmm_socket_open returned with %d, %x", ret, *habfd);return ret;
}
根据p->data_pos获取recv到的数据#define GSL_RPC_READ_ARG(p, id, p_arg, type) \
152  ({ \
153          void *p_arg_data = NULL; \
154          int ret = gsl_rpc_get_arg_ptr(p, id, &p_arg_data, sizeof(type)); \
155          if (ret == 0) { \
156                  *p_arg = *((type *)p_arg_data); \
157          } \
158  \
159          ret; \
160  })static inline int gsl_rpc_get_arg_ptr(struct gsl_hab_payload *p,
105          uint32_t id, void **p_data, size_t size)
106  {
107          int ret = -EINVAL;
108  
109          if ((p->data_pos + size + gsl_rpc_header_size) <= p->data_size) {
110                  struct gsl_rpc_header_t *hdr
111                          = (struct gsl_rpc_header_t *)(p->data + p->data_pos);
112  
113                  if ((hdr->magic == GSL_HAB_DATA_MAGIC) &&
114                          (hdr->id == id) && (hdr->size == size)) {
115                          struct gsl_rpc_footer_t *footer = NULL;
116                          uint32_t checksum;
117  
118                          checksum = gsl_rpc_gen_checksum(&hdr->data, hdr->size);
119                          *p_data = (void *)&hdr->data;
120                          p->data_pos += size + gsl_rpc_header_size;
121                          footer = (struct gsl_rpc_footer_t *)
122                                  (p->data + p->data_pos);
123                          p->data_pos += sizeof(struct gsl_rpc_footer_t);
124  
125                          if (checksum == footer->checksum)
126                                  ret = 0;
127                          else
128                                  LOGE("checksum mismatch %d != %d",
129                                          checksum, footer->checksum);
130                  } else {
131                          struct gsl_rpc_header_t *call_hdr
132                                  = (struct gsl_rpc_header_t *)p->data;
133                          size_t dump_size
134                                  = call_hdr->size + gsl_rpc_header_size
135                                          + sizeof(struct gsl_rpc_footer_t);
136  
137                          dump_size = (dump_size <= p->data_size) ?
138                                                  dump_size : p->data_size;
139                          LOGE("@%d: argument type or size mismatch: call id %d",
140                                  p->data_pos, call_hdr->id);
141                          LOGE("size %d magic 0x%X/0x%X, id %d/%d, size %d/%d",
142                                  call_hdr->size, hdr->magic, GSL_HAB_DATA_MAGIC,
143                                  hdr->id, id, hdr->size, size);
144                          gsl_hab_payload_dump(p, dump_size);
145                  }
146          }
147  
148          return ret;
149  }
int gsl_rpc_write(struct gsl_hab_payload *p, const void *data, size_t len)
{return GSL_RPC_WRITE_DATA(p, GSL_RPC_BLOB_DATA, p_data, len,do {if (data && len) memcpy(p_data, data, len); } while (0));
}#define GSL_RPC_WRITE_DATA(p, type, data_ptr, len, action) \
({ \int status = 0; \
\if ((p->data_pos + gsl_rpc_header_size + len +\sizeof(struct gsl_rpc_footer_t) > p->data_size)) { \status = grow_data(p, len); \} \
\if (status == 0) { \struct gsl_rpc_header_t *hdr = (struct gsl_rpc_header_t *) \(p->data + p->data_pos); \struct gsl_rpc_footer_t *ftr = (struct gsl_rpc_footer_t *) \(p->data + p->data_pos + gsl_rpc_header_size + len); \void *data_ptr = (void *)&hdr->data; \uint32_t checksum = 0; \
\action; \checksum = gsl_rpc_gen_checksum(data_ptr, len); \hdr->magic = GSL_HAB_DATA_MAGIC; \hdr->id = type; \hdr->version = 2; \hdr->size = len; \ftr->checksum = checksum; \p->data_pos += len + gsl_rpc_header_size \+ sizeof(struct gsl_rpc_footer_t); \} \
\status; \
})

通过hab发送数据

static int gsl_rpc_send_(const char *fname, int line_num, void *data,157          size_t size, struct hgsl_hab_channel_t *hab_channel)
158  {
159          int ret = gsl_hab_send(hab_channel->socket,
160                  (unsigned char *)data, size);
161  
162          if (ret)
163                  LOGE("failed to send @ %s:%d", fname, line_num);
164  
165          return ret;
166  }
int gsl_hab_send(int habfd, unsigned char *p, size_t sz)
{return habmm_socket_send(habfd, p, sz, 0);
}

通过hab接收数据

static int gsl_rpc_recv_(const char *fname, int line_num, void *data,170          size_t size, struct hgsl_hab_channel_t *hab_channel, int interruptible)
171  {
172          int ret = gsl_hab_recv(hab_channel->socket,
173                  (unsigned char *)data, size, interruptible);
174  175          return ret;
176  }

static int gsl_rpc_transact_ext(uint32_t opcode, uint32_t version,struct hgsl_hab_channel_t *hab_channel, bool interruptible)
{int ret = -EINVAL;struct gsl_hab_payload *data = &hab_channel->send_buf;struct gsl_hab_payload *reply = &hab_channel->recv_buf;if (data && reply) {void *p_data;uint32_t data_size, max_size;uint32_t recv_opcode;if (hab_channel->wait_retry && interruptible) {ret = 0;} else if (hab_channel->wait_retry) {LOGE("channel is waiting for retry for uninterruptible RPC call");ret = -EINVAL;goto out;} else {gsl_rpc_set_call_params(data, opcode, version);ret = gsl_rpc_finalize(data);if (!ret) {ret = gsl_rpc_get_data_params(data,&p_data, &data_size, &max_size);} else {LOGE("failed to set footer, err %d", ret);goto out;}if (!ret) {//通过hab_channel发送数据ret = gsl_rpc_send(p_data,data->data_pos, hab_channel);} else {LOGE("failed to get data params, err %d", ret);goto out;}}if (!ret) {ret = gsl_rpc_get_data_params(reply,&p_data, &data_size, &max_size);} else {LOGE("failed to send data, err %d", ret);goto out;}//接收hab_channel数据if (!ret) {ret = gsl_rpc_recv(p_data, max_size, hab_channel, interruptible);} else {LOGE("failed to get data params, err %d", ret);goto out;}if (ret == -EINTR) {goto out;} else if (!ret) {//判断是否opcode一致ret = gsl_rpc_get_call_params(reply,&recv_opcode, NULL);} else {LOGE("failed to recv data, err %d", ret);goto out;}if (!ret) {if (recv_opcode != opcode) {if (opcode != RPC_DISCONNECT)LOGE("recv opcode %d (%s), expected %d (%s)",recv_opcode,hgsl_get_rpc_fname(recv_opcode),opcode,hgsl_get_rpc_fname(opcode));ret = -EINVAL;}} else {LOGE("failed to parse data, err %d", ret);}}out:return ret;
}

通过hypervisor 发送和接收数据

static int rpc_handshake(struct hgsl_hyp_priv_t *priv,struct hgsl_hab_channel_t *hab_channel)
{int ret = 0;int rval = GSL_SUCCESS;struct gsl_hab_payload *send_buf = NULL;struct gsl_hab_payload *recv_buf = NULL;struct handshake_params_t params = { 0 };int tmp = 0;enum gsl_rpc_server_type_t server_type = GSL_RPC_SERVER_TYPE_LAST;enum gsl_rpc_server_mode_t server_mode = GSL_RPC_SERVER_MODE_LAST;RPC_TRACE();ret = hgsl_rpc_parcel_reset(hab_channel);if (ret) {LOGE("hgsl_rpc_parcel_reset failed %d", ret);goto out;}send_buf = &hab_channel->send_buf;recv_buf = &hab_channel->recv_buf;params.client_type = g_client_type;params.client_version = g_client_version;params.pid = priv->client_pid;params.size = sizeof(params);/* send the current process name to the server */strlcpy(params.name, priv->client_name, sizeof(params.name));LOGD("client process name is (%s)", params.name);//将数据写入hab_channel->send_buf中ret = gsl_rpc_write(send_buf, &params, sizeof(params));if (ret) {LOGE("gsl_rpc_write failed %d", ret);goto out;}//将数据发送通过hab发送到qnx端habmm_socket_sendret = gsl_rpc_transact_ext(RPC_HANDSHAKE, 1, hab_channel, 0);if (ret) {LOGE("gsl_rpc_transact_ext failed %d", ret);goto out;}//将recv_buf中的数据hdr->data指向rval//如果获取到数据rval不等于GSL_SUCCESS,qnx sent侧发送失败ret = gsl_rpc_read_int32_l(recv_buf, &rval);if ((!ret) && (rval != GSL_SUCCESS)) {LOGE("BE sent error %d", rval);ret = -EINVAL;}if (!ret) {ret = gsl_rpc_read_int32_l(recv_buf, &priv->conn_id);if (ret) {LOGE("Failed to read conn_id %d", ret);goto out;}ret = gsl_rpc_read_int32_l(recv_buf, &tmp);if (ret) {LOGE("Failed to read server_type %d", ret);goto out;}server_type = (enum gsl_rpc_server_type_t)tmp;ret = gsl_rpc_read_int32_l(recv_buf, &tmp);if (ret) {LOGE("Failed to read server_mode %d", ret);goto out;}server_mode = (enum gsl_rpc_server_mode_t)tmp;LOGI("Successfully connected to server, got connection id %d",priv->conn_id);} else {LOGE("handshake failed, %d", ret);}out:RPC_TRACE_DONE();return ret;
}

 发送RPC_CONTEXT_CREATE到qnx be 端

int hgsl_hyp_ctxt_create(struct hgsl_hab_channel_t *hab_channel,struct hgsl_ioctl_ctxt_create_params *hgsl_params)
{struct context_create_params_t rpc_params = { 0 };struct gsl_hab_payload *send_buf = NULL;struct gsl_hab_payload *recv_buf = NULL;int ret = 0;RPC_TRACE();if (!hab_channel) {LOGE("invalid hab_channel");ret = -EINVAL;goto out;}ret = hgsl_rpc_parcel_reset(hab_channel);if (ret) {LOGE("hgsl_rpc_parcel_reset failed %d", ret);goto out;}send_buf = &hab_channel->send_buf;recv_buf = &hab_channel->recv_buf;rpc_params.size = sizeof(rpc_params);rpc_params.devhandle = hgsl_params->devhandle;rpc_params.type = hgsl_params->type;rpc_params.flags = hgsl_params->flags;ret = gsl_rpc_write(send_buf, &rpc_params, sizeof(rpc_params));if (ret) {LOGE("gsl_rpc_write failed, %d", ret);goto out;}ret = gsl_rpc_transact(RPC_CONTEXT_CREATE, hab_channel);if (ret) {LOGE("gsl_rpc_transact failed, %d", ret);goto out;}ret = gsl_rpc_read_uint32_l(recv_buf, &hgsl_params->ctxthandle);if (ret) {LOGE("gsl_rpc_read_uint32_l failed, %d", ret);goto out;}out:RPC_TRACE_DONE();return ret;
}
static int gsl_rpc_transact(uint32_t opcode,struct hgsl_hab_channel_t *hab_channel)
{int ret = gsl_rpc_transact_ext(opcode, 0, hab_channel, false);if (ret == -EINTR) {LOGE("noninterruptible transaction was interrupted");ret = -EINVAL;}return ret;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/236596.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一、神经元与激活函数

神经网络是一种大规模的并行分布式处理器&#xff0c;天然具有存储并使用经验知识的能力。它从两个方面上模拟大脑:(1)网络获取的知识是通过学习来获取的;(2)内部神经元的连接强度&#xff0c;即突触权重&#xff0c;用于储存获取的知识。—— Haykin [1994] 生物学家在20世纪初…

XILINX-Zynq UltraScale+MPSoc 开发笔记

1. 资料信息 2. IDE集成开发环境 3. petalinux开发 3.1 环境搭建 1. 创建一个ubuntu18.04&#xff08;或者其他版本&#xff09;&#xff0c;根据UG1144文档安装ubuntu下对petalinux的依懒工具。 2. 下载petalinux对应版本&#xff0c;链接&#xff1a;Downloads (xilinx.co…

Python---端口和端口号的介绍

1. 问题思考 不同电脑上的飞秋之间进行数据通信&#xff0c;它是如何保证把数据给飞秋而不是给其它软件呢? 其实&#xff0c;每运行一个网络程序都会有一个端口&#xff0c;想要给对应的程序发送数据&#xff0c;找到对应的端口即可。 端口效果图: 2. 什么是端口 端口是传…

电巢助力第十届图像技术高峰论坛圆满落幕,回顾西电与电巢的校企合作四年硕果累累

图像技术高峰论坛圆满落幕 12月17日&#xff0c;由中国图象图形学学会、陕西省科学技术协会主办、西安电子科技大学通信工程学院、陕西省创新驱动共同体承办的“第十届图像技术高峰论坛暨陕西第五届图像处理与分析研讨会”在陕西西安成功举办。电巢科技作为本次论坛的承办单位&…

某电子文档安全管理系统 SQL注入漏洞复现

漏洞介绍 亿赛通电子文档安全管理系统 (简称: CDG)是一款电子文档安全加密软件&#xff0c;该系统利用驱动层透明加密技术&#xff0c;通过对电子文档的加密保护&#xff0c;防止内部员工泄密和外部人员非法窃取企业核心重要数据资产&#xff0c;对电子文档进行全生命周期防护…

未来仓储新玩法小空间做大文章

身处智能消费时代的大家都应该有深刻感受&#xff0c;物流速度在逐年增快。根据国家邮政局预估&#xff0c;2020 年快递业务吞吐量超 740 亿件&#xff0c;同比增长 18%。 面对日益增加的商品交付量&#xff0c;不得不重新定义产品分销方式&#xff0c;从而满足当今互联网消费…

从零开始学HBase:打造你的大数据技能库!

介绍&#xff1a;HBase是一个分布式的、面向列的开源数据库&#xff0c;源于Fay Chang所撰写的Google论文“Bigtable&#xff1a;一个结构化数据的分布式存储系统”。类似于Bigtable利用了Google文件系统&#xff08;File System&#xff09;提供的分布式数据存储&#xff0c;H…

<八>JavaScript中的对象及对像的增删改查

使用基本数据变量所创建的变量都是独立的&#xff0c;不能成为一个整体&#xff0c;对象属于复合型的数据类型&#xff0c;在对象中可以保存多个不同的数据类型的属性。 一、对象的分类 1.1内建对象 由ES标准中定义的对象 比如&#xff1a;Match、String、Number、Boolean、…

华为atlas300安装教程

1、安装包位置&#xff1a; /data/ai_install_packages 2、添加HwHiAiUser用户&#xff1a; groupadd -g 1000 HwHiAiUser useradd -g HwHiAiUser -u 1000 -d /home/HwHiAiUser -m HwHiAiUser -s /bin/bash 3、安装驱动&#xff1a; ./Ascend-hdk-310p-npu-driver_6.0.0_l…

前端FLV视频直播解决方案

项目背景&#xff1a; 1. 后台给出一个地址&#xff0c;持续不断的推送flv视频流。 2.前端需要接收视频流&#xff0c;并寻找合适的播放插件。 一开始&#xff1a; 其实用的是xgplayer&#xff08;西瓜视频&#xff09;。 官网地址&#xff1a;西瓜播放器 使用的是直播&a…

DELL MD3600F更换控制器电池

1、存储左上角闪红灯&#xff0c;管理软件提示控制器1电池故障&#xff0c;需取出控制器更换上新电池。 2、通过管理软件确认两个控制器编号&#xff1b;确认到下面的是控制器1 3、拔掉控制器上插的线&#xff08;SAS线、网线、光纤线&#xff09;&#xff0c;打好标签&#xf…

外贸SEO建站系统有哪些?海洋建站的优势?

外贸SEO建站怎么做比较好&#xff1f;如何做谷歌独立站SEO优化&#xff1f; 外贸企业越来越需要建立自己的在线形象&#xff0c;以吸引更多的潜在客户。而要实现这一目标&#xff0c;外贸SEO建站系统是一种非常有效的手段。那么&#xff0c;外贸SEO建站系统有哪些呢&#xff1…

常见 平滑函数

平滑函数是指具有较为连续和缓和性质的数学函数。这类函数通常在局部小范围内变化不大&#xff0c;避免了突变或者急剧的波动。以下是一些常见的平滑函数&#xff1a; 高斯函数&#xff08;Gaussian Function&#xff09; 高斯函数是一种常见的平滑函数&#xff0c;具有钟形曲…

五、从0开始卷出一个新项目瑞萨RZN2L之RZT2L BaseProject coremark的移植

感谢来自b站热心帅气的同学分享的RZT2L移植经验总结的md文档 1 需要注意的小点 1.1 使用Flash运行调试前&#xff0c;新板子需要erase 1.2 在线debug&#xff0c;需要修改startup.c 2 coremark工程建立 2.1 工程创建 2.2 src 用户c代码移植 2.3 debug调试 …

【python】进阶--->网络编程(一)

一、网络编程 网络 : 为了联络多方然后进行通信,将数据从一方传递给另一方. 网络协议 : 不同计算机只需要通过联网,那么就可以相互进行传递数据,那么不同种类的计算机之间就和不同语言的人之间沟通一样,需要一种大家都认可都遵循的协议即可. 那么计算机都遵循的网络通信协议叫…

Kafka--Kafka日志索引详解以及生产常见问题分析与总结

一、Kafka的Log日志梳理 ​ 这一部分数据主要包含当前Broker节点的消息数据(在Kafka中称为Log日志)。这是一部分无状态的数据&#xff0c;也就是说每个Kafka的Broker节点都是以相同的逻辑运行。这种无状态的服务设计让Kafka集群能够比较容易的进行水平扩展。比如你需要用一个新…

嵌入式开发工程师

嵌入式开发 岗位需求 上岗必备 文章目录 嵌入式开发前言一、负责新产品的电路图、PCB、嵌入式程序、软硬件调试等工作二、负责对现有产品进行硬件优化、调试、维护、排故等工作三、 负责各种单片机,传感器,元器件选型以及BOM表整理四、 负责硬件产品研发和量产过程中项目设计…

网络技术基础与计算思维实验教程_3.1_单BSS实验(基本服务集合实验)

无线局域网的最小基本组件是基本服务BSS 实验内容 实验目的 实验原理 实验步骤 为了显示AP的有效通信范围 切换到物理工作区 把物理工作区导航到城市家园 直接在城市家园放置AP0 可以看到AP0的通信范围 放置笔记本电脑 在默认情况下 笔记本电脑上 安装了以太网卡 现在换成无…

大模型之二十一-小语言模型塞道开启

当前提到大语言模型&#xff0c;大家想到的都是动辄百亿规模以上参数量的模型&#xff0c;13B、70B都是稀疏平常入门级的&#xff0c;但是目前从模型层面来看&#xff0c;模型参数量的规模两极分化已经来临&#xff0c;早期各大公司为了效果怼上去&#xff0c;采取了简单粗暴的…

[Angular] 笔记 4:ngFor

ngFor 是一个 for 循环&#xff0c;只能用于循环遍历 list&#xff0c;不能用于遍历单个实体。 下图中的 pokemons 通常是数据库中的数据&#xff1a; 例子&#xff1a; app.components.ts: // 使用类型检查 interface Pokemon {id: number;name: string;type: string;// is…