iPXE
|
00001 /* 00002 * Copyright (C) 2010 Piotr JaroszyĆski <p.jaroszynski@gmail.com> 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of the 00007 * License, or any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef _IPXE_LINUX_H 00020 #define _IPXE_LINUX_H 00021 00022 FILE_LICENCE(GPL2_OR_LATER); 00023 00024 /** @file 00025 * 00026 * Linux devices, drivers and device requests. 00027 */ 00028 00029 #include <ipxe/list.h> 00030 #include <ipxe/device.h> 00031 #include <ipxe/settings.h> 00032 00033 /** 00034 * Convert a Linux error number to an iPXE status code 00035 * 00036 * @v errno Linux error number 00037 * @ret rc iPXE status code (before negation) 00038 */ 00039 #define ELINUX( errno ) EPLATFORM ( EINFO_EPLATFORM, errno ) 00040 00041 /** A linux device */ 00042 struct linux_device { 00043 /** Generic device */ 00044 struct device dev; 00045 /** Driver that's handling the device */ 00046 struct linux_driver *driver; 00047 /** Private data used by drivers */ 00048 void *priv; 00049 }; 00050 00051 struct linux_device_request; 00052 00053 /** A linux driver */ 00054 struct linux_driver { 00055 /** Name */ 00056 char *name; 00057 /** Probe function */ 00058 int (*probe)(struct linux_device *device, struct linux_device_request *request); 00059 /** Remove function */ 00060 void (*remove)(struct linux_device *device); 00061 /** Can the driver probe any more devices? */ 00062 int can_probe; 00063 }; 00064 00065 /** Linux driver table */ 00066 #define LINUX_DRIVERS __table(struct linux_driver, "linux_drivers") 00067 00068 /** Declare a Linux driver */ 00069 #define __linux_driver __table_entry(LINUX_DRIVERS, 01) 00070 00071 /** 00072 * Set linux device driver-private data 00073 * 00074 * @v device Linux device 00075 * @v priv Private data 00076 */ 00077 static inline void linux_set_drvdata(struct linux_device * device, void *priv) 00078 { 00079 device->priv = priv; 00080 } 00081 00082 /** 00083 * Get linux device driver-private data 00084 * 00085 * @v device Linux device 00086 * @ret priv Private data 00087 */ 00088 static inline void *linux_get_drvdata(struct linux_device *device) 00089 { 00090 return device->priv; 00091 } 00092 00093 /** 00094 * A device request. 00095 * 00096 * To be created and filled by the UI code. 00097 */ 00098 struct linux_device_request { 00099 /** Driver name. Compared to the linux drivers' names */ 00100 char *driver; 00101 /** List node */ 00102 struct list_head list; 00103 /** List of settings */ 00104 struct list_head settings; 00105 }; 00106 00107 /** A device request setting */ 00108 struct linux_setting { 00109 /** Name */ 00110 char *name; 00111 /** Value */ 00112 char *value; 00113 /** Was the setting already applied? */ 00114 int applied; 00115 /** List node */ 00116 struct list_head list; 00117 }; 00118 00119 /** 00120 * List of requested devices. 00121 * 00122 * Filled by the UI code. Linux root_driver walks over this list looking for an 00123 * appropriate driver to handle each request by matching the driver's name. 00124 */ 00125 extern struct list_head linux_device_requests; 00126 00127 /** 00128 * List of global settings to apply. 00129 * 00130 * Filled by the UI code. Linux root_driver applies these settings. 00131 */ 00132 extern struct list_head linux_global_settings; 00133 00134 /** 00135 * Look for the last occurrence of a setting with the specified name 00136 * 00137 * @v name Name of the setting to look for 00138 * @v settings List of the settings to look through 00139 */ 00140 struct linux_setting *linux_find_setting(char *name, struct list_head *settings); 00141 00142 /** 00143 * Apply a list of linux settings to a settings block 00144 * 00145 * @v new_settings List of linux_setting's to apply 00146 * @v settings_block Settings block to apply the settings to 00147 * @ret rc 0 on success 00148 */ 00149 extern void linux_apply_settings(struct list_head *new_settings, struct settings *settings_block); 00150 00151 00152 #endif /* _IPXE_LINUX_H */