📄 device.h
字号:
/* This file is part of the program psim. Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#ifndef _DEVICE_H_#define _DEVICE_H_#ifndef INLINE_DEVICE#define INLINE_DEVICE#endif/* declared in basics.h, this object is used everywhere *//* typedef struct _device device; *//* Introduction: As explained in earlier sections, the device, device instance, property and interrupts lie at the heart of PSIM's device model. In the below a synopsis of the device object and the operations it supports are given. Details of this object can be found in the files <<device.h>> and <<device.c>>. *//* Device creation: */INLINE_DEVICE\(device *) device_create(device *parent, const char *base, const char *name, const char *unit_address, const char *args);INLINE_DEVICE\(void) device_usage(int verbose);/* Device initialization: */INLINE_DEVICE\(void) device_clean(device *root, void *data);INLINE_DEVICE\(void) device_init_static_properties(device *me, void *data);INLINE_DEVICE\(void) device_init_address(device *me, void *data);INLINE_DEVICE\(void) device_init_runtime_properties(device *me, void *data);INLINE_DEVICE\(void) device_init_data(device *me, void *data);/* Relationships: A device is able to determine its relationship to other devices within the tree. Operations include querying for a devices parent, sibling, child, name, and path (from the root). */INLINE_DEVICE\(device *) device_parent(device *me);INLINE_DEVICE\(device *) device_root(device *me);INLINE_DEVICE\(device *) device_sibling(device *me);INLINE_DEVICE\(device *) device_child(device *me);INLINE_DEVICE\(const char *) device_name(device *me);INLINE_DEVICE\(const char *) device_base(device *me);INLINE_DEVICE\(const char *) device_path(device *me);INLINE_DEVICE\(void *) device_data(device *me);INLINE_DEVICE\(psim *) device_system(device *me);typedef struct _device_unit { int nr_cells; unsigned_cell cells[4]; /* unused cells are zero */} device_unit;INLINE_DEVICE\(const device_unit *) device_unit_address(device *me);INLINE_DEVICE\(int) device_decode_unit(device *bus, const char *unit, device_unit *address);INLINE_DEVICE\(int) device_encode_unit(device *bus, const device_unit *unit_address, char *buf, int sizeof_buf);/* Convert an Open Firmware size into a form suitable for attach address calls. Return a zero result if the address should be ignored when looking for attach addresses */INLINE_DEVICE\(int) device_address_to_attach_address(device *me, const device_unit *address, int *attach_space, unsigned_word *attach_address, device *client);/* Convert an Open Firmware size into a form suitable for attach address calls Return a zero result if the address should be ignored */INLINE_DEVICE\(int) device_size_to_attach_size(device *me, const device_unit *size, unsigned *nr_bytes, device *client);INLINE_DEVICE\(unsigned) device_nr_address_cells(device *me);INLINE_DEVICE\(unsigned) device_nr_size_cells(device *me);/* Properties: Attached to a device are a number of properties. Each property has a size and type (both of which can be queried). A device is able to iterate over or query and set a properties value. *//* The following are valid property types. The property `array' is for generic untyped data. */typedef enum { array_property, boolean_property, ihandle_property, /*runtime*/ integer_property, range_array_property, reg_array_property, string_property, string_array_property,} device_property_type;typedef struct _device_property device_property;struct _device_property { device *owner; const char *name; device_property_type type; unsigned sizeof_array; const void *array; const device_property *original; object_disposition disposition;};/* iterate through the properties attached to a device */INLINE_DEVICE\(const device_property *) device_next_property(const device_property *previous);INLINE_DEVICE\(const device_property *) device_find_property(device *me, const char *property); /* NULL for first property *//* Manipulate the properties belonging to a given device. SET on the other hand will force the properties value. The simulation is aborted if the property was present but of a conflicting type. FIND returns the specified properties value, aborting the simulation if the property is missing. Code locating a property should first check its type (using device_find_property above) and then obtain its value using the below. void device_add_<type>_property(device *, const char *, <type>) void device_add_*_array_property(device *, const char *, const <type>*, int) void device_set_*_property(device *, const char *, <type>) void device_set_*_array_property(device *, const char *, const <type>*, int) <type> device_find_*_property(device *, const char *) int device_find_*_array_property(device *, const char *, int, <type>*) */INLINE_DEVICE\(void) device_add_array_property(device *me, const char *property, const void *array, int sizeof_array);INLINE_DEVICE\(void) device_set_array_property(device *me, const char *property, const void *array, int sizeof_array);INLINE_DEVICE\(const device_property *) device_find_array_property(device *me, const char *property);INLINE_DEVICE\(void) device_add_boolean_property(device *me, const char *property, int bool);INLINE_DEVICE\(int) device_find_boolean_property(device *me, const char *property);typedef struct _ihandle_runtime_property_spec { const char *full_path;} ihandle_runtime_property_spec;INLINE_DEVICE\(void) device_add_ihandle_runtime_property(device *me, const char *property, const ihandle_runtime_property_spec *ihandle);INLINE_DEVICE\(void) device_find_ihandle_runtime_property(device *me, const char *property, ihandle_runtime_property_spec *ihandle);INLINE_DEVICE\(void) device_set_ihandle_property(device *me, const char *property, device_instance *ihandle);INLINE_DEVICE\(device_instance *) device_find_ihandle_property(device *me, const char *property);INLINE_DEVICE\(void) device_add_integer_property(device *me, const char *property, signed_cell integer);INLINE_DEVICE\(signed_cell) device_find_integer_property(device *me, const char *property);INLINE_DEVICE\(int) device_find_integer_array_property(device *me, const char *property, unsigned index, signed_cell *integer);typedef struct _range_property_spec { device_unit child_address; device_unit parent_address; device_unit size;} range_property_spec;INLINE_DEVICE\(void) device_add_range_array_property(device *me, const char *property, const range_property_spec *ranges, unsigned nr_ranges);INLINE_DEVICE\(int) device_find_range_array_property(device *me, const char *property, unsigned index, range_property_spec *range);typedef struct _reg_property_spec { device_unit address; device_unit size;} reg_property_spec;INLINE_DEVICE\(void) device_add_reg_array_property(device *me, const char *property, const reg_property_spec *reg, unsigned nr_regs);INLINE_DEVICE\(int) device_find_reg_array_property(device *me, const char *property, unsigned index, reg_property_spec *reg);INLINE_DEVICE\(void) device_add_string_property(device *me, const char *property, const char *string);INLINE_DEVICE\(const char *) device_find_string_property(device *me, const char *property);typedef const char *string_property_spec;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -