Blame view

drivers/iommu/io-pgtable.c 1.64 KB
caab277b1   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
fdb1d7be7   Will Deacon   iommu: introduce ...
2
3
4
  /*
   * Generic page table allocator for IOMMUs.
   *
fdb1d7be7   Will Deacon   iommu: introduce ...
5
6
7
8
9
10
   * Copyright (C) 2014 ARM Limited
   *
   * Author: Will Deacon <will.deacon@arm.com>
   */
  
  #include <linux/bug.h>
b77cf11f0   Rob Herring   iommu: Allow io-p...
11
  #include <linux/io-pgtable.h>
fdb1d7be7   Will Deacon   iommu: introduce ...
12
13
  #include <linux/kernel.h>
  #include <linux/types.h>
fdb1d7be7   Will Deacon   iommu: introduce ...
14
  static const struct io_pgtable_init_fns *
54c6d242f   Cosmin-Gabriel Samoila   iommu/io-pgtable:...
15
  io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = {
e1d3c0fd7   Will Deacon   iommu: add ARM LP...
16
17
18
19
20
  #ifdef CONFIG_IOMMU_IO_PGTABLE_LPAE
  	[ARM_32_LPAE_S1] = &io_pgtable_arm_32_lpae_s1_init_fns,
  	[ARM_32_LPAE_S2] = &io_pgtable_arm_32_lpae_s2_init_fns,
  	[ARM_64_LPAE_S1] = &io_pgtable_arm_64_lpae_s1_init_fns,
  	[ARM_64_LPAE_S2] = &io_pgtable_arm_64_lpae_s2_init_fns,
d08d42de6   Rob Herring   iommu: io-pgtable...
21
  	[ARM_MALI_LPAE] = &io_pgtable_arm_mali_lpae_init_fns,
e1d3c0fd7   Will Deacon   iommu: add ARM LP...
22
  #endif
e5fc9753b   Robin Murphy   iommu/io-pgtable:...
23
24
25
  #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S
  	[ARM_V7S] = &io_pgtable_arm_v7s_init_fns,
  #endif
fdb1d7be7   Will Deacon   iommu: introduce ...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  };
  
  struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
  					    struct io_pgtable_cfg *cfg,
  					    void *cookie)
  {
  	struct io_pgtable *iop;
  	const struct io_pgtable_init_fns *fns;
  
  	if (fmt >= IO_PGTABLE_NUM_FMTS)
  		return NULL;
  
  	fns = io_pgtable_init_table[fmt];
  	if (!fns)
  		return NULL;
  
  	iop = fns->alloc(cfg, cookie);
  	if (!iop)
  		return NULL;
  
  	iop->fmt	= fmt;
  	iop->cookie	= cookie;
  	iop->cfg	= *cfg;
  
  	return &iop->ops;
  }
b77cf11f0   Rob Herring   iommu: Allow io-p...
52
  EXPORT_SYMBOL_GPL(alloc_io_pgtable_ops);
fdb1d7be7   Will Deacon   iommu: introduce ...
53
54
55
56
57
58
59
60
61
62
63
  
  /*
   * It is the IOMMU driver's responsibility to ensure that the page table
   * is no longer accessible to the walker by this point.
   */
  void free_io_pgtable_ops(struct io_pgtable_ops *ops)
  {
  	struct io_pgtable *iop;
  
  	if (!ops)
  		return;
fb485eb18   Robin Murphy   iommu/io-pgtable-...
64
  	iop = io_pgtable_ops_to_pgtable(ops);
507e4c9d1   Robin Murphy   iommu/io-pgtable:...
65
  	io_pgtable_tlb_flush_all(iop);
fdb1d7be7   Will Deacon   iommu: introduce ...
66
67
  	io_pgtable_init_table[iop->fmt]->free(iop);
  }
b77cf11f0   Rob Herring   iommu: Allow io-p...
68
  EXPORT_SYMBOL_GPL(free_io_pgtable_ops);