sandbox_host.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * sandbox host uclass
  4. *
  5. * Copyright 2022 Google LLC
  6. */
  7. #ifndef __SANDBOX_HOST__
  8. #define __SANDBOX_HOST__
  9. /**
  10. * struct host_sb_plat - platform data for a host device
  11. *
  12. * @label: Label for this device (allocated)
  13. * @filename: Name of file this is attached to, or NULL (allocated)
  14. * @fd: File descriptor of file, or 0 for none (file is not open)
  15. */
  16. struct host_sb_plat {
  17. char *label;
  18. char *filename;
  19. int fd;
  20. };
  21. /**
  22. * struct host_ops - operations supported by UCLASS_HOST
  23. */
  24. struct host_ops {
  25. /**
  26. * @attach_file: - Attach a new file to the device
  27. *
  28. * @attach_file.dev: Device to update
  29. * @attach_file.filename: Name of the file, e.g. "/path/to/disk.img"
  30. * @attach_file.Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on
  31. * other error
  32. */
  33. int (*attach_file)(struct udevice *dev, const char *filename);
  34. /**
  35. * @detach_file: - Detach a file from the device
  36. *
  37. * @detach_file.dev: Device to detach from
  38. * @detach_file.Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other
  39. * error
  40. */
  41. int (*detach_file)(struct udevice *dev);
  42. };
  43. #define host_get_ops(dev) ((struct host_ops *)(dev)->driver->ops)
  44. /**
  45. * host_attach_file() - Attach a new file to the device
  46. *
  47. * @dev: Device to update
  48. * @filename: Name of the file, e.g. "/path/to/disk.img"
  49. * Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on
  50. * other error
  51. */
  52. int host_attach_file(struct udevice *dev, const char *filename);
  53. /**
  54. * host_detach_file() - Detach a file from the device
  55. *
  56. * @dev: Device to detach from
  57. * Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other
  58. * error
  59. */
  60. int host_detach_file(struct udevice *dev);
  61. /**
  62. * host_create_device() - Create a new host device
  63. *
  64. * Any existing device with the same label is removed and unbound first
  65. *
  66. * @label: Label of the attachment, e.g. "test1"
  67. * @removable: true if the device should be marked as removable, false
  68. * if it is fixed. See enum blk_flag_t
  69. * @devp: Returns the device created, on success
  70. * Returns: 0 if OK, -ve on error
  71. */
  72. int host_create_device(const char *label, bool removable,
  73. struct udevice **devp);
  74. /**
  75. * host_create_attach_file() - Create a new host device attached to a file
  76. *
  77. * @label: Label of the attachment, e.g. "test1"
  78. * @filename: Name of the file, e.g. "/path/to/disk.img"
  79. * @removable: true if the device should be marked as removable, false
  80. * if it is fixed. See enum blk_flag_t
  81. * @devp: Returns the device created, on success
  82. * Returns: 0 if OK, -ve on error
  83. */
  84. int host_create_attach_file(const char *label, const char *filename,
  85. bool removable, struct udevice **devp);
  86. /**
  87. * host_find_by_label() - Find a host by label
  88. *
  89. * Searches all host devices to find one with the given label
  90. *
  91. * @label: Label to find
  92. * Returns: associated device, or NULL if not found
  93. */
  94. struct udevice *host_find_by_label(const char *label);
  95. /**
  96. * host_get_cur_dev() - Get the current device
  97. *
  98. * Returns current device, or NULL if none
  99. */
  100. struct udevice *host_get_cur_dev(void);
  101. /**
  102. * host_set_cur_dev() - Set the current device
  103. *
  104. * Sets the current device, or clears it if @dev is NULL
  105. *
  106. * @dev: Device to set as the current one
  107. */
  108. void host_set_cur_dev(struct udevice *dev);
  109. #endif /* __SANDBOX_HOST__ */