Lines Matching refs:mdev_state
129 struct mdev_state { struct
155 static int mtty_trigger_interrupt(struct mdev_state *mdev_state); argument
173 static void mtty_create_config_space(struct mdev_state *mdev_state) in mtty_create_config_space() argument
176 STORE_LE32((u32 *) &mdev_state->vconfig[0x0], 0x32534348); in mtty_create_config_space()
179 STORE_LE16((u16 *) &mdev_state->vconfig[0x4], 0x0001); in mtty_create_config_space()
182 STORE_LE16((u16 *) &mdev_state->vconfig[0x6], 0x0200); in mtty_create_config_space()
185 mdev_state->vconfig[0x8] = 0x10; in mtty_create_config_space()
188 mdev_state->vconfig[0x9] = 0x02; in mtty_create_config_space()
191 mdev_state->vconfig[0xa] = 0x00; in mtty_create_config_space()
194 mdev_state->vconfig[0xb] = 0x07; in mtty_create_config_space()
198 STORE_LE32((u32 *) &mdev_state->vconfig[0x10], 0x000001); in mtty_create_config_space()
199 mdev_state->bar_mask[0] = ~(MTTY_IO_BAR_SIZE) + 1; in mtty_create_config_space()
201 if (mdev_state->nr_ports == 2) { in mtty_create_config_space()
203 STORE_LE32((u32 *) &mdev_state->vconfig[0x14], 0x000001); in mtty_create_config_space()
204 mdev_state->bar_mask[1] = ~(MTTY_IO_BAR_SIZE) + 1; in mtty_create_config_space()
208 STORE_LE32((u32 *) &mdev_state->vconfig[0x2c], 0x32534348); in mtty_create_config_space()
210 mdev_state->vconfig[0x34] = 0x00; /* Cap Ptr */ in mtty_create_config_space()
211 mdev_state->vconfig[0x3d] = 0x01; /* interrupt pin (INTA#) */ in mtty_create_config_space()
214 mdev_state->vconfig[0x40] = 0x23; in mtty_create_config_space()
215 mdev_state->vconfig[0x43] = 0x80; in mtty_create_config_space()
216 mdev_state->vconfig[0x44] = 0x23; in mtty_create_config_space()
217 mdev_state->vconfig[0x48] = 0x23; in mtty_create_config_space()
218 mdev_state->vconfig[0x4c] = 0x23; in mtty_create_config_space()
220 mdev_state->vconfig[0x60] = 0x50; in mtty_create_config_space()
221 mdev_state->vconfig[0x61] = 0x43; in mtty_create_config_space()
222 mdev_state->vconfig[0x62] = 0x49; in mtty_create_config_space()
223 mdev_state->vconfig[0x63] = 0x20; in mtty_create_config_space()
224 mdev_state->vconfig[0x64] = 0x53; in mtty_create_config_space()
225 mdev_state->vconfig[0x65] = 0x65; in mtty_create_config_space()
226 mdev_state->vconfig[0x66] = 0x72; in mtty_create_config_space()
227 mdev_state->vconfig[0x67] = 0x69; in mtty_create_config_space()
228 mdev_state->vconfig[0x68] = 0x61; in mtty_create_config_space()
229 mdev_state->vconfig[0x69] = 0x6c; in mtty_create_config_space()
230 mdev_state->vconfig[0x6a] = 0x2f; in mtty_create_config_space()
231 mdev_state->vconfig[0x6b] = 0x55; in mtty_create_config_space()
232 mdev_state->vconfig[0x6c] = 0x41; in mtty_create_config_space()
233 mdev_state->vconfig[0x6d] = 0x52; in mtty_create_config_space()
234 mdev_state->vconfig[0x6e] = 0x54; in mtty_create_config_space()
237 static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset, in handle_pci_cfg_write() argument
248 mdev_state->vconfig[0x3c] = buf[0]; in handle_pci_cfg_write()
263 if ((mdev_state->nr_ports == 1) && (bar_index == 1)) { in handle_pci_cfg_write()
264 STORE_LE32(&mdev_state->vconfig[offset], 0); in handle_pci_cfg_write()
272 bar_mask = mdev_state->bar_mask[bar_index]; in handle_pci_cfg_write()
276 cfg_addr |= (mdev_state->vconfig[offset] & 0x3ul); in handle_pci_cfg_write()
277 STORE_LE32(&mdev_state->vconfig[offset], cfg_addr); in handle_pci_cfg_write()
282 STORE_LE32(&mdev_state->vconfig[offset], 0); in handle_pci_cfg_write()
291 static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, in handle_bar_write() argument
300 if (mdev_state->s[index].dlab) { in handle_bar_write()
301 mdev_state->s[index].divisor |= data; in handle_bar_write()
305 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_write()
308 if (mdev_state->s[index].rxtx.count < in handle_bar_write()
309 mdev_state->s[index].max_fifo_size) { in handle_bar_write()
310 mdev_state->s[index].rxtx.fifo[ in handle_bar_write()
311 mdev_state->s[index].rxtx.head] = data; in handle_bar_write()
312 mdev_state->s[index].rxtx.count++; in handle_bar_write()
313 CIRCULAR_BUF_INC_IDX(mdev_state->s[index].rxtx.head); in handle_bar_write()
314 mdev_state->s[index].overrun = false; in handle_bar_write()
320 if ((mdev_state->s[index].uart_reg[UART_IER] & in handle_bar_write()
322 (mdev_state->s[index].rxtx.count == in handle_bar_write()
323 mdev_state->s[index].intr_trigger_level)) { in handle_bar_write()
329 mtty_trigger_interrupt(mdev_state); in handle_bar_write()
335 mdev_state->s[index].overrun = true; in handle_bar_write()
341 if (mdev_state->s[index].uart_reg[UART_IER] & in handle_bar_write()
343 mtty_trigger_interrupt(mdev_state); in handle_bar_write()
345 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_write()
350 if (mdev_state->s[index].dlab) in handle_bar_write()
351 mdev_state->s[index].divisor |= (u16)data << 8; in handle_bar_write()
353 mdev_state->s[index].uart_reg[offset] = data; in handle_bar_write()
354 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_write()
356 (mdev_state->s[index].rxtx.head == in handle_bar_write()
357 mdev_state->s[index].rxtx.tail)) { in handle_bar_write()
362 mtty_trigger_interrupt(mdev_state); in handle_bar_write()
365 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_write()
371 mdev_state->s[index].fcr = data; in handle_bar_write()
373 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_write()
376 mdev_state->s[index].rxtx.count = 0; in handle_bar_write()
377 mdev_state->s[index].rxtx.head = 0; in handle_bar_write()
378 mdev_state->s[index].rxtx.tail = 0; in handle_bar_write()
380 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_write()
384 mdev_state->s[index].intr_trigger_level = 1; in handle_bar_write()
388 mdev_state->s[index].intr_trigger_level = 4; in handle_bar_write()
392 mdev_state->s[index].intr_trigger_level = 8; in handle_bar_write()
396 mdev_state->s[index].intr_trigger_level = 14; in handle_bar_write()
405 mdev_state->s[index].intr_trigger_level = 1; in handle_bar_write()
407 mdev_state->s[index].max_fifo_size = MAX_FIFO_SIZE; in handle_bar_write()
409 mdev_state->s[index].max_fifo_size = 1; in handle_bar_write()
410 mdev_state->s[index].intr_trigger_level = 1; in handle_bar_write()
417 mdev_state->s[index].dlab = true; in handle_bar_write()
418 mdev_state->s[index].divisor = 0; in handle_bar_write()
420 mdev_state->s[index].dlab = false; in handle_bar_write()
422 mdev_state->s[index].uart_reg[offset] = data; in handle_bar_write()
426 mdev_state->s[index].uart_reg[offset] = data; in handle_bar_write()
428 if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) && in handle_bar_write()
433 mtty_trigger_interrupt(mdev_state); in handle_bar_write()
436 if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) && in handle_bar_write()
441 mtty_trigger_interrupt(mdev_state); in handle_bar_write()
451 mdev_state->s[index].uart_reg[offset] = data; in handle_bar_write()
459 static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state, in handle_bar_read() argument
466 if (mdev_state->s[index].dlab) { in handle_bar_read()
467 *buf = (u8)mdev_state->s[index].divisor; in handle_bar_read()
471 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_read()
473 if (mdev_state->s[index].rxtx.head != in handle_bar_read()
474 mdev_state->s[index].rxtx.tail) { in handle_bar_read()
475 *buf = mdev_state->s[index].rxtx.fifo[ in handle_bar_read()
476 mdev_state->s[index].rxtx.tail]; in handle_bar_read()
477 mdev_state->s[index].rxtx.count--; in handle_bar_read()
478 CIRCULAR_BUF_INC_IDX(mdev_state->s[index].rxtx.tail); in handle_bar_read()
481 if (mdev_state->s[index].rxtx.head == in handle_bar_read()
482 mdev_state->s[index].rxtx.tail) { in handle_bar_read()
490 if (mdev_state->s[index].uart_reg[UART_IER] & in handle_bar_read()
492 mtty_trigger_interrupt(mdev_state); in handle_bar_read()
494 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_read()
499 if (mdev_state->s[index].dlab) { in handle_bar_read()
500 *buf = (u8)(mdev_state->s[index].divisor >> 8); in handle_bar_read()
503 *buf = mdev_state->s[index].uart_reg[offset] & 0x0f; in handle_bar_read()
508 u8 ier = mdev_state->s[index].uart_reg[UART_IER]; in handle_bar_read()
511 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_read()
513 if ((ier & UART_IER_RLSI) && mdev_state->s[index].overrun) in handle_bar_read()
518 (mdev_state->s[index].rxtx.count >= in handle_bar_read()
519 mdev_state->s[index].intr_trigger_level)) in handle_bar_read()
524 (mdev_state->s[index].rxtx.head == in handle_bar_read()
525 mdev_state->s[index].rxtx.tail)) in handle_bar_read()
530 (mdev_state->s[index].uart_reg[UART_MCR] & in handle_bar_read()
540 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_read()
546 *buf = mdev_state->s[index].uart_reg[offset]; in handle_bar_read()
553 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_read()
555 if (mdev_state->s[index].rxtx.head != in handle_bar_read()
556 mdev_state->s[index].rxtx.tail) in handle_bar_read()
560 if (mdev_state->s[index].overrun) in handle_bar_read()
564 if (mdev_state->s[index].rxtx.head == in handle_bar_read()
565 mdev_state->s[index].rxtx.tail) in handle_bar_read()
568 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_read()
575 mutex_lock(&mdev_state->rxtx_lock); in handle_bar_read()
577 if (mdev_state->s[index].uart_reg[UART_MCR] & in handle_bar_read()
579 if (mdev_state->s[index].rxtx.count < in handle_bar_read()
580 mdev_state->s[index].max_fifo_size) in handle_bar_read()
584 mutex_unlock(&mdev_state->rxtx_lock); in handle_bar_read()
589 *buf = mdev_state->s[index].uart_reg[offset]; in handle_bar_read()
597 static void mdev_read_base(struct mdev_state *mdev_state) in mdev_read_base() argument
607 if (!mdev_state->region_info[index].size) in mdev_read_base()
610 start_lo = (*(u32 *)(mdev_state->vconfig + pos)) & in mdev_read_base()
612 mem_type = (*(u32 *)(mdev_state->vconfig + pos)) & in mdev_read_base()
617 start_hi = (*(u32 *)(mdev_state->vconfig + pos + 4)); in mdev_read_base()
629 mdev_state->region_info[index].start = ((u64)start_hi << 32) | in mdev_read_base()
637 struct mdev_state *mdev_state; in mdev_access() local
645 mdev_state = mdev_get_drvdata(mdev); in mdev_access()
646 if (!mdev_state) { in mdev_access()
651 mutex_lock(&mdev_state->ops_lock); in mdev_access()
664 handle_pci_cfg_write(mdev_state, offset, buf, count); in mdev_access()
666 memcpy(buf, (mdev_state->vconfig + offset), count); in mdev_access()
673 if (!mdev_state->region_info[index].start) in mdev_access()
674 mdev_read_base(mdev_state); in mdev_access()
682 *buf, mdev_state->s[index].dlab); in mdev_access()
684 handle_bar_write(index, mdev_state, offset, buf, count); in mdev_access()
686 handle_bar_read(index, mdev_state, offset, buf, count); in mdev_access()
692 *buf, mdev_state->s[index].dlab); in mdev_access()
706 mutex_unlock(&mdev_state->ops_lock); in mdev_access()
713 struct mdev_state *mdev_state; in mtty_create() local
732 mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); in mtty_create()
733 if (mdev_state == NULL) in mtty_create()
736 mdev_state->nr_ports = nr_ports; in mtty_create()
737 mdev_state->irq_index = -1; in mtty_create()
738 mdev_state->s[0].max_fifo_size = MAX_FIFO_SIZE; in mtty_create()
739 mdev_state->s[1].max_fifo_size = MAX_FIFO_SIZE; in mtty_create()
740 mutex_init(&mdev_state->rxtx_lock); in mtty_create()
741 mdev_state->vconfig = kzalloc(MTTY_CONFIG_SPACE_SIZE, GFP_KERNEL); in mtty_create()
743 if (mdev_state->vconfig == NULL) { in mtty_create()
744 kfree(mdev_state); in mtty_create()
748 mutex_init(&mdev_state->ops_lock); in mtty_create()
749 mdev_state->mdev = mdev; in mtty_create()
750 mdev_set_drvdata(mdev, mdev_state); in mtty_create()
752 mtty_create_config_space(mdev_state); in mtty_create()
755 list_add(&mdev_state->next, &mdev_devices_list); in mtty_create()
763 struct mdev_state *mds, *tmp_mds; in mtty_remove()
764 struct mdev_state *mdev_state = mdev_get_drvdata(mdev); in mtty_remove() local
769 if (mdev_state == mds) { in mtty_remove()
770 list_del(&mdev_state->next); in mtty_remove()
772 kfree(mdev_state->vconfig); in mtty_remove()
773 kfree(mdev_state); in mtty_remove()
785 struct mdev_state *mdev_state; in mtty_reset() local
790 mdev_state = mdev_get_drvdata(mdev); in mtty_reset()
791 if (!mdev_state) in mtty_reset()
920 struct mdev_state *mdev_state; in mtty_set_irqs() local
925 mdev_state = mdev_get_drvdata(mdev); in mtty_set_irqs()
926 if (!mdev_state) in mtty_set_irqs()
929 mutex_lock(&mdev_state->ops_lock); in mtty_set_irqs()
940 if (mdev_state->intx_evtfd) in mtty_set_irqs()
941 eventfd_ctx_put(mdev_state->intx_evtfd); in mtty_set_irqs()
956 mdev_state->intx_evtfd = evt; in mtty_set_irqs()
957 mdev_state->irq_fd = fd; in mtty_set_irqs()
958 mdev_state->irq_index = index; in mtty_set_irqs()
973 if (mdev_state->msi_evtfd) in mtty_set_irqs()
974 eventfd_ctx_put(mdev_state->msi_evtfd); in mtty_set_irqs()
976 mdev_state->irq_index = VFIO_PCI_INTX_IRQ_INDEX; in mtty_set_irqs()
986 if (mdev_state->msi_evtfd) in mtty_set_irqs()
994 mdev_state->msi_evtfd = evt; in mtty_set_irqs()
995 mdev_state->irq_fd = fd; in mtty_set_irqs()
996 mdev_state->irq_index = index; in mtty_set_irqs()
1012 mutex_unlock(&mdev_state->ops_lock); in mtty_set_irqs()
1016 static int mtty_trigger_interrupt(struct mdev_state *mdev_state) in mtty_trigger_interrupt() argument
1020 if ((mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) && in mtty_trigger_interrupt()
1021 (!mdev_state->msi_evtfd)) in mtty_trigger_interrupt()
1023 else if ((mdev_state->irq_index == VFIO_PCI_INTX_IRQ_INDEX) && in mtty_trigger_interrupt()
1024 (!mdev_state->intx_evtfd)) { in mtty_trigger_interrupt()
1029 if (mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) in mtty_trigger_interrupt()
1030 ret = eventfd_signal(mdev_state->msi_evtfd, 1); in mtty_trigger_interrupt()
1032 ret = eventfd_signal(mdev_state->intx_evtfd, 1); in mtty_trigger_interrupt()
1048 struct mdev_state *mdev_state; in mtty_get_region_info() local
1054 mdev_state = mdev_get_drvdata(mdev); in mtty_get_region_info()
1055 if (!mdev_state) in mtty_get_region_info()
1062 mutex_lock(&mdev_state->ops_lock); in mtty_get_region_info()
1072 if (mdev_state->nr_ports == 2) in mtty_get_region_info()
1080 mdev_state->region_info[bar_index].size = size; in mtty_get_region_info()
1081 mdev_state->region_info[bar_index].vfio_offset = in mtty_get_region_info()
1088 mutex_unlock(&mdev_state->ops_lock); in mtty_get_region_info()
1132 struct mdev_state *mdev_state; in mtty_ioctl() local
1137 mdev_state = mdev_get_drvdata(mdev); in mtty_ioctl()
1138 if (!mdev_state) in mtty_ioctl()
1158 memcpy(&mdev_state->dev_info, &info, sizeof(info)); in mtty_ioctl()
1200 (info.index >= mdev_state->dev_info.num_irqs)) in mtty_ioctl()
1224 mdev_state->dev_info.num_irqs, in mtty_ioctl()
1335 struct mdev_state *mds; in available_instances_show()