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
20 FILE_LICENCE ( GPL2_OR_LATER );
23 #include <ipxe/interface.h>
24 #include <ipxe/blockdev.h>
33 * Read from block device
35 * @v control Control interface
36 * @v data Data interface
37 * @v lba Starting logical block address
38 * @v count Number of logical blocks
39 * @v buffer Data buffer
40 * @v len Length of data buffer
41 * @ret rc Return status code
43 int block_read ( struct interface *control, struct interface *data,
44 uint64_t lba, unsigned int count,
45 userptr_t buffer, size_t len ) {
46 struct interface *dest;
47 block_read_TYPE ( void * ) *op =
48 intf_get_dest_op ( control, block_read, &dest );
49 void *object = intf_object ( dest );
53 rc = op ( object, data, lba, count, buffer, len );
55 /* Default is to fail to issue the command */
64 * Write to block device
66 * @v control Control interface
67 * @v data Data interface
68 * @v lba Starting logical block address
69 * @v count Number of logical blocks
70 * @v buffer Data buffer
71 * @v len Length of data buffer
72 * @ret rc Return status code
74 int block_write ( struct interface *control, struct interface *data,
75 uint64_t lba, unsigned int count,
76 userptr_t buffer, size_t len ) {
77 struct interface *dest;
78 block_write_TYPE ( void * ) *op =
79 intf_get_dest_op ( control, block_write, &dest );
80 void *object = intf_object ( dest );
84 rc = op ( object, data, lba, count, buffer, len );
86 /* Default is to fail to issue the command */
95 * Read block device capacity
97 * @v control Control interface
98 * @v data Data interface
99 * @ret rc Return status code
101 int block_read_capacity ( struct interface *control, struct interface *data ) {
102 struct interface *dest;
103 block_read_capacity_TYPE ( void * ) *op =
104 intf_get_dest_op ( control, block_read_capacity, &dest );
105 void *object = intf_object ( dest );
109 rc = op ( object, data );
111 /* Default is to fail to issue the command */
120 * Report block device capacity
123 * @v capacity Block device capacity
125 void block_capacity ( struct interface *intf,
126 struct block_device_capacity *capacity ) {
127 struct interface *dest;
128 block_capacity_TYPE ( void * ) *op =
129 intf_get_dest_op ( intf, block_capacity, &dest );
130 void *object = intf_object ( dest );
133 op ( object, capacity );
135 /* Default is to do nothing */