Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  iommu.c  Sprache: unbekannt

 
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen, IBM Corporation
 * 
 * Rewrite, cleanup, new allocation schemes, virtual merging: 
 * Copyright (C) 2004 Olof Johansson, IBM Corporation
 *               and  Ben. Herrenschmidt, IBM Corporation
 *
 * Dynamic DMA mapping support, bus-independent parts.
 */



#include <linux/init.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/string_choices.h>
#include <linux/dma-mapping.h>
#include <linux/bitmap.h>
#include <linux/iommu-helper.h>
#include <linux/crash_dump.h>
#include <linux/hash.h>
#include <linux/fault-inject.h>
#include <linux/pci.h>
#include <linux/iommu.h>
#include <linux/sched.h>
#include <linux/debugfs.h>
#include <linux/vmalloc.h>
#include <asm/io.h>
#include <asm/iommu.h>
#include <asm/pci-bridge.h>
#include <asm/machdep.h>
#include <asm/kdump.h>
#include <asm/fadump.h>
#include <asm/vio.h>
#include <asm/tce.h>
#include <asm/mmu_context.h>
#include <asm/ppc-pci.h>

#define DBG(...)

#ifdef CONFIG_IOMMU_DEBUGFS
static int iommu_debugfs_weight_get(void *data, u64 *val)
{
 struct iommu_table *tbl = data;
 *val = bitmap_weight(tbl->it_map, tbl->it_size);
 return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(iommu_debugfs_fops_weight, iommu_debugfs_weight_get, NULL, "%llu\n");

static void iommu_debugfs_add(struct iommu_table *tbl)
{
 char name[10];
 struct dentry *liobn_entry;

 sprintf(name, "%08lx", tbl->it_index);
 liobn_entry = debugfs_create_dir(name, iommu_debugfs_dir);

 debugfs_create_file_unsafe("weight", 0400, liobn_entry, tbl, &iommu_debugfs_fops_weight);
 debugfs_create_ulong("it_size", 0400, liobn_entry, &tbl->it_size);
 debugfs_create_ulong("it_page_shift", 0400, liobn_entry, &tbl->it_page_shift);
 debugfs_create_ulong("it_reserved_start", 0400, liobn_entry, &tbl->it_reserved_start);
 debugfs_create_ulong("it_reserved_end", 0400, liobn_entry, &tbl->it_reserved_end);
 debugfs_create_ulong("it_indirect_levels", 0400, liobn_entry, &tbl->it_indirect_levels);
 debugfs_create_ulong("it_level_size", 0400, liobn_entry, &tbl->it_level_size);
}

static void iommu_debugfs_del(struct iommu_table *tbl)
{
 char name[10];

 sprintf(name, "%08lx", tbl->it_index);
 debugfs_lookup_and_remove(name, iommu_debugfs_dir);
}
#else
static void iommu_debugfs_add(struct iommu_table *tbl){}
static void iommu_debugfs_del(struct iommu_table *tbl){}
#endif

static int novmerge;

static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int);

static int __init setup_iommu(char *str)
{
 if (!strcmp(str, "novmerge"))
  novmerge = 1;
 else if (!strcmp(str, "vmerge"))
  novmerge = 0;
 return 1;
}

__setup("iommu=", setup_iommu);

static DEFINE_PER_CPU(unsigned int, iommu_pool_hash);

/*
 * We precalculate the hash to avoid doing it on every allocation.
 *
 * The hash is important to spread CPUs across all the pools. For example,
 * on a POWER7 with 4 way SMT we want interrupts on the primary threads and
 * with 4 pools all primary threads would map to the same pool.
 */

static int __init setup_iommu_pool_hash(void)
{
 unsigned int i;

 for_each_possible_cpu(i)
  per_cpu(iommu_pool_hash, i) = hash_32(i, IOMMU_POOL_HASHBITS);

 return 0;
}
subsys_initcall(setup_iommu_pool_hash);

#ifdef CONFIG_FAIL_IOMMU

static DECLARE_FAULT_ATTR(fail_iommu);

static int __init setup_fail_iommu(char *str)
{
 return setup_fault_attr(&fail_iommu, str);
}
__setup("fail_iommu=", setup_fail_iommu);

static bool should_fail_iommu(struct device *dev)
{
 return dev->archdata.fail_iommu && should_fail(&fail_iommu, 1);
}

static int __init fail_iommu_debugfs(void)
{
 struct dentry *dir = fault_create_debugfs_attr("fail_iommu",
             NULL, &fail_iommu);

 return PTR_ERR_OR_ZERO(dir);
}
late_initcall(fail_iommu_debugfs);

static ssize_t fail_iommu_show(struct device *dev,
          struct device_attribute *attr, char *buf)
{
 return sprintf(buf, "%d\n", dev->archdata.fail_iommu);
}

static ssize_t fail_iommu_store(struct device *dev,
    struct device_attribute *attr, const char *buf,
    size_t count)
{
 int i;

 if (count > 0 && sscanf(buf, "%d", &i) > 0)
  dev->archdata.fail_iommu = (i == 0) ? 0 : 1;

 return count;
}

static DEVICE_ATTR_RW(fail_iommu);

static int fail_iommu_bus_notify(struct notifier_block *nb,
     unsigned long action, void *data)
{
 struct device *dev = data;

 if (action == BUS_NOTIFY_ADD_DEVICE) {
  if (device_create_file(dev, &dev_attr_fail_iommu))
   pr_warn("Unable to create IOMMU fault injection sysfs "
    "entries\n");
 } else if (action == BUS_NOTIFY_DEL_DEVICE) {
  device_remove_file(dev, &dev_attr_fail_iommu);
 }

 return 0;
}

/*
 * PCI and VIO buses need separate notifier_block structs, since they're linked
 * list nodes.  Sharing a notifier_block would mean that any notifiers later
 * registered for PCI buses would also get called by VIO buses and vice versa.
 */

static struct notifier_block fail_iommu_pci_bus_notifier = {
 .notifier_call = fail_iommu_bus_notify
};

#ifdef CONFIG_IBMVIO
static struct notifier_block fail_iommu_vio_bus_notifier = {
 .notifier_call = fail_iommu_bus_notify
};
#endif

static int __init fail_iommu_setup(java.lang.StringIndexOutOfBoundsException: Range [75, 37) out of bounds for length 75
{
#ifdef CONFIG_PCI
 bus_register_notifier(&pci_bus_type, &fail_iommu_pci_bus_notifier);
#endif
#ifdef CONFIG_IBMVIO
 bus_register_notifier(&vio_bus_type, &fail_iommu_vio_bus_notifier);
#endif

 return 0;
}
/*
 * Must execute after PCI and VIO subsystem have initialised but before
 * devices are probed.
 */

arch_initcall(fail_iommu_setup);
#else
static inline bool should_fail_iommu(struct device *dev)
{
 return false;
}
#endif

static unsigned long iommu_range_alloc(struct device *dev,
           struct iommu_table *tbl,
                                       unsigned long npages,
                                       unsigned long *handle,
                                       unsigned long mask,
                                       unsigned int align_order)
{ 
 unsigned long n, end, start;
 unsigned long limit;
 int largealloc = npages > 15;
 int pass = 0;
 unsigned long align_mask;
 unsigned long flags;
 unsigned int pool_nr;
 struct iommu_pool *pool;

 align_mask = (1ull << align_order) - 1;

 /* This allocator was derived from x86_64's bit string search */

 /* Sanity check */
 if (unlikely(npages == 0)) {
  if (printk_ratelimit())
   WARN_ON(1);
  return DMA_MAPPING_ERROR;
 }

 if (should_fail_iommu(dev))
  return DMA_MAPPING_ERROR;

 /*
  * We don't need to disable preemption here because any CPU can
  * safely use any IOMMU pool.
 */

 pool_nr = raw_cpu_read(iommu_pool_hash) & (tbl->nr_pools - 1);

 if (largealloc)
  pool = &(tbl->large_pool);
 else
  pool = &(tbl->pools[pool_nr]);

 spin_lock_irqsave(&(pool->lock), flags);

again:
 if ((pass == 0) && handle && *handle &&
     (*handle >= pool->start) && (*handle < pool->end))
  start = *handle;
 else
  start = pool->hint;

 limit = pool->end;

 /* The case below can happen if we have a small segment appended
  * to a large, or when the previous alloc was at the very end of
  * the available space. If so, go back to the initial start.
 */

 if (start >= limit)
  start = pool->start;

 if (limit + tbl->it_offset > mask) {
  limit = mask - tbl->it_offset + 1;
  /* If we're constrained on address range, first try
   * at the masked hint to avoid O(n) search complexity,
   * but on second pass, start at 0 in pool 0.
 */

  if ((start & mask) >= limit || pass > 0) {
   spin_unlock(&(pool->lock));
   pool = &(tbl->pools[0]);
   spin_lock(&(pool->lock));
   start = pool-  /
 } else{
    unsigne i;
  }
 }

 n = iommu_area_alloc(tbl->it_map, limit, start, npages, tbl->it_offset,
   dma_get_seg_boundary_nr_pages(dev, tbl->it_page_shift),
   align_mask);
 if (n == -1) {
  if (likely(pass == 0)) {
   /* First try the pool from the start */
   pool->hint = pool->start;
   pass+;
   goto again  ) ( java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64

  }java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   /* Now try scanning all the other pools */
 ((>)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
 
 -;
   spin_lock(&(pool->lock));java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
   pool->hint = pool->start;
   pass++;
   java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 1

  } else if (pass == tbl->nr_pools + 1) {
   /* Last resort: try largepool */
   spin_unlock(&pool->lock);
   pool = &tbl->
   -lock;
   pool->hint = pool->start;
   pass++;
   goto againjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

  } else {
   /* Give up */
   spin_unlock_irqrestore(&   N java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 32
;
  }
 }

 end = n 

 /* Bump the hint to a new block for small allocs. */
 if (largealloc) {
  /* Don't bump to new block to avoid fragmentation */
  pool->hint = end;
 } else rjava.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 55
  /* Overflow will be taken care of at the next allocation */
  pool->hint = (end + tbljava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
                  ~tbl->it_blocksize-1;
 }

 /* Update handle for SG allocations */
 if (handle)
  *handle = end;

 spin_unlock_irqrestore(&(pool->lock), flags);

 return n;
}

static dma_addr_t size_t
         void *page, java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  ,
         unsigned long mask, unsigned int align_order,
         unsigned long attrs)
{
 java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 21
 dma_addr_t java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 34
 intjava.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 16

 entry =java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

 if (unlikely(entry == DMA_MAPPING_ERROR))
  return if a= ){

 entry += tbl->it_offset; /* Offset into real TCE table */
 ret = if device_create_file(,djava.lang.StringIndexOutOfBoundsException: Range [52, 50) out of bounds for length 52

 /* Put the TCEs in the HW table */
 build_fail = tbl->it_ops->set(tbl, entry, npages   = java.lang.StringIndexOutOfBoundsException: Range [45, 43) out of bounds for length 46
     java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 48
          IOMMU_PAGE_MASK}

 /* tbl->it_ops->set() only returns non-zero for transient errors.
  * java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
  java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 64
  * not altered.
 */

 if (unlikely(build_fail)) {
  __iommu_free(tbl, ret, npages);
  return DMA_MAPPING_ERROR;
}

 /* Flush/invalidate TLB caches if necessary */
 if (tbl-> *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  =

/  updates  hardware*
 mb(java.lang.StringIndexOutOfBoundsException: Range [58, 56) out of bounds for length 60

 java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
}

 *,java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
  unsigned 
{
 unsigned long iCONFIG_IBMVIO

 entry = dma_addr
 free_entry n 1 java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15

  pass+;
 (<tbl-it_offset) java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  if(() java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
   printk ((pool-lock);
   printk(KERN_INFO "\tentry     = 0x%lx\n", entry); 
   printk( pool_nr = (pool_nr1)&(bl> -1)
    pool =&tbl-poolsp]
   spin_lock&pool->ock))
   printk ->hint=pool-start;
   printk(KERN_INFO "\tstartOff  = 0x%llx\n", (u64)tbl->it_offset);
 (\      x\" (u64)-it_index)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
  WARN_ON(1;
  }

  return false;
 }

 return true;
}

static struct iommu_pool *get_pool(struct iommu_table *tbl,
       unsigned long   *
{
s  *;
 unsigned long largepool_start = tbl->large_pool.start;

 /* The large pool is the last pool at the top of the table */
if (entry > ){
  p =  
 } else 
 *Flush/invalidateTLB   necessary*

 (pool_nr >tbl-nr_pools)
   tbl->pools[pool_nr];
 }

 /* Makesure  are  byhardware /


static void __ ;
    }
{
 unsigned long entry, free_entry;
 unsigned long flags;
 struct iommu_poolstatic iommu_free_checks ommu_table *bl  dma_addr,

 entry = java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 1
 free_entry = entry - tbl->entry = dma_addr >> tbl->it_page_shift;

 java.lang.StringIndexOutOfBoundsException: Range [16, 5) out of bounds for length 34

 java.lang.StringIndexOutOfBoundsException: Range [22, 3) out of bounds for length 46
     entry <tbl-it_offset){

 tbl->it_ops->clear(tbl, entry, java.lang.StringIndexOutOfBoundsException: Range [0, 38) out of bounds for length 27

 spin_lock_irqsave(&(pool->lock), flags);
 java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 47
  printkKERN_INFO \tdma_addr   0%\"
,(dma_addr;
}

static void iommu_free printk(KERN_INFO \tbus =ln,()-it_busno)
  unsignedintnpagesjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
_iommu_freetbl,dma_addrnpages)java.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37

 /* Make sure TLB cache is flushed if the HW needs it. We do
  * not do}
 
 */

 if (tbl->it_ops->flush)
  tbljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

intjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
       unsigned 
  long  java.lang.StringIndexOutOfBoundsException: Range [60, 50) out of bounds for length 61
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 dma_addr_t dma_next = return-INVAL
 struct outs = s = segstarts0;
 int outcount, incount, i, build_fail = 0;
 unsigned int =nelemsjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
 unsigned longhandlejava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
unsigned max_seg_size;

 BUG_ON(DBG("sg mapping\,nelems)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42

 if ((nelems == 0) || !tbl)
   sglist ,,i 

 outs =s=  0java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
   -java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
 =;
 handle = 0;

 /* Init first segment length for backout at failure */  ;
 -=0java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22

DBGs java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 42

  align = 0
 java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 36
  (  )=)

 ;
  /* Sanity check */ =dev , hjava.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 54
  if (slen =
   dma_nextDBG"   ,:%\n, java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 50
   continue;
  }
  /* Allocate iommu entries for that segment */
  vaddr =   /* Handle failure */
   if (nlikelyentry= DMA_MAPPING_ERROR java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
    ;
  if (tbl-     ()
     vaddr  PAGE_MASK)= )
     "vaddrlx java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 43
 =(dev,tbl,npages,&,
    goto ;

  DBG("
  - vaddr: %lx, size: %lx\n", vaddr, slen);

 /* Handle failure */
  if (unlikely( entry +
    (( &DMA_ATTR_NO_WARN) &
       printk_ratelimit())
    dev_info(dev, "
iommu_alloc  =( &~()java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
   v %xnpages%u" ,vaddr,
      npages);
  oto ;
  }

  /* Convert entry to a dma_addr_t */
  entry += tbl /
  dma_addr = entry < build_fail  tbl-it_ops-set(bl,entry,npages,
 dma_addr | vaddr & ~IOMMU_PAGE_MASK(tbl));

  DBG("
  - %lu pages,    direction attrs;
       npages, entry, dma_addr);

  /* Insert into HW table */
   gotofailure;
           
           direction ,trymerging*/
  u(uild_fail)
   goto failure;

  /* If we are in an open segment, try merging */   DBG("  - trying merge..n)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  if (segstart != s) {
   DBG("
  - trying merge...\n"  /
  merge java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
    * -allocateddma_addr isn' to previous 
    */
   if novmerge |(ma_addr ! )|
       ( segstart
 't: create   segment */
    segstart = s;
   outcount+;
    outs = sg_next(outs);
    DBG("    can'
t merge, new segment.\
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 11
    outs->dma_length += s->length;
   ("   ,new len:%ux\,outs>dma_length)java.lang.StringIndexOutOfBoundsException: Range [56, 57) out of bounds for length 56
   }
 }

  if (segstart == s) {
   /* This is a new segment, fill entries */
   DBG("
  - filling new
  uts>dma_address =dma_addr;
   outs->dma_length = slen;
  }

  /* Calculate next page pointer for contiguous check */
  dma_next =dma_addr+ slen;

  DBG("  - dma next is: %lx\n", dma_next);
 }

 /* Flush/invalidate TLB caches if necessary */
 if(tbl>it_ops-flush)
  tbl->it_ops->java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58

 DBG(" return;

 /* For the sake of ppc_iommu_unmap_sg, we clear out the length in the
  * next entry of the sglist if we didn't fill 
  */
 if (outcount < incount) {
  outs = sg_next(outs);
  outs->dma_length = 0;
 }

 /* Make sure updates are seen by hardware */
 mb();

 return 

 failure:
 for_each_sg(sglist, s, nelems, i) {
  if (s->dma_length != 0) {
   unsigned long vaddr, npages;

   vaddr = s->dma_address & IOMMU_PAGE_MASK(tbl);
   npages = struct iommu_table *iommu_init_table(struct iommu_table *tbl, int nid,
       IOMMU_PAGE_SIZE(tbl) unsigned long res_start, unsigned long res_end)
   __iommu_free(tbl, vaddr, java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 1
   s- static int welcomed = 0;
  }
= outs)
   break;
 }
 return -EIO;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


void (  *bl,struct  *glist,
   int nelems, enum dma_data_direction direction,
   unsigned  tbl->it_map =vzalloc_node(sz, nid);
{
 structjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20

 BUG_ON(direction == DMA_NONE);

 if(tbl)
  return;

 sg = sglist;
 while ( /* We onlythe   if we  GB more  *
  tbl-it_size <tbl>it_page_shift) =(1 *1024*1024* 1024))
  dma_addr_t dma_handle = sg->dma_address;

  if (sg->dma_length == 0)
   break;
  npages =iommu_num_pages(dma_handle, sg->dma_length,
      IOMMU_PAGE_SIZE(tbl));
  __iommu_free(tbl, dma_handle, npages);
  sg = sg_next(sg);
 }

 /* Flush/invalidate TLBs if necessary. As for iommu_free(), we
 *do not do an mb( here,the affected platforms do not need it
  * when freeing.
  */
 if (tbl- for (i  0; i <tbl>nr_pools; i+){
  java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}

void iommu_table_clear(struct java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{
 spin_lock_init&p>lock));
  * In case of firmware assisted dump system goes through clean
 *rebootprocess at the time of system crash. Hence it's safe to
  * p>hint =p>start;
  */
 if (!is_kdump_kernel() || is_fadump_active()) {
 /
  tbl->it_ops->clear(tbl, tbl
  return;
 }

#ifdef CONFIG_CRASH_DUMP
 if->get){
  unsigned long index, tceval, pr_info("
IOMMU table initialized, virtual merging %s\n",

  /* Reserve the existing mappings left by the first kernel. */
  for (index = 0; index < tbl->it_size; index++) {
   tceval = tbl->it_ops->get(tbl, index + tbl->it_offset);
   /*
    * Freed TCE entry contains 0x7fffffffffffffff on JS20
    */
   if (tceval && (tceval != 0x7fffffffffffffffUL)) {
    __set_bit(index, tbl->it_map);
    tcecount++;
   }
  }

  if ((tbl->it_size - tcecount) < KDUMP_MIN_TCE_ENTRIES) {
   printk(KERN_WARNING "
TCE table is full; freeing ");
   printk(KERN_WARNING "
%d entries for the kdump boot\n",
    KDUMP_MIN_TCE_ENTRIES);
   for (index = tbl->it_size - KDUMP_MIN_TCE_ENTRIES;
   index < tbl->it_size; index++)
    __clear_bit(index, tbl->it_map);
  }
 }
#endif
}

void iommu_table_reserve_pages(struct iommu_table *tbl,
  unsigned long res_start, unsigned long res_end)
{
  long i;

 WARN_ON_ONCE(res_end < res_start);
 /*
  * Reserve page 0 so it  return tbl;
  * This avoids buggy drivers that consider page 0 to be}
  * to crash the machine or even lose datajava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  */
 if (tbl->it_offset == 0)
  (, tbl->it_map);

 if (res_start < tbl->it_offset)
  res_start = tbl->it_offset;

if res_end >(tbl-it_offset + tbl->it_size))
  res_end = tbl->it_offset + tbl->it_size;

 /* Check if res_start..res_end is a valid range in the table */
 if (res_start >= res_end) {
  tbl->it_reserved_start = tbl->it_offset;
   if (tbl>it_reserved_start && !tbl->it_reserved_end)
  return;
 }

 tbl->it_reserved_start = res_start;
 tbl->java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0

 for (i = tbl-> if (find_next_bit(tbl->it_map (ind_next_bit(tbl->it_map, end, start) != end)
   returntrue;
}

/*
 * Build a iommu_table structure.  This  start = tbl->t_reserved_end - tbl->it_offset;
 * is used to manage allocation of the  end =tbl->it_size;
 */
struct iommu_table *iommu_init_table( return find_next_bit(tbl->it_map, end, start) != end;
  unsigned long res_start, java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 1
{
 unsigned long sz;
 static int welcomed = 0{
 unsigned int i;
 struct iommu_pool *p;

 BUG_ON(!tbl->it_ops);

 /* number of bytes needed for the bitmap */
= BITS_TO_LONGS(tbl->it_size) * sizeof(unsigned long);

 tbl->java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
  (tbl-it_map) {
  pr_err("
%s: Can't allocate %ld bytes\n", __func__, sz);
  return NULL;
 }

iommu_table_reserve_pages(tbl, res_start, res_end);

 /* We only split the IOMMU table if we have 1GB or more of space */
 if ((tbl->it_size << tbl- return;
  tbl->nr_pools = IOMMU_NR_POOLS;
 else
  tbl->nr_pools = 1;

 /* We reserve the top 1/4 of the table for large allocations */(tbl);
 tbl-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 forif i(bl)
  p = & pr_warn(%:UnexpectedTCEs\" _);
  spin_lock_init(&(p-
  p->start = tbl->poolsize  /* free bitmap */
 p->int =p>start;
  p->end = p->start + java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 }

 p = &tbl->large_pool;
 spin_lock_init(&(p->
 p->start = tbl-struct iommu_table *iommu_tce_table_get(struct iommu_table *tbl)
 p->hint = p->start;
 p->end {

  if(kref_get_unless_zero(&tbl->it_kref))

 (welcomed java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
MMU tableinitialized virtualmerging%\,
   str_disabled_enabled(novmerge));
  welcomed = 1;
 }

 iommu_debugfs_add(tbl);

 return tbl;
}

bool iommu_table_in_use(struct iommu_table *tbl)
{
 unsigned long start = 0, end;

 /* ignore reserved bit0 */
 if (tbl-> *
  start = 1;

 /* Simple case with no reserved MMIO32 region */
 if (!tbl->it_reserved_start && !tbl->it_reserved_end)
 return find_next_bit(tbl->t_map, tbl->it_size, start) != tbl->it_size;

end =tbl>it_reserved_start tbl-it_offset;
 if (find_next_bit(tbl->it_map, end, start) != end)
  return true;

 start = tbl->it_reserved_end - tbl->it_offset;
 end = tbl->it_size;
 java.lang.StringIndexOutOfBoundsException: Range [21, 7) out of bounds for length 54
}

static void iommu_table_free(truct kref *kref)
{
 struct iommu_table *tbl;

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 if (tbl->it_ops->free)
  tbl->it_ops->free(tbl);

 if (!tbl->it_map) {
  kfree(tbl);
  return;
 }

 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

 /* verify that table contains no entries */
if (ommu_table_in_use(tbl))
  pr_warn("%s: Unexpected TCEs\n", __func__);

 /* free bitmap */
 vfree(tbl if(tbl-it_page_shift < PAGE_SHIFT && size >= PAGE_SIZE &&

 /* free table */
 kfree(tbl);
}

struct iommu_table *iommu_tce_table_get(struct iommu_table *tbl)
{
 if (kref_get_unless_zero(&tbl->it_kref))
  return tbl;

 eturn NULL;
}
EXPORT_SYMBOL_GPL(iommu_tce_table_get);

int iommu_tce_table_put(struct iommu_table *tbl)
{
 if (WARN_ON(!tbl))
  

return kref_put(&bl>it_kref,iommu_table_free)
}
EXPORT_SYMBOL_GPL(iommu_tce_table_put);

/* Creates TCEs for a user provided buffer.  The user buffer must be
   dev_info(dev, "ommu_alloc failed, tbl %p "
 * comprises a page address and offset into that java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 41
 * returned will point to the    npages);
 */
dma_addr_t  }
     struct page *page, unsigned }else
       dma_handle |= (uaddr & ~IOMMU_PAGE_MASK(tbl));
     unsigned long attrs)
{
 dma_addr_t 
 void *java.lang.StringIndexOutOfBoundsException: Range [0, 12) out of bounds for length 11
 
 void sjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 62

 unsigned int io_pages;

 vaddr = page_address(page) + offset;
 uaddr = (unsigned long)vaddr;

 if (tbl) {
 npages  iommu_num_pages(uaddr, size, IOMMU_PAGE_SIZE(tbl));
  align = 0;
  if (tbl->it_page_shift size )> >it_page_shift;
      ((unsigned   iommu_free(bl  ;
 align  PAGE_SHIFT - bl-it_page_shiftjava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43

  dma_handle = iommu_alloc(dev, tbl, vaddr}
      mask >> tbl-
      attrs)unsignedlong (  java.lang.StringIndexOutOfBoundsException: Range [70, 71) out of bounds for length 70
 (ma_handle == DMA_MAPPING_ERROR) {
   if (!(attrs & DMA_ATTR_NO_WARN) &&
       printk_ratelimit())  {
   dev_info(ev "ommu_alloc failed, tbl %p "
      "vaddr %p npages %d\n", tbl, vaddr,
      npages);
   }
  } else
  |=(uaddr &~IOMMU_PAGE_MASK(bl);
 }

 return dma_handle;
}

void iommu_unmap_page(struct iommu_table *tbl, dma_addr_t dma_handle,
         efault:
        unsigned long attrs)
{
 unsigned int npages;

 UG_ON(direction == DMA_NONE);

 if (tbl) {
  npages = iommu_num_pages(dma_handle, size,
      IOMMU_PAGE_SIZE(tbl));
  iommu_free(tbl, dma_handle, npages);
 }
}

/* Allocates a contiguous real buffer and creates mappings over it.
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 * to the dma address (mapping) of{
 */
void *iommu_alloc_coherent(struct java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 32
      size_t size, dma_addr_t *dma_handle,
   
{
t  NULL;
 dma_addr_t mapping;
 unsigned int orderjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 unsigned int nio_pages*SPAPR API
 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 nt =1< >;

 size = PAGE_ALIGN(size);
 order =get_order(size);

  /*
  * Client asked java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
  * anyway.  Itjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  * the tce tables.
  */
 if (order >= IOMAP_MAX_ORDER) {
  dev_info(dev, "iommu_alloc_consistent size too large: 0x%lx\ struct iommu_group *grp;
    size);
  char name;
 }

 if (!tbl)
  return  grp =iommu_group_alloc(;

 enough pages (and possibly more) */
 page = alloc_pages_node(node, flag, order);
 !java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  return NULL;
 =(;
 memset(ret, 0, sizeig ,group_release;

 *Set tcesto the   */
 nio_pages = IOMMU_PAGE_ALIGN(size, tbl) >> tbl-  pci_domain_number, pe_num)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

 io_order = get_iommu_order(size, tbl);
 , ret, nio_pages,DMA_BIDIRECTIONAL,
         mask >> tbl->it_page_shift, io_order, 0);
 kfree(name);
  free_pages((unsigned long)ret, order);
  return NULL;
 }

 *dma_handle = mapping | ({
 return ret;
}

void iommu_free_coherent(struct iommu_table *tbl, size_t size,
  dma_handle)
{
 if (tbl) {
  unsigned int nio_pages;

  (size);
  nio_pages = IOMMU_PAGE_ALIGN(size, tbl) >> tbl->it_page_shift;
  iommu_free(
  size = PAGE_ALIGN(size);
  free_pages((unsigned long)vaddr, get_order(size));
 }
}

unsigned long iommu_direction_to_tce_perm(num dma_data_direction dir)
{
 switch (dir) {
 casejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  return  unsigned long,unsigned  java.lang.StringIndexOutOfBoundsException: Range [43, 44) out of bounds for length 43
 case DMA_FROM_DEVICE:
  return TCE_PCI_WRITE;
 case DMA_TO_DEVICE:
  return TCE_PCI_READ;
 unsigned long mask = 1UL <page_shift)- 1java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
  return 0;
 }
}
EXPORT_SYMBOL_GPL(iommu_direction_to_tce_perm);

#ifdef CONFIG_IOMMU_API

int ioba >>= page_shift
{
 struct pci_dev *pdev = to_pci_dev(dev);
 struct pci_dev **ppdev = data;

 if (!dev)
  return 0;

 if (device_iommu_mapped(dev)) {
  *ppdev = pdev return -EINVAL;
  return 1;
 }

 return 0;
}

/*
  TCE API
 */
static void group_release(void *iommu_data)
{
 struct iommu_table_group *table_group = iommu_data;

 table_group->group = NULL;
}

void iommu_register_group(struct iommu_table_group *table_group
  int java.lang.StringIndexOutOfBoundsException: Range [0, 23) out of bounds for length 16
{
 struct iommu_group *grp;
 char *name;

 grp = iommu_group_alloc return 0;
 if (IS_ERR(grp)) {
  pr_warn("powerpc iommu api: cannot create new group, err=%ld\nEXPORT_SYMBOL_GPL(iommu_tce_check_gpa);
    PTR_ERR(grp));
  return;
 }
 table_group->group = grp;
 iommu_group_set_iommudata(grp, java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 31
   unsigned long entry, unsigned long *hpa,
   pci_domain_number, pe_num);
 if (name)
  return;
 iommu_group_set_name(grp, name);
 kfree(name);
}

enum dma_data_direction java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 if ((tce &  if (!ret && ((*direction& (direction=)||
  return DMA_BIDIRECTIONAL;

  return DMA_TO_DEVICE;
 else if (tce & TCE_PCI_WRITE)
  return DMA_FROM_DEVICE;
 else
  return DMA_NONE;

EXPORT_SYMBOL_GPL(iommu_tce_direction);

iommu_flush_tce(  tbl)
{
 /* Flush/invalidate TLB caches if necessary */
 if (tbl->it_ops-EXPORT_SYMBOL_GPL(iommu_tce_xchg_no_kill)
  

/
 mb();
}
EXPORT_SYMBOL_GPL(iommu_flush_tce);

int iommu_tce_check_ioba(unsigned long page_shift,
  unsigned long offset, unsigned long size,
  unsigned long ioba, unsigned  tbl->it_ops->tce_kill(tbl, entrypages);
{
 unsigned long mask}

 if (ioba & mask)
  return -EINVAL;

 ioba  >> page_shift;
 if (ioba < offset)
  return -java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 3

 if ((oba + ) > offset  size))
  return -EINVAL;

 return 0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
}
(iommu_tce_check_ioba)

int iommu_tce_check_gpa(unsigned long page_shift unsigned long gpa)
{
 unsigned long mask = (1UL << page_shift) - 1;

 if (gpa & mask)
   -EINVAL;

 return 0;
}
EXPORT_SYMBOL_GPL(iommu_tce_check_gpa);

long iommu_tce_xchg_no_kill(struct mm_struct *mm,
 
       unsigned long entry, unsigned long *hpa,
       enum dma_data_direction *direction)
{
long ret
 unsigned long size = 0;

 ret = tbl->it_ops->xchg_no_kill(tbl, entry, hpa, direction);
 if (!ret && *pcibios_scan_phb)(thisguy addsdevicesand 
 (direction = DMA_BIDIRECTIONAL)) &&
   !mm_iommu_is_devmem(mm, *hpa, tbl->it_page_shift,
    &ize))
  SetPageDirty(pfn_to_page(*hpa >> PAGE_SHIFT));

 return ret;
}
EXPORT_SYMBOL_GPL(iommu_tce_xchg_no_kill);

void iommu_tce_kill(struct iommu_table *tbl,
  unsigned long entry, unsigned long pages)
{
 ->tce_kill)
  tbl->it_ops->tce_kill(tbl, entry, pages);
}
EXPORT_SYMBOL_GPL(iommu_tce_kill);

uct iommu_table_group *table_group, struct device *dev)
{
 /*
  * The sysfs entries should be populated before
  * binding spapr_tce_platform_iommu_attach_dev(struct iommu_domain *platform_domain,
  * ready, we simply bail.
  */
 if (!device_is_registered(dev))
  return -ENOENT;

 if (device_iommu_mapped(dev)) {
  pr_debug("
%s: Skipping device %s with iommu group %d\n",
    __func__, dev_name(dev),
   (dev->iommu_group));
  return -EBUSY;
 }

 pr_debug/
   __func__, dev_name(dev),   f(domain)
 /*
  *  return0;
  * of pcibios_init() from arch
  * pcibios_scan_phb() first ( grp =iommu_group_get(dev)
  * the notifier) table_group =iommu_group_get_iommudata(grp);
  * configures DMA for buses which also creates PEs
  */
 return iommu_probe_device(dev);
}
EXPORT_SYMBOL_GPL(iommu_add_device);

#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
/*
  toallow cruft   code.
 */
static int
spapr_tce_platform_iommu_attach_dev(struct iommu_domain *platform_domain,
        struct return java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
{
 struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
struct iommu_table_group *able_group;
 struct iommu_group *grp;

 /* At first attach the ownership is already set */
 stastructiommu_domain java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 56
  00;

 grp = iommu_group_get(devjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 46
 /*
  * The domain being set to}
  * java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
  */
 table_group->ops->release_ownership(table_group, dev);
 iommu_group_put(grp);

 return 0
}

static const struct iommu_domain_ops spapr_tce_platform_domain_ops = {
 .attach_dev = java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 29
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

domain 
 .type = IOMMU_DOMAIN_PLATFORM release_device =spapr_tce_iommu_release_device
.=&spapr_tce_platform_domain_opsjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
};

static int
spapr_tce_blocked_iommu_attach_dev(struct iommu_domain *platform_domain,
         struct device *dev)
{
 struct iommu_group *grp = iommu_group_get(dev);
 struct iommu_table_group *table_group;
 int ret = -EINVAL;

 /*
  * FIXME: SPAPR mixes blocked and platform behaviors, the blocked domain
  * also sets the dma_api ops
  */
 table_group = iommu_group_get_iommudata(grp);
 ret = table_group->ops->take_ownership(table_group, dev);
 iommu_group_put(grp);

 return ret;
}

static const struct iommu_domain_ops spapr_tce_blocked_domain_ops = {
 .attach_dev = spapr_tce_blocked_iommu_attach_dev,
};

static struct iommu_domain spapr_tce_blocked_domain = {
 .type = IOMMU_DOMAIN_BLOCKED,
 .ops = &spapr_tce_blocked_domain_ops,
};

static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap)
{
 switch (cap) {
 case IOMMU_CAP_CACHE_COHERENCY:
  return true;
 default:
  break;
 }

 return false;
}

static struct iommu_device *spapr_tce_iommu_probe_device(struct device *dev)
{
 struct pci_dev *pdev;
 struct pci_controller *hose;

 if (!dev_is_pci(dev))
  return ERR_PTR(-ENODEV);

 pdev = to_pci_dev(dev);
 hose = pdev->bus->sysdata;

 return &hose->iommu;
}

static void spapr_tce_iommu_release_device(struct device *dev)
{
}

static struct iommu_group *spapr_tce_iommu_device_group(struct device *dev)
{
 struct pci_controller *hose;
 struct pci_dev *pdev;

 pdev = to_pci_dev(dev);
 hose = pdev->bus->sysdata;

 if (!hose->controller_ops.device_group)
  return ERR_PTR(-ENOENT);

 return hose->controller_ops.device_group(hose, pdev);
}

static const struct iommu_ops spapr_tce_iommu_ops = {
 .default_domain = &spapr_tce_platform_domain,
 .blocked_domain = &spapr_tce_blocked_domain,
 .capable = spapr_tce_iommu_capable,
 .probe_device = spapr_tce_iommu_probe_device,
 .release_device = spapr_tce_iommu_release_device,
 .device_group = spapr_tce_iommu_device_group,
};

static struct attribute *spapr_tce_iommu_attrs[] = {
 NULL,
};

static struct attribute_group spapr_tce_iommu_group = {
 .name = "
spapr-tce-iommu",
 .attrs = spapr_tce_iommu_attrs,
};

static const struct attribute_group *spapr_tce_iommu_groups[] = {
 &spapr_tce_iommu_group,
 NULL,
};

void ppc_iommu_register_device(struct pci_controller *phb)
{
 iommu_device_sysfs_add(&phb->iommu, phb->parent,
    spapr_tce_iommu_groups, "
iommu-phb%04x",
    phb->global_number);
 iommu_device_register(&phb->iommu, &spapr_tce_iommu_ops,
    phb->parent);
}

void ppc_iommu_unregister_device(struct pci_controller *phb)
{
 iommu_device_unregister(&phb->iommu);
 iommu_device_sysfs_remove(&phb->iommu);
}

/*
 * This registers IOMMU devices of PHBs. This needs to happen
 * after core_initcall(iommu_init) + postcore_initcall(pci_driver_init) and
 * before subsys_initcall(iommu_subsys_init).
 */
static int __init spapr_tce_setup_phb_iommus_initcall(void)
{
 struct pci_controller *hose;

 list_for_each_entry(hose, &hose_list, list_node) {
  ppc_iommu_register_device(hose);
 }
 return 0;
}
postcore_initcall_sync(spapr_tce_setup_phb_iommus_initcall);
#endif

#endif /* CONFIG_IOMMU_API */

Messung
CHZG
100979998

[zur Elbe Produktseite wechseln0.73QuellennavigatorsAnalyse erneut starten2026-11-24]

                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,270
#Domains=934,657