You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

linux.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef _IPXE_LINUX_H
  19. #define _IPXE_LINUX_H
  20. FILE_LICENCE(GPL2_OR_LATER);
  21. /** @file
  22. *
  23. * Linux devices, drivers and device requests.
  24. */
  25. #include <ipxe/list.h>
  26. #include <ipxe/device.h>
  27. #include <ipxe/settings.h>
  28. /**
  29. * Convert a Linux error number to an iPXE status code
  30. *
  31. * @v errno Linux error number
  32. * @ret rc iPXE status code (before negation)
  33. */
  34. #define ELINUX( errno ) EPLATFORM ( EINFO_EPLATFORM, errno )
  35. /** A linux device */
  36. struct linux_device {
  37. /** Generic device */
  38. struct device dev;
  39. /** Driver that's handling the device */
  40. struct linux_driver *driver;
  41. /** Private data used by drivers */
  42. void *priv;
  43. };
  44. struct linux_device_request;
  45. /** A linux driver */
  46. struct linux_driver {
  47. /** Name */
  48. char *name;
  49. /** Probe function */
  50. int (*probe)(struct linux_device *device, struct linux_device_request *request);
  51. /** Remove function */
  52. void (*remove)(struct linux_device *device);
  53. /** Can the driver probe any more devices? */
  54. int can_probe;
  55. };
  56. /** Linux driver table */
  57. #define LINUX_DRIVERS __table(struct linux_driver, "linux_drivers")
  58. /** Declare a Linux driver */
  59. #define __linux_driver __table_entry(LINUX_DRIVERS, 01)
  60. /**
  61. * Set linux device driver-private data
  62. *
  63. * @v device Linux device
  64. * @v priv Private data
  65. */
  66. static inline void linux_set_drvdata(struct linux_device * device, void *priv)
  67. {
  68. device->priv = priv;
  69. }
  70. /**
  71. * Get linux device driver-private data
  72. *
  73. * @v device Linux device
  74. * @ret priv Private data
  75. */
  76. static inline void *linux_get_drvdata(struct linux_device *device)
  77. {
  78. return device->priv;
  79. }
  80. /**
  81. * A device request.
  82. *
  83. * To be created and filled by the UI code.
  84. */
  85. struct linux_device_request {
  86. /** Driver name. Compared to the linux drivers' names */
  87. char *driver;
  88. /** List node */
  89. struct list_head list;
  90. /** List of settings */
  91. struct list_head settings;
  92. };
  93. /** A device request setting */
  94. struct linux_setting {
  95. /** Name */
  96. char *name;
  97. /** Value */
  98. char *value;
  99. /** Was the setting already applied? */
  100. int applied;
  101. /** List node */
  102. struct list_head list;
  103. };
  104. /**
  105. * List of requested devices.
  106. *
  107. * Filled by the UI code. Linux root_driver walks over this list looking for an
  108. * appropriate driver to handle each request by matching the driver's name.
  109. */
  110. extern struct list_head linux_device_requests;
  111. /**
  112. * List of global settings to apply.
  113. *
  114. * Filled by the UI code. Linux root_driver applies these settings.
  115. */
  116. extern struct list_head linux_global_settings;
  117. /**
  118. * Look for the last occurrence of a setting with the specified name
  119. *
  120. * @v name Name of the setting to look for
  121. * @v settings List of the settings to look through
  122. */
  123. struct linux_setting *linux_find_setting(char *name, struct list_head *settings);
  124. /**
  125. * Apply a list of linux settings to a settings block
  126. *
  127. * @v new_settings List of linux_setting's to apply
  128. * @v settings_block Settings block to apply the settings to
  129. * @ret rc 0 on success
  130. */
  131. extern void linux_apply_settings(struct list_head *new_settings, struct settings *settings_block);
  132. #endif /* _IPXE_LINUX_H */