Home | History | Annotate | Download | only in pcbios
      1 /*
      2  * Copyright (C) 2009 Fen Systems Ltd <mbrown (at) fensystems.co.uk>.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      9  *   Redistributions of source code must retain the above copyright
     10  *   notice, this list of conditions and the following disclaimer.
     11  *
     12  *   Redistributions in binary form must reproduce the above copyright
     13  *   notice, this list of conditions and the following disclaimer in
     14  *   the documentation and/or other materials provided with the
     15  *   distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     28  * OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 FILE_LICENCE ( BSD2 );
     32 
     33 /** @file
     34  *
     35  * SRP boot firmware table
     36  *
     37  */
     38 
     39 #include <assert.h>
     40 #include <realmode.h>
     41 #include <gpxe/srp.h>
     42 #include <gpxe/ib_srp.h>
     43 #include <gpxe/acpi.h>
     44 #include <gpxe/sbft.h>
     45 
     46 #define sbftab __use_data16 ( sbftab )
     47 /** The sBFT used by gPXE */
     48 struct gpxe_sbft __data16 ( sbftab ) = {
     49 	/* Table header */
     50 	.table = {
     51 		/* ACPI header */
     52 		.acpi = {
     53 			.signature = SBFT_SIG,
     54 			.length = sizeof ( sbftab ),
     55 			.revision = 1,
     56 			.oem_id = "FENSYS",
     57 			.oem_table_id = "gPXE",
     58 		},
     59 		.scsi_offset = offsetof ( typeof ( sbftab ), scsi ),
     60 		.srp_offset = offsetof ( typeof ( sbftab ), srp ),
     61 		.ib_offset = offsetof ( typeof ( sbftab ), ib ),
     62 	},
     63 };
     64 
     65 /**
     66  * Fill in all variable portions of sBFT
     67  *
     68  * @v srp		SRP device
     69  * @ret rc		Return status code
     70  */
     71 int sbft_fill_data ( struct srp_device *srp ) {
     72 	struct sbft_scsi_subtable *sbft_scsi = &sbftab.scsi;
     73 	struct sbft_srp_subtable *sbft_srp = &sbftab.srp;
     74 	struct sbft_ib_subtable *sbft_ib = &sbftab.ib;
     75 	struct ib_srp_parameters *ib_params;
     76 	struct segoff rm_sbftab = {
     77 		.segment = rm_ds,
     78 		.offset = __from_data16 ( &sbftab ),
     79 	};
     80 
     81 	/* Fill in the SCSI subtable */
     82 	memcpy ( &sbft_scsi->lun, &srp->lun, sizeof ( sbft_scsi->lun ) );
     83 
     84 	/* Fill in the SRP subtable */
     85 	memcpy ( &sbft_srp->port_ids, &srp->port_ids,
     86 		 sizeof ( sbft_srp->port_ids ) );
     87 
     88 	/* Fill in the IB subtable */
     89 	assert ( srp->transport == &ib_srp_transport );
     90 	ib_params = ib_srp_params ( srp );
     91 	memcpy ( &sbft_ib->sgid, &ib_params->sgid, sizeof ( sbft_ib->sgid ) );
     92 	memcpy ( &sbft_ib->dgid, &ib_params->dgid, sizeof ( sbft_ib->dgid ) );
     93 	memcpy ( &sbft_ib->service_id, &ib_params->service_id,
     94 		 sizeof ( sbft_ib->service_id ) );
     95 	sbft_ib->pkey = ib_params->pkey;
     96 
     97 	/* Update checksum */
     98 	acpi_fix_checksum ( &sbftab.table.acpi );
     99 
    100 	DBGC ( &sbftab, "SRP Boot Firmware Table at %04x:%04x:\n",
    101 	       rm_sbftab.segment, rm_sbftab.offset );
    102 	DBGC_HDA ( &sbftab, rm_sbftab, &sbftab, sizeof ( sbftab ) );
    103 
    104 	return 0;
    105 }
    106