1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2020-2021 NXP
6 #include <linux/init.h>
7 #include <linux/interconnect.h>
8 #include <linux/ioctl.h>
9 #include <linux/list.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/videodev2.h>
14 #include <media/v4l2-device.h>
15 #include <media/v4l2-event.h>
16 #include <media/v4l2-mem2mem.h>
17 #include <media/v4l2-ioctl.h>
18 #include <media/videobuf2-v4l2.h>
19 #include <media/videobuf2-dma-contig.h>
20 #include <media/videobuf2-vmalloc.h>
25 #include "vpu_helpers.h"
27 void vpu_inst_lock(struct vpu_inst *inst)
29 mutex_lock(&inst->lock);
32 void vpu_inst_unlock(struct vpu_inst *inst)
34 mutex_unlock(&inst->lock);
37 dma_addr_t vpu_get_vb_phy_addr(struct vb2_buffer *vb, u32 plane_no)
39 if (plane_no >= vb->num_planes)
41 return vb2_dma_contig_plane_dma_addr(vb, plane_no) +
42 vb->planes[plane_no].data_offset;
45 unsigned int vpu_get_vb_length(struct vb2_buffer *vb, u32 plane_no)
47 if (plane_no >= vb->num_planes)
49 return vb2_plane_size(vb, plane_no) - vb->planes[plane_no].data_offset;
52 void vpu_set_buffer_state(struct vb2_v4l2_buffer *vbuf, unsigned int state)
54 struct vpu_vb2_buffer *vpu_buf = to_vpu_vb2_buffer(vbuf);
56 vpu_buf->state = state;
59 unsigned int vpu_get_buffer_state(struct vb2_v4l2_buffer *vbuf)
61 struct vpu_vb2_buffer *vpu_buf = to_vpu_vb2_buffer(vbuf);
63 return vpu_buf->state;
66 void vpu_v4l2_set_error(struct vpu_inst *inst)
68 struct vb2_queue *src_q;
69 struct vb2_queue *dst_q;
72 dev_err(inst->dev, "some error occurs in codec\n");
73 if (inst->fh.m2m_ctx) {
74 src_q = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx);
75 dst_q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx);
78 wake_up(&src_q->done_wq);
79 wake_up(&dst_q->done_wq);
81 vpu_inst_unlock(inst);
84 int vpu_notify_eos(struct vpu_inst *inst)
86 static const struct v4l2_event ev = {
88 .type = V4L2_EVENT_EOS
91 vpu_trace(inst->dev, "[%d]\n", inst->id);
92 v4l2_event_queue_fh(&inst->fh, &ev);
97 int vpu_notify_source_change(struct vpu_inst *inst)
99 static const struct v4l2_event ev = {
101 .type = V4L2_EVENT_SOURCE_CHANGE,
102 .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION
105 vpu_trace(inst->dev, "[%d]\n", inst->id);
106 v4l2_event_queue_fh(&inst->fh, &ev);
110 int vpu_set_last_buffer_dequeued(struct vpu_inst *inst)
114 if (!inst || !inst->fh.m2m_ctx)
117 q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx);
118 if (!list_empty(&q->done_list))
121 if (q->last_buffer_dequeued)
123 vpu_trace(inst->dev, "last buffer dequeued\n");
124 q->last_buffer_dequeued = true;
125 wake_up(&q->done_wq);
126 vpu_notify_eos(inst);
130 bool vpu_is_source_empty(struct vpu_inst *inst)
132 struct v4l2_m2m_buffer *buf = NULL;
134 if (!inst->fh.m2m_ctx)
136 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) {
137 if (vpu_get_buffer_state(&buf->vb) == VPU_BUF_STATE_IDLE)
143 const struct vpu_format *vpu_try_fmt_common(struct vpu_inst *inst, struct v4l2_format *f)
145 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
150 const struct vpu_format *fmt;
151 const struct vpu_core_resources *res;
154 fmt = vpu_helper_find_format(inst, type, pixmp->pixelformat);
156 fmt = vpu_helper_enum_format(inst, type, 0);
159 pixmp->pixelformat = fmt->pixfmt;
162 res = vpu_get_resource(inst);
164 stride = res->stride;
166 pixmp->width = vpu_helper_valid_frame_width(inst, pixmp->width);
168 pixmp->height = vpu_helper_valid_frame_height(inst, pixmp->height);
169 pixmp->flags = fmt->flags;
170 pixmp->num_planes = fmt->num_planes;
171 if (pixmp->field == V4L2_FIELD_ANY)
172 pixmp->field = V4L2_FIELD_NONE;
173 for (i = 0; i < pixmp->num_planes; i++) {
174 bytesperline = max_t(s32, pixmp->plane_fmt[i].bytesperline, 0);
175 sizeimage = vpu_helper_get_plane_size(pixmp->pixelformat,
180 pixmp->field > V4L2_FIELD_NONE ? 1 : 0,
182 sizeimage = max_t(s32, pixmp->plane_fmt[i].sizeimage, sizeimage);
183 pixmp->plane_fmt[i].bytesperline = bytesperline;
184 pixmp->plane_fmt[i].sizeimage = sizeimage;
190 static bool vpu_check_ready(struct vpu_inst *inst, u32 type)
194 if (inst->state == VPU_CODEC_STATE_DEINIT || inst->id < 0)
196 if (!inst->ops->check_ready)
198 return call_vop(inst, check_ready, type);
201 int vpu_process_output_buffer(struct vpu_inst *inst)
203 struct v4l2_m2m_buffer *buf = NULL;
204 struct vb2_v4l2_buffer *vbuf = NULL;
206 if (!inst || !inst->fh.m2m_ctx)
209 if (!vpu_check_ready(inst, inst->out_format.type))
212 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) {
214 if (vpu_get_buffer_state(vbuf) == VPU_BUF_STATE_IDLE)
222 dev_dbg(inst->dev, "[%d]frame id = %d / %d\n",
223 inst->id, vbuf->sequence, inst->sequence);
224 return call_vop(inst, process_output, &vbuf->vb2_buf);
227 int vpu_process_capture_buffer(struct vpu_inst *inst)
229 struct v4l2_m2m_buffer *buf = NULL;
230 struct vb2_v4l2_buffer *vbuf = NULL;
232 if (!inst || !inst->fh.m2m_ctx)
235 if (!vpu_check_ready(inst, inst->cap_format.type))
238 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) {
240 if (vpu_get_buffer_state(vbuf) == VPU_BUF_STATE_IDLE)
247 return call_vop(inst, process_capture, &vbuf->vb2_buf);
250 struct vb2_v4l2_buffer *vpu_next_src_buf(struct vpu_inst *inst)
252 struct vb2_v4l2_buffer *src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx);
254 if (!src_buf || vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_IDLE)
257 while (vpu_vb_is_codecconfig(src_buf)) {
258 v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx);
259 vpu_set_buffer_state(src_buf, VPU_BUF_STATE_IDLE);
260 v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
262 src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx);
263 if (!src_buf || vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_IDLE)
270 void vpu_skip_frame(struct vpu_inst *inst, int count)
272 struct vb2_v4l2_buffer *src_buf;
273 enum vb2_buffer_state state;
280 src_buf = v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx);
281 if (!src_buf || vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_IDLE)
283 if (vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_DECODED)
284 state = VB2_BUF_STATE_DONE;
286 state = VB2_BUF_STATE_ERROR;
288 vpu_set_buffer_state(src_buf, VPU_BUF_STATE_IDLE);
289 v4l2_m2m_buf_done(src_buf, state);
293 struct vb2_v4l2_buffer *vpu_find_buf_by_sequence(struct vpu_inst *inst, u32 type, u32 sequence)
295 struct v4l2_m2m_buffer *buf = NULL;
296 struct vb2_v4l2_buffer *vbuf = NULL;
298 if (!inst || !inst->fh.m2m_ctx)
301 if (V4L2_TYPE_IS_OUTPUT(type)) {
302 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) {
304 if (vbuf->sequence == sequence)
309 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) {
311 if (vbuf->sequence == sequence)
320 struct vb2_v4l2_buffer *vpu_find_buf_by_idx(struct vpu_inst *inst, u32 type, u32 idx)
322 struct v4l2_m2m_buffer *buf = NULL;
323 struct vb2_v4l2_buffer *vbuf = NULL;
325 if (!inst || !inst->fh.m2m_ctx)
328 if (V4L2_TYPE_IS_OUTPUT(type)) {
329 v4l2_m2m_for_each_src_buf(inst->fh.m2m_ctx, buf) {
331 if (vbuf->vb2_buf.index == idx)
336 v4l2_m2m_for_each_dst_buf(inst->fh.m2m_ctx, buf) {
338 if (vbuf->vb2_buf.index == idx)
347 int vpu_get_num_buffers(struct vpu_inst *inst, u32 type)
351 if (!inst || !inst->fh.m2m_ctx)
354 if (V4L2_TYPE_IS_OUTPUT(type))
355 q = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx);
357 q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx);
359 return q->num_buffers;
362 static void vpu_m2m_device_run(void *priv)
366 static void vpu_m2m_job_abort(void *priv)
368 struct vpu_inst *inst = priv;
369 struct v4l2_m2m_ctx *m2m_ctx = inst->fh.m2m_ctx;
371 v4l2_m2m_job_finish(m2m_ctx->m2m_dev, m2m_ctx);
374 static const struct v4l2_m2m_ops vpu_m2m_ops = {
375 .device_run = vpu_m2m_device_run,
376 .job_abort = vpu_m2m_job_abort
379 static int vpu_vb2_queue_setup(struct vb2_queue *vq,
380 unsigned int *buf_count,
381 unsigned int *plane_count,
382 unsigned int psize[],
383 struct device *allocators[])
385 struct vpu_inst *inst = vb2_get_drv_priv(vq);
386 struct vpu_format *cur_fmt;
389 cur_fmt = vpu_get_format(inst, vq->type);
392 if (*plane_count != cur_fmt->num_planes)
394 for (i = 0; i < cur_fmt->num_planes; i++) {
395 if (psize[i] < cur_fmt->sizeimage[i])
401 if (V4L2_TYPE_IS_OUTPUT(vq->type))
402 *buf_count = max_t(unsigned int, *buf_count, inst->min_buffer_out);
404 *buf_count = max_t(unsigned int, *buf_count, inst->min_buffer_cap);
405 *plane_count = cur_fmt->num_planes;
406 for (i = 0; i < cur_fmt->num_planes; i++)
407 psize[i] = cur_fmt->sizeimage[i];
412 static int vpu_vb2_buf_init(struct vb2_buffer *vb)
414 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
416 vpu_set_buffer_state(vbuf, VPU_BUF_STATE_IDLE);
420 static int vpu_vb2_buf_out_validate(struct vb2_buffer *vb)
422 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
424 vbuf->field = V4L2_FIELD_NONE;
429 static int vpu_vb2_buf_prepare(struct vb2_buffer *vb)
431 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
432 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
433 struct vpu_format *cur_fmt;
436 cur_fmt = vpu_get_format(inst, vb->type);
437 for (i = 0; i < cur_fmt->num_planes; i++) {
438 if (vpu_get_vb_length(vb, i) < cur_fmt->sizeimage[i]) {
439 dev_dbg(inst->dev, "[%d] %s buf[%d] is invalid\n",
440 inst->id, vpu_type_name(vb->type), vb->index);
441 vpu_set_buffer_state(vbuf, VPU_BUF_STATE_ERROR);
448 static void vpu_vb2_buf_finish(struct vb2_buffer *vb)
450 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
451 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
452 struct vb2_queue *q = vb->vb2_queue;
454 if (vbuf->flags & V4L2_BUF_FLAG_LAST)
455 vpu_notify_eos(inst);
457 if (list_empty(&q->done_list))
458 call_void_vop(inst, on_queue_empty, q->type);
461 void vpu_vb2_buffers_return(struct vpu_inst *inst, unsigned int type, enum vb2_buffer_state state)
463 struct vb2_v4l2_buffer *buf;
465 if (V4L2_TYPE_IS_OUTPUT(type)) {
466 while ((buf = v4l2_m2m_src_buf_remove(inst->fh.m2m_ctx))) {
467 vpu_set_buffer_state(buf, VPU_BUF_STATE_IDLE);
468 v4l2_m2m_buf_done(buf, state);
471 while ((buf = v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx))) {
472 vpu_set_buffer_state(buf, VPU_BUF_STATE_IDLE);
473 v4l2_m2m_buf_done(buf, state);
478 static int vpu_vb2_start_streaming(struct vb2_queue *q, unsigned int count)
480 struct vpu_inst *inst = vb2_get_drv_priv(q);
481 struct vpu_format *fmt = vpu_get_format(inst, q->type);
484 vpu_inst_unlock(inst);
485 ret = vpu_inst_register(inst);
488 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_QUEUED);
492 vpu_trace(inst->dev, "[%d] %s %c%c%c%c %dx%d %u(%u) %u(%u) %u(%u) %d\n",
493 inst->id, vpu_type_name(q->type),
498 fmt->width, fmt->height,
499 fmt->sizeimage[0], fmt->bytesperline[0],
500 fmt->sizeimage[1], fmt->bytesperline[1],
501 fmt->sizeimage[2], fmt->bytesperline[2],
503 call_void_vop(inst, start, q->type);
504 vb2_clear_last_buffer_dequeued(q);
509 static void vpu_vb2_stop_streaming(struct vb2_queue *q)
511 struct vpu_inst *inst = vb2_get_drv_priv(q);
513 vpu_trace(inst->dev, "[%d] %s\n", inst->id, vpu_type_name(q->type));
515 call_void_vop(inst, stop, q->type);
516 vpu_vb2_buffers_return(inst, q->type, VB2_BUF_STATE_ERROR);
517 if (V4L2_TYPE_IS_OUTPUT(q->type))
521 static void vpu_vb2_buf_queue(struct vb2_buffer *vb)
523 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
524 struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
526 if (V4L2_TYPE_IS_OUTPUT(vb->type))
527 vbuf->sequence = inst->sequence++;
529 v4l2_m2m_buf_queue(inst->fh.m2m_ctx, vbuf);
530 vpu_process_output_buffer(inst);
531 vpu_process_capture_buffer(inst);
534 static const struct vb2_ops vpu_vb2_ops = {
535 .queue_setup = vpu_vb2_queue_setup,
536 .buf_init = vpu_vb2_buf_init,
537 .buf_out_validate = vpu_vb2_buf_out_validate,
538 .buf_prepare = vpu_vb2_buf_prepare,
539 .buf_finish = vpu_vb2_buf_finish,
540 .start_streaming = vpu_vb2_start_streaming,
541 .stop_streaming = vpu_vb2_stop_streaming,
542 .buf_queue = vpu_vb2_buf_queue,
543 .wait_prepare = vb2_ops_wait_prepare,
544 .wait_finish = vb2_ops_wait_finish,
547 static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
549 struct vpu_inst *inst = priv;
552 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
553 inst->out_format.type = src_vq->type;
554 src_vq->io_modes = VB2_MMAP | VB2_DMABUF;
555 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
556 src_vq->ops = &vpu_vb2_ops;
557 src_vq->mem_ops = &vb2_dma_contig_memops;
558 if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer)
559 src_vq->mem_ops = &vb2_vmalloc_memops;
560 src_vq->drv_priv = inst;
561 src_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
562 src_vq->min_buffers_needed = 1;
563 src_vq->dev = inst->vpu->dev;
564 src_vq->lock = &inst->lock;
565 ret = vb2_queue_init(src_vq);
569 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
570 inst->cap_format.type = dst_vq->type;
571 dst_vq->io_modes = VB2_MMAP | VB2_DMABUF;
572 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
573 dst_vq->ops = &vpu_vb2_ops;
574 dst_vq->mem_ops = &vb2_dma_contig_memops;
575 if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer)
576 dst_vq->mem_ops = &vb2_vmalloc_memops;
577 dst_vq->drv_priv = inst;
578 dst_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
579 dst_vq->min_buffers_needed = 1;
580 dst_vq->dev = inst->vpu->dev;
581 dst_vq->lock = &inst->lock;
582 ret = vb2_queue_init(dst_vq);
584 vb2_queue_release(src_vq);
591 static int vpu_v4l2_release(struct vpu_inst *inst)
593 vpu_trace(inst->vpu->dev, "%p\n", inst);
595 vpu_release_core(inst->core);
596 put_device(inst->dev);
598 if (inst->workqueue) {
599 cancel_work_sync(&inst->msg_work);
600 destroy_workqueue(inst->workqueue);
601 inst->workqueue = NULL;
604 v4l2_ctrl_handler_free(&inst->ctrl_handler);
605 mutex_destroy(&inst->lock);
606 v4l2_fh_del(&inst->fh);
607 v4l2_fh_exit(&inst->fh);
609 call_void_vop(inst, cleanup);
614 int vpu_v4l2_open(struct file *file, struct vpu_inst *inst)
616 struct vpu_dev *vpu = video_drvdata(file);
617 struct vpu_func *func;
620 if (!inst || !inst->ops)
623 if (inst->type == VPU_CORE_TYPE_ENC)
624 func = &vpu->encoder;
626 func = &vpu->decoder;
628 atomic_set(&inst->ref_count, 0);
631 inst->core = vpu_request_core(vpu, inst->type);
633 inst->dev = get_device(inst->core->dev);
634 mutex_init(&inst->lock);
635 INIT_LIST_HEAD(&inst->cmd_q);
636 inst->id = VPU_INST_NULL_ID;
637 inst->release = vpu_v4l2_release;
638 inst->pid = current->pid;
639 inst->tgid = current->tgid;
640 inst->min_buffer_cap = 2;
641 inst->min_buffer_out = 2;
642 v4l2_fh_init(&inst->fh, func->vfd);
643 v4l2_fh_add(&inst->fh);
645 ret = call_vop(inst, ctrl_init);
649 inst->fh.m2m_ctx = v4l2_m2m_ctx_init(func->m2m_dev, inst, vpu_m2m_queue_init);
650 if (IS_ERR(inst->fh.m2m_ctx)) {
651 dev_err(vpu->dev, "v4l2_m2m_ctx_init fail\n");
652 ret = PTR_ERR(inst->fh.m2m_ctx);
656 inst->fh.ctrl_handler = &inst->ctrl_handler;
657 file->private_data = &inst->fh;
658 inst->state = VPU_CODEC_STATE_DEINIT;
659 inst->workqueue = alloc_workqueue("vpu_inst", WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
660 if (inst->workqueue) {
661 INIT_WORK(&inst->msg_work, vpu_inst_run_work);
662 ret = kfifo_init(&inst->msg_fifo,
664 rounddown_pow_of_two(sizeof(inst->msg_buffer)));
666 destroy_workqueue(inst->workqueue);
667 inst->workqueue = NULL;
670 vpu_trace(vpu->dev, "tgid = %d, pid = %d, type = %s, inst = %p\n",
671 inst->tgid, inst->pid, vpu_core_type_desc(inst->type), inst);
679 int vpu_v4l2_close(struct file *file)
681 struct vpu_dev *vpu = video_drvdata(file);
682 struct vpu_inst *inst = to_inst(file);
684 vpu_trace(vpu->dev, "tgid = %d, pid = %d, inst = %p\n", inst->tgid, inst->pid, inst);
687 if (inst->fh.m2m_ctx) {
688 v4l2_m2m_ctx_release(inst->fh.m2m_ctx);
689 inst->fh.m2m_ctx = NULL;
691 vpu_inst_unlock(inst);
693 call_void_vop(inst, release);
694 vpu_inst_unregister(inst);
700 int vpu_add_func(struct vpu_dev *vpu, struct vpu_func *func)
702 struct video_device *vfd;
711 func->m2m_dev = v4l2_m2m_init(&vpu_m2m_ops);
712 if (IS_ERR(func->m2m_dev)) {
713 dev_err(vpu->dev, "v4l2_m2m_init fail\n");
715 return PTR_ERR(func->m2m_dev);
718 vfd = video_device_alloc();
720 v4l2_m2m_release(func->m2m_dev);
721 dev_err(vpu->dev, "alloc vpu decoder video device fail\n");
724 vfd->release = video_device_release;
725 vfd->vfl_dir = VFL_DIR_M2M;
726 vfd->v4l2_dev = &vpu->v4l2_dev;
727 vfd->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
728 if (func->type == VPU_CORE_TYPE_ENC) {
729 strscpy(vfd->name, "amphion-vpu-encoder", sizeof(vfd->name));
730 vfd->fops = venc_get_fops();
731 vfd->ioctl_ops = venc_get_ioctl_ops();
733 strscpy(vfd->name, "amphion-vpu-decoder", sizeof(vfd->name));
734 vfd->fops = vdec_get_fops();
735 vfd->ioctl_ops = vdec_get_ioctl_ops();
738 ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
740 video_device_release(vfd);
741 v4l2_m2m_release(func->m2m_dev);
744 video_set_drvdata(vfd, vpu);
747 ret = v4l2_m2m_register_media_controller(func->m2m_dev, func->vfd, func->function);
749 v4l2_m2m_release(func->m2m_dev);
750 func->m2m_dev = NULL;
751 video_unregister_device(func->vfd);
759 void vpu_remove_func(struct vpu_func *func)
765 v4l2_m2m_unregister_media_controller(func->m2m_dev);
766 v4l2_m2m_release(func->m2m_dev);
767 func->m2m_dev = NULL;
770 video_unregister_device(func->vfd);