bm.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:14k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  *
  3.  * Module name: bm.h
  4.  *   $Revision: 41 $
  5.  *
  6.  *****************************************************************************/
  7. /*
  8.  *  Copyright (C) 2000, 2001 Andrew Grover
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  */
  24. #ifndef __BM_H__
  25. #define __BM_H__
  26. #include <actypes.h>
  27. #include <acexcep.h>
  28. /*****************************************************************************
  29.  *                               Types & Defines
  30.  *****************************************************************************/
  31. /*
  32.  * Output Flags (Debug):
  33.  * ---------------------
  34.  */
  35. #define BM_PRINT_ALL (0x00000000)
  36. #define BM_PRINT_GROUP (0x00000001)
  37. #define BM_PRINT_LINKAGE (0x00000002)
  38. #define BM_PRINT_IDENTIFICATION (0x00000004)
  39. #define BM_PRINT_POWER (0x00000008)
  40. #define BM_PRINT_PRESENT (0x00000010)
  41. /*
  42.  * BM_COMMAND:
  43.  * -----------
  44.  */
  45. typedef u32 BM_COMMAND;
  46. #define BM_COMMAND_UNKNOWN ((BM_COMMAND) 0x00)
  47. #define BM_COMMAND_GET_POWER_STATE ((BM_COMMAND) 0x01)
  48. #define BM_COMMAND_SET_POWER_STATE ((BM_COMMAND) 0x02)
  49. #define BM_COMMAND_DEVICE_SPECIFIC ((BM_COMMAND) 0x80)
  50. /*
  51.  * BM_NOTIFY:
  52.  * ----------
  53.  * Standard ACPI notification values, from section 5.6.3 of the ACPI 2.0
  54.  * specification.  Note that the Bus Manager internally handles all
  55.  * standard ACPI notifications -- driver modules are never sent these
  56.  * values (see "Bus Manager Notifications", below).
  57.  */
  58. typedef u32 BM_NOTIFY;
  59. #define BM_NOTIFY_BUS_CHECK ((BM_NOTIFY) 0x00)
  60. #define BM_NOTIFY_DEVICE_CHECK ((BM_NOTIFY) 0x01)
  61. #define BM_NOTIFY_DEVICE_WAKE ((BM_NOTIFY) 0x02)
  62. #define BM_NOTIFY_EJECT_REQUEST ((BM_NOTIFY) 0x03)
  63. #define BM_NOTIFY_DEVICE_CHECK_LIGHT ((BM_NOTIFY) 0x04)
  64. #define BM_NOTIFY_FREQUENCY_MISMATCH ((BM_NOTIFY) 0x05)
  65. #define BM_NOTIFY_BUS_MODE_MISMATCH ((BM_NOTIFY) 0x06)
  66. #define BM_NOTIFY_POWER_FAULT ((BM_NOTIFY) 0x07)
  67. /*
  68.  * These are a higher-level abstraction of ACPI notifications, intended
  69.  * for consumption by driver modules to facilitate Pn_p.
  70.  */
  71. #define BM_NOTIFY_UNKNOWN ((BM_NOTIFY) 0x00)
  72. #define BM_NOTIFY_DEVICE_ADDED ((BM_NOTIFY) 0x01)
  73. #define BM_NOTIFY_DEVICE_REMOVED ((BM_NOTIFY) 0x02)
  74. /*
  75.  * BM_HANDLE:
  76.  * ----------
  77.  */
  78. typedef u32 BM_HANDLE;
  79. #define BM_HANDLE_ROOT ((BM_HANDLE) 0x00000000)
  80. #define BM_HANDLE_UNKNOWN ((BM_HANDLE) 0xFFFFFFFF)
  81. #define BM_HANDLES_MAX 100
  82. /*
  83.  * BM_HANDLE_LIST:
  84.  * ---------------
  85.  */
  86. typedef struct
  87. {
  88. u32 count;
  89. BM_HANDLE handles[BM_HANDLES_MAX];
  90. } BM_HANDLE_LIST;
  91. /*
  92.  * BM_DEVICE_TYPE:
  93.  * ---------------
  94.  */
  95. typedef u32 BM_DEVICE_TYPE;
  96. #define BM_TYPE_UNKNOWN ((BM_DEVICE_TYPE) 0x00000000)
  97. #define BM_TYPE_SYSTEM ((BM_DEVICE_TYPE) 0x00000001)
  98. #define BM_TYPE_SCOPE ((BM_DEVICE_TYPE) 0x00000002)
  99. #define BM_TYPE_PROCESSOR ((BM_DEVICE_TYPE) 0x00000003)
  100. #define BM_TYPE_THERMAL_ZONE ((BM_DEVICE_TYPE) 0x00000004)
  101. #define BM_TYPE_POWER_RESOURCE ((BM_DEVICE_TYPE) 0x00000005)
  102. #define BM_TYPE_DEVICE ((BM_DEVICE_TYPE) 0x00000006)
  103. #define BM_TYPE_FIXED_BUTTON ((BM_DEVICE_TYPE) 0x00000007)
  104. /*
  105.  * BM_DEVICE_UID:
  106.  * --------------
  107.  */
  108. typedef char BM_DEVICE_UID[9];
  109. #define BM_UID_UNKNOWN '0'
  110. /*
  111.  * BM_DEVICE_HID:
  112.  * --------------
  113.  */
  114. typedef char BM_DEVICE_HID[9];
  115. #define BM_HID_UNKNOWN ''
  116. #define BM_HID_POWER_BUTTON "PNP0C0C"
  117. #define BM_HID_SLEEP_BUTTON "PNP0C0E"
  118. /*
  119.  * BM_DEVICE_ADR:
  120.  * --------------
  121.  */
  122. typedef u32 BM_DEVICE_ADR;
  123. #define BM_ADDRESS_UNKNOWN 0
  124. /*
  125.  * BM_DEVICE_FLAGS:
  126.  * ----------------
  127.  * The encoding of BM_DEVICE_FLAGS is illustrated below.
  128.  * Note that a set bit (1) indicates the property is TRUE
  129.  * (e.g. if bit 0 is set then the device has dynamic status).
  130.  * +--+------------+-+-+-+-+-+-+-+
  131.  * |31| Bits 30:7  |6|5|4|3|2|1|0|
  132.  * +--+------------+-+-+-+-+-+-+-+
  133.  *   |       |      | | | | | | |
  134.  *   |       |      | | | | | | +- Dynamic status?
  135.  *   |       |      | | | | | +--- Identifiable?
  136.  *   |       |      | | | | +----- Configurable?
  137.  *   |       |      | | | +------- Power Control?
  138.  *   |       |      | | +--------- Ejectable?
  139.  *   |       |      | +----------- Docking Station?
  140.  *   |       |      +------------- Fixed-Feature?
  141.  *   |       +-------------------- <Reserved>
  142.  *   +---------------------------- Driver Control?
  143.  *
  144.  * Dynamic status:  Device has a _STA object.
  145.  * Identifiable:    Device has a _HID and/or _ADR and possibly other
  146.  *                  identification objects defined.
  147.  * Configurable:    Device has a _CRS and possibly other configuration
  148.  *                  objects defined.
  149.  * Power Control:   Device has a _PR0 and/or _PS0 and possibly other
  150.  *                  power management objects defined.
  151.  * Ejectable:       Device has an _EJD and/or _EJx and possibly other
  152.  *                  dynamic insertion/removal objects defined.
  153.  * Docking Station: Device has a _DCK object defined.
  154.  * Fixed-Feature:   Device does not exist in the namespace; was
  155.  *                  enumerated as a fixed-feature (e.g. power button).
  156.  * Driver Control:  A driver has been installed for this device.
  157.  */
  158. typedef u32 BM_DEVICE_FLAGS;
  159. #define BM_FLAGS_UNKNOWN ((BM_DEVICE_FLAGS) 0x00000000)
  160. #define BM_FLAGS_DYNAMIC_STATUS ((BM_DEVICE_FLAGS) 0x00000001)
  161. #define BM_FLAGS_IDENTIFIABLE ((BM_DEVICE_FLAGS) 0x00000002)
  162. #define BM_FLAGS_CONFIGURABLE ((BM_DEVICE_FLAGS) 0x00000004)
  163. #define BM_FLAGS_POWER_CONTROL ((BM_DEVICE_FLAGS) 0x00000008)
  164. #define BM_FLAGS_EJECTABLE ((BM_DEVICE_FLAGS) 0x00000010)
  165. #define BM_FLAGS_DOCKING_STATION ((BM_DEVICE_FLAGS) 0x00000020)
  166. #define BM_FLAGS_FIXED_FEATURE ((BM_DEVICE_FLAGS) 0x00000040)
  167. #define BM_FLAGS_DRIVER_CONTROL ((BM_DEVICE_FLAGS) 0x80000000)
  168. /*
  169.  * Device PM Flags:
  170.  * ----------------
  171.  * +-----------+-+-+-+-+-+-+-+
  172.  * | Bits 31:7 |6|5|4|3|2|1|0|
  173.  * +-----------+-+-+-+-+-+-+-+
  174.  *       |      | | | | | | |
  175.  *       |      | | | | | | +- D0 Support?
  176.  *       |      | | | | | +--- D1 Support?
  177.  *       |      | | | | +----- D2 Support?
  178.  *       |      | | | +------- D3 Support?
  179.  *       |      | | +--------- Power State Queriable?
  180.  *       |      | +----------- Inrush Current?
  181.  *       |      +------------- Wake Capable?
  182.  *       +-------------------- <Reserved>
  183.  *
  184.  * D0-D3 Support:   Device supports corresponding Dx state.
  185.  * Power State:     Device has a _PSC (current power state) object defined.
  186.  * Inrush Current:  Device has an _IRC (inrush current) object defined.
  187.  * Wake Capable:    Device has a _PRW (wake-capable) object defined.
  188.  */
  189. #define BM_FLAGS_D0_SUPPORT ((BM_DEVICE_FLAGS) 0x00000001)
  190. #define BM_FLAGS_D1_SUPPORT ((BM_DEVICE_FLAGS) 0x00000002)
  191. #define BM_FLAGS_D2_SUPPORT ((BM_DEVICE_FLAGS) 0x00000004)
  192. #define BM_FLAGS_D3_SUPPORT ((BM_DEVICE_FLAGS) 0x00000008)
  193. #define BM_FLAGS_POWER_STATE ((BM_DEVICE_FLAGS) 0x00000010)
  194. #define BM_FLAGS_INRUSH_CURRENT ((BM_DEVICE_FLAGS) 0x00000020)
  195. #define BM_FLAGS_WAKE_CAPABLE ((BM_DEVICE_FLAGS) 0x00000040)
  196. /*
  197.  * BM_DEVICE_STATUS:
  198.  * -----------------
  199.  * The encoding of BM_DEVICE_STATUS is illustrated below.
  200.  * Note that a set bit (1) indicates the property is TRUE
  201.  * (e.g. if bit 0 is set then the device is present).
  202.  * +-----------+-+-+-+-+-+
  203.  * | Bits 31:4 |4|3|2|1|0|
  204.  * +-----------+-+-+-+-+-+
  205.  *       |      | | | | |
  206.  *       |      | | | | +- Present?
  207.  *       |      | | | +--- Enabled?
  208.  *       |      | | +----- Show in UI?
  209.  *       |      | +------- Functioning?
  210.  *       |      +--------- Battery Present?
  211.  *       +---------------- <Reserved>
  212.  */
  213. typedef u32 BM_DEVICE_STATUS;
  214. #define BM_STATUS_UNKNOWN ((BM_DEVICE_STATUS) 0x00000000)
  215. #define BM_STATUS_PRESENT ((BM_DEVICE_STATUS) 0x00000001)
  216. #define BM_STATUS_ENABLED ((BM_DEVICE_STATUS) 0x00000002)
  217. #define BM_STATUS_SHOW_UI ((BM_DEVICE_STATUS) 0x00000004)
  218. #define BM_STATUS_FUNCTIONING ((BM_DEVICE_STATUS) 0x00000008)
  219. #define BM_STATUS_BATTERY_PRESENT ((BM_DEVICE_STATUS) 0x00000010)
  220. #define BM_STATUS_DEFAULT ((BM_DEVICE_STATUS) 0x0000000F)
  221. /*
  222.  * BM_POWER_STATE:
  223.  * ---------------
  224.  */
  225. typedef u32 BM_POWER_STATE;
  226. /*
  227.  * BM_DEVICE_ID:
  228.  * -------------
  229.  */
  230. typedef struct
  231. {
  232. BM_DEVICE_TYPE type;
  233. BM_DEVICE_UID uid;
  234. BM_DEVICE_HID hid;
  235. BM_DEVICE_ADR adr;
  236. } BM_DEVICE_ID;
  237. /*
  238.  * BM_DEVICE_POWER:
  239.  * ----------------
  240.  * Structure containing basic device power management information.
  241.  */
  242. typedef struct
  243. {
  244. BM_DEVICE_FLAGS flags;
  245. BM_POWER_STATE state;
  246. BM_DEVICE_FLAGS dx_supported[ACPI_S_STATE_COUNT];
  247. } BM_DEVICE_POWER;
  248. /*
  249.  * BM_DEVICE:
  250.  * ----------
  251.  */
  252. typedef struct
  253. {
  254. BM_HANDLE handle;
  255. acpi_handle   acpi_handle;
  256. BM_DEVICE_FLAGS flags;
  257. BM_DEVICE_STATUS status;
  258. BM_DEVICE_ID id;
  259. BM_DEVICE_POWER power;
  260. } BM_DEVICE;
  261. /*
  262.  * BM_SEARCH:
  263.  * ----------
  264.  * Structure used for searching the ACPI Bus Manager's device hierarchy.
  265.  */
  266. typedef struct
  267. {
  268. BM_DEVICE_ID criteria;
  269. BM_HANDLE_LIST results;
  270. } BM_SEARCH;
  271. /*
  272.  * BM_REQUEST:
  273.  * -----------
  274.  * Structure used for sending requests to/through the ACPI Bus Manager.
  275.  */
  276. typedef struct
  277. {
  278. acpi_status status;
  279. BM_COMMAND command;
  280. BM_HANDLE handle;
  281. acpi_buffer buffer;
  282. } BM_REQUEST;
  283. /*
  284.  * Driver Registration:
  285.  * --------------------
  286.  */
  287. /* Driver Context */
  288. typedef void * BM_DRIVER_CONTEXT;
  289. /* Notification Callback Function */
  290. typedef
  291. acpi_status (*BM_DRIVER_NOTIFY) (
  292. BM_NOTIFY notify_type,
  293. BM_HANDLE device_handle,
  294. BM_DRIVER_CONTEXT *context);
  295. /* Request Callback Function */
  296. typedef
  297. acpi_status (*BM_DRIVER_REQUEST) (
  298. BM_REQUEST *request,
  299. BM_DRIVER_CONTEXT context);
  300. /* Driver Registration */
  301. typedef struct
  302. {
  303. BM_DRIVER_NOTIFY notify;
  304. BM_DRIVER_REQUEST request;
  305. BM_DRIVER_CONTEXT context;
  306. } BM_DRIVER;
  307. /*
  308.  * BM_NODE:
  309.  * --------
  310.  * Structure used to maintain the device hierarchy.
  311.  */
  312. typedef struct _BM_NODE
  313. {
  314. BM_DEVICE device;
  315. BM_DRIVER driver;
  316. struct _BM_NODE *parent;
  317. struct _BM_NODE *next;
  318. struct
  319. {
  320. struct _BM_NODE *head;
  321. struct _BM_NODE *tail;
  322. } scope;
  323. } BM_NODE;
  324. /*
  325.  * BM_NODE_LIST:
  326.  * -------------
  327.  * Structure used to maintain an array of node pointers.
  328.  */
  329. typedef struct
  330. {
  331. u32 count;
  332. BM_NODE *nodes[BM_HANDLES_MAX];
  333. } BM_NODE_LIST;
  334. /*****************************************************************************
  335.  *                                  Macros
  336.  *****************************************************************************/
  337. /*
  338.  * Device Presence:
  339.  * ----------------
  340.  * Note that status (_STA) means something different for power resources
  341.  * (they're assumed to always be present).
  342.  */
  343. #define BM_DEVICE_PRESENT(d) ((d->id.type!=BM_TYPE_POWER_RESOURCE)?(d->status & BM_STATUS_PRESENT):TRUE)
  344. #define BM_NODE_PRESENT(n) ((n->device.id.type!=BM_TYPE_POWER_RESOURCE)?(n->device.status & BM_STATUS_PRESENT):TRUE)
  345. /*
  346.  * Device Flags:
  347.  * -------------
  348.  */
  349. #define BM_IS_DRIVER_CONTROL(d) (d->flags & BM_FLAGS_DRIVER_CONTROL)
  350. #define BM_IS_POWER_CONTROL(d) (d->flags & BM_FLAGS_POWER_CONTROL)
  351.  /*
  352.  * Device Power Flags:
  353.  * -------------------
  354.  */
  355. #define BM_IS_POWER_STATE(d) (d->power.flags & BM_FLAGS_POWER_STATE)
  356. /*****************************************************************************
  357.  *                             Function Prototypes
  358.  *****************************************************************************/
  359. /* bm.c */
  360. acpi_status
  361. bm_initialize (void);
  362. acpi_status
  363. bm_terminate (void);
  364. acpi_status
  365. bm_get_status (
  366. BM_DEVICE *device);
  367. acpi_status
  368. bm_get_handle (
  369. acpi_handle             acpi_handle,
  370. BM_HANDLE               *device_handle);
  371. acpi_status
  372. bm_get_node (
  373. BM_HANDLE               device_handle,
  374. acpi_handle             acpi_handle,
  375. BM_NODE **node);
  376. /* bmsearch.c */
  377. acpi_status
  378. bm_search(
  379. BM_HANDLE               device_handle,
  380. BM_DEVICE_ID            *criteria,
  381. BM_HANDLE_LIST          *results);
  382. /* bmnotify.c */
  383. void
  384. bm_notify (
  385. acpi_handle             acpi_handle,
  386. u32                     notify_value,
  387. void                    *context);
  388. /* bm_request.c */
  389. acpi_status
  390. bm_request (
  391. BM_REQUEST *request_info);
  392. /* bmdriver.c */
  393. acpi_status
  394. bm_get_device_power_state (
  395. BM_HANDLE               device_handle,
  396. BM_POWER_STATE *state);
  397. acpi_status
  398. bm_set_device_power_state (
  399. BM_HANDLE               device_handle,
  400. BM_POWER_STATE state);
  401. acpi_status
  402. bm_get_device_status (
  403. BM_HANDLE               device_handle,
  404. BM_DEVICE_STATUS        *device_status);
  405. acpi_status
  406. bm_get_device_info (
  407. BM_HANDLE               device_handle,
  408. BM_DEVICE **device_info);
  409. acpi_status
  410. bm_get_device_context (
  411. BM_HANDLE               device_handle,
  412. BM_DRIVER_CONTEXT *context);
  413. acpi_status
  414. bm_register_driver (
  415. BM_DEVICE_ID *criteria,
  416. BM_DRIVER *driver);
  417. acpi_status
  418. bm_unregister_driver (
  419. BM_DEVICE_ID *criteria,
  420. BM_DRIVER *driver);
  421. /* bmpm.c */
  422. acpi_status
  423. bm_get_pm_capabilities (
  424. BM_NODE *node);
  425. acpi_status
  426. bm_get_power_state (
  427. BM_NODE *node);
  428. acpi_status
  429. bm_set_power_state (
  430. BM_NODE *node,
  431. BM_POWER_STATE          target_state);
  432. /* bmpower.c */
  433. acpi_status
  434. bm_pr_initialize (void);
  435. acpi_status
  436. bm_pr_terminate (void);
  437. /* bmutils.c */
  438. acpi_status
  439. bm_cast_buffer (
  440. acpi_buffer             *buffer,
  441. void                    **pointer,
  442. u32                     length);
  443. acpi_status
  444. bm_copy_to_buffer (
  445. acpi_buffer             *buffer,
  446. void                    *data,
  447. u32                     length);
  448. acpi_status
  449. bm_extract_package_data (
  450. acpi_object             *package,
  451. acpi_buffer             *format,
  452. acpi_buffer             *buffer);
  453. acpi_status
  454. bm_evaluate_object (
  455. acpi_handle             acpi_handle,
  456. acpi_string             pathname,
  457. acpi_object_list        *arguments,
  458. acpi_buffer             *buffer);
  459. acpi_status
  460. bm_evaluate_simple_integer (
  461. acpi_handle             acpi_handle,
  462. acpi_string             pathname,
  463. u32                     *data);
  464. acpi_status
  465. bm_evaluate_reference_list (
  466. acpi_handle             acpi_handle,
  467. acpi_string             pathname,
  468. BM_HANDLE_LIST          *reference_list);
  469. /* ACPI Bus Driver OSL */
  470. acpi_status
  471. bm_osl_generate_event (
  472. BM_HANDLE device_handle,
  473. char *device_type,
  474. char *device_instance,
  475. u32 event_type,
  476. u32 event_data);
  477. #endif  /* __BM_H__ */