iPXE
blockdev.c
Go to the documentation of this file.
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 * 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.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <errno.h>
28#include <ipxe/interface.h>
29#include <ipxe/blockdev.h>
30
31/** @file
32 *
33 * Block devices
34 *
35 */
36
37/**
38 * Read from block device
39 *
40 * @v control Control interface
41 * @v data Data interface
42 * @v lba Starting logical block address
43 * @v count Number of logical blocks
44 * @v buffer Data buffer
45 * @v len Length of data buffer
46 * @ret rc Return status code
47 */
48int block_read ( struct interface *control, struct interface *data,
49 uint64_t lba, unsigned int count, void *buffer,
50 size_t len ) {
51 struct interface *dest;
52 block_read_TYPE ( void * ) *op =
54 void *object = intf_object ( dest );
55 int rc;
56
57 if ( op ) {
58 rc = op ( object, data, lba, count, buffer, len );
59 } else {
60 /* Default is to fail to issue the command */
61 rc = -EOPNOTSUPP;
62 }
63
64 intf_put ( dest );
65 return rc;
66}
67
68/**
69 * Write to block device
70 *
71 * @v control Control interface
72 * @v data Data interface
73 * @v lba Starting logical block address
74 * @v count Number of logical blocks
75 * @v buffer Data buffer
76 * @v len Length of data buffer
77 * @ret rc Return status code
78 */
80 uint64_t lba, unsigned int count, void *buffer,
81 size_t len ) {
82 struct interface *dest;
83 block_write_TYPE ( void * ) *op =
85 void *object = intf_object ( dest );
86 int rc;
87
88 if ( op ) {
89 rc = op ( object, data, lba, count, buffer, len );
90 } else {
91 /* Default is to fail to issue the command */
92 rc = -EOPNOTSUPP;
93 }
94
95 intf_put ( dest );
96 return rc;
97}
98
99/**
100 * Read block device capacity
101 *
102 * @v control Control interface
103 * @v data Data interface
104 * @ret rc Return status code
105 */
107 struct interface *dest;
108 block_read_capacity_TYPE ( void * ) *op =
110 void *object = intf_object ( dest );
111 int rc;
112
113 if ( op ) {
114 rc = op ( object, data );
115 } else {
116 /* Default is to fail to issue the command */
117 rc = -EOPNOTSUPP;
118 }
119
120 intf_put ( dest );
121 return rc;
122}
123
124/**
125 * Report block device capacity
126 *
127 * @v intf Interface
128 * @v capacity Block device capacity
129 */
131 struct block_device_capacity *capacity ) {
132 struct interface *dest;
133 block_capacity_TYPE ( void * ) *op =
135 void *object = intf_object ( dest );
136
137 if ( op ) {
138 op ( object, capacity );
139 } else {
140 /* Default is to do nothing */
141 }
142
143 intf_put ( dest );
144}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned long long uint64_t
Definition stdint.h:13
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition blockdev.c:106
int block_write(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, void *buffer, size_t len)
Write to block device.
Definition blockdev.c:79
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, void *buffer, size_t len)
Read from block device.
Definition blockdev.c:48
void block_capacity(struct interface *intf, struct block_device_capacity *capacity)
Report block device capacity.
Definition blockdev.c:130
Block devices.
#define block_write_TYPE(object_type)
Definition blockdev.h:38
#define block_read_capacity_TYPE(object_type)
Definition blockdev.h:45
#define block_capacity_TYPE(object_type)
Definition blockdev.h:50
#define block_read_TYPE(object_type)
Definition blockdev.h:30
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
Error codes.
static unsigned int count
Number of entries.
Definition dwmac.h:220
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
uint64_t lba
Starting block number.
Definition int13.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EOPNOTSUPP
Operation not supported on socket.
Definition errno.h:605
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition interface.c:160
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition interface.c:150
Object interfaces.
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition interface.h:270
uint32_t control
Control.
Definition myson.h:3
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
Block device capacity.
Definition blockdev.h:18
An object interface.
Definition interface.h:125
struct interface * intf
Original interface.
Definition interface.h:159