2005-04-16 18:20:36 -04:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000,2002-2005 Silicon Graphics, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Routines for PCI DMA mapping. See Documentation/DMA-API.txt for
|
|
|
|
* a description of how these routines should be used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2008-04-29 04:00:32 -04:00
|
|
|
#include <linux/dma-attrs.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
#include <asm/dma.h>
|
2006-04-14 17:03:54 -04:00
|
|
|
#include <asm/sn/intr.h>
|
2005-04-25 14:32:16 -04:00
|
|
|
#include <asm/sn/pcibus_provider_defs.h>
|
|
|
|
#include <asm/sn/pcidev.h>
|
2005-07-06 18:26:51 -04:00
|
|
|
#include <asm/sn/sn_sal.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2007-10-22 14:02:46 -04:00
|
|
|
#define SG_ENT_VIRT_ADDRESS(sg) (sg_virt((sg)))
|
2005-04-16 18:20:36 -04:00
|
|
|
#define SG_ENT_PHYS_ADDRESS(SG) virt_to_phys(SG_ENT_VIRT_ADDRESS(SG))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sn_dma_supported - test a DMA mask
|
|
|
|
* @dev: device to test
|
|
|
|
* @mask: DMA mask to test
|
|
|
|
*
|
|
|
|
* Return whether the given PCI device DMA address mask can be supported
|
|
|
|
* properly. For example, if your device can only drive the low 24-bits
|
|
|
|
* during PCI bus mastering, then you would pass 0x00ffffff as the mask to
|
|
|
|
* this function. Of course, SN only supports devices that have 32 or more
|
|
|
|
* address bits when using the PMU.
|
|
|
|
*/
|
|
|
|
int sn_dma_supported(struct device *dev, u64 mask)
|
|
|
|
{
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
|
|
|
if (mask < 0x7fffffff)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_supported);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sn_dma_set_mask - set the DMA mask
|
|
|
|
* @dev: device to set
|
|
|
|
* @dma_mask: new mask
|
|
|
|
*
|
|
|
|
* Set @dev's DMA mask if the hw supports it.
|
|
|
|
*/
|
|
|
|
int sn_dma_set_mask(struct device *dev, u64 dma_mask)
|
|
|
|
{
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
|
|
|
if (!sn_dma_supported(dev, dma_mask))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*dev->dma_mask = dma_mask;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_set_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sn_dma_alloc_coherent - allocate memory for coherent DMA
|
|
|
|
* @dev: device to allocate for
|
|
|
|
* @size: size of the region
|
|
|
|
* @dma_handle: DMA (bus) address
|
|
|
|
* @flags: memory allocation flags
|
|
|
|
*
|
|
|
|
* dma_alloc_coherent() returns a pointer to a memory region suitable for
|
|
|
|
* coherent DMA traffic to/from a PCI device. On SN platforms, this means
|
|
|
|
* that @dma_handle will have the %PCIIO_DMA_CMD flag set.
|
|
|
|
*
|
|
|
|
* This interface is usually used for "command" streams (e.g. the command
|
|
|
|
* queue for a SCSI controller). See Documentation/DMA-API.txt for
|
|
|
|
* more information.
|
|
|
|
*/
|
|
|
|
void *sn_dma_alloc_coherent(struct device *dev, size_t size,
|
2005-10-21 03:21:03 -04:00
|
|
|
dma_addr_t * dma_handle, gfp_t flags)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
void *cpuaddr;
|
|
|
|
unsigned long phys_addr;
|
2005-07-12 19:03:00 -04:00
|
|
|
int node;
|
2005-04-25 14:26:03 -04:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the memory.
|
|
|
|
*/
|
2005-07-12 19:03:00 -04:00
|
|
|
node = pcibus_to_node(pdev->bus);
|
|
|
|
if (likely(node >=0)) {
|
2006-01-24 17:30:56 -05:00
|
|
|
struct page *p = alloc_pages_node(node, flags, get_order(size));
|
2005-07-12 19:03:00 -04:00
|
|
|
|
|
|
|
if (likely(p))
|
|
|
|
cpuaddr = page_address(p);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
} else
|
2006-01-24 17:30:56 -05:00
|
|
|
cpuaddr = (void *)__get_free_pages(flags, get_order(size));
|
2005-07-12 19:03:00 -04:00
|
|
|
|
|
|
|
if (unlikely(!cpuaddr))
|
2005-04-16 18:20:36 -04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(cpuaddr, 0x0, size);
|
|
|
|
|
|
|
|
/* physical addr. of the memory we just got */
|
|
|
|
phys_addr = __pa(cpuaddr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 64 bit address translations should never fail.
|
|
|
|
* 32 bit translations can fail if there are insufficient mapping
|
|
|
|
* resources.
|
|
|
|
*/
|
|
|
|
|
2006-04-14 17:03:54 -04:00
|
|
|
*dma_handle = provider->dma_map_consistent(pdev, phys_addr, size,
|
|
|
|
SN_DMA_ADDR_PHYS);
|
2005-04-16 18:20:36 -04:00
|
|
|
if (!*dma_handle) {
|
2008-03-04 18:15:00 -05:00
|
|
|
printk(KERN_ERR "%s: out of ATEs\n", __func__);
|
2005-04-16 18:20:36 -04:00
|
|
|
free_pages((unsigned long)cpuaddr, get_order(size));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpuaddr;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_alloc_coherent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sn_pci_free_coherent - free memory associated with coherent DMAable region
|
|
|
|
* @dev: device to free for
|
|
|
|
* @size: size to free
|
|
|
|
* @cpu_addr: kernel virtual address to free
|
|
|
|
* @dma_handle: DMA address associated with this region
|
|
|
|
*
|
|
|
|
* Frees the memory allocated by dma_alloc_coherent(), potentially unmapping
|
|
|
|
* any associated IOMMU mappings.
|
|
|
|
*/
|
|
|
|
void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
|
|
|
|
dma_addr_t dma_handle)
|
|
|
|
{
|
2005-04-25 14:26:03 -04:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
2005-04-25 14:26:03 -04:00
|
|
|
provider->dma_unmap(pdev, dma_handle, 0);
|
2005-04-16 18:20:36 -04:00
|
|
|
free_pages((unsigned long)cpu_addr, get_order(size));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_free_coherent);
|
|
|
|
|
|
|
|
/**
|
2008-04-29 04:00:32 -04:00
|
|
|
* sn_dma_map_single_attrs - map a single page for DMA
|
2005-04-16 18:20:36 -04:00
|
|
|
* @dev: device to map for
|
|
|
|
* @cpu_addr: kernel virtual address of the region to map
|
|
|
|
* @size: size of the region
|
|
|
|
* @direction: DMA direction
|
2008-04-29 04:00:32 -04:00
|
|
|
* @attrs: optional dma attributes
|
2005-04-16 18:20:36 -04:00
|
|
|
*
|
|
|
|
* Map the region pointed to by @cpu_addr for DMA and return the
|
|
|
|
* DMA address.
|
|
|
|
*
|
|
|
|
* We map this to the one step pcibr_dmamap_trans interface rather than
|
|
|
|
* the two step pcibr_dmamap_alloc/pcibr_dmamap_addr because we have
|
|
|
|
* no way of saving the dmamap handle from the alloc to later free
|
|
|
|
* (which is pretty much unacceptable).
|
|
|
|
*
|
2008-04-29 04:00:32 -04:00
|
|
|
* mappings with the DMA_ATTR_WRITE_BARRIER get mapped with
|
|
|
|
* dma_map_consistent() so that writes force a flush of pending DMA.
|
|
|
|
* (See "SGI Altix Architecture Considerations for Linux Device Drivers",
|
|
|
|
* Document Number: 007-4763-001)
|
|
|
|
*
|
2005-04-16 18:20:36 -04:00
|
|
|
* TODO: simplify our interface;
|
|
|
|
* figure out how to save dmamap handle so can use two step.
|
|
|
|
*/
|
2008-04-29 04:00:32 -04:00
|
|
|
dma_addr_t sn_dma_map_single_attrs(struct device *dev, void *cpu_addr,
|
|
|
|
size_t size, int direction,
|
|
|
|
struct dma_attrs *attrs)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
unsigned long phys_addr;
|
2005-04-25 14:26:03 -04:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2008-04-29 04:00:32 -04:00
|
|
|
int dmabarr;
|
|
|
|
|
|
|
|
dmabarr = dma_get_attr(DMA_ATTR_WRITE_BARRIER, attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
|
|
|
phys_addr = __pa(cpu_addr);
|
2008-04-29 04:00:32 -04:00
|
|
|
if (dmabarr)
|
|
|
|
dma_addr = provider->dma_map_consistent(pdev, phys_addr,
|
|
|
|
size, SN_DMA_ADDR_PHYS);
|
|
|
|
else
|
|
|
|
dma_addr = provider->dma_map(pdev, phys_addr, size,
|
|
|
|
SN_DMA_ADDR_PHYS);
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
if (!dma_addr) {
|
2008-03-04 18:15:00 -05:00
|
|
|
printk(KERN_ERR "%s: out of ATEs\n", __func__);
|
2005-04-16 18:20:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return dma_addr;
|
|
|
|
}
|
2008-04-29 04:00:32 -04:00
|
|
|
EXPORT_SYMBOL(sn_dma_map_single_attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
/**
|
2008-04-29 04:00:32 -04:00
|
|
|
* sn_dma_unmap_single_attrs - unamp a DMA mapped page
|
2005-04-16 18:20:36 -04:00
|
|
|
* @dev: device to sync
|
|
|
|
* @dma_addr: DMA address to sync
|
|
|
|
* @size: size of region
|
|
|
|
* @direction: DMA direction
|
2008-04-29 04:00:32 -04:00
|
|
|
* @attrs: optional dma attributes
|
2005-04-16 18:20:36 -04:00
|
|
|
*
|
|
|
|
* This routine is supposed to sync the DMA region specified
|
|
|
|
* by @dma_handle into the coherence domain. On SN, we're always cache
|
|
|
|
* coherent, so we just need to free any ATEs associated with this mapping.
|
|
|
|
*/
|
2008-04-29 04:00:32 -04:00
|
|
|
void sn_dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr,
|
|
|
|
size_t size, int direction,
|
|
|
|
struct dma_attrs *attrs)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2005-04-25 14:26:03 -04:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
2005-04-25 14:26:03 -04:00
|
|
|
|
|
|
|
provider->dma_unmap(pdev, dma_addr, direction);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
2008-04-29 04:00:32 -04:00
|
|
|
EXPORT_SYMBOL(sn_dma_unmap_single_attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
/**
|
2008-04-29 04:00:32 -04:00
|
|
|
* sn_dma_unmap_sg_attrs - unmap a DMA scatterlist
|
2005-04-16 18:20:36 -04:00
|
|
|
* @dev: device to unmap
|
|
|
|
* @sg: scatterlist to unmap
|
|
|
|
* @nhwentries: number of scatterlist entries
|
|
|
|
* @direction: DMA direction
|
2008-04-29 04:00:32 -04:00
|
|
|
* @attrs: optional dma attributes
|
2005-04-16 18:20:36 -04:00
|
|
|
*
|
|
|
|
* Unmap a set of streaming mode DMA translations.
|
|
|
|
*/
|
2008-04-29 04:00:32 -04:00
|
|
|
void sn_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sgl,
|
|
|
|
int nhwentries, int direction,
|
|
|
|
struct dma_attrs *attrs)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
int i;
|
2005-04-25 14:26:03 -04:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2007-10-16 05:27:26 -04:00
|
|
|
struct scatterlist *sg;
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
2007-10-16 05:27:26 -04:00
|
|
|
for_each_sg(sgl, sg, nhwentries, i) {
|
2005-04-25 14:26:03 -04:00
|
|
|
provider->dma_unmap(pdev, sg->dma_address, direction);
|
2005-04-16 18:20:36 -04:00
|
|
|
sg->dma_address = (dma_addr_t) NULL;
|
|
|
|
sg->dma_length = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-04-29 04:00:32 -04:00
|
|
|
EXPORT_SYMBOL(sn_dma_unmap_sg_attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
/**
|
2008-04-29 04:00:32 -04:00
|
|
|
* sn_dma_map_sg_attrs - map a scatterlist for DMA
|
2005-04-16 18:20:36 -04:00
|
|
|
* @dev: device to map for
|
|
|
|
* @sg: scatterlist to map
|
|
|
|
* @nhwentries: number of entries
|
|
|
|
* @direction: direction of the DMA transaction
|
2008-04-29 04:00:32 -04:00
|
|
|
* @attrs: optional dma attributes
|
|
|
|
*
|
|
|
|
* mappings with the DMA_ATTR_WRITE_BARRIER get mapped with
|
|
|
|
* dma_map_consistent() so that writes force a flush of pending DMA.
|
|
|
|
* (See "SGI Altix Architecture Considerations for Linux Device Drivers",
|
|
|
|
* Document Number: 007-4763-001)
|
2005-04-16 18:20:36 -04:00
|
|
|
*
|
|
|
|
* Maps each entry of @sg for DMA.
|
|
|
|
*/
|
2008-04-29 04:00:32 -04:00
|
|
|
int sn_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
|
|
|
|
int nhwentries, int direction, struct dma_attrs *attrs)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
unsigned long phys_addr;
|
2007-10-16 05:27:26 -04:00
|
|
|
struct scatterlist *saved_sg = sgl, *sg;
|
2005-04-25 14:26:03 -04:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
|
2005-04-16 18:20:36 -04:00
|
|
|
int i;
|
2008-04-29 04:00:32 -04:00
|
|
|
int dmabarr;
|
|
|
|
|
|
|
|
dmabarr = dma_get_attr(DMA_ATTR_WRITE_BARRIER, attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup a DMA address for each entry in the scatterlist.
|
|
|
|
*/
|
2007-10-16 05:27:26 -04:00
|
|
|
for_each_sg(sgl, sg, nhwentries, i) {
|
2008-04-29 04:00:32 -04:00
|
|
|
dma_addr_t dma_addr;
|
2005-04-16 18:20:36 -04:00
|
|
|
phys_addr = SG_ENT_PHYS_ADDRESS(sg);
|
2008-04-29 04:00:32 -04:00
|
|
|
if (dmabarr)
|
|
|
|
dma_addr = provider->dma_map_consistent(pdev,
|
|
|
|
phys_addr,
|
|
|
|
sg->length,
|
|
|
|
SN_DMA_ADDR_PHYS);
|
|
|
|
else
|
|
|
|
dma_addr = provider->dma_map(pdev, phys_addr,
|
|
|
|
sg->length,
|
|
|
|
SN_DMA_ADDR_PHYS);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2008-04-29 04:00:32 -04:00
|
|
|
sg->dma_address = dma_addr;
|
2005-04-16 18:20:36 -04:00
|
|
|
if (!sg->dma_address) {
|
2008-03-04 18:15:00 -05:00
|
|
|
printk(KERN_ERR "%s: out of ATEs\n", __func__);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free any successfully allocated entries.
|
|
|
|
*/
|
|
|
|
if (i > 0)
|
2008-04-29 04:00:32 -04:00
|
|
|
sn_dma_unmap_sg_attrs(dev, saved_sg, i,
|
|
|
|
direction, attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sg->dma_length = sg->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nhwentries;
|
|
|
|
}
|
2008-04-29 04:00:32 -04:00
|
|
|
EXPORT_SYMBOL(sn_dma_map_sg_attrs);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
void sn_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
size_t size, int direction)
|
|
|
|
{
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_sync_single_for_cpu);
|
|
|
|
|
|
|
|
void sn_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
|
|
|
|
size_t size, int direction)
|
|
|
|
{
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_sync_single_for_device);
|
|
|
|
|
|
|
|
void sn_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nelems, int direction)
|
|
|
|
{
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_sync_sg_for_cpu);
|
|
|
|
|
|
|
|
void sn_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
|
|
|
|
int nelems, int direction)
|
|
|
|
{
|
|
|
|
BUG_ON(dev->bus != &pci_bus_type);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_sync_sg_for_device);
|
|
|
|
|
2008-07-25 22:44:49 -04:00
|
|
|
int sn_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(sn_dma_mapping_error);
|
|
|
|
|
|
|
|
char *sn_pci_get_legacy_mem(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
if (!SN_PCIBUS_BUSSOFT(bus))
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
|
|
|
return (char *)(SN_PCIBUS_BUSSOFT(bus)->bs_legacy_mem | __IA64_UNCACHED_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sn_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
int ret;
|
2005-09-23 13:31:53 -04:00
|
|
|
struct ia64_sal_retval isrv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, try the SN_SAL_IOIF_PCI_SAFE SAL call which can work
|
|
|
|
* around hw issues at the pci bus level. SGI proms older than
|
2007-05-11 17:55:43 -04:00
|
|
|
* 4.10 don't implement this.
|
2005-09-23 13:31:53 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
SAL_CALL(isrv, SN_SAL_IOIF_PCI_SAFE,
|
2006-02-13 05:29:57 -05:00
|
|
|
pci_domain_nr(bus), bus->number,
|
|
|
|
0, /* io */
|
|
|
|
0, /* read */
|
|
|
|
port, size, __pa(val));
|
2005-09-23 13:31:53 -04:00
|
|
|
|
|
|
|
if (isrv.status == 0)
|
|
|
|
return size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the above failed, retry using the SAL_PROBE call which should
|
|
|
|
* be present in all proms (but which cannot work round PCI chipset
|
2007-05-11 17:55:43 -04:00
|
|
|
* bugs). This code is retained for compatibility with old
|
2005-09-23 13:31:53 -04:00
|
|
|
* pre-4.10 proms, and should be removed at some point in the future.
|
|
|
|
*/
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
if (!SN_PCIBUS_BUSSOFT(bus))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
addr = SN_PCIBUS_BUSSOFT(bus)->bs_legacy_io | __IA64_UNCACHED_OFFSET;
|
|
|
|
addr += port;
|
|
|
|
|
|
|
|
ret = ia64_sn_probe_mem(addr, (long)size, (void *)val);
|
|
|
|
|
|
|
|
if (ret == 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
*val = -1;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
|
|
|
|
{
|
|
|
|
int ret = size;
|
|
|
|
unsigned long paddr;
|
|
|
|
unsigned long *addr;
|
2005-09-23 13:31:53 -04:00
|
|
|
struct ia64_sal_retval isrv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, try the SN_SAL_IOIF_PCI_SAFE SAL call which can work
|
|
|
|
* around hw issues at the pci bus level. SGI proms older than
|
2007-05-11 17:55:43 -04:00
|
|
|
* 4.10 don't implement this.
|
2005-09-23 13:31:53 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
SAL_CALL(isrv, SN_SAL_IOIF_PCI_SAFE,
|
2006-02-13 05:29:57 -05:00
|
|
|
pci_domain_nr(bus), bus->number,
|
|
|
|
0, /* io */
|
|
|
|
1, /* write */
|
|
|
|
port, size, __pa(&val));
|
2005-09-23 13:31:53 -04:00
|
|
|
|
|
|
|
if (isrv.status == 0)
|
|
|
|
return size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the above failed, retry using the SAL_PROBE call which should
|
|
|
|
* be present in all proms (but which cannot work round PCI chipset
|
2007-05-11 17:55:43 -04:00
|
|
|
* bugs). This code is retained for compatibility with old
|
2005-09-23 13:31:53 -04:00
|
|
|
* pre-4.10 proms, and should be removed at some point in the future.
|
|
|
|
*/
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
if (!SN_PCIBUS_BUSSOFT(bus)) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put the phys addr in uncached space */
|
|
|
|
paddr = SN_PCIBUS_BUSSOFT(bus)->bs_legacy_io | __IA64_UNCACHED_OFFSET;
|
|
|
|
paddr += port;
|
|
|
|
addr = (unsigned long *)paddr;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
*(volatile u8 *)(addr) = (u8)(val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*(volatile u16 *)(addr) = (u16)(val);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
*(volatile u32 *)(addr) = (u32)(val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|