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.

blockdev.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
  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 Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <errno.h>
  21. #include <ipxe/interface.h>
  22. #include <ipxe/blockdev.h>
  23. /** @file
  24. *
  25. * Block devices
  26. *
  27. */
  28. /**
  29. * Read from block device
  30. *
  31. * @v control Control interface
  32. * @v data Data interface
  33. * @v lba Starting logical block address
  34. * @v count Number of logical blocks
  35. * @v buffer Data buffer
  36. * @v len Length of data buffer
  37. * @ret rc Return status code
  38. */
  39. int block_read ( struct interface *control, struct interface *data,
  40. uint64_t lba, unsigned int count,
  41. userptr_t buffer, size_t len ) {
  42. struct interface *dest;
  43. block_read_TYPE ( void * ) *op =
  44. intf_get_dest_op ( control, block_read, &dest );
  45. void *object = intf_object ( dest );
  46. int rc;
  47. if ( op ) {
  48. rc = op ( object, data, lba, count, buffer, len );
  49. } else {
  50. /* Default is to fail to issue the command */
  51. rc = -EOPNOTSUPP;
  52. }
  53. intf_put ( dest );
  54. return rc;
  55. }
  56. /**
  57. * Write to block device
  58. *
  59. * @v control Control interface
  60. * @v data Data interface
  61. * @v lba Starting logical block address
  62. * @v count Number of logical blocks
  63. * @v buffer Data buffer
  64. * @v len Length of data buffer
  65. * @ret rc Return status code
  66. */
  67. int block_write ( struct interface *control, struct interface *data,
  68. uint64_t lba, unsigned int count,
  69. userptr_t buffer, size_t len ) {
  70. struct interface *dest;
  71. block_write_TYPE ( void * ) *op =
  72. intf_get_dest_op ( control, block_write, &dest );
  73. void *object = intf_object ( dest );
  74. int rc;
  75. if ( op ) {
  76. rc = op ( object, data, lba, count, buffer, len );
  77. } else {
  78. /* Default is to fail to issue the command */
  79. rc = -EOPNOTSUPP;
  80. }
  81. intf_put ( dest );
  82. return rc;
  83. }
  84. /**
  85. * Read block device capacity
  86. *
  87. * @v control Control interface
  88. * @v data Data interface
  89. * @ret rc Return status code
  90. */
  91. int block_read_capacity ( struct interface *control, struct interface *data ) {
  92. struct interface *dest;
  93. block_read_capacity_TYPE ( void * ) *op =
  94. intf_get_dest_op ( control, block_read_capacity, &dest );
  95. void *object = intf_object ( dest );
  96. int rc;
  97. if ( op ) {
  98. rc = op ( object, data );
  99. } else {
  100. /* Default is to fail to issue the command */
  101. rc = -EOPNOTSUPP;
  102. }
  103. intf_put ( dest );
  104. return rc;
  105. }
  106. /**
  107. * Report block device capacity
  108. *
  109. * @v intf Interface
  110. * @v capacity Block device capacity
  111. */
  112. void block_capacity ( struct interface *intf,
  113. struct block_device_capacity *capacity ) {
  114. struct interface *dest;
  115. block_capacity_TYPE ( void * ) *op =
  116. intf_get_dest_op ( intf, block_capacity, &dest );
  117. void *object = intf_object ( dest );
  118. if ( op ) {
  119. op ( object, capacity );
  120. } else {
  121. /* Default is to do nothing */
  122. }
  123. intf_put ( dest );
  124. }