usnic_uiom.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. *
  17. */
  18. #ifndef USNIC_UIOM_H_
  19. #define USNIC_UIOM_H_
  20. #include <linux/list.h>
  21. #include <linux/scatterlist.h>
  22. #include "usnic_uiom_interval_tree.h"
  23. #define USNIC_UIOM_READ (1)
  24. #define USNIC_UIOM_WRITE (2)
  25. #define USNIC_UIOM_MAX_PD_CNT (1000)
  26. #define USNIC_UIOM_MAX_MR_CNT (1000000)
  27. #define USNIC_UIOM_MAX_MR_SIZE (~0UL)
  28. #define USNIC_UIOM_PAGE_SIZE (PAGE_SIZE)
  29. struct usnic_uiom_dev {
  30. struct device *dev;
  31. struct list_head link;
  32. };
  33. struct usnic_uiom_pd {
  34. struct iommu_domain *domain;
  35. spinlock_t lock;
  36. struct rb_root rb_root;
  37. struct list_head devs;
  38. int dev_cnt;
  39. };
  40. struct usnic_uiom_reg {
  41. struct usnic_uiom_pd *pd;
  42. unsigned long va;
  43. size_t length;
  44. int offset;
  45. int page_size;
  46. int writable;
  47. struct list_head chunk_list;
  48. struct work_struct work;
  49. struct mm_struct *mm;
  50. unsigned long diff;
  51. };
  52. struct usnic_uiom_chunk {
  53. struct list_head list;
  54. int nents;
  55. struct scatterlist page_list[0];
  56. };
  57. struct usnic_uiom_pd *usnic_uiom_alloc_pd(void);
  58. void usnic_uiom_dealloc_pd(struct usnic_uiom_pd *pd);
  59. int usnic_uiom_attach_dev_to_pd(struct usnic_uiom_pd *pd, struct device *dev);
  60. void usnic_uiom_detach_dev_from_pd(struct usnic_uiom_pd *pd,
  61. struct device *dev);
  62. struct device **usnic_uiom_get_dev_list(struct usnic_uiom_pd *pd);
  63. void usnic_uiom_free_dev_list(struct device **devs);
  64. struct usnic_uiom_reg *usnic_uiom_reg_get(struct usnic_uiom_pd *pd,
  65. unsigned long addr, size_t size,
  66. int access, int dmasync);
  67. void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr, int closing);
  68. int usnic_uiom_init(char *drv_name);
  69. void usnic_uiom_fini(void);
  70. #endif /* USNIC_UIOM_H_ */