Lines Matching defs:softc

68 static void amdvi_dump_cmds(struct amdvi_softc *softc, int count);
69 static void amdvi_print_dev_cap(struct amdvi_softc *softc);
124 amdvi_pci_read(struct amdvi_softc *softc, int off)
127 return (pci_cfgregread(softc->pci_seg, PCI_RID2BUS(softc->pci_rid),
128 PCI_RID2SLOT(softc->pci_rid), PCI_RID2FUNC(softc->pci_rid),
172 amdvi_dev_support_iotlb(struct amdvi_softc *softc, uint16_t devid)
182 KASSERT(softc, ("softc is NULL"));
183 cfg = softc->dev_cfg;
186 for (i = 0; i < softc->dev_cfg_cnt; i++) {
196 device_printf(softc->dev,
207 amdvi_hw_enable_iotlb(struct amdvi_softc *softc)
210 softc->iotlb = false;
214 supported = (softc->ivhd_flag & IVHD_FLAG_IOTLB) ? true : false;
216 if (softc->pci_cap & AMDVI_PCI_CAP_IOTLB) {
218 device_printf(softc->dev, "IOTLB disabled by BIOS.\n");
221 device_printf(softc->dev, "IOTLB disabled by user.\n");
227 softc->iotlb = supported;
233 amdvi_init_cmd(struct amdvi_softc *softc)
235 struct amdvi_ctrl *ctrl = softc->ctrl;
238 softc->cmd_max = 1 << ctrl->cmd.len;
240 softc->cmd = malloc(sizeof(struct amdvi_cmd) *
241 softc->cmd_max, M_AMDVI, M_WAITOK | M_ZERO);
243 if ((uintptr_t)softc->cmd & PAGE_MASK)
246 ctrl->cmd.base = vtophys(softc->cmd) / PAGE_SIZE;
264 amdvi_get_cmd_tail(struct amdvi_softc *softc)
269 KASSERT(softc, ("softc is NULL"));
270 KASSERT(softc->cmd != NULL, ("cmd is NULL"));
272 ctrl = softc->ctrl;
275 tail = (struct amdvi_cmd *)((uint8_t *)softc->cmd +
285 amdvi_update_cmd_tail(struct amdvi_softc *softc)
291 KASSERT(softc->cmd != NULL, ("cmd is NULL"));
293 ctrl = softc->ctrl;
296 ctrl->cmd_tail = MOD_INC(ctrl->cmd_tail, size, softc->cmd_max);
297 softc->total_cmd++;
300 device_printf(softc->dev, "cmd_tail: %s Tail:0x%x, Head:0x%x.\n",
313 amdvi_cmd_cmp(struct amdvi_softc *softc, const uint64_t data)
318 cmd = amdvi_get_cmd_tail(softc);
321 pa = vtophys(&softc->cmp_data);
327 amdvi_update_cmd_tail(softc);
332 amdvi_cmd_inv_dte(struct amdvi_softc *softc, uint16_t devid)
336 cmd = amdvi_get_cmd_tail(softc);
340 amdvi_update_cmd_tail(softc);
342 device_printf(softc->dev, "Invalidated DTE:0x%x\n", devid);
348 amdvi_cmd_inv_iommu_pages(struct amdvi_softc *softc, uint16_t domain_id,
354 cmd = amdvi_get_cmd_tail(softc);
366 amdvi_update_cmd_tail(softc);
372 amdvi_cmd_inv_iotlb(struct amdvi_softc *softc, uint16_t devid)
377 if (!softc->iotlb)
385 cmd = amdvi_get_cmd_tail(softc);
389 device_printf(softc->dev, "Invalidate IOTLB devID 0x%x"
397 amdvi_update_cmd_tail(softc);
403 amdvi_cmd_inv_intr_map(struct amdvi_softc *softc,
408 cmd = amdvi_get_cmd_tail(softc);
412 amdvi_update_cmd_tail(softc);
414 device_printf(softc->dev, "Invalidate INTR map of devID 0x%x\n", devid);
421 amdvi_inv_domain(struct amdvi_softc *softc, uint16_t domain_id)
425 cmd = amdvi_get_cmd_tail(softc);
432 amdvi_cmd_inv_iommu_pages(softc, domain_id, AMDVI_INVD_PAGE_ALL_ADDR,
436 device_printf(softc->dev, "Invalidate domain:0x%x\n", domain_id);
442 amdvi_cmp_wait(struct amdvi_softc *softc)
445 struct amdvi_ctrl *ctrl = softc->ctrl;
452 read = &softc->cmp_data;
454 amdvi_cmd_cmp(softc, VERIFY);
459 status = (VERIFY == softc->cmp_data) ? true : false;
463 device_printf(softc->dev, "CMD completion DONE Tail:0x%x, "
471 amdvi_wait(struct amdvi_softc *softc)
476 KASSERT(softc, ("softc is NULL"));
478 ctrl = softc->ctrl;
485 if (amdvi_cmp_wait(softc))
489 device_printf(softc->dev, "Error: completion failed"
493 amdvi_dump_cmds(softc, 1);
497 amdvi_dump_cmds(struct amdvi_softc *softc, int count)
503 ctrl = softc->ctrl;
504 device_printf(softc->dev, "Dump last %d command(s):\n", count);
510 softc->cmd_max);
512 cmd = (struct amdvi_cmd *)((uint8_t *)softc->cmd + off);
516 off = MOD_INC(off, sizeof(struct amdvi_cmd), softc->cmd_max);
521 amdvi_init_event(struct amdvi_softc *softc)
525 ctrl = softc->ctrl;
527 softc->event_max = 1 << ctrl->event.len;
528 softc->event = malloc(sizeof(struct amdvi_event) *
529 softc->event_max, M_AMDVI, M_WAITOK | M_ZERO);
530 if ((uintptr_t)softc->event & PAGE_MASK) {
531 device_printf(softc->dev, "Event buffer not aligned on page.");
534 ctrl->event.base = vtophys(softc->event) / PAGE_SIZE;
687 amdvi_print_events(struct amdvi_softc *softc)
693 ctrl = softc->ctrl;
695 for (i = 0; i < softc->event_max; i++) {
696 event = &softc->event[ctrl->evt_head / size];
699 device_printf(softc->dev, "\t[Event%d: Head:0x%x Tail:0x%x]\n",
703 softc->event_max);
708 amdvi_init_dte(struct amdvi_softc *softc)
712 ctrl = softc->ctrl;
726 struct amdvi_softc *softc;
729 softc = device_get_softc(dev);
730 off = softc->cap_off;
736 cap = amdvi_pci_read(softc, off);
742 softc->pci_cap = cap >> 24;
743 device_printf(softc->dev, "PCI cap 0x%x@0x%x feature:%b\n",
744 cap, off, softc->pci_cap,
753 struct amdvi_softc *softc;
756 softc = (struct amdvi_softc *)arg;
757 ctrl = softc->ctrl;
758 device_printf(softc->dev, "EVT INTR %ld Status:0x%x"
759 " EVT Head:0x%x Tail:0x%x]\n", softc->event_intr_cnt++,
762 softc->total_cmd, ctrl->cmd_tail, ctrl->cmd_head);
764 amdvi_print_events(softc);
772 struct amdvi_softc *softc;
775 softc = device_get_softc(dev);
776 mmio_dev = softc->pci_dev;
782 amdvi_alloc_intr_resources(struct amdvi_softc *softc)
788 dev = softc->dev;
789 mmio_dev = softc->pci_dev;
792 ctrl = softc->ctrl;
795 err = IVHD_SETUP_INTR(mmio_dev, amdvi_event_intr, softc, "fault");
803 amdvi_print_dev_cap(struct amdvi_softc *softc)
808 cfg = softc->dev_cfg;
809 for (i = 0; i < softc->dev_cfg_cnt; i++) {
810 device_printf(softc->dev, "device [0x%x - 0x%x] "
823 struct amdvi_softc *softc;
826 softc = (struct amdvi_softc *)arg1;
831 result = softc->ctrl->cmd_head;
836 result = softc->ctrl->cmd_tail;
841 result = softc->ctrl->evt_head;
846 result = softc->ctrl->evt_tail;
852 device_printf(softc->dev, "Unknown sysctl:%d\n", type);
859 amdvi_add_sysctl(struct amdvi_softc *softc)
865 dev = softc->dev;
870 &softc->event_intr_cnt, "Event interrupt count");
872 &softc->total_cmd, "Command submitted count");
874 &softc->pci_rid, 0, "IOMMU RID");
876 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, softc, 0,
879 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, softc, 1,
882 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, softc, 2,
885 CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_MPSAFE, softc, 3,
890 amdvi_setup_hw(struct amdvi_softc *softc)
895 dev = softc->dev;
897 amdvi_hw_enable_iotlb(softc);
899 amdvi_print_dev_cap(softc);
905 if ((status = amdvi_init_cmd(softc)) != 0) {
909 if ((status = amdvi_init_event(softc)) != 0) {
913 if ((status = amdvi_init_dte(softc)) != 0) {
917 if ((status = amdvi_alloc_intr_resources(softc)) != 0) {
920 amdvi_add_sysctl(softc);
925 amdvi_teardown_hw(struct amdvi_softc *softc)
929 dev = softc->dev;
936 if (softc->cmd)
937 free(softc->cmd, M_AMDVI);
939 if (softc->event)
940 free(softc->event, M_AMDVI);
985 struct amdvi_softc *softc;
989 softc = device_get_softc(ivhd_devs[i]);
990 KASSERT(softc, ("softc is NULL"));
996 if (create && ((softc->pci_cap & AMDVI_PCI_CAP_NPCACHE) == 0))
999 amdvi_inv_domain(softc, domain_id);
1000 amdvi_wait(softc);
1200 struct amdvi_softc *softc;
1204 softc = device_get_softc(ivhd_devs[i]);
1205 for (j = 0; j < softc->dev_cfg_cnt; j++)
1206 if ((devid >= softc->dev_cfg[j].start_id) &&
1207 (devid <= softc->dev_cfg[j].end_id))
1208 return (softc);
1220 amdvi_set_dte(struct amdvi_domain *domain, struct amdvi_softc *softc,
1226 KASSERT(softc, ("softc is NULL for pci_rid:0x%x\n", devid));
1232 if (amdvi_dev_support_iotlb(softc, devid) && softc->iotlb)
1259 amdvi_inv_device(struct amdvi_softc *softc, uint16_t devid)
1261 KASSERT(softc, ("softc is NULL"));
1263 amdvi_cmd_inv_dte(softc, devid);
1265 if (amdvi_dev_support_iotlb(softc, devid))
1266 amdvi_cmd_inv_iotlb(softc, devid);
1268 amdvi_wait(softc);
1275 struct amdvi_softc *softc;
1283 softc = amdvi_find_iommu(devid);
1284 if (softc == NULL)
1286 amdvi_set_dte(domain, softc, devid, true);
1287 amdvi_inv_device(softc, devid);
1294 struct amdvi_softc *softc;
1301 softc = amdvi_find_iommu(devid);
1302 if (softc == NULL)
1304 amdvi_set_dte(domain, softc, devid, false);
1305 amdvi_inv_device(softc, devid);
1312 struct amdvi_softc *softc;
1317 softc = device_get_softc(ivhd_devs[i]);
1318 KASSERT(softc, ("softc is NULL\n"));
1319 ctrl = softc->ctrl;
1328 if (softc->ivhd_flag & IVHD_FLAG_COH)
1330 if (softc->ivhd_flag & IVHD_FLAG_HTT)
1332 if (softc->ivhd_flag & IVHD_FLAG_RPPW)
1334 if (softc->ivhd_flag & IVHD_FLAG_PPW)
1336 if (softc->ivhd_flag & IVHD_FLAG_ISOC)
1347 struct amdvi_softc *softc;
1351 softc = device_get_softc(ivhd_devs[i]);
1352 KASSERT(softc, ("softc is NULL\n"));
1353 ctrl = softc->ctrl;