ReactOS 0.4.17-dev-1190-g4c812f4
default_handlers.c File Reference
Include dependency graph for default_handlers.c:

Go to the source code of this file.

Classes

struct  pci_region_device
 
struct  pci_region_ctx
 
struct  memory_region_ctx
 
struct  io_region_ctx
 
struct  protected_io_range
 

Macros

#define PCI_ROOT_PNP_ID   "PNP0A03"
 
#define PCI_EXPRESS_ROOT_PNP_ID   "PNP0A08"
 
#define PCI_HEADER_SIZE   0x40
 
#define PCI_HEADER_TYPE_REG   0x0E
 
#define PCI_HEADER_TYPE_MASK   0x7F
 
#define PCI_HEADER_TYPE_NORMAL   0x00
 
#define PCI_HEADER_TYPE_PCI_BRIDGE   0x01
 
#define PCI_HEADER_TYPE_CARDBUS_BRIDGE   0x02
 
#define PCI_HEADER_TYPE_NO_DEVICE   0xFF
 
#define PCI_SECONDARY_BUS_REG   0x19
 
#define PCI_SUBSYSTEM_VENDOR_ID_REG   0x2C
 
#define PCI_EXPANSION_ROM_REG   0x30
 
#define PCI_INTERRUPT_LINE_REG   0x3C
 

Enumerations

enum  pci_region_state { PCI_REGION_STATE_UNKNOWN = 0 , PCI_REGION_STATE_OPEN , PCI_REGION_STATE_NOT_FOUND , PCI_REGION_STATE_UNREACHABLE }
 
enum  pci_device_kind { PCI_DEVICE_KIND_NONE , PCI_DEVICE_KIND_NORMAL , PCI_DEVICE_KIND_BRIDGE , PCI_DEVICE_KIND_UNCONFIGURED_BRIDGE }
 
enum  io_protection_kind { IO_PROTECTION_KIND_ALWAYS , IO_PROTECTION_KIND_XP_AND_ABOVE }
 

Functions

static uacpi_namespace_node * find_pci_root (uacpi_namespace_node *node)
 
static uacpi_bool pci_address_equal (const uacpi_pci_address *lhs, const uacpi_pci_address *rhs)
 
static void pci_region_device_close (struct pci_region_device *dev)
 
static uacpi_bool pci_region_device_open (struct pci_region_device *dev, const uacpi_pci_address *address)
 
static enum pci_device_kind pci_region_device_probe (struct pci_region_device *dev, const uacpi_pci_address *address, uacpi_u8 *out_secondary_bus)
 
static const uacpi_char * pci_region_state_to_string (uacpi_u8 state)
 
static struct pci_region_device * pci_region_resolve (struct pci_region_ctx *ctx)
 
static void pci_region_ctx_free (struct pci_region_ctx *ctx)
 
static uacpi_size pci_region_collect_devices (uacpi_namespace_node *pci_root, uacpi_namespace_node *device, struct pci_region_device *out)
 
static uacpi_status pci_region_find_devices (struct pci_region_ctx *ctx, uacpi_namespace_node *pci_root, uacpi_namespace_node *device)
 
static uacpi_status pci_region_attach (uacpi_region_attach_data *data)
 
static uacpi_status pci_region_detach (uacpi_region_detach_data *data)
 
static uacpi_bool pci_write_is_protected (struct pci_region_device *dev, uacpi_size offset)
 
static uacpi_status pci_region_do_rw (uacpi_region_op op, uacpi_region_rw_data *data)
 
static uacpi_status handle_pci_region (uacpi_region_op op, uacpi_handle op_data)
 
static uacpi_status memory_region_attach (uacpi_region_attach_data *data)
 
static uacpi_status memory_region_detach (uacpi_region_detach_data *data)
 
static uacpi_status io_region_attach (uacpi_region_attach_data *data)
 
static uacpi_status io_region_detach (uacpi_region_detach_data *data)
 
static uacpi_status memory_region_do_rw (uacpi_region_op op, uacpi_region_rw_data *data)
 
static uacpi_status handle_memory_region (uacpi_region_op op, uacpi_handle op_data)
 
static uacpi_status table_data_region_do_rw (uacpi_region_op op, uacpi_region_rw_data *data)
 
static uacpi_status handle_table_data_region (uacpi_region_op op, uacpi_handle op_data)
 
static uacpi_bool io_port_is_protected (uacpi_u64 port)
 
static uacpi_status io_region_do_rw (uacpi_region_op op, uacpi_region_rw_data *data)
 
static uacpi_status handle_io_region (uacpi_region_op op, uacpi_handle op_data)
 
void uacpi_install_default_address_space_handlers (void)
 

Variables

static const struct protected_io_range protected_io_ranges []
 

Macro Definition Documentation

◆ PCI_EXPANSION_ROM_REG

#define PCI_EXPANSION_ROM_REG   0x30

Definition at line 25 of file default_handlers.c.

◆ PCI_EXPRESS_ROOT_PNP_ID

#define PCI_EXPRESS_ROOT_PNP_ID   "PNP0A08"

Definition at line 14 of file default_handlers.c.

◆ PCI_HEADER_SIZE

#define PCI_HEADER_SIZE   0x40

Definition at line 16 of file default_handlers.c.

◆ PCI_HEADER_TYPE_CARDBUS_BRIDGE

#define PCI_HEADER_TYPE_CARDBUS_BRIDGE   0x02

Definition at line 21 of file default_handlers.c.

◆ PCI_HEADER_TYPE_MASK

#define PCI_HEADER_TYPE_MASK   0x7F

Definition at line 18 of file default_handlers.c.

◆ PCI_HEADER_TYPE_NO_DEVICE

#define PCI_HEADER_TYPE_NO_DEVICE   0xFF

Definition at line 22 of file default_handlers.c.

◆ PCI_HEADER_TYPE_NORMAL

#define PCI_HEADER_TYPE_NORMAL   0x00

Definition at line 19 of file default_handlers.c.

◆ PCI_HEADER_TYPE_PCI_BRIDGE

#define PCI_HEADER_TYPE_PCI_BRIDGE   0x01

Definition at line 20 of file default_handlers.c.

◆ PCI_HEADER_TYPE_REG

#define PCI_HEADER_TYPE_REG   0x0E

Definition at line 17 of file default_handlers.c.

◆ PCI_INTERRUPT_LINE_REG

#define PCI_INTERRUPT_LINE_REG   0x3C

Definition at line 26 of file default_handlers.c.

◆ PCI_ROOT_PNP_ID

#define PCI_ROOT_PNP_ID   "PNP0A03"

Definition at line 13 of file default_handlers.c.

◆ PCI_SECONDARY_BUS_REG

#define PCI_SECONDARY_BUS_REG   0x19

Definition at line 23 of file default_handlers.c.

◆ PCI_SUBSYSTEM_VENDOR_ID_REG

#define PCI_SUBSYSTEM_VENDOR_ID_REG   0x2C

Definition at line 24 of file default_handlers.c.

Enumeration Type Documentation

◆ io_protection_kind

Enumerator
IO_PROTECTION_KIND_ALWAYS 
IO_PROTECTION_KIND_XP_AND_ABOVE 

Definition at line 654 of file default_handlers.c.

654 {
656
657 // Only after AML has queried _OSI for Windows XP or anything newer
659};
@ IO_PROTECTION_KIND_ALWAYS
@ IO_PROTECTION_KIND_XP_AND_ABOVE

◆ pci_device_kind

Enumerator
PCI_DEVICE_KIND_NONE 
PCI_DEVICE_KIND_NORMAL 
PCI_DEVICE_KIND_BRIDGE 
PCI_DEVICE_KIND_UNCONFIGURED_BRIDGE 

Definition at line 94 of file default_handlers.c.

94 {
95 // There's no device at this address
97
100
101 // A bridge that has no secondary bus assigned
103};
@ PCI_DEVICE_KIND_BRIDGE
@ PCI_DEVICE_KIND_NORMAL
@ PCI_DEVICE_KIND_NONE
@ PCI_DEVICE_KIND_UNCONFIGURED_BRIDGE

◆ pci_region_state

Enumerator
PCI_REGION_STATE_UNKNOWN 
PCI_REGION_STATE_OPEN 
PCI_REGION_STATE_NOT_FOUND 
PCI_REGION_STATE_UNREACHABLE 

Definition at line 56 of file default_handlers.c.

56 {
61};
@ PCI_REGION_STATE_UNKNOWN
@ PCI_REGION_STATE_NOT_FOUND
@ PCI_REGION_STATE_UNREACHABLE
@ PCI_REGION_STATE_OPEN

Function Documentation

◆ find_pci_root()

static uacpi_namespace_node * find_pci_root ( uacpi_namespace_node *  node)
static

Definition at line 28 of file default_handlers.c.

29{
30 static const uacpi_char *pci_root_ids[] = {
34 };
36
37 while (parent != uacpi_namespace_root()) {
38 if (uacpi_device_matches_pnp_id(parent, pci_root_ids)) {
40 "found a PCI root node %.4s controlling region %.4s",
41 parent->name.text, node->name.text
42 );
43 return parent;
44 }
45
46 parent = parent->parent;
47 }
48
50 node, "unable to find PCI root controlling",
52 );
53 return node;
54}
#define PCI_EXPRESS_ROOT_PNP_ID
#define PCI_ROOT_PNP_ID
#define uacpi_trace(...)
Definition: log.h:33
uacpi_namespace_node * uacpi_namespace_root(void)
Definition: namespace.c:264
char uacpi_char
Definition: types.h:44
#define UACPI_NULL
Definition: types.h:33
@ UACPI_STATUS_NOT_FOUND
Definition: status.h:17
r parent
Definition: btrfs.c:3010
void uacpi_trace_region_error(uacpi_namespace_node *node, uacpi_char *message, uacpi_status ret)
Definition: opregion.c:25
Definition: dlist.c:348
uacpi_bool uacpi_device_matches_pnp_id(uacpi_namespace_node *node, const uacpi_char *const *list)
Definition: utilities.c:905

Referenced by pci_region_attach().

◆ handle_io_region()

static uacpi_status handle_io_region ( uacpi_region_op  op,
uacpi_handle  op_data 
)
static

Definition at line 763 of file default_handlers.c.

764{
765 switch (op) {
767 return io_region_attach(op_data);
769 return io_region_detach(op_data);
772 return io_region_do_rw(op, op_data);
773 default:
775 }
776}
static uacpi_status io_region_detach(uacpi_region_detach_data *data)
static uacpi_status io_region_attach(uacpi_region_attach_data *data)
static uacpi_status io_region_do_rw(uacpi_region_op op, uacpi_region_rw_data *data)
UINT op
Definition: effect.c:235
@ UACPI_STATUS_INVALID_ARGUMENT
Definition: status.h:18
@ UACPI_REGION_OP_DETACH
Definition: types.h:377
@ UACPI_REGION_OP_WRITE
Definition: types.h:381
@ UACPI_REGION_OP_READ
Definition: types.h:380
@ UACPI_REGION_OP_ATTACH
Definition: types.h:375

Referenced by uacpi_install_default_address_space_handlers().

◆ handle_memory_region()

static uacpi_status handle_memory_region ( uacpi_region_op  op,
uacpi_handle  op_data 
)
static

Definition at line 614 of file default_handlers.c.

615{
616 switch (op) {
618 return memory_region_attach(op_data);
620 return memory_region_detach(op_data);
623 return memory_region_do_rw(op, op_data);
624 default:
626 }
627}
static uacpi_status memory_region_do_rw(uacpi_region_op op, uacpi_region_rw_data *data)
static uacpi_status memory_region_attach(uacpi_region_attach_data *data)
static uacpi_status memory_region_detach(uacpi_region_detach_data *data)

Referenced by uacpi_install_default_address_space_handlers().

◆ handle_pci_region()

static uacpi_status handle_pci_region ( uacpi_region_op  op,
uacpi_handle  op_data 
)
static

Definition at line 504 of file default_handlers.c.

505{
506 switch (op) {
508 return pci_region_attach(op_data);
510 return pci_region_detach(op_data);
513 return pci_region_do_rw(op, op_data);
514 default:
516 }
517}
static uacpi_status pci_region_do_rw(uacpi_region_op op, uacpi_region_rw_data *data)
static uacpi_status pci_region_detach(uacpi_region_detach_data *data)
static uacpi_status pci_region_attach(uacpi_region_attach_data *data)

Referenced by uacpi_install_default_address_space_handlers().

◆ handle_table_data_region()

static uacpi_status handle_table_data_region ( uacpi_region_op  op,
uacpi_handle  op_data 
)
static

Definition at line 640 of file default_handlers.c.

641{
642 switch (op) {
645 return UACPI_STATUS_OK;
648 return table_data_region_do_rw(op, op_data);
649 default:
651 }
652}
static uacpi_status table_data_region_do_rw(uacpi_region_op op, uacpi_region_rw_data *data)
@ UACPI_STATUS_OK
Definition: status.h:11

Referenced by uacpi_install_default_address_space_handlers().

◆ io_port_is_protected()

static uacpi_bool io_port_is_protected ( uacpi_u64  port)
static

Definition at line 714 of file default_handlers.c.

715{
716 const struct protected_io_range *range;
718
719 for (i = 0; i < UACPI_ARRAY_SIZE(protected_io_ranges); ++i) {
721
722 if (port < range->first || port > range->last)
723 continue;
724 if (range->kind == IO_PROTECTION_KIND_ALWAYS)
725 return UACPI_TRUE;
726
729 }
730
731 return UACPI_FALSE;
732}
range
Definition: d3dx9_private.h:58
static const struct protected_io_range protected_io_ranges[]
USHORT port
Definition: uri.c:210
#define UACPI_ARRAY_SIZE(arr)
Definition: helpers.h:5
size_t uacpi_size
Definition: types.h:37
#define UACPI_FALSE
Definition: types.h:30
#define UACPI_TRUE
Definition: types.h:29
const GLint * first
Definition: glext.h:5794
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uacpi_vendor_interface uacpi_latest_queried_vendor_interface(void)
Definition: osi.c:136
@ UACPI_VENDOR_INTERFACE_WINDOWS_XP
Definition: osi.h:15

Referenced by io_region_do_rw().

◆ io_region_attach()

static uacpi_status io_region_attach ( uacpi_region_attach_data *  data)
static

Definition at line 566 of file default_handlers.c.

567{
568 struct io_region_ctx *ctx;
569 uacpi_generic_region_info *info = &data->generic_info;
571
572 ctx = uacpi_kernel_alloc(sizeof(*ctx));
573 if (ctx == UACPI_NULL)
575
576 ctx->base = info->base;
577
578 ret = uacpi_kernel_io_map(ctx->base, info->length, &ctx->handle);
581 data->region_node, "unable to map an IO", ret
582 );
583 uacpi_free(ctx, sizeof(*ctx));
584 return ret;
585 }
586
587 data->out_region_context = ctx;
588 return ret;
589}
#define uacpi_free(mem, _)
Definition: stdlib.h:96
#define uacpi_unlikely_error(expr)
Definition: status.h:50
uacpi_status
Definition: status.h:10
@ UACPI_STATUS_OUT_OF_MEMORY
Definition: status.h:13
return ret
Definition: mutex.c:147
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
uacpi_status uacpi_kernel_io_map(uacpi_io_addr base, uacpi_size len, uacpi_handle *out_handle)
Definition: uacpiosl.c:165
void * uacpi_kernel_alloc(uacpi_size size)
Definition: uacpiosl.c:111

Referenced by handle_io_region().

◆ io_region_detach()

static uacpi_status io_region_detach ( uacpi_region_detach_data *  data)
static

Definition at line 591 of file default_handlers.c.

592{
593 struct io_region_ctx *ctx = data->region_context;
594
595 uacpi_kernel_io_unmap(ctx->handle);
596 uacpi_free(ctx, sizeof(*ctx));
597 return UACPI_STATUS_OK;
598}
void uacpi_kernel_io_unmap(uacpi_handle handle)
Definition: uacpiosl.c:171

Referenced by handle_io_region().

◆ io_region_do_rw()

static uacpi_status io_region_do_rw ( uacpi_region_op  op,
uacpi_region_rw_data *  data 
)
static

Definition at line 734 of file default_handlers.c.

737{
738 struct io_region_ctx *ctx = data->region_context;
741
742 offset = data->offset - ctx->base;
743 width = data->byte_width;
744
745 if (io_port_is_protected(data->offset)) {
747 "denied AML %s access to protected port 0x%04"UACPI_PRIX64,
748 op == UACPI_REGION_OP_READ ? "read" : "write",
749 UACPI_FMT64(data->offset)
750 );
751
753 data->value = 0;
754
755 return UACPI_STATUS_OK;
756 }
757
758 return op == UACPI_REGION_OP_READ ?
759 uacpi_system_io_read(ctx->handle, offset, width, &data->value) :
761}
static uacpi_bool io_port_is_protected(uacpi_u64 port)
uacpi_status uacpi_system_io_write(uacpi_handle handle, uacpi_size offset, uacpi_u8 width, uacpi_u64 in)
Definition: io.c:1223
uacpi_status uacpi_system_io_read(uacpi_handle handle, uacpi_size offset, uacpi_u8 width, uacpi_u64 *out)
Definition: io.c:1191
#define UACPI_PRIX64
Definition: types.h:61
uint8_t uacpi_u8
Definition: types.h:19
#define UACPI_FMT64(val)
Definition: types.h:62
GLint GLint GLsizei width
Definition: gl.h:1546
GLintptr offset
Definition: glext.h:5920
Definition: pdh_main.c:64

Referenced by handle_io_region().

◆ memory_region_attach()

static uacpi_status memory_region_attach ( uacpi_region_attach_data *  data)
static

Definition at line 525 of file default_handlers.c.

526{
527 struct memory_region_ctx *ctx;
529
530 ctx = uacpi_kernel_alloc(sizeof(*ctx));
531 if (ctx == UACPI_NULL)
533
534 ctx->size = data->generic_info.length;
535
536 // FIXME: this really shouldn't try to map everything at once
537 ctx->phys = data->generic_info.base;
538 ctx->virt = uacpi_kernel_map(ctx->phys, ctx->size);
539
540 if (uacpi_unlikely(ctx->virt == UACPI_MAP_FAILED)) {
542 uacpi_trace_region_error(data->region_node, "unable to map", ret);
543 uacpi_free(ctx, sizeof(*ctx));
544 goto out;
545 }
546
547 data->out_region_context = ctx;
548out:
549 return ret;
550}
#define uacpi_unlikely(expr)
Definition: compiler.h:88
@ UACPI_STATUS_MAPPING_FAILED
Definition: status.h:12
#define UACPI_MAP_FAILED
Definition: kernel_api.h:13
void * uacpi_kernel_map(uacpi_phys_addr addr, uacpi_size len)
Definition: uacpiosl.c:191
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by handle_memory_region().

◆ memory_region_detach()

static uacpi_status memory_region_detach ( uacpi_region_detach_data *  data)
static

Definition at line 552 of file default_handlers.c.

553{
554 struct memory_region_ctx *ctx = data->region_context;
555
556 uacpi_kernel_unmap(ctx->virt, ctx->size);
557 uacpi_free(ctx, sizeof(*ctx));
558 return UACPI_STATUS_OK;
559}
void uacpi_kernel_unmap(void *addr, uacpi_size len)
Definition: uacpiosl.c:198

Referenced by handle_memory_region().

◆ memory_region_do_rw()

static uacpi_status memory_region_do_rw ( uacpi_region_op  op,
uacpi_region_rw_data *  data 
)
static

Definition at line 600 of file default_handlers.c.

603{
604 struct memory_region_ctx *ctx = data->region_context;
606
607 offset = data->address - ctx->phys;
608
609 return op == UACPI_REGION_OP_READ ?
610 uacpi_system_memory_read(ctx->virt, offset, data->byte_width, &data->value) :
612}
uacpi_status uacpi_system_memory_read(void *ptr, uacpi_size offset, uacpi_u8 width, uacpi_u64 *out)
Definition: io.c:1132
uacpi_status uacpi_system_memory_write(void *ptr, uacpi_size offset, uacpi_u8 width, uacpi_u64 in)
Definition: io.c:1158

Referenced by handle_memory_region().

◆ pci_address_equal()

static uacpi_bool pci_address_equal ( const uacpi_pci_address *  lhs,
const uacpi_pci_address *  rhs 
)
static

Definition at line 105 of file default_handlers.c.

108{
109 return lhs->segment == rhs->segment && lhs->bus == rhs->bus &&
110 lhs->device == rhs->device && lhs->function == rhs->function;
111}
uacpi_u8 device
Definition: types.h:90
uacpi_u8 bus
Definition: types.h:89
uacpi_u8 function
Definition: types.h:91
uacpi_u16 segment
Definition: types.h:88

Referenced by pci_region_device_open(), and pci_region_resolve().

◆ pci_region_attach()

static uacpi_status pci_region_attach ( uacpi_region_attach_data *  data)
static

Definition at line 372 of file default_handlers.c.

373{
374 uacpi_namespace_node *node, *pci_root, *device;
375 struct pci_region_ctx *ctx;
378
379 node = data->region_node;
380 pci_root = find_pci_root(node);
381
382 /*
383 * Find the actual device object that is supposed to be controlling
384 * this operation region.
385 */
386 device = node;
387 while (device) {
389
392 return ret;
393
395 break;
396
397 device = device->parent;
398 }
399
403 node, "unable to find device responsible for", ret
404 );
405 return ret;
406 }
407
411
412 ctx->node = device;
413
414 ret = uacpi_eval_simple_integer(pci_root, "_SEG", &value);
415 if (ret == UACPI_STATUS_OK)
416 ctx->root_address.segment = value;
417
418 ret = uacpi_eval_simple_integer(pci_root, "_BBN", &value);
419 if (ret == UACPI_STATUS_OK)
420 ctx->root_address.bus = value;
421
424 uacpi_free(ctx, sizeof(*ctx));
425 return ret;
426 }
427
428 data->out_region_context = ctx;
429 return UACPI_STATUS_OK;
430}
static uacpi_status pci_region_find_devices(struct pci_region_ctx *ctx, uacpi_namespace_node *pci_root, uacpi_namespace_node *device)
static uacpi_namespace_node * find_pci_root(uacpi_namespace_node *node)
#define uacpi_kernel_alloc_zeroed
Definition: stdlib.h:127
uacpi_status uacpi_namespace_node_type(const uacpi_namespace_node *node, uacpi_object_type *out_type)
Definition: namespace.c:781
uint64_t uacpi_u64
Definition: types.h:22
uacpi_object_type
Definition: types.h:110
@ UACPI_OBJECT_DEVICE
Definition: types.h:117
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
Definition: devices.h:37
uacpi_namespace_node * node
uacpi_status uacpi_eval_simple_integer(uacpi_namespace_node *parent, const uacpi_char *path, uacpi_u64 *out_value)
Definition: uacpi.c:924

Referenced by handle_pci_region().

◆ pci_region_collect_devices()

static uacpi_size pci_region_collect_devices ( uacpi_namespace_node *  pci_root,
uacpi_namespace_node *  device,
struct pci_region_device *  out 
)
static

Definition at line 286 of file default_handlers.c.

290{
292 uacpi_size depth = 0, count = 0, i;
295 uacpi_u64 adr;
296
297 for (node = device; node != UACPI_NULL && node != pci_root;
298 node = node->parent)
299 depth++;
300
301 // There's no root above the device, the best we can do is use its _ADR
302 if (node == UACPI_NULL)
303 depth = 1;
304
305 while (depth-- != 0) {
306 node = device;
307 for (i = 0; i < depth; ++i)
308 node = node->parent;
309
312 break;
313
314 ret = uacpi_eval_simple_integer(node, "_ADR", &adr);
315 if (ret != UACPI_STATUS_OK)
316 break;
317
318 if (out != UACPI_NULL) {
319 out[count].function = (adr >> 0) & 0xFF;
320 out[count].device = (adr >> 16) & 0xFF;
321 }
322 count++;
323 }
324
325 return count;
326}
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by pci_region_find_devices().

◆ pci_region_ctx_free()

static void pci_region_ctx_free ( struct pci_region_ctx *  ctx)
static

Definition at line 268 of file default_handlers.c.

269{
271
272 for (i = 0; i < ctx->num_devices; ++i)
273 pci_region_device_close(&ctx->devices[i]);
274
275 if (ctx->devices != UACPI_NULL)
276 uacpi_free(ctx->devices, ctx->num_devices * sizeof(*ctx->devices));
277
278 uacpi_free(ctx, sizeof(*ctx));
279}
static void pci_region_device_close(struct pci_region_device *dev)

Referenced by pci_region_detach().

◆ pci_region_detach()

static uacpi_status pci_region_detach ( uacpi_region_detach_data *  data)
static

Definition at line 432 of file default_handlers.c.

433{
434 pci_region_ctx_free(data->region_context);
435 return UACPI_STATUS_OK;
436}
static void pci_region_ctx_free(struct pci_region_ctx *ctx)

Referenced by handle_pci_region().

◆ pci_region_device_close()

static void pci_region_device_close ( struct pci_region_device *  dev)
static

Definition at line 113 of file default_handlers.c.

114{
115 if (!dev->is_open)
116 return;
117
119 dev->is_open = UACPI_FALSE;
120}
void uacpi_kernel_pci_device_close(uacpi_handle)
Definition: uacpiosl.c:251

Referenced by pci_region_ctx_free(), pci_region_device_open(), and pci_region_resolve().

◆ pci_region_device_open()

static uacpi_bool pci_region_device_open ( struct pci_region_device *  dev,
const uacpi_pci_address *  address 
)
static

Definition at line 123 of file default_handlers.c.

126{
128
129 if (dev->is_open) {
130 if (pci_address_equal(&dev->address, address))
131 return UACPI_TRUE;
132
134 }
135
137 if (ret != UACPI_STATUS_OK)
138 return UACPI_FALSE;
139
140 dev->address = *address;
141 dev->is_open = UACPI_TRUE;
142 return UACPI_TRUE;
143}
static uacpi_bool pci_address_equal(const uacpi_pci_address *lhs, const uacpi_pci_address *rhs)
GLuint address
Definition: glext.h:9393
uacpi_status uacpi_kernel_pci_device_open(uacpi_pci_address address, uacpi_handle *out_handle)
Definition: uacpiosl.c:242

Referenced by pci_region_device_probe(), and pci_region_resolve().

◆ pci_region_device_probe()

static enum pci_device_kind pci_region_device_probe ( struct pci_region_device *  dev,
const uacpi_pci_address *  address,
uacpi_u8 *  out_secondary_bus 
)
static

Definition at line 146 of file default_handlers.c.

150{
152 uacpi_u8 header_type;
153
156
158 dev->handle, PCI_HEADER_TYPE_REG, &header_type
159 );
160 if (ret != UACPI_STATUS_OK || header_type == PCI_HEADER_TYPE_NO_DEVICE)
162
163 switch (header_type & PCI_HEADER_TYPE_MASK) {
166 break;
167 default:
169 }
170
172 dev->handle, PCI_SECONDARY_BUS_REG, out_secondary_bus
173 );
174 if (ret != UACPI_STATUS_OK || *out_secondary_bus == 0)
176
178}
#define PCI_HEADER_TYPE_CARDBUS_BRIDGE
#define PCI_HEADER_TYPE_NO_DEVICE
static uacpi_bool pci_region_device_open(struct pci_region_device *dev, const uacpi_pci_address *address)
#define PCI_HEADER_TYPE_PCI_BRIDGE
#define PCI_HEADER_TYPE_MASK
#define PCI_HEADER_TYPE_REG
#define PCI_SECONDARY_BUS_REG
uacpi_status uacpi_kernel_pci_read8(uacpi_handle device, uacpi_size offset, uacpi_u8 *value)
Definition: uacpiosl.c:257

Referenced by pci_region_resolve().

◆ pci_region_do_rw()

static uacpi_status pci_region_do_rw ( uacpi_region_op  op,
uacpi_region_rw_data *  data 
)
static

Definition at line 463 of file default_handlers.c.

466{
469 struct pci_region_device *dev;
470
471 offset = data->offset;
472 width = data->byte_width;
473
474 dev = pci_region_resolve(data->region_context);
475 if (dev == UACPI_NULL) {
477 "faking a PCI device %s access",
478 op == UACPI_REGION_OP_READ ? "read" : "write"
479 );
480
481 if (op == UACPI_REGION_OP_READ) {
482 static uacpi_u64 ffs = 0xFFFFFFFFFFFFFFFF;
483 uacpi_memcpy(&data->value, &ffs, width);
484 }
485
486 return UACPI_STATUS_OK;
487 }
488
490 return uacpi_pci_read(dev->handle, offset, width, &data->value);
491
494 "denied AML write access to protected offset 0x%02zX of PCI "
495 "device %04X:%02X:%02X:%01X", offset, dev->address.segment,
496 dev->address.bus, dev->address.device, dev->address.function
497 );
498 return UACPI_STATUS_OK;
499 }
500
501 return uacpi_pci_write(dev->handle, offset, width, data->value);
502}
static uacpi_bool pci_write_is_protected(struct pci_region_device *dev, uacpi_size offset)
static struct pci_region_device * pci_region_resolve(struct pci_region_ctx *ctx)
uacpi_status uacpi_pci_write(uacpi_handle handle, uacpi_size offset, uacpi_u8 width, uacpi_u64 in)
Definition: io.c:1282
uacpi_status uacpi_pci_read(uacpi_handle handle, uacpi_size offset, uacpi_u8 width, uacpi_u64 *out)
Definition: io.c:1250
#define uacpi_memcpy
Definition: stdlib.h:34
#define ffs
Definition: port.h:360

Referenced by handle_pci_region().

◆ pci_region_find_devices()

static uacpi_status pci_region_find_devices ( struct pci_region_ctx *  ctx,
uacpi_namespace_node *  pci_root,
uacpi_namespace_node *  device 
)
static

Definition at line 328 of file default_handlers.c.

332{
336 uacpi_u64 adr;
337
339 if (count != 0) {
343
344 ctx->devices = devices;
345 ctx->num_devices = pci_region_collect_devices(
346 pci_root, device, devices
347 );
348 return UACPI_STATUS_OK;
349 }
350
351 ret = uacpi_eval_simple_integer(pci_root, "_ADR", &adr);
352 if (ret != UACPI_STATUS_OK) {
354 "unable to determine the PCI address of %.4s",
355 device->name.text
356 );
357 return UACPI_STATUS_OK;
358 }
359
363
364 devices->function = (adr >> 0) & 0xFF;
365 devices->device = (adr >> 16) & 0xFF;
366
367 ctx->devices = devices;
368 ctx->num_devices = 1;
369 return UACPI_STATUS_OK;
370}
static uacpi_size pci_region_collect_devices(uacpi_namespace_node *pci_root, uacpi_namespace_node *device, struct pci_region_device *out)
static struct all_devices * devices
Definition: dsm_ctrl.c:48

Referenced by pci_region_attach().

◆ pci_region_resolve()

static struct pci_region_device * pci_region_resolve ( struct pci_region_ctx *  ctx)
static

Definition at line 211 of file default_handlers.c.

212{
213 struct pci_region_device *dev;
214 uacpi_pci_address address = ctx->root_address;
216 enum pci_device_kind kind;
218 uacpi_u8 bus;
219
220 // The region doesn't belong to any device, see pci_region_find_devices()
221 if (ctx->num_devices == 0)
222 return UACPI_NULL;
223
224 for (i = 0;; ++i) {
225 dev = &ctx->devices[i];
226
227 address.device = dev->device;
228 address.function = dev->function;
229
230 // Nothing below us, so this is the one
231 if ((i + 1) == ctx->num_devices)
232 break;
233
234 kind = pci_region_device_probe(dev, &address, &bus);
235 if (kind == PCI_DEVICE_KIND_BRIDGE) {
236 address.bus = bus;
237 continue;
238 }
239
240 // Whatever is below a normal device belongs to it, so we're done
241 if (kind != PCI_DEVICE_KIND_NORMAL)
243 break;
244 }
245
246 // Whatever is below the device we stopped at is of no use anymore
247 while (++i < ctx->num_devices)
248 pci_region_device_close(&ctx->devices[i]);
249
253
254 if (state != ctx->state || !pci_address_equal(&address, &ctx->address)) {
256 "PCI device %.4s %s at %04X:%02X:%02X:%01X", ctx->node->name.text,
258 address.device, address.function
259 );
260
261 ctx->address = address;
262 ctx->state = state;
263 }
264
266}
static int state
Definition: maze.c:121
pci_device_kind
static const uacpi_char * pci_region_state_to_string(uacpi_u8 state)
static enum pci_device_kind pci_region_device_probe(struct pci_region_device *dev, const uacpi_pci_address *address, uacpi_u8 *out_secondary_bus)

Referenced by pci_region_do_rw().

◆ pci_region_state_to_string()

static const uacpi_char * pci_region_state_to_string ( uacpi_u8  state)
static

Definition at line 180 of file default_handlers.c.

181{
182 switch (state) {
184 return "detected";
186 return "is not present or powered off";
187 default:
188 return "is unreachable due to a missing or unconfigured bridge";
189 }
190}

Referenced by pci_region_resolve().

◆ pci_write_is_protected()

static uacpi_bool pci_write_is_protected ( struct pci_region_device *  dev,
uacpi_size  offset 
)
static

Definition at line 439 of file default_handlers.c.

442{
444 uacpi_u8 header_type;
445
446 if (offset >= PCI_HEADER_SIZE)
447 return UACPI_FALSE;
448
450 return UACPI_TRUE;
452 return UACPI_TRUE;
453
455 dev->handle, PCI_HEADER_TYPE_REG, &header_type
456 );
458 return UACPI_TRUE;
459
460 return (header_type & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL;
461}
#define PCI_INTERRUPT_LINE_REG
#define PCI_HEADER_SIZE
#define PCI_EXPANSION_ROM_REG
#define PCI_HEADER_TYPE_NORMAL
#define PCI_SUBSYSTEM_VENDOR_ID_REG

Referenced by pci_region_do_rw().

◆ table_data_region_do_rw()

static uacpi_status table_data_region_do_rw ( uacpi_region_op  op,
uacpi_region_rw_data *  data 
)
static

Definition at line 629 of file default_handlers.c.

632{
634
635 return op == UACPI_REGION_OP_READ ?
636 uacpi_system_memory_read(addr, 0, data->byte_width, &data->value) :
637 uacpi_system_memory_write(addr, 0, data->byte_width, data->value);
638}
uacpi_uintptr uacpi_virt_addr
Definition: types.h:36
GLenum const GLvoid * addr
Definition: glext.h:9621
#define UACPI_VIRT_ADDR_TO_PTR(vaddr)
Definition: utilities.h:21

Referenced by handle_table_data_region().

◆ uacpi_install_default_address_space_handlers()

void uacpi_install_default_address_space_handlers ( void  )

Definition at line 778 of file default_handlers.c.

779{
781
783
788 );
789
794 );
795
800 );
801
806 );
807}
struct _root root
static uacpi_status handle_table_data_region(uacpi_region_op op, uacpi_handle op_data)
static uacpi_status handle_io_region(uacpi_region_op op, uacpi_handle op_data)
static uacpi_status handle_memory_region(uacpi_region_op op, uacpi_handle op_data)
static uacpi_status handle_pci_region(uacpi_region_op op, uacpi_handle op_data)
#define UACPI_ADDRESS_SPACE_HANDLER_DEFAULT
Definition: types.h:73
@ UACPI_ADDRESS_SPACE_SYSTEM_MEMORY
Definition: types.h:43
@ UACPI_ADDRESS_SPACE_PCI_CONFIG
Definition: types.h:45
@ UACPI_ADDRESS_SPACE_TABLE_DATA
Definition: types.h:58
@ UACPI_ADDRESS_SPACE_SYSTEM_IO
Definition: types.h:44
uacpi_status uacpi_install_address_space_handler_with_flags(uacpi_namespace_node *device_node, enum uacpi_address_space space, uacpi_region_handler handler, uacpi_handle handler_context, uacpi_u16 flags)
Definition: opregion.c:882

Referenced by uacpi_initialize().

Variable Documentation

◆ protected_io_ranges

const struct protected_io_range protected_io_ranges[]
static

Definition at line 672 of file default_handlers.c.

Referenced by io_port_is_protected().