1450N/A/*
1450N/A * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A/*
1450N/A * ati_pcigart.h -- ATI PCI GART support -*- linux-c -*-
1450N/A * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
1450N/A */
1450N/A/*
1450N/A * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
1450N/A * All Rights Reserved.
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the "Software"),
1450N/A * to deal in the Software without restriction, including without limitation
1450N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1450N/A * and/or sell copies of the Software, and to permit persons to whom the
1450N/A * Software is furnished to do so, subject to the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the next
1450N/A * paragraph) shall be included in all copies or substantial portions of the
1450N/A * Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1450N/A * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1450N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1450N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1450N/A * DEALINGS IN THE SOFTWARE.
1450N/A *
1450N/A * Authors:
1450N/A * Gareth Hughes <gareth@valinux.com>
1450N/A *
1450N/A */
1450N/A
1450N/A#include "drmP.h"
1450N/A
1450N/A#define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
1450N/A#define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */
1450N/A#define ATI_PCIGART_TABLE_SIZE 32768
1450N/A
1450N/Aint
1450N/Adrm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
1450N/A{
1450N/A unsigned long pages;
1450N/A drm_sg_mem_t *entry;
1450N/A drm_dma_handle_t *dmah;
1450N/A u32 *pci_gart = NULL, page_base;
1450N/A int i, j, k;
1450N/A int pagenum;
1450N/A size_t bulksize;
1450N/A
1450N/A entry = dev->sg;
1450N/A if (entry == NULL) {
1450N/A DRM_ERROR("no scatter/gather memory!\n");
1450N/A return (0);
1450N/A }
1450N/A
1450N/A if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
1450N/A /* GART table in system memory */
1450N/A entry->dmah_gart = drm_pci_alloc(dev, ATI_PCIGART_TABLE_SIZE, 0,
1450N/A 0xfffffffful, 1);
1450N/A if (entry->dmah_gart == NULL) {
1450N/A DRM_ERROR("cannot allocate PCI GART table!\n");
1450N/A return (0);
1450N/A }
1450N/A gart_info->addr = (void *)entry->dmah_gart->vaddr;
1450N/A gart_info->bus_addr = entry->dmah_gart->paddr;
1450N/A pci_gart = (u32 *)entry->dmah_gart->vaddr;
1450N/A } else {
1450N/A /* GART table in framebuffer memory */
1450N/A pci_gart = gart_info->addr;
1450N/A }
1450N/A
1450N/A pages = DRM_MIN(entry->pages, ATI_MAX_PCIGART_PAGES);
1450N/A bzero(pci_gart, ATI_PCIGART_TABLE_SIZE);
1450N/A#ifndef __lint
1450N/A ASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE);
1450N/A#endif
1450N/A
1450N/A dmah = entry->dmah_sg;
1450N/A pagenum = 0;
1450N/A for (i = 0; i < dmah->cookie_num; i++) {
1450N/A bulksize = dmah->cookie.dmac_size;
1450N/A for (k = 0; k < bulksize / PAGE_SIZE; k++) {
1450N/A entry->busaddr[pagenum] =
1450N/A dmah->cookie.dmac_address + k * PAGE_SIZE;
1450N/A page_base = (u32) entry->busaddr[pagenum];
1450N/A if (pagenum ++ == pages)
1450N/A goto out;
1450N/A for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE);
1450N/A j++) {
1450N/A if (gart_info->is_pcie)
1450N/A *pci_gart = (page_base >> 8) | 0xc;
1450N/A else
1450N/A *pci_gart = page_base;
1450N/A pci_gart++;
1450N/A page_base += ATI_PCIGART_PAGE_SIZE;
1450N/A }
1450N/A }
1450N/A ddi_dma_nextcookie(dmah->dma_hdl, &dmah->cookie);
1450N/A }
1450N/A
1450N/Aout:
1450N/A if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
1450N/A (void) ddi_dma_sync(entry->dmah_gart->dma_hdl, 0,
1450N/A entry->dmah_gart->real_sz, DDI_DMA_SYNC_FORDEV);
1450N/A }
1450N/A
1450N/A return (1);
1450N/A}
1450N/A
1450N/Aextern int
1450N/Adrm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
1450N/A{
1450N/A _NOTE(ARGUNUSED(gart_info))
1450N/A
1450N/A drm_dma_handle_t *dmah;
1450N/A
1450N/A if (dev->sg == NULL) {
1450N/A DRM_ERROR("no scatter/gather memory!\n");
1450N/A return (0);
1450N/A }
1450N/A dmah = dev->sg->dmah_gart;
1450N/A dev->sg->dmah_gart = NULL;
1450N/A if (dmah)
1450N/A drm_pci_free(dev, dmah);
1450N/A return (1);
1450N/A}