2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
27 #include <ipxe/interface.h>
28 #include <ipxe/blockdev.h>
37 * Read from block device
39 * @v control Control interface
40 * @v data Data interface
41 * @v lba Starting logical block address
42 * @v count Number of logical blocks
43 * @v buffer Data buffer
44 * @v len Length of data buffer
45 * @ret rc Return status code
47 int block_read ( struct interface *control, struct interface *data,
48 uint64_t lba, unsigned int count,
49 userptr_t buffer, size_t len ) {
50 struct interface *dest;
51 block_read_TYPE ( void * ) *op =
52 intf_get_dest_op ( control, block_read, &dest );
53 void *object = intf_object ( dest );
57 rc = op ( object, data, lba, count, buffer, len );
59 /* Default is to fail to issue the command */
68 * Write to block device
70 * @v control Control interface
71 * @v data Data interface
72 * @v lba Starting logical block address
73 * @v count Number of logical blocks
74 * @v buffer Data buffer
75 * @v len Length of data buffer
76 * @ret rc Return status code
78 int block_write ( struct interface *control, struct interface *data,
79 uint64_t lba, unsigned int count,
80 userptr_t buffer, size_t len ) {
81 struct interface *dest;
82 block_write_TYPE ( void * ) *op =
83 intf_get_dest_op ( control, block_write, &dest );
84 void *object = intf_object ( dest );
88 rc = op ( object, data, lba, count, buffer, len );
90 /* Default is to fail to issue the command */
99 * Read block device capacity
101 * @v control Control interface
102 * @v data Data interface
103 * @ret rc Return status code
105 int block_read_capacity ( struct interface *control, struct interface *data ) {
106 struct interface *dest;
107 block_read_capacity_TYPE ( void * ) *op =
108 intf_get_dest_op ( control, block_read_capacity, &dest );
109 void *object = intf_object ( dest );
113 rc = op ( object, data );
115 /* Default is to fail to issue the command */
124 * Report block device capacity
127 * @v capacity Block device capacity
129 void block_capacity ( struct interface *intf,
130 struct block_device_capacity *capacity ) {
131 struct interface *dest;
132 block_capacity_TYPE ( void * ) *op =
133 intf_get_dest_op ( intf, block_capacity, &dest );
134 void *object = intf_object ( dest );
137 op ( object, capacity );
139 /* Default is to do nothing */