Lines Matching +full:bypass +full:- +full:slot +full:- +full:no
1 /*-
2 * Copyright (c) 2015-2016 Nathan Whitehorn
3 * Copyright (c) 2017-2018 Semihalf
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186 if (!OF_hasprop(ofw_bus_get_node(dev), "ibm,opal-phbid")) in opalpci_probe()
189 device_set_desc(dev, "OPAL Host-PCI bridge"); in opalpci_probe()
198 bus_write_8(sc->r_reg, 0x210, PHB3_TCE_KILL_INVAL_ALL); in pci_phb3_tce_invalidate_entire()
207 return (1 << (flsl(val + (val - 1)) - 1)); in round_pow2()
212 * "ibm,supported-tce-sizes", to denote the TCE sizes available. This allows us
213 * to avoid hard-coding the maximum TCE size allowed, and instead provide a sane
221 cell_t sizes[64]; /* Property is a list of bit-widths, up to 64-bits */ in max_tce_size()
226 count = OF_getencprop(node, "ibm,supported-tce-sizes", in max_tce_size()
233 return (1ULL << sizes[count - 1]); in max_tce_size()
253 switch (OF_getproplen(node, "ibm,opal-phbid")) { in opalpci_attach()
255 OF_getencprop(node, "ibm,opal-phbid", id, 8); in opalpci_attach()
256 sc->phb_id = ((uint64_t)id[0] << 32) | id[1]; in opalpci_attach()
259 OF_getencprop(node, "ibm,opal-phbid", id, 4); in opalpci_attach()
260 sc->phb_id = id[0]; in opalpci_attach()
264 OF_getproplen(node, "ibm,opal-phbid")); in opalpci_attach()
269 device_printf(dev, "OPAL ID %#lx\n", sc->phb_id); in opalpci_attach()
272 sc->r_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in opalpci_attach()
274 if (sc->r_reg == NULL) { in opalpci_attach()
276 (uintmax_t)sc->phb_id); in opalpci_attach()
284 err = opal_call(OPAL_PCI_RESET, sc->phb_id, OPAL_RESET_PCI_IODA_TABLE, in opalpci_attach()
290 err = opal_call(OPAL_PCI_RESET, sc->phb_id, OPAL_RESET_PHB_COMPLETE, in opalpci_attach()
297 while ((err = opal_call(OPAL_PCI_POLL, sc->phb_id)) > 0) { in opalpci_attach()
304 err = opal_call(OPAL_PCI_RESET, sc->phb_id, OPAL_RESET_PHB_COMPLETE, in opalpci_attach()
311 while ((err = opal_call(OPAL_PCI_POLL, sc->phb_id)) > 0) { in opalpci_attach()
321 err = opal_call(OPAL_PCI_SET_PE, sc->phb_id, OPAL_PCI_DEFAULT_PE, in opalpci_attach()
332 if (OF_getencprop(node, "ibm,opal-num-pes", &npe, 4) != 4) in opalpci_attach()
335 err = opal_call(OPAL_PCI_MAP_PE_MMIO_WINDOW, sc->phb_id, in opalpci_attach()
341 if (OF_getencprop(node, "ibm,opal-available-m64-ranges", in opalpci_attach()
348 if (OF_getencprop(node, "ibm,opal-m64-window", in opalpci_attach()
350 opal_call(OPAL_PCI_PHB_MMIO_ENABLE, sc->phb_id, in opalpci_attach()
352 opal_call(OPAL_PCI_SET_PHB_MEM_WINDOW, sc->phb_id, in opalpci_attach()
356 opal_call(OPAL_PCI_MAP_PE_MMIO_WINDOW, sc->phb_id, in opalpci_attach()
359 opal_call(OPAL_PCI_PHB_MMIO_ENABLE, sc->phb_id, in opalpci_attach()
364 * Enable IOMMU for PE1 - map everything 1:1 using in opalpci_attach()
375 device_printf(dev, "Mapping 0-%#jx for DMA\n", (uintmax_t)maxmem); in opalpci_attach()
376 sc->tce = contigmalloc(tce_tbl_size, in opalpci_attach()
379 if (sc->tce == NULL) in opalpci_attach()
381 (uintmax_t)sc->phb_id); in opalpci_attach()
384 sc->tce[i] = htobe64((i * tce_size) | OPAL_PCI_TCE_R | OPAL_PCI_TCE_W); in opalpci_attach()
388 err = opal_call(OPAL_PCI_MAP_PE_DMA_WINDOW, sc->phb_id, in opalpci_attach()
390 1, pmap_kextract((uint64_t)&sc->tce[0]), in opalpci_attach()
397 err = opal_call(OPAL_PCI_MAP_PE_DMA_WINDOW_REAL, sc->phb_id, in opalpci_attach()
401 device_printf(dev, "DMA 64b bypass mapping failed: %d\n", err); in opalpci_attach()
409 if (ofw_bus_is_compatible(dev, "power8-pciex")) in opalpci_attach()
412 opal_call(OPAL_PCI_TCE_KILL, sc->phb_id, OPAL_PCI_TCE_KILL_ALL, in opalpci_attach()
418 sc->msi_vmem = NULL; in opalpci_attach()
419 if (OF_getproplen(node, "ibm,opal-msi-ranges") > 0) { in opalpci_attach()
421 OF_getencprop(node, "ibm,opal-msi-ranges", in opalpci_attach()
423 sc->msi_base = msi_ranges[0]; in opalpci_attach()
425 sc->msi_vmem = vmem_create("OPAL MSI", msi_ranges[0], in opalpci_attach()
428 sc->base_msi_irq = powerpc_register_pic(dev, in opalpci_attach()
442 if (ofw_bus_is_compatible(dev, "ibm,ioda2-phb")) { in opalpci_attach()
453 &sc->ofw_sc.sc_dmat); in opalpci_attach()
468 * Unfreeze non-config-space PCI operations. Let this fail silently in opalpci_attach()
469 * if e.g. there is no current freeze. in opalpci_attach()
471 opal_call(OPAL_PCI_EEH_FREEZE_CLEAR, sc->phb_id, OPAL_PCI_DEFAULT_PE, in opalpci_attach()
475 * OPAL stores 64-bit BARs in a special property rather than "ranges" in opalpci_attach()
477 if (OF_getencprop(node, "ibm,opal-m64-window", in opalpci_attach()
481 sc->ofw_sc.sc_nrange++; in opalpci_attach()
482 sc->ofw_sc.sc_range = realloc(sc->ofw_sc.sc_range, in opalpci_attach()
483 sc->ofw_sc.sc_nrange * sizeof(sc->ofw_sc.sc_range[0]), in opalpci_attach()
485 rp = &sc->ofw_sc.sc_range[sc->ofw_sc.sc_nrange-1]; in opalpci_attach()
486 rp->pci_hi = OFW_PCI_PHYS_HI_SPACE_MEM64 | in opalpci_attach()
488 rp->pci = ((uint64_t)m64window[0] << 32) | m64window[1]; in opalpci_attach()
489 rp->host = ((uint64_t)m64window[2] << 32) | m64window[3]; in opalpci_attach()
490 rp->size = ((uint64_t)m64window[4] << 32) | m64window[5]; in opalpci_attach()
491 rman_manage_region(&sc->ofw_sc.sc_mem_rman, rp->pci, in opalpci_attach()
492 rp->pci + rp->size - 1); in opalpci_attach()
499 opalpci_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, in opalpci_read_config() argument
512 config_addr = (bus << 8) | ((slot & 0x1f) << 3) | (func & 0x7); in opalpci_read_config()
516 error = opal_call(OPAL_PCI_CONFIG_READ_BYTE, sc->phb_id, in opalpci_read_config()
521 error = opal_call(OPAL_PCI_CONFIG_READ_HALF_WORD, sc->phb_id, in opalpci_read_config()
526 error = opal_call(OPAL_PCI_CONFIG_READ_WORD, sc->phb_id, in opalpci_read_config()
537 * Poking config state for non-existant devices can make in opalpci_read_config()
542 (word == ((1UL << (8 * width)) - 1))) { in opalpci_read_config()
544 opal_call(OPAL_PCI_EEH_FREEZE_STATUS, sc->phb_id, in opalpci_read_config()
550 sc->phb_id, OPAL_PCI_DEFAULT_PE, in opalpci_read_config()
561 opalpci_write_config(device_t dev, u_int bus, u_int slot, u_int func, in opalpci_write_config() argument
570 config_addr = (bus << 8) | ((slot & 0x1f) << 3) | (func & 0x7); in opalpci_write_config()
574 error = opal_call(OPAL_PCI_CONFIG_WRITE_BYTE, sc->phb_id, in opalpci_write_config()
578 error = opal_call(OPAL_PCI_CONFIG_WRITE_HALF_WORD, sc->phb_id, in opalpci_write_config()
582 error = opal_call(OPAL_PCI_CONFIG_WRITE_WORD, sc->phb_id, in opalpci_write_config()
589 * Poking config state for non-existant devices can make in opalpci_write_config()
594 sc->phb_id, OPAL_PCI_DEFAULT_PE, in opalpci_write_config()
617 if (sc->msi_vmem == NULL) in opalpci_alloc_msi()
620 err = vmem_xalloc(sc->msi_vmem, count, powerof2(count), 0, 0, in opalpci_alloc_msi()
639 if (sc->msi_vmem == NULL) in opalpci_release_msi()
642 vmem_xfree(sc->msi_vmem, irqs[0] - sc->base_msi_irq, count); in opalpci_release_msi()
667 if (sc->msi_vmem == NULL) in opalpci_map_msi()
670 xive = irq - sc->base_msi_irq - sc->msi_base; in opalpci_map_msi()
671 opal_call(OPAL_PCI_SET_XIVE_PE, sc->phb_id, OPAL_PCI_DEFAULT_PE, xive); in opalpci_map_msi()
674 if (dinfo->cfg.msi.msi_alloc > 0 && in opalpci_map_msi()
675 (dinfo->cfg.msi.msi_ctrl & PCIM_MSICTRL_64BIT) == 0) { in opalpci_map_msi()
677 err = opal_call(OPAL_GET_MSI_32, sc->phb_id, in opalpci_map_msi()
682 err = opal_call(OPAL_GET_MSI_64, sc->phb_id, in opalpci_map_msi()
700 opal_call(OPAL_PCI_MSI_EOI, sc->phb_id, irq, priv); in opalpic_pic_enable()
708 opal_call(OPAL_PCI_MSI_EOI, sc->phb_id, irq); in opalpic_pic_eoi()
719 return (sc->ofw_sc.sc_dmat); in opalpci_get_dma_tag()