linux-old/include/asm-sh64/pci.h
<<
>>
Prefs
   1
   2/*
   3**
   4**                      P C I  -  C O M M O N  Internal Interface
   5**
   6** Module:    This module includes all functions that can be used for all included
   7**            bridge.
   8**
   9** Copyright: This file is subject to the terms and conditions of the GNU General Public
  10**            License.  See the file "COPYING" in the main directory of this archive
  11**            for more details.
  12**
  13**            Copyright (C) 2001   Roberto Giai Meniet (giai@while1.com)  
  14**                                 Franco  Ometti      (ometti@while1.com) 
  15**
  16** File:      include/asm-sh64/pci.h
  17**
  18** Note:      For a good view of this file use TABSTOP=8
  19**
  20*/
  21
  22
  23/*
  24** System includes
  25*/
  26#include <linux/types.h>
  27#include <linux/slab.h>
  28#include <asm/scatterlist.h>
  29#include <linux/string.h>
  30#include <asm/io.h>
  31
  32struct pci_dev;
  33
  34#ifndef __ASM_SH64_PCI_H
  35#define __ASM_SH64_PCI_H
  36
  37#ifdef __KERNEL__
  38
  39/* 
  40** Can be used to override the logic in pci_scan_bus for skipping
  41** already-configured bus numbers - to be used for buggy BIOSes
  42** or architectures with incomplete PCI setup by the loader 
  43*/
  44#define pcibios_assign_all_busses()     1
  45#define pcibios_scan_all_fns()          0
  46
  47/* 
  48** These are currently the correct values for the STM overdrive board.
  49** We need some way of setting this on a board specific way, it will
  50** not be the same on other boards I think
  51*/
  52#if defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
  53#define PCIBIOS_MIN_IO          0x2000
  54#define PCIBIOS_MIN_MEM         0x40000000
  55#endif
  56
  57
  58/*
  59** Set penalize isa irq function
  60*/
  61static inline void pcibios_penalize_isa_irq(int irq)
  62{
  63        /* We don't do dynamic PCI IRQ allocation */
  64}
  65
  66
  67/* 
  68** Dynamic DMA mapping stuff.
  69** SuperH has everything mapped statically like x86.
  70*/
  71
  72/* 
  73** Allocate and map kernel buffer using consistent mode DMA for a device.
  74** hwdev should be valid struct pci_dev pointer for PCI devices,
  75** NULL for PCI-like buses (ISA, EISA).
  76** Returns non-NULL cpu-view pointer to the buffer if successful and
  77** sets *dma_addrp to the pci side dma address as well, else *dma_addrp
  78** is undefined.
  79*/
  80extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  81                                  dma_addr_t *dma_handle);
  82
  83/* 
  84** Free and unmap a consistent DMA buffer.
  85** cpu_addr is what was returned from pci_alloc_consistent,
  86** size must be the same as what as passed into pci_alloc_consistent,
  87** and likewise dma_addr must be the same as what *dma_addrp was set to.
  88**
  89** References to the memory and mappings associated with cpu_addr/dma_addr
  90** past this call are illegal.
  91*/
  92extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
  93                                void *vaddr, dma_addr_t dma_handle);
  94
  95/* 
  96** Map a single buffer of the indicated size for DMA in streaming mode.
  97** The 32-bit bus address to use is returned.
  98**
  99** Once the device is given the dma address, the device owns this memory
 100** until either pci_unmap_single or pci_dma_sync_single is performed.
 101*/
 102static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
 103                                        size_t size,int direction)
 104{
 105        dma_cache_wback_inv((unsigned long)ptr, size);
 106        return virt_to_bus(ptr);
 107}
 108
 109
 110/*
 111** Unmap a single streaming mode DMA translation.  The dma_addr and size
 112** must match what was provided for in a previous pci_map_single call.  All
 113** other usages are undefined.
 114**
 115** After this call, reads by the cpu to the buffer are guarenteed to see
 116** whatever the device wrote there.
 117*/
 118static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
 119                                    size_t size,int direction)
 120{
 121        /* Nothing to do */
 122}
 123
 124/*
 125 * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
 126 * to pci_map_single, but takes a struct page instead of a virtual address
 127 */
 128static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
 129                                      unsigned long offset, size_t size, int direction)
 130{
 131        return ((dma_addr_t)(page - mem_map) *
 132                (dma_addr_t) PAGE_SIZE +
 133                (dma_addr_t) offset);
 134}
 135
 136static inline void pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
 137                                  size_t size, int direction)
 138{
 139        /* Nothing to do */
 140}
 141
 142/* 
 143** Map a set of buffers described by scatterlist in streaming
 144** mode for DMA.  This is the scather-gather version of the
 145** above pci_map_single interface.  Here the scatter gather list
 146** elements are each tagged with the appropriate dma address
 147** and length.  They are obtained via sg_dma_{address,length}(SG).
 148**
 149** NOTE: An implementation may be able to use a smaller number of
 150**       DMA address/length pairs than there are SG table elements.
 151**       (for example via virtual mapping capabilities)
 152**       The routine returns the number of addr/length pairs actually
 153**       used, at most nents.
 154**
 155** Device ownership issues as mentioned above for pci_map_single are
 156** the same here.
 157*/
 158static inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
 159                             int nents,int direction)
 160{
 161        int i;
 162
 163        for (i = 0; i < nents; i++) {
 164                if (sg[i].address) {
 165                        dma_cache_wback_inv((unsigned long)sg[i].address,
 166                                            sg[i].length);
 167                        sg[i].dma_address = virt_to_bus(sg[i].address);
 168                } else {
 169                        sg[i].dma_address = page_to_bus(sg[i].page) +
 170                                            sg[i].offset;
 171                        dma_cache_wback_inv((unsigned long) bus_to_virt(sg[i].dma_address), sg[i].length);
 172                }
 173        }
 174
 175        return nents;
 176}
 177
 178
 179/* 
 180** Unmap a set of streaming mode DMA translations.
 181** Again, cpu read rules concerning calls here are the same as for
 182** pci_unmap_single() above.
 183*/
 184static inline void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
 185                                int nents,int direction)
 186{
 187        int i;
 188
 189        if (direction == PCI_DMA_TODEVICE)
 190                return;
 191        
 192        for (i = 0; i < nents; i++) {
 193                if (!sg[i].address)
 194                        continue;
 195
 196                dma_cache_wback_inv((unsigned long)sg[i].address, sg[i].length);
 197        }
 198}
 199
 200
 201/* 
 202** Make physical memory consistent for a single
 203** streaming mode DMA translation after a transfer.
 204**
 205** If you perform a pci_map_single() but wish to interrogate the
 206** buffer using the cpu, yet do not wish to teardown the PCI dma
 207** mapping, you must call this function before doing so.  At the
 208** next point you give the PCI dma address back to the card, the
 209** device again owns the buffer.
 210*/
 211static inline void pci_dma_sync_single(struct pci_dev *hwdev,
 212                                       dma_addr_t dma_handle,
 213                                       size_t size,int direction)
 214{
 215        if (direction == PCI_DMA_NONE)
 216                BUG();
 217        
 218        dma_cache_wback_inv((unsigned long) bus_to_virt(dma_handle), size);
 219}
 220
 221
 222/* 
 223** Make physical memory consistent for a set of streaming
 224** mode DMA translations after a transfer.
 225**
 226** The same as pci_dma_sync_single but for a scatter-gather list,
 227** same rules and usage.
 228*/
 229static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
 230                                   struct scatterlist *sg,
 231                                   int nelems,int direction)
 232{
 233        int i;
 234
 235        for (i = 0; i < nelems; i++)
 236                dma_cache_wback_inv((unsigned long)sg[i].address, sg[i].length);
 237}
 238
 239
 240/* 
 241** Return whether the given PCI device DMA address mask can
 242** be supported properly.  For example, if your device can
 243** only drive the low 24-bits during PCI bus mastering, then
 244** you would pass 0x00ffffff as the mask to this function.
 245*/
 246extern inline int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
 247{
 248        return 1;
 249}
 250
 251
 252/* Not supporting more than 32-bit PCI bus addresses now, but
 253 * must satisfy references to this function.  Change if needed.
 254 */
 255#define pci_dac_dma_supported(pci_dev, mask) (0)
 256 
 257/* Return the index of the PCI controller for device PDEV. */
 258#define pci_controller_num(PDEV)        (0)
 259
 260/* 
 261** These macros should be used after a pci_map_sg call has been done
 262** to get bus addresses of each of the SG entries and their lengths.
 263** You should only work with the number of sg entries pci_map_sg
 264** returns, or alternatively stop on the first sg_dma_len(sg) which
 265** is 0.
 266*/
 267#define sg_dma_address(sg)      ((sg)->dma_address)
 268#define sg_dma_len(sg)          ((sg)->length)
 269
 270#define PCI_DMA_BUS_IS_PHYS     (1)
 271
 272#endif /* __KERNEL__ */
 273
 274#endif /* __ASM_SH64_PCI_H */
 275
 276
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.