drm_pci.c revision 60405de4d8688d96dd05157c28db3ade5c9bc234
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Use is subject to license terms.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* BEGIN CSTYLED */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * \brief PCI consistent, DMA-accessible memory functions.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * \author Eric Anholt <anholt@FreeBSD.org>
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright 2003 Eric Anholt.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * All Rights Reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Permission is hereby granted, free of charge, to any person obtaining a
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * copy of this software and associated documentation files (the "Software"),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * to deal in the Software without restriction, including without limitation
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * the rights to use, copy, modify, merge, publish, distribute, sublicense,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and/or sell copies of the Software, and to permit persons to whom the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Software is furnished to do so, subject to the following conditions:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The above copyright notice and this permission notice (including the next
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * paragraph) shall be included in all copies or substantial portions of the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/**********************************************************************/
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/** \name PCI memory */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* END CSTYLED */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore#pragma ident "%Z%%M% %I% %E% SMI"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* Device info struct */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore uint16_t drm_venid; /* drm devcie's vendor id */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore uint16_t drm_devid; /* drm device's device id */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore uint8_t drm_irq; /* drm device's interrupt line */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned long offset;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore unsigned long size;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore/* Get IRQ line */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amorestatic int device_get_info(drm_device_info_t *data, ddi_acc_handle_t pch)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore venid is %x, devid is %x,irq is %x \n",
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amorepci_get_info(drm_softstate_t *softstate, int *bus, int *slot, int *func)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, softstate->dip,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DDI_PROP_DONTPASS, "reg", (int **)®s_list, &nregs)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DRM_ERROR("pci_get_info: get pci function bus device failed");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore bzero(&drm_info, sizeof (drm_device_info_t));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ret = device_get_info(&drm_info, softstate->pci_cfg_hdl);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore bzero(&drm_info, sizeof (drm_device_info_t));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ret = device_get_info(&drm_info, softstate->pci_cfg_hdl);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore bzero(&drm_info, sizeof (drm_device_info_t));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ret = device_get_info(&drm_info, softstate->pci_cfg_hdl);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoreagp_remap(struct drm_softstate *softstate, struct drm_local_map *map)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "agp_remap: map->handle:%lx map->offset %llx, map->size %lx\n",
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long)map->handle, map->offset.off,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore map->handle = (void *)((softstate->agp_umem_kvaddr) +
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long)(map->offset.off - softstate->agp->base));
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DRM_DEBUG("agp_remap: map->dev_addr is %lx",
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoreagp_remap_free(struct drm_softstate *softstate, struct drm_local_map *map)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredrm_core_ioremap(struct drm_local_map *map, struct drm_softstate *softstate)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredrm_core_ioremapfree(struct drm_local_map *map, struct drm_softstate *softstate)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredrm_core_findmap(struct drm_softstate *dev, unsigned long offset)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((unsigned long)map->offset.off == offset)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * pci_alloc_consistent()
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long long)0,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long long)0xffffffff,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long long)0xffffffff,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long long)4096,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long long)0xffffffff,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long long)0xffffffff,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredrm_pci_alloc(drm_softstate_t *dev, uint32_t size,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* allocat continous physical memory for hw status page */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DRM_ERROR("drm_pci_alloc:ddi_dma_alloc_handle failed\n");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if (ret = ddi_dma_mem_alloc(dev->hw_dma_handle,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DRM_ERROR("drm_pci_alloc: ddi_dma_mem_alloc failed\n");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ret = ddi_dma_addr_bind_handle(dev->hw_dma_handle,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((ret != DDI_DMA_MAPPED) || (num_cookies != 1)) {
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) ddi_dma_unbind_handle(dev->hw_dma_handle);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DRM_ERROR("drm_pci_alloc: alloc contiguous phys memory failed");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * pci_free_consistent()
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (void) ddi_dma_unbind_handle(dev->hw_dma_handle);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredo_get_pci_res(drm_softstate_t *softstate, drm_pci_resource_t *resp)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DDI_DEV_T_ANY, softstate->dip, DDI_PROP_DONTPASS,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "assigned-addresses", (caddr_t)®s, &length) !=
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore DRM_ERROR("do_get_pci_res: ddi_getlongprop failed!\n");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long)regs[resp->regnum].pci_phys_low;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore (unsigned long)regs[resp->regnum].pci_size_low;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredrm_get_resource_start(drm_softstate_t *softstate, unsigned int regnum)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "drm_get_resource_start: "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "DRM_GET_PCI_RESOURCE ioctl failed");
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredrm_get_resource_len(drm_softstate_t *softstate, unsigned int regnum)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "drm_get_resource_len: "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "DRM_GET_PCI_RESOURCE ioctl failed");