2 * Copyright (C) 2015 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 );
29 * Hyper Text Transfer Protocol (HTTP) block device
34 #include <ipxe/uaccess.h>
35 #include <ipxe/blocktrans.h>
36 #include <ipxe/blockdev.h>
37 #include <ipxe/acpi.h>
38 #include <ipxe/http.h>
40 /** Block size used for HTTP block device requests */
41 #define HTTP_BLKSIZE 512
44 * Read from block device
46 * @v http HTTP transaction
47 * @v data Data interface
48 * @v lba Starting logical block address
49 * @v count Number of logical blocks
50 * @v buffer Data buffer
51 * @v len Length of data buffer
52 * @ret rc Return status code
54 int http_block_read ( struct http_transaction *http, struct interface *data,
55 uint64_t lba, unsigned int count, userptr_t buffer,
57 struct http_request_range range;
61 assert ( len == ( count * HTTP_BLKSIZE ) );
63 /* Construct request range descriptor */
64 range.start = ( lba * HTTP_BLKSIZE );
67 /* Start a range request to retrieve the block(s) */
68 if ( ( rc = http_open ( data, &http_get, http->uri, &range,
72 /* Insert block device translator */
73 if ( ( rc = block_translate ( data, buffer, len ) ) != 0 ) {
74 DBGC ( http, "HTTP %p could not insert block translator: %s\n",
75 http, strerror ( rc ) );
82 intf_restart ( data, rc );
88 * Read block device capacity
90 * @v control Control interface
91 * @v data Data interface
92 * @ret rc Return status code
94 int http_block_read_capacity ( struct http_transaction *http,
95 struct interface *data ) {
98 /* Start a HEAD request to retrieve the capacity */
99 if ( ( rc = http_open ( data, &http_head, http->uri, NULL,
103 /* Insert block device translator */
104 if ( ( rc = block_translate ( data, UNULL, HTTP_BLKSIZE ) ) != 0 ) {
105 DBGC ( http, "HTTP %p could not insert block translator: %s\n",
106 http, strerror ( rc ) );
113 intf_restart ( data, rc );
119 * Describe device in ACPI table
121 * @v http HTTP transaction
123 * @v len Length of ACPI table
124 * @ret rc Return status code
126 int http_acpi_describe ( struct http_transaction *http,
127 struct acpi_description_header *acpi, size_t len ) {
129 DBGC ( http, "HTTP %p cannot yet describe device in an ACPI table\n",