iPXE
efi_pci.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <ipxe/pci.h>
29 #include <ipxe/acpi.h>
30 #include <ipxe/efi/efi.h>
31 #include <ipxe/efi/efi_pci.h>
32 #include <ipxe/efi/efi_driver.h>
35 
36 /** @file
37  *
38  * iPXE PCI I/O API for EFI
39  *
40  */
41 
42 /* Disambiguate the various error causes */
43 #define EINFO_EEFI_PCI \
44  __einfo_uniqify ( EINFO_EPLATFORM, 0x01, \
45  "Could not open PCI I/O protocol" )
46 #define EINFO_EEFI_PCI_NOT_PCI \
47  __einfo_platformify ( EINFO_EEFI_PCI, EFI_UNSUPPORTED, \
48  "Not a PCI device" )
49 #define EEFI_PCI_NOT_PCI __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )
50 #define EINFO_EEFI_PCI_IN_USE \
51  __einfo_platformify ( EINFO_EEFI_PCI, EFI_ACCESS_DENIED, \
52  "PCI device already has a driver" )
53 #define EEFI_PCI_IN_USE __einfo_error ( EINFO_EEFI_PCI_IN_USE )
54 #define EEFI_PCI( efirc ) \
55  EPLATFORM ( EINFO_EEFI_PCI, efirc, \
56  EEFI_PCI_NOT_PCI, EEFI_PCI_IN_USE )
57 
58 /******************************************************************************
59  *
60  * iPXE PCI API
61  *
62  ******************************************************************************
63  */
64 
65 /**
66  * Find closest bus:dev.fn address range within a root bridge
67  *
68  * @v pci Starting PCI device
69  * @v handle EFI PCI root bridge handle
70  * @v range PCI bus:dev.fn address range to fill in
71  * @ret rc Return status code
72  */
73 static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle,
74  struct pci_range *range ) {
76  union {
77  void *interface;
79  } root;
80  union {
81  union acpi_resource *res;
82  void *raw;
83  } acpi;
84  uint32_t best = 0;
88  unsigned int tag;
89  EFI_STATUS efirc;
90  int rc;
91 
92  /* Return empty range on error */
93  range->start = 0;
94  range->count = 0;
95 
96  /* Open root bridge I/O protocol */
97  if ( ( efirc = bs->OpenProtocol ( handle,
99  &root.interface, efi_image_handle, handle,
100  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
101  rc = -EEFI ( efirc );
102  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
103  PCI_ARGS ( pci ), efi_handle_name ( handle ),
104  strerror ( rc ) );
105  goto err_open;
106  }
107 
108  /* Get ACPI resource descriptors */
109  if ( ( efirc = root.root->Configuration ( root.root,
110  &acpi.raw ) ) != 0 ) {
111  rc = -EEFI ( efirc );
112  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
113  "%s: %s\n", PCI_ARGS ( pci ),
114  efi_handle_name ( handle ), strerror ( rc ) );
115  goto err_config;
116  }
117 
118  /* Parse resource descriptors */
119  for ( ; ( ( tag = acpi_resource_tag ( acpi.res ) ) !=
121  acpi.res = acpi_resource_next ( acpi.res ) ) {
122 
123  /* Ignore anything other than a bus number range descriptor */
125  continue;
126  if ( acpi.res->qword.type != ACPI_ADDRESS_TYPE_BUS )
127  continue;
128 
129  /* Get range for this descriptor */
130  start = PCI_BUSDEVFN ( root.root->SegmentNumber,
131  le64_to_cpu ( acpi.res->qword.min ),
132  0, 0 );
133  count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ),
134  0, 0 );
135  DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via "
136  "%s\n", PCI_ARGS ( pci ), root.root->SegmentNumber,
137  PCI_BUS ( start ), PCI_BUS ( start + count - 1 ),
138  efi_handle_name ( handle ) );
139 
140  /* Check for a matching or new closest range */
141  index = ( pci->busdevfn - start );
142  if ( ( index < count ) || ( index > best ) ) {
143  range->start = start;
144  range->count = count;
145  best = index;
146  }
147 
148  /* Stop if this range contains the target bus:dev.fn address */
149  if ( index < count )
150  break;
151  }
152 
153  /* If no range descriptors were seen, assume that the root
154  * bridge has a single bus.
155  */
156  if ( ! range->count ) {
157  range->start = PCI_BUSDEVFN ( root.root->SegmentNumber,
158  0, 0, 0 );
159  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
160  }
161 
162  /* Success */
163  rc = 0;
164 
165  err_config:
168  err_open:
169  return rc;
170 }
171 
172 /**
173  * Find closest bus:dev.fn address range within any root bridge
174  *
175  * @v pci Starting PCI device
176  * @v range PCI bus:dev.fn address range to fill in
177  * @v handle PCI root bridge I/O handle to fill in
178  * @ret rc Return status code
179  */
180 static int efipci_discover_any ( struct pci_device *pci,
181  struct pci_range *range,
182  EFI_HANDLE *handle ) {
184  uint32_t best = 0;
185  uint32_t index;
186  struct pci_range tmp;
187  EFI_HANDLE *handles;
188  UINTN num_handles;
189  UINTN i;
190  EFI_STATUS efirc;
191  int rc;
192 
193  /* Return an empty range and no handle on error */
194  range->start = 0;
195  range->count = 0;
196  *handle = NULL;
197 
198  /* Enumerate all root bridge I/O protocol handles */
199  if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
201  NULL, &num_handles, &handles ) ) != 0 ) {
202  rc = -EEFI ( efirc );
203  DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
204  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
205  goto err_locate;
206  }
207 
208  /* Iterate over all root bridge I/O protocols */
209  for ( i = 0 ; i < num_handles ; i++ ) {
210 
211  /* Get matching or closest range for this root bridge */
212  if ( ( rc = efipci_discover_one ( pci, handles[i],
213  &tmp ) ) != 0 )
214  continue;
215 
216  /* Check for a matching or new closest range */
217  index = ( pci->busdevfn - tmp.start );
218  if ( ( index < tmp.count ) || ( index > best ) ) {
219  range->start = tmp.start;
220  range->count = tmp.count;
221  best = index;
222  }
223 
224  /* Stop if this range contains the target bus:dev.fn address */
225  if ( index < tmp.count ) {
226  *handle = handles[i];
227  break;
228  }
229  }
230 
231  /* Check for a range containing the target bus:dev.fn address */
232  if ( ! *handle ) {
233  rc = -ENOENT;
234  goto err_range;
235  }
236 
237  /* Success */
238  rc = 0;
239 
240  err_range:
241  bs->FreePool ( handles );
242  err_locate:
243  return rc;
244 }
245 
246 /**
247  * Find next PCI bus:dev.fn address range in system
248  *
249  * @v busdevfn Starting PCI bus:dev.fn address
250  * @v range PCI bus:dev.fn address range to fill in
251  */
252 static void efipci_discover ( uint32_t busdevfn, struct pci_range *range ) {
253  struct pci_device pci;
255 
256  /* Find range */
257  memset ( &pci, 0, sizeof ( pci ) );
258  pci_init ( &pci, busdevfn );
259  efipci_discover_any ( &pci, range, &handle );
260 }
261 
262 /**
263  * Open EFI PCI root bridge I/O protocol
264  *
265  * @v pci PCI device
266  * @ret handle EFI PCI root bridge handle
267  * @ret root EFI PCI root bridge I/O protocol, or NULL if not found
268  * @ret rc Return status code
269  */
270 static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle,
273  struct pci_range tmp;
274  union {
275  void *interface;
277  } u;
278  EFI_STATUS efirc;
279  int rc;
280 
281  /* Find matching root bridge I/O protocol handle */
282  if ( ( rc = efipci_discover_any ( pci, &tmp, handle ) ) != 0 )
283  return rc;
284 
285  /* (Re)open PCI root bridge I/O protocol */
286  if ( ( efirc = bs->OpenProtocol ( *handle,
288  &u.interface, efi_image_handle, *handle,
289  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
290  rc = -EEFI ( efirc );
291  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
292  PCI_ARGS ( pci ), efi_handle_name ( *handle ),
293  strerror ( rc ) );
294  return rc;
295  }
296 
297  /* Return opened protocol */
298  *root = u.root;
299 
300  return 0;
301 }
302 
303 /**
304  * Close EFI PCI root bridge I/O protocol
305  *
306  * @v handle EFI PCI root bridge handle
307  */
310 
311  /* Close protocol */
314 }
315 
316 /**
317  * Calculate EFI PCI configuration space address
318  *
319  * @v pci PCI device
320  * @v location Encoded offset and width
321  * @ret address EFI PCI address
322  */
323 static unsigned long efipci_address ( struct pci_device *pci,
324  unsigned long location ) {
325 
326  return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
327  PCI_SLOT ( pci->busdevfn ),
328  PCI_FUNC ( pci->busdevfn ),
329  EFIPCI_OFFSET ( location ) );
330 }
331 
332 /**
333  * Read from PCI configuration space
334  *
335  * @v pci PCI device
336  * @v location Encoded offset and width
337  * @ret value Value
338  * @ret rc Return status code
339  */
340 int efipci_read ( struct pci_device *pci, unsigned long location,
341  void *value ) {
344  EFI_STATUS efirc;
345  int rc;
346 
347  /* Open root bridge */
348  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
349  goto err_root;
350 
351  /* Read from configuration space */
352  if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
353  efipci_address ( pci, location ), 1,
354  value ) ) != 0 ) {
355  rc = -EEFI ( efirc );
356  DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
357  "failed: %s\n", PCI_ARGS ( pci ),
358  EFIPCI_OFFSET ( location ), strerror ( rc ) );
359  goto err_read;
360  }
361 
362  err_read:
364  err_root:
365  return rc;
366 }
367 
368 /**
369  * Write to PCI configuration space
370  *
371  * @v pci PCI device
372  * @v location Encoded offset and width
373  * @v value Value
374  * @ret rc Return status code
375  */
376 int efipci_write ( struct pci_device *pci, unsigned long location,
377  unsigned long value ) {
380  EFI_STATUS efirc;
381  int rc;
382 
383  /* Open root bridge */
384  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
385  goto err_root;
386 
387  /* Read from configuration space */
388  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
389  efipci_address ( pci, location ), 1,
390  &value ) ) != 0 ) {
391  rc = -EEFI ( efirc );
392  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
393  "failed: %s\n", PCI_ARGS ( pci ),
394  EFIPCI_OFFSET ( location ), strerror ( rc ) );
395  goto err_write;
396  }
397 
398  err_write:
400  err_root:
401  return rc;
402 }
403 
404 /**
405  * Map PCI bus address as an I/O address
406  *
407  * @v bus_addr PCI bus address
408  * @v len Length of region
409  * @ret io_addr I/O address, or NULL on error
410  */
411 void * efipci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
412  size_t len ) {
413  union {
414  union acpi_resource *res;
415  void *raw;
416  } u;
419  unsigned int tag;
421  uint64_t start;
422  uint64_t end;
423  EFI_STATUS efirc;
424  int rc;
425 
426  /* Open root bridge */
427  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
428  goto err_root;
429 
430  /* Get ACPI resource descriptors */
431  if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
432  rc = -EEFI ( efirc );
433  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
434  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
435  goto err_config;
436  }
437 
438  /* Parse resource descriptors */
439  for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
440  u.res = acpi_resource_next ( u.res ) ) {
441 
442  /* Ignore anything other than a memory range descriptor */
444  continue;
445  if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
446  continue;
447 
448  /* Ignore descriptors that do not cover this memory range */
449  offset = le64_to_cpu ( u.res->qword.offset );
450  start = ( offset + le64_to_cpu ( u.res->qword.min ) );
451  end = ( start + le64_to_cpu ( u.res->qword.len ) );
452  DBGC2 ( pci, "EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
453  "-> [%08llx,%08llx)\n", PCI_ARGS ( pci ), start, end,
454  ( start - offset ), ( end - offset ) );
455  if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
456  continue;
457 
458  /* Use this address space descriptor */
459  DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
460  PCI_ARGS ( pci ), bus_addr, len );
461  bus_addr -= offset;
462  DBGC2 ( pci, "%08lx\n", bus_addr );
463  break;
464  }
465  if ( tag == ACPI_END_RESOURCE ) {
466  DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
467  "root bridge address space\n",
468  PCI_ARGS ( pci ), bus_addr, len );
469  }
470 
471  err_config:
473  err_root:
474  return ioremap ( bus_addr, len );
475 }
476 
486 
487 /******************************************************************************
488  *
489  * EFI PCI DMA mappings
490  *
491  ******************************************************************************
492  */
493 
494 /**
495  * Map buffer for DMA
496  *
497  * @v dma DMA device
498  * @v map DMA mapping to fill in
499  * @v addr Buffer address
500  * @v len Length of buffer
501  * @v flags Mapping flags
502  * @ret rc Return status code
503  */
504 static int efipci_dma_map ( struct dma_device *dma, struct dma_mapping *map,
505  physaddr_t addr, size_t len, int flags ) {
506  struct efi_pci_device *efipci =
507  container_of ( dma, struct efi_pci_device, pci.dma );
508  struct pci_device *pci = &efipci->pci;
509  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
512  UINTN count;
513  VOID *mapping;
514  EFI_STATUS efirc;
515  int rc;
516 
517  /* Sanity check */
518  assert ( map->dma == NULL );
519  assert ( map->offset == 0 );
520  assert ( map->token == NULL );
521 
522  /* Determine operation */
523  switch ( flags ) {
524  case DMA_TX:
526  break;
527  case DMA_RX:
529  break;
530  default:
532  break;
533  }
534 
535  /* Map buffer (if non-zero length) */
536  count = len;
537  if ( len ) {
538  if ( ( efirc = pci_io->Map ( pci_io, op, phys_to_virt ( addr ),
539  &count, &bus, &mapping ) ) != 0 ) {
540  rc = -EEFI ( efirc );
541  DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %08lx+%zx: "
542  "%s\n", PCI_ARGS ( pci ), addr, len,
543  strerror ( rc ) );
544  goto err_map;
545  }
546  } else {
547  bus = addr;
548  mapping = NULL;
549  }
550 
551  /* Check that full length was mapped. The UEFI specification
552  * allows for multiple mappings to be required, but even the
553  * EDK2 PCI device drivers will fail if a platform ever
554  * requires this.
555  */
556  if ( count != len ) {
557  DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
558  "%08lx+%zx\n", PCI_ARGS ( pci ), addr, len );
559  rc = -ENOTSUP;
560  goto err_len;
561  }
562 
563  /* Populate mapping */
564  map->dma = dma;
565  map->offset = ( bus - addr );
566  map->token = mapping;
567 
568  /* Increment mapping count (for debugging) */
569  if ( DBG_LOG )
570  dma->mapped++;
571 
572  return 0;
573 
574  err_len:
575  pci_io->Unmap ( pci_io, mapping );
576  err_map:
577  return rc;
578 }
579 
580 /**
581  * Unmap buffer
582  *
583  * @v dma DMA device
584  * @v map DMA mapping
585  */
586 static void efipci_dma_unmap ( struct dma_device *dma,
587  struct dma_mapping *map ) {
588  struct efi_pci_device *efipci =
589  container_of ( dma, struct efi_pci_device, pci.dma );
590  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
591 
592  /* Unmap buffer (if non-zero length) */
593  if ( map->token )
594  pci_io->Unmap ( pci_io, map->token );
595 
596  /* Clear mapping */
597  map->dma = NULL;
598  map->offset = 0;
599  map->token = NULL;
600 
601  /* Decrement mapping count (for debugging) */
602  if ( DBG_LOG )
603  dma->mapped--;
604 }
605 
606 /**
607  * Allocate and map DMA-coherent buffer
608  *
609  * @v dma DMA device
610  * @v map DMA mapping to fill in
611  * @v len Length of buffer
612  * @v align Physical alignment
613  * @ret addr Buffer address, or NULL on error
614  */
615 static void * efipci_dma_alloc ( struct dma_device *dma,
616  struct dma_mapping *map,
617  size_t len, size_t align __unused ) {
618  struct efi_pci_device *efipci =
619  container_of ( dma, struct efi_pci_device, pci.dma );
620  struct pci_device *pci = &efipci->pci;
621  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
622  unsigned int pages;
623  VOID *addr;
624  EFI_STATUS efirc;
625  int rc;
626 
627  /* Calculate number of pages */
628  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
629 
630  /* Allocate (page-aligned) buffer */
631  if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
632  EfiBootServicesData, pages,
633  &addr, 0 ) ) != 0 ) {
634  rc = -EEFI ( efirc );
635  DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
636  "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
637  goto err_alloc;
638  }
639 
640  /* Clear buffer */
641  memset ( addr, 0, ( pages * EFI_PAGE_SIZE ) );
642 
643  /* Map buffer */
644  if ( ( rc = efipci_dma_map ( dma, map, virt_to_phys ( addr ),
645  ( pages * EFI_PAGE_SIZE ),
646  DMA_BI ) ) != 0 )
647  goto err_map;
648 
649  /* Increment allocation count (for debugging) */
650  if ( DBG_LOG )
651  dma->allocated++;
652 
653  return addr;
654 
655  efipci_dma_unmap ( dma, map );
656  err_map:
657  pci_io->FreeBuffer ( pci_io, pages, addr );
658  err_alloc:
659  return NULL;
660 }
661 
662 /**
663  * Unmap and free DMA-coherent buffer
664  *
665  * @v dma DMA device
666  * @v map DMA mapping
667  * @v addr Buffer address
668  * @v len Length of buffer
669  */
670 static void efipci_dma_free ( struct dma_device *dma, struct dma_mapping *map,
671  void *addr, size_t len ) {
672  struct efi_pci_device *efipci =
673  container_of ( dma, struct efi_pci_device, pci.dma );
674  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
675  unsigned int pages;
676 
677  /* Calculate number of pages */
678  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
679 
680  /* Unmap buffer */
681  efipci_dma_unmap ( dma, map );
682 
683  /* Free buffer */
684  pci_io->FreeBuffer ( pci_io, pages, addr );
685 
686  /* Decrement allocation count (for debugging) */
687  if ( DBG_LOG )
688  dma->allocated--;
689 }
690 
691 /**
692  * Allocate and map DMA-coherent buffer from external (user) memory
693  *
694  * @v dma DMA device
695  * @v map DMA mapping to fill in
696  * @v len Length of buffer
697  * @v align Physical alignment
698  * @ret addr Buffer address, or NULL on error
699  */
701  struct dma_mapping *map,
702  size_t len, size_t align ) {
703  void *addr;
704 
706  return virt_to_user ( addr );
707 }
708 
709 /**
710  * Unmap and free DMA-coherent buffer from external (user) memory
711  *
712  * @v dma DMA device
713  * @v map DMA mapping
714  * @v addr Buffer address
715  * @v len Length of buffer
716  */
717 static void efipci_dma_ufree ( struct dma_device *dma, struct dma_mapping *map,
718  userptr_t addr, size_t len ) {
719 
720  efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len );
721 }
722 
723 /**
724  * Set addressable space mask
725  *
726  * @v dma DMA device
727  * @v mask Addressable space mask
728  */
729 static void efipci_dma_set_mask ( struct dma_device *dma, physaddr_t mask ) {
730  struct efi_pci_device *efipci =
731  container_of ( dma, struct efi_pci_device, pci.dma );
732  struct pci_device *pci = &efipci->pci;
733  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
735  UINT64 attrs;
736  int is64;
737  EFI_STATUS efirc;
738  int rc;
739 
740  /* Set dual address cycle attribute for 64-bit capable devices */
741  is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
745  if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
746  rc = -EEFI ( efirc );
747  DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
748  PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
749  strerror ( rc ) );
750  /* Ignore failure: errors will manifest in mapping attempts */
751  return;
752  }
753 }
754 
755 /** EFI PCI DMA operations */
757  .map = efipci_dma_map,
758  .unmap = efipci_dma_unmap,
759  .alloc = efipci_dma_alloc,
760  .free = efipci_dma_free,
761  .umalloc = efipci_dma_umalloc,
762  .ufree = efipci_dma_ufree,
763  .set_mask = efipci_dma_set_mask,
764 };
765 
766 /******************************************************************************
767  *
768  * EFI PCI device instantiation
769  *
770  ******************************************************************************
771  */
772 
773 /**
774  * Open EFI PCI device
775  *
776  * @v device EFI device handle
777  * @v attributes Protocol opening attributes
778  * @v efipci EFI PCI device to fill in
779  * @ret rc Return status code
780  */
782  struct efi_pci_device *efipci ) {
784  union {
785  EFI_PCI_IO_PROTOCOL *pci_io;
786  void *interface;
787  } pci_io;
788  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
789  unsigned int busdevfn;
790  EFI_STATUS efirc;
791  int rc;
792 
793  /* See if device is a PCI device */
794  if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
795  &pci_io.interface, efi_image_handle,
796  device, attributes ) ) != 0 ) {
797  rc = -EEFI_PCI ( efirc );
798  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
799  efi_handle_name ( device ), strerror ( rc ) );
800  goto err_open_protocol;
801  }
802  efipci->io = pci_io.pci_io;
803 
804  /* Get PCI bus:dev.fn address */
805  if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
806  &pci_bus, &pci_dev,
807  &pci_fn ) ) != 0 ) {
808  rc = -EEFI ( efirc );
809  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
810  efi_handle_name ( device ), strerror ( rc ) );
811  goto err_get_location;
812  }
813  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
814  pci_init ( &efipci->pci, busdevfn );
815  dma_init ( &efipci->pci.dma, &efipci_dma_operations );
816  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
817  PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
818 
819  /* Try to enable I/O cycles, memory cycles, and bus mastering.
820  * Some platforms will 'helpfully' report errors if these bits
821  * can't be enabled (for example, if the card doesn't actually
822  * support I/O cycles). Work around any such platforms by
823  * enabling bits individually and simply ignoring any errors.
824  */
825  pci_io.pci_io->Attributes ( pci_io.pci_io,
828  pci_io.pci_io->Attributes ( pci_io.pci_io,
831  pci_io.pci_io->Attributes ( pci_io.pci_io,
834 
835  /* Populate PCI device */
836  if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
837  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
838  "configuration: %s\n",
839  PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
840  goto err_pci_read_config;
841  }
842 
843  return 0;
844 
845  err_pci_read_config:
846  err_get_location:
849  err_open_protocol:
850  return rc;
851 }
852 
853 /**
854  * Close EFI PCI device
855  *
856  * @v device EFI device handle
857  */
860 
863 }
864 
865 /**
866  * Get EFI PCI device information
867  *
868  * @v device EFI device handle
869  * @v efipci EFI PCI device to fill in
870  * @ret rc Return status code
871  */
872 int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) {
873  int rc;
874 
875  /* Open PCI device, if possible */
877  efipci ) ) != 0 )
878  return rc;
879 
880  /* Close PCI device */
881  efipci_close ( device );
882 
883  return 0;
884 }
885 
886 /******************************************************************************
887  *
888  * EFI PCI driver
889  *
890  ******************************************************************************
891  */
892 
893 /**
894  * Check to see if driver supports a device
895  *
896  * @v device EFI device handle
897  * @ret rc Return status code
898  */
900  struct efi_pci_device efipci;
901  uint8_t hdrtype;
902  int rc;
903 
904  /* Get PCI device information */
905  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
906  return rc;
907 
908  /* Do not attempt to drive bridges */
909  hdrtype = efipci.pci.hdrtype;
910  if ( ( hdrtype & PCI_HEADER_TYPE_MASK ) != PCI_HEADER_TYPE_NORMAL ) {
911  DBGC ( device, "EFIPCI " PCI_FMT " type %02x is not type %02x\n",
912  PCI_ARGS ( &efipci.pci ), hdrtype,
914  return -ENOTTY;
915  }
916 
917  /* Look for a driver */
918  if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
919  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
920  "has no driver\n", PCI_ARGS ( &efipci.pci ),
921  efipci.pci.vendor, efipci.pci.device,
922  efipci.pci.class );
923  return rc;
924  }
925  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
926  "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
927  efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
928 
929  return 0;
930 }
931 
932 /**
933  * Attach driver to device
934  *
935  * @v efidev EFI device
936  * @ret rc Return status code
937  */
938 static int efipci_start ( struct efi_device *efidev ) {
939  EFI_HANDLE device = efidev->device;
940  struct efi_pci_device *efipci;
941  int rc;
942 
943  /* Allocate PCI device */
944  efipci = zalloc ( sizeof ( *efipci ) );
945  if ( ! efipci ) {
946  rc = -ENOMEM;
947  goto err_alloc;
948  }
949 
950  /* Open PCI device */
953  efipci ) ) != 0 ) {
954  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
955  efi_handle_name ( device ), strerror ( rc ) );
957  goto err_open;
958  }
959 
960  /* Find driver */
961  if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
962  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
963  PCI_ARGS ( &efipci->pci ) );
964  goto err_find_driver;
965  }
966 
967  /* Mark PCI device as a child of the EFI device */
968  efipci->pci.dev.parent = &efidev->dev;
969  list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
970 
971  /* Probe driver */
972  if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
973  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
974  "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
975  efipci->pci.id->name, strerror ( rc ) );
976  goto err_probe;
977  }
978  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
979  PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
980 
981  efidev_set_drvdata ( efidev, efipci );
982  return 0;
983 
984  pci_remove ( &efipci->pci );
985  err_probe:
986  list_del ( &efipci->pci.dev.siblings );
987  err_find_driver:
988  efipci_close ( device );
989  err_open:
990  free ( efipci );
991  err_alloc:
992  return rc;
993 }
994 
995 /**
996  * Detach driver from device
997  *
998  * @v efidev EFI device
999  */
1000 static void efipci_stop ( struct efi_device *efidev ) {
1001  struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
1002  EFI_HANDLE device = efidev->device;
1003 
1004  pci_remove ( &efipci->pci );
1005  list_del ( &efipci->pci.dev.siblings );
1006  assert ( efipci->pci.dma.mapped == 0 );
1007  assert ( efipci->pci.dma.allocated == 0 );
1008  efipci_close ( device );
1009  free ( efipci );
1010 }
1011 
1012 /** EFI PCI driver */
1013 struct efi_driver efipci_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
1014  .name = "PCI",
1015  .supported = efipci_supported,
1016  .start = efipci_start,
1017  .stop = efipci_stop,
1018 };
int(* map)(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: dma.h:70
#define PCI_FUNC(busdevfn)
Definition: pci.h:281
static __always_inline void struct dma_mapping size_t size_t align
Definition: dma.h:222
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2085
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
#define PCI_BUS(busdevfn)
Definition: pci.h:279
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
struct dma_device dma
DMA device.
Definition: pci.h:210
static void efipci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
Definition: efi_pci.c:252
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition: efi_pci.c:872
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:292
EFI driver interface.
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:308
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
struct stp_switch root
Root switch.
Definition: stp.h:26
uint32_t class
Device class.
Definition: pci.h:227
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
Error codes.
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:284
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:270
A read operation from system memory by a bus master.
Definition: PciIo.h:83
static int efipci_start(struct efi_device *efidev)
Attach driver to device.
Definition: efi_pci.c:938
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:504
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition: dma.h:461
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:54
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition: pci.h:57
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:525
struct efi_driver efipci_driver __efi_driver(EFI_DRIVER_NORMAL)
EFI PCI driver.
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:781
#define DBGC(...)
Definition: compiler.h:505
#define DMA_BI
Device will both read data from and write data to host memory.
Definition: dma.h:138
int pci_can_probe(void)
Check if PCI bus probing is allowed.
long index
Definition: bigint.h:62
#define ENOENT
No such file or directory.
Definition: errno.h:514
unsigned int UINT32
Definition: ProcessorBind.h:98
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
unsigned long long uint64_t
Definition: stdint.h:13
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
Definition: PciIo.h:527
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
Definition: efi_pci.c:376
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1348
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:322
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:361
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:52
struct device * parent
Bus device.
Definition: device.h:85
static __always_inline void unsigned long bus_addr
Definition: pcibios.h:154
struct device dev
Generic device.
Definition: pci.h:208
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:152
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:586
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned long tmp
Definition: linux_pci.h:63
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
Definition: acpi.h:104
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
Definition: uaccess.h:373
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition: PciIo.h:60
void * efipci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
Definition: efi_pci.c:411
uint32_t userptr_t
A pointer to a user buffer.
Definition: libkir.h:159
uint16_t device
Device ID.
Definition: pci.h:225
#define PCI_HEADER_TYPE_NORMAL
Normal header.
Definition: pci.h:54
PROVIDE_PCIAPI(efi, pci_discover, efipci_discover)
static int efipci_discover_any(struct pci_device *pci, struct pci_range *range, EFI_HANDLE *handle)
Find closest bus:dev.fn address range within any root bridge.
Definition: efi_pci.c:180
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An object interface.
Definition: interface.h:124
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static void efipci_dma_ufree(struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
Definition: efi_pci.c:717
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:65
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
Definition: PciIo.h:101
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:531
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:132
uint16_t count
Number of entries.
Definition: ena.h:22
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition: PciIo.h:61
static userptr_t efipci_dma_umalloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer from external (user) memory.
Definition: efi_pci.c:700
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static void efipci_stop(struct efi_device *efidev)
Detach driver from device.
Definition: efi_pci.c:1000
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
static __always_inline void struct pci_range * range
Definition: pcidirect.h:46
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:810
#define ACPI_ADDRESS_TYPE_BUS
A bus number address space type.
Definition: acpi.h:82
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:526
uint8_t flags
Flags.
Definition: ena.h:18
uint8_t hdrtype
Header type.
Definition: pci.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
ACPI data structures.
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
physaddr_t offset
Address offset.
Definition: dma.h:39
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1917
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
#define PCI_SLOT(busdevfn)
Definition: pci.h:280
PCI bus.
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
A PCI device.
Definition: pci.h:206
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:85
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:182
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
Definition: PciIo.h:66
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:346
unsigned char uint8_t
Definition: stdint.h:10
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:32
static int efipci_supported(EFI_HANDLE device)
Check to see if driver supports a device.
Definition: efi_pci.c:899
UINT64 UINTN
Unsigned value of native width.
DMA operations.
Definition: dma.h:59
An EFI device.
Definition: efi_driver.h:17
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:117
Provides both read and write access to system memory by both the processor and a bus master.
Definition: PciIo.h:92
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
Definition: PciIo.h:59
#define VOID
Undeclared type.
Definition: Base.h:271
unsigned int uint32_t
Definition: stdint.h:12
An ACPI resource descriptor.
Definition: acpi.h:85
unsigned long long UINT64
Definition: ProcessorBind.h:96
const char * name
Name.
Definition: pci.h:172
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1936
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:79
uint16_t vendor
Vendor ID.
Definition: pci.h:223
EFI API.
PROVIDE_PCIAPI_INLINE(efi, pci_can_probe)
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:113
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:135
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
unsigned int mapped
Total number of mappings (for debugging)
Definition: dma.h:53
unsigned long physaddr_t
Definition: stdint.h:20
An EFI driver.
Definition: efi_driver.h:33
An EFI PCI device.
Definition: efi_pci.h:21
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
unsigned int allocated
Total number of allocations (for debugging)
Definition: dma.h:55
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
Definition: acpi.h:79
#define EEFI_PCI(efirc)
Definition: efi_pci.c:54
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:858
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
u32 addr
Definition: sky2.h:8
struct list_head children
Devices attached to this device.
Definition: device.h:83
PCI Root Bridge I/O protocol as defined in the UEFI 2.0 specification.
void * token
Platform mapping token.
Definition: dma.h:43
EFI driver interface.
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
struct pci_device_id * id
Driver device ID.
Definition: pci.h:243
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:288
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
static int efipci_discover_one(struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range)
Find closest bus:dev.fn address range within a root bridge.
Definition: efi_pci.c:73
Allocate any available range of pages that satisfies the request.
Definition: UefiSpec.h:35
union @17 u
const char * name
Name.
Definition: efi_driver.h:35
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define DBGCP(...)
Definition: compiler.h:539
__be32 raw[7]
Definition: CIB_PRM.h:28
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1520
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
EFI_SYSTEM_TABLE * efi_systab
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition: efi_pci.c:756
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
A write operation from system memory by a bus master.
Definition: PciIo.h:87
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition: efi_pci.c:729
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:528
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:323
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:334
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
EFI PCI I/O Protocol provides the basic Memory, I/O, PCI configuration, and DMA interfaces that a dri...
#define le64_to_cpu(value)
Definition: byteswap.h:114
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:74
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
uint64_t tag
Identity tag.
Definition: edd.h:30
struct device dev
Generic device.
Definition: efi_driver.h:19
#define DBG_LOG
Definition: compiler.h:317
A DMA mapping.
Definition: dma.h:32
uint16_t handle
Handle.
Definition: smbios.h:16
uint32_t len
Length.
Definition: ena.h:14
static void efipci_dma_free(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
Definition: efi_pci.c:670
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:324
uint8_t bus
Bus.
Definition: edd.h:14
static void * efipci_dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused)
Allocate and map DMA-coherent buffer.
Definition: efi_pci.c:615
Definition: efi.h:59
int efipci_read(struct pci_device *pci, unsigned long location, void *value)
Read from PCI configuration space.
Definition: efi_pci.c:340
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1994
A DMA-capable device.
Definition: dma.h:47
void * memset(void *dest, int character, size_t len) __nonnull
#define EFI_DRIVER_NORMAL
Normal drivers.
Definition: efi_driver.h:65
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.